webgl_materials_cars.html 19 KB

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