webgl_materials_cars.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - materials - cube reflection [cars]</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. background:#000;
  10. color:#fff;
  11. padding:0;
  12. margin:0;
  13. overflow:hidden;
  14. font-family:georgia;
  15. text-align:center;
  16. }
  17. h1 { }
  18. a { color:skyblue; text-decoration:none }
  19. canvas { pointer-events:none; z-index:10; position:relative; }
  20. #log { position:absolute; top:50px; text-align:left; display:block; z-index:100 }
  21. #d { position:absolute; width: 100%; text-align:center; margin:1em 0 -4.5em 0; z-index:1000; }
  22. .bwrap { margin:0.5em 0 0 0 }
  23. button { font-family:georgia; border:0; background:#000; color:#fff; padding:0.2em 0.5em; cursor:pointer; border-radius:3px; }
  24. button:hover { background:#333 }
  25. #buttons_cars button { color:#fa0 }
  26. #car_info { text-align:center; }
  27. #car_name { font-size:1em }
  28. #car_author { font-size:1em }
  29. #oldie { background:rgb(50,0,0) !important; color:#fff !important; margin-top:7em!important }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="d">
  34. <div id="info">
  35. <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> webgl demo :
  36. texture by <a href="http://www.humus.name/index.php?page=Textures" target="_blank">Humus</a> :
  37. <span id="car_info">
  38. <span id="car_name">Bugatti Veyron model</span>
  39. by <span id="car_author"><a href="http://artist-3d.com/free_3d_models/dnm/model_disp.php?uid=1129" target="_blank">Troyano</a></span>
  40. </span>
  41. </div>
  42. <div id="buttons_cars" class="bwrap">
  43. <button id="veyron">Bugatti Veyron</button>
  44. <button id="gallardo">Lamborghini Gallardo</button>
  45. <button id="f50">Ferrari F50</button>
  46. <button id="camaro">Chevrolet Camaro</button>
  47. </div>
  48. <div id="buttons_materials" class="bwrap"></div>
  49. </div>
  50. <div id="log"></div>
  51. <script src="../build/Three.js"></script>
  52. <script src="js/Detector.js"></script>
  53. <script src="js/RequestAnimationFrame.js"></script>
  54. <script src="js/Stats.js"></script>
  55. <script>
  56. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  57. var STATS_ENABLED = false;
  58. var CARS = {
  59. "veyron": {
  60. name: "Bugatti Veyron",
  61. url: "obj/veyron/VeyronNoUv_bin.js",
  62. author: '<a href="http://artist-3d.com/free_3d_models/dnm/model_disp.php?uid=1129" target="_blank">Troyano</a>',
  63. init_rotation: [ 0, 0, 0 /*0.3, 1.57, 0.0*/ ],
  64. scale: 5.5,
  65. init_material: 4,
  66. body_materials: [ 2 ],
  67. object: null,
  68. buttons: null,
  69. materials: null
  70. },
  71. "gallardo": {
  72. name: "Lamborghini Gallardo",
  73. url: "obj/gallardo/GallardoNoUv_bin.js",
  74. author: '<a href="http://artist-3d.com/free_3d_models/dnm/model_disp.php?uid=1711" target="_blank">machman_3d</a>',
  75. init_rotation: [ 0, 0, 0 /*0.2, 1.77, 0.0*/ ],
  76. scale: 3.7,
  77. init_material: 9,
  78. body_materials: [ 3 ],
  79. object: null,
  80. buttons: null,
  81. materials: null
  82. },
  83. "f50": {
  84. name: "Ferrari F50",
  85. url: "obj/f50/F50NoUv_bin.js",
  86. author: '<a href="http://artist-3d.com/free_3d_models/dnm/model_disp.php?uid=1687" target="_blank">daniel sathya</a>',
  87. init_rotation: [ 0, 0, 0 /*0.2, 1.37, 0.0*/ ],
  88. scale: 0.175,
  89. init_material: 2,
  90. body_materials: [ 3, 6, 7, 8, 9, 10, 23, 24 ],
  91. object: null,
  92. buttons: null,
  93. materials: null
  94. },
  95. "camaro": {
  96. name: "Chevrolet Camaro",
  97. url: "obj/camaro/CamaroNoUv_bin.js",
  98. author: '<a href="http://www.turbosquid.com/3d-models/blender-camaro/411348" target="_blank">dskfnwn</a>',
  99. init_rotation: [ 0.0, 0.0, 0.0 /*0, 1, 0*/ ],
  100. scale: 75,
  101. init_material: 0,
  102. body_materials: [ 0 ],
  103. object: null,
  104. buttons: null,
  105. materials: null
  106. }
  107. };
  108. var container, stats;
  109. var camera, scene, webglRenderer;
  110. var cameraCube, sceneCube;
  111. var m, mi;
  112. var directionalLight, pointLight;
  113. var mouseX = 0, mouseY = 0;
  114. var windowHalfX = window.innerWidth / 2;
  115. var windowHalfY = window.innerHeight / 2;
  116. var loader = new THREE.BinaryLoader( true );
  117. document.body.appendChild( loader.statusDomElement );
  118. init();
  119. animate();
  120. function init() {
  121. container = document.createElement('div');
  122. document.body.appendChild(container);
  123. camera = new THREE.Camera( 70, window.innerWidth / window.innerHeight, 1, 100000 );
  124. // camera.position.z = 1000;
  125. camera.updateMatrix();
  126. cameraCube = new THREE.Camera( 70, window.innerWidth / window.innerHeight, 1, 100000 );
  127. scene = new THREE.Scene();
  128. sceneCube = new THREE.Scene();
  129. // LIGHTS
  130. var ambient = new THREE.AmbientLight( 0x555555 );
  131. scene.add( ambient );
  132. directionalLight = new THREE.DirectionalLight( 0xffffff, 2 );
  133. directionalLight.position.x = 2;
  134. directionalLight.position.y = 1.2;
  135. directionalLight.position.z = 10;
  136. directionalLight.position.normalize();
  137. scene.add( directionalLight );
  138. directionalLight = new THREE.DirectionalLight( 0xffffff, 1 );
  139. directionalLight.position.x = - 2;
  140. directionalLight.position.y = 1.2;
  141. directionalLight.position.z = - 10;
  142. directionalLight.position.normalize();
  143. scene.add( directionalLight );
  144. pointLight = new THREE.PointLight( 0xffaa00, 2 );
  145. pointLight.position.x = 2000;
  146. pointLight.position.y = 1200;
  147. pointLight.position.z = 10000;
  148. scene.add( pointLight );
  149. // Skybox
  150. var shader = THREE.ShaderUtils.lib[ "cube" ];
  151. shader.uniforms[ "tCube" ].texture = textureCube;
  152. var material = new THREE.ShaderMaterial( {
  153. fragmentShader: shader.fragmentShader,
  154. vertexShader: shader.vertexShader,
  155. uniforms: shader.uniforms,
  156. depthWrite: false
  157. } ),
  158. mesh = new THREE.Mesh( new THREE.CubeGeometry( 100, 100, 100, 1, 1, 1, null, true ), material );
  159. sceneCube.add( mesh );
  160. //
  161. webglRenderer = new THREE.WebGLRenderer();
  162. webglRenderer.setSize( window.innerWidth, window.innerHeight );
  163. webglRenderer.setFaceCulling( 0 );
  164. webglRenderer.autoClear = false;
  165. container.appendChild( webglRenderer.domElement );
  166. if ( STATS_ENABLED ) {
  167. stats = new Stats();
  168. stats.domElement.style.position = 'absolute';
  169. stats.domElement.style.top = '0px';
  170. stats.domElement.style.zIndex = 100;
  171. container.appendChild( stats.domElement );
  172. }
  173. document.addEventListener('mousemove', onDocumentMouseMove, false);
  174. var r = "textures/cube/Bridge2/";
  175. var urls = [ r + "posx.jpg", r + "negx.jpg",
  176. r + "posy.jpg", r + "negy.jpg",
  177. r + "posz.jpg", r + "negz.jpg" ];
  178. var textureCube = THREE.ImageUtils.loadTextureCube( urls );
  179. // common materials
  180. var mlib = {
  181. "Orange": new THREE.MeshLambertMaterial( { color: 0xff6600, envMap: textureCube, combine: THREE.MixOperation, reflectivity: 0.3 } ),
  182. "Blue": new THREE.MeshLambertMaterial( { color: 0x001133, envMap: textureCube, combine: THREE.MixOperation, reflectivity: 0.3 } ),
  183. "Red": new THREE.MeshLambertMaterial( { color: 0x660000, envMap: textureCube, combine: THREE.MixOperation, reflectivity: 0.25 } ),
  184. "Black": new THREE.MeshLambertMaterial( { color: 0x000000, envMap: textureCube, combine: THREE.MixOperation, reflectivity: 0.15 } ),
  185. "White": new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: textureCube, combine: THREE.MixOperation, reflectivity: 0.25 } ),
  186. "Carmine": new THREE.MeshPhongMaterial( { color: 0x770000, specular:0xffaaaa, envMap: textureCube, combine: THREE.MultiplyOperation } ),
  187. "Gold": new THREE.MeshPhongMaterial( { color: 0xaa9944, specular:0xbbaa99, shininess:50, envMap: textureCube, combine: THREE.MultiplyOperation } ),
  188. "Bronze": new THREE.MeshPhongMaterial( { color: 0x150505, specular:0xee6600, shininess:10, envMap: textureCube, combine: THREE.MixOperation, reflectivity: 0.25 } ),
  189. "Chrome": new THREE.MeshPhongMaterial( { color: 0xffffff, specular:0xffffff, envMap: textureCube, combine: THREE.Multiply } ),
  190. "Orange metal": new THREE.MeshLambertMaterial( { color: 0xff6600, envMap: textureCube, combine: THREE.MultiplyOperation } ),
  191. "Blue metal": new THREE.MeshLambertMaterial( { color: 0x001133, envMap: textureCube, combine: THREE.MultiplyOperation } ),
  192. "Red metal": new THREE.MeshLambertMaterial( { color: 0x770000, envMap: textureCube, combine: THREE.MultiplyOperation } ),
  193. "Green metal": new THREE.MeshLambertMaterial( { color: 0x007711, envMap: textureCube, combine: THREE.MultiplyOperation } ),
  194. "Black metal": new THREE.MeshLambertMaterial( { color: 0x222222, envMap: textureCube, combine: THREE.MultiplyOperation } ),
  195. "Pure chrome": new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: textureCube } ),
  196. "Dark chrome": new THREE.MeshLambertMaterial( { color: 0x444444, envMap: textureCube } ),
  197. "Darker chrome":new THREE.MeshLambertMaterial( { color: 0x222222, envMap: textureCube } ),
  198. "Black glass": new THREE.MeshLambertMaterial( { color: 0x101016, envMap: textureCube, opacity: 0.975, transparent: true } ),
  199. "Dark glass": new THREE.MeshLambertMaterial( { color: 0x101046, envMap: textureCube, opacity: 0.25, transparent: true } ),
  200. "Blue glass": new THREE.MeshLambertMaterial( { color: 0x668899, envMap: textureCube, opacity: 0.75, transparent: true } ),
  201. "Light glass": new THREE.MeshBasicMaterial( { color: 0x223344, envMap: textureCube, opacity: 0.25, transparent: true, combine: THREE.MixOperation, reflectivity: 0.25 } ),
  202. "Red glass": new THREE.MeshLambertMaterial( { color: 0xff0000, opacity: 0.75, transparent: true } ),
  203. "Yellow glass": new THREE.MeshLambertMaterial( { color: 0xffffaa, opacity: 0.75, transparent: true } ),
  204. "Orange glass": new THREE.MeshLambertMaterial( { color: 0x995500, opacity: 0.75, transparent: true } ),
  205. "Orange glass 50": new THREE.MeshLambertMaterial( { color: 0xffbb00, opacity: 0.5, transparent: true } ),
  206. "Red glass 50": new THREE.MeshLambertMaterial( { color: 0xff0000, opacity: 0.5, transparent: true } ),
  207. "Fullblack rough": new THREE.MeshLambertMaterial( { color: 0x000000 } ),
  208. "Black rough": new THREE.MeshLambertMaterial( { color: 0x050505 } ),
  209. "Darkgray rough": new THREE.MeshLambertMaterial( { color: 0x090909 } ),
  210. "Red rough": new THREE.MeshLambertMaterial( { color: 0x330500 } ),
  211. "Darkgray shiny": new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0x050505 } ),
  212. "Gray shiny": new THREE.MeshPhongMaterial( { color: 0x050505, shininess: 20 } )
  213. }
  214. // Gallardo materials
  215. CARS[ "gallardo" ].materials = {
  216. body: [
  217. [ "Orange", mlib[ "Orange" ] ],
  218. [ "Blue", mlib[ "Blue" ] ],
  219. [ "Red", mlib[ "Red" ] ],
  220. [ "Black", mlib[ "Black" ] ],
  221. [ "White", mlib[ "White" ] ],
  222. [ "Orange metal", mlib[ "Orange metal" ] ],
  223. [ "Blue metal", mlib[ "Blue metal" ] ],
  224. [ "Green metal", mlib[ "Green metal" ] ],
  225. [ "Black metal", mlib[ "Black metal" ] ],
  226. [ "Carmine", mlib[ "Carmine" ] ],
  227. [ "Gold", mlib[ "Gold" ] ],
  228. [ "Bronze", mlib[ "Bronze" ] ],
  229. [ "Chrome", mlib[ "Chrome" ] ]
  230. ]
  231. }
  232. m = CARS[ "gallardo" ].materials;
  233. mi = CARS[ "gallardo" ].init_material;
  234. CARS[ "gallardo" ].mmap = {
  235. 0: mlib[ "Pure chrome" ], // wheels chrome
  236. 1: mlib[ "Black rough" ], // tire
  237. 2: mlib[ "Black glass" ], // windshield
  238. 3: m.body[ mi ][ 1 ], // body
  239. 4: mlib[ "Red glass" ], // back lights
  240. 5: mlib[ "Yellow glass" ], // front lights
  241. 6: mlib[ "Dark chrome" ] // windshield rim
  242. }
  243. // Veyron materials
  244. CARS[ "veyron" ].materials = {
  245. body: [
  246. [ "Orange metal", mlib[ "Orange metal" ] ],
  247. [ "Blue metal", mlib[ "Blue metal" ] ],
  248. [ "Red metal", mlib[ "Red metal" ] ],
  249. [ "Green metal", mlib[ "Green metal" ] ],
  250. [ "Black metal", mlib[ "Black metal" ] ],
  251. [ "Gold", mlib[ "Gold" ] ],
  252. [ "Bronze", mlib[ "Bronze" ] ],
  253. [ "Chrome", mlib[ "Chrome" ] ]
  254. ],
  255. }
  256. m = CARS[ "veyron" ].materials;
  257. mi = CARS[ "veyron" ].init_material;
  258. CARS[ "veyron" ].mmap = {
  259. 0: mlib[ "Black rough" ], // tires + inside
  260. 1: mlib[ "Pure chrome" ], // wheels + extras chrome
  261. 2: m.body[ mi ][ 1 ], // back / top / front torso
  262. 3: mlib[ "Dark glass" ], // glass
  263. 4: mlib[ "Pure chrome" ], // sides torso
  264. 5: mlib[ "Pure chrome" ], // engine
  265. 6: mlib[ "Red glass 50" ], // backlights
  266. 7: mlib[ "Orange glass 50" ] // backsignals
  267. }
  268. // F50 materials
  269. CARS[ "f50" ].materials = {
  270. body: [
  271. [ "Orange", mlib[ "Orange" ] ],
  272. [ "Blue", mlib[ "Blue" ] ],
  273. [ "Red", mlib[ "Red" ] ],
  274. [ "Black", mlib[ "Black" ] ],
  275. [ "White", mlib[ "White" ] ],
  276. [ "Orange metal", mlib[ "Orange metal" ] ],
  277. [ "Blue metal", mlib[ "Blue metal" ] ],
  278. [ "Black metal", mlib[ "Black metal" ] ],
  279. [ "Carmine", mlib[ "Carmine" ] ],
  280. [ "Gold", mlib[ "Gold" ] ],
  281. [ "Bronze", mlib[ "Bronze" ] ],
  282. [ "Chrome", mlib[ "Chrome" ] ]
  283. ],
  284. }
  285. m = CARS[ "f50" ].materials;
  286. mi = CARS[ "f50" ].init_material;
  287. CARS[ "f50" ].mmap = {
  288. 0: mlib[ "Dark chrome" ], // interior + rim
  289. 1: mlib[ "Pure chrome" ], // wheels + gears chrome
  290. 2: mlib[ "Blue glass" ], // glass
  291. 3: m.body[ mi ][ 1 ], // torso mid + front spoiler
  292. 4: mlib[ "Darkgray shiny" ], // interior + behind seats
  293. 5: mlib[ "Darkgray shiny" ], // tiny dots in interior
  294. 6: m.body[ mi ][ 1 ], // back torso
  295. 7: m.body[ mi ][ 1 ], // right mirror decal
  296. 8: m.body[ mi ][ 1 ], // front decal
  297. 9: m.body[ mi ][ 1 ], // front torso
  298. 10: m.body[ mi ][ 1 ], // left mirror decal
  299. 11: mlib[ "Pure chrome" ], // engine
  300. 12: mlib[ "Darkgray rough" ], // tires side
  301. 13: mlib[ "Darkgray rough" ], // tires bottom
  302. 14: mlib[ "Darkgray shiny" ], // bottom
  303. 15: mlib[ "Black rough" ], // ???
  304. 16: mlib[ "Orange glass" ], // front signals
  305. 17: mlib[ "Dark chrome" ], // wheels center
  306. 18: mlib[ "Red glass" ], // back lights
  307. 19: mlib[ "Black rough" ], // ???
  308. 20: mlib[ "Red rough" ], // seats
  309. 21: mlib[ "Black rough" ], // back plate
  310. 22: mlib[ "Black rough" ], // front light dots
  311. 23: m.body[ mi ][ 1 ], // back torso
  312. 24: m.body[ mi ][ 1 ] // back torso center
  313. }
  314. // Camero materials
  315. CARS[ "camaro" ].materials = {
  316. body: [
  317. [ "Orange", mlib[ "Orange" ] ],
  318. [ "Blue", mlib[ "Blue" ] ],
  319. [ "Red", mlib[ "Red" ] ],
  320. [ "Black", mlib[ "Black" ] ],
  321. [ "White", mlib[ "White" ] ],
  322. [ "Orange metal", mlib[ "Orange metal" ] ],
  323. [ "Blue metal", mlib[ "Blue metal" ] ],
  324. [ "Red metal", mlib[ "Red metal" ] ],
  325. [ "Green metal", mlib[ "Green metal" ] ],
  326. [ "Black metal", mlib[ "Black metal" ] ],
  327. [ "Gold", mlib[ "Gold" ] ],
  328. [ "Bronze", mlib[ "Bronze" ] ],
  329. [ "Chrome", mlib[ "Chrome" ] ]
  330. ],
  331. }
  332. m = CARS[ "camaro" ].materials;
  333. mi = CARS[ "camaro" ].init_material;
  334. CARS[ "camaro" ].mmap = {
  335. 0: m.body[ mi ][ 1 ], // car body
  336. 1: mlib[ "Pure chrome" ], // wheels chrome
  337. 2: mlib[ "Pure chrome" ], // grille chrome
  338. 3: mlib[ "Dark chrome" ], // door lines
  339. 4: mlib[ "Light glass" ], // windshield
  340. 5: mlib[ "Gray shiny" ], // interior
  341. 6: mlib[ "Black rough" ], // tire
  342. 7: mlib[ "Fullblack rough" ], // tireling
  343. 8: mlib[ "Fullblack rough" ] // behind grille
  344. }
  345. loader.load( { model: CARS[ "veyron" ].url, callback: function( geometry ) { createScene( geometry, "veyron" ) } } );
  346. for( var c in CARS ) initCarButton( c );
  347. }
  348. function initCarButton( car ) {
  349. $( car ).addEventListener( 'click', function() {
  350. if ( ! CARS[ car ].object ) {
  351. loader.statusDomElement.style.display = "block";
  352. loader.load( { model: CARS[ car ].url, callback: function( geometry ) { createScene( geometry, car ) } } );
  353. } else {
  354. switchCar( car );
  355. }
  356. }, false);
  357. }
  358. function $( id ) { return document.getElementById( id ) }
  359. function button_name( car, index ) { return "m_" + car + "_" + index }
  360. function switchCar( car ) {
  361. for ( var c in CARS ) {
  362. if ( c != car && CARS[ c ].object ) {
  363. CARS[ c ].object.visible = false;
  364. CARS[ c ].buttons.style.display = "none";
  365. }
  366. }
  367. CARS[ car ].object.visible = true;
  368. CARS[ car ].buttons.style.display = "block";
  369. $( "car_name" ).innerHTML = CARS[ car ].name + " model";
  370. $( "car_author" ).innerHTML = CARS[ car ].author;
  371. }
  372. function createButtons( materials, car ) {
  373. var buttons, i, src = "";
  374. for( i = 0; i < materials.length; i++ ) {
  375. src += '<button id="' + button_name( car, i ) + '">' + materials[ i ][ 0 ] + '</button> ';
  376. }
  377. buttons = document.createElement("div");
  378. buttons.innerHTML = src;
  379. $( "buttons_materials" ).appendChild( buttons );
  380. return buttons;
  381. }
  382. function attachButtonMaterials( materials, geometry, material_indices, car ) {
  383. for( var i = 0; i < materials.length; i++ ) {
  384. $( button_name( car, i ) ).counter = i;
  385. $( button_name( car, i ) ).addEventListener( 'click', function() {
  386. for ( var j = 0; j < material_indices.length; j++ ) {
  387. geometry.materials[ material_indices [ j ] ][ 0 ] = materials[ this.counter ][ 1 ];
  388. }
  389. }, false );
  390. }
  391. }
  392. function createScene( geometry, car ) {
  393. loader.statusDomElement.innerHTML = "Creating model ...";
  394. var m = new THREE.MeshFaceMaterial(),
  395. s = CARS[ car ].scale * 1,
  396. r = CARS[ car ].init_rotation,
  397. materials = CARS[ car ].materials,
  398. mi = CARS[ car ].init_material,
  399. bm = CARS[ car ].body_materials;
  400. for ( var i in CARS[ car ].mmap ) {
  401. geometry.materials[ i ][ 0 ] = CARS[ car ].mmap[ i ];
  402. }
  403. var mesh = new THREE.Mesh( geometry, m );
  404. mesh.rotation.x = r[ 0 ];
  405. mesh.rotation.y = r[ 1 ];
  406. mesh.rotation.z = r[ 2 ];
  407. mesh.scale.x = mesh.scale.y = mesh.scale.z = s;
  408. scene.add( mesh );
  409. CARS[ car ].object = mesh;
  410. CARS[ car ].buttons = createButtons( materials.body, car );
  411. attachButtonMaterials( materials.body, geometry, bm, car );
  412. switchCar( car );
  413. loader.statusDomElement.style.display = "none";
  414. loader.statusDomElement.innerHTML = "Loading model ...";
  415. }
  416. function onDocumentMouseMove(event) {
  417. mouseY = ( event.clientY - window.innerHeight );
  418. }
  419. //
  420. function animate() {
  421. requestAnimationFrame( animate );
  422. render();
  423. }
  424. function render() {
  425. var timer = - new Date().getTime() * 0.0002;
  426. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  427. camera.position.x = 1000 * Math.cos( timer );
  428. camera.position.z = 1000 * Math.sin( timer );
  429. cameraCube.target.position.x = - camera.position.x;
  430. cameraCube.target.position.y = - camera.position.y;
  431. cameraCube.target.position.z = - camera.position.z;
  432. webglRenderer.clear();
  433. webglRenderer.render( sceneCube, cameraCube );
  434. webglRenderer.render( scene, camera );
  435. if ( STATS_ENABLED ) stats.update();
  436. }
  437. function log( text ) {
  438. var e = document.getElementById("log");
  439. e.innerHTML = text + "<br/>" + e.innerHTML;
  440. }
  441. </script>
  442. </body>
  443. </html>