scene_test.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - scene loader test</title>
  5. <meta charset="utf-8">
  6. <style type="text/css">
  7. body {
  8. background:#000;
  9. color:#fff;
  10. padding:0;
  11. margin:0;
  12. overflow:hidden;
  13. font-family:georgia;
  14. text-align:center;
  15. }
  16. #info {
  17. position: absolute;
  18. top: 0px; width: 100%;
  19. padding: 5px;
  20. font-family: Monospace;
  21. font-size: 13px;
  22. text-align: center;
  23. z-index:100;
  24. }
  25. #progress {
  26. color:red;
  27. top:7em;
  28. width: 100%;
  29. font-size:3em;
  30. font-variant:small-caps;
  31. font-weight:bold;
  32. position:absolute;
  33. z-index:100;
  34. text-align: center;
  35. text-shadow: #000 0px 0px 10px;
  36. display:none;
  37. }
  38. #start {
  39. color:#fff;
  40. text-shadow: #000 0px 0px 2px;
  41. padding:0.1em 0.3em;
  42. width:3em;
  43. text-align: center;
  44. /*
  45. font-size:0.8em;
  46. -moz-box-shadow: 0px 0px 5px #000;
  47. -webkit-box-shadow: 0px 0px 5px #000;
  48. box-shadow: 0px 0px 5px #000;
  49. */
  50. display:none;
  51. }
  52. .enabled {
  53. color: lime!important;
  54. cursor:pointer;
  55. }
  56. .enabled:hover {
  57. text-shadow: #0f0 0px 0px 5px !important;
  58. }
  59. .disabled {
  60. background:gray;
  61. cursor:default;
  62. }
  63. a { color:red }
  64. canvas { pointer-events:none; z-index:10; }
  65. #log { position:absolute; top:0; display:block; text-align:left; z-index:1000; pointer-events:none; }
  66. </style>
  67. </head>
  68. <body>
  69. <div id="info">
  70. <a href="http://github.com/mrdoob/three.js">three.js</a> - scene loader test
  71. </div>
  72. <div id="progress">
  73. <span id="message">Loading ...</span>
  74. <center><div id="start" class="disabled">Start</div></center>
  75. </div>
  76. <pre id="log"></pre>
  77. <script type="text/javascript" src="../build/ThreeExtras.js"></script>
  78. <script type="text/javascript" src="js/Stats.js"></script>
  79. <script type="text/javascript">
  80. var SCREEN_WIDTH = window.innerWidth;
  81. var SCREEN_HEIGHT = window.innerHeight;
  82. var container,stats;
  83. var camera, scene, loaded;
  84. var renderer;
  85. var mesh, zmesh, geometry;
  86. var mouseX = 0, mouseY = 0;
  87. var windowHalfX = window.innerWidth / 2;
  88. var windowHalfY = window.innerHeight / 2;
  89. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  90. init();
  91. function $( id ) {
  92. return document.getElementById( id );
  93. }
  94. function init() {
  95. container = document.createElement( 'div' );
  96. document.body.appendChild( container );
  97. var loadScene = createLoadScene();
  98. scene = loadScene.scene;
  99. camera = loadScene.camera;
  100. renderer = new THREE.WebGLRenderer();
  101. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  102. renderer.domElement.style.position = "relative";
  103. container.appendChild( renderer.domElement );
  104. $( "start" ).addEventListener( 'click', onStartClick, false );
  105. setInterval( loop, 1000/60 );
  106. var callback_sync = function( result ) {
  107. /*
  108. scene = result.scene;
  109. camera = result.currentCamera;
  110. camera.aspect = window.innerWidth / window.innerHeight;
  111. camera.updateProjectionMatrix();
  112. renderer.setClearColor( result.bgColor.hex, result.bgAlpha );
  113. */
  114. }
  115. var callback_async = function( result ) {
  116. loaded = result;
  117. var mat_veyron = result.geometries[ "veyron" ].materials;
  118. mat_veyron[ 0 ][ 0 ] = result.materials[ "interior" ];
  119. mat_veyron[ 1 ][ 0 ] = result.materials[ "chrome" ];
  120. mat_veyron[ 2 ][ 0 ] = result.materials[ "darkerchrome" ];
  121. mat_veyron[ 3 ][ 0 ] = result.materials[ "glass" ];
  122. mat_veyron[ 4 ][ 0 ] = result.materials[ "chrome" ];
  123. mat_veyron[ 5 ][ 0 ] = result.materials[ "chrome" ];
  124. $( "message" ).style.display = "none";
  125. $( "start" ).style.display = "block";
  126. $( "start" ).className = "enabled";
  127. }
  128. $( "progress" ).style.display = "block";
  129. SceneUtils.loadScene( "scenes/test_scene.js", callback_sync, callback_async );
  130. stats = new Stats();
  131. stats.domElement.style.position = 'absolute';
  132. stats.domElement.style.top = '0px';
  133. stats.domElement.style.zIndex = 100;
  134. container.appendChild( stats.domElement );
  135. }
  136. function setButtonActive( id ) {
  137. $( "start" ).style.backgroundColor = "green";
  138. }
  139. function onStartClick() {
  140. $( "progress" ).style.display = "none";
  141. scene = loaded.scene;
  142. camera = loaded.currentCamera;
  143. camera.aspect = window.innerWidth / window.innerHeight;
  144. camera.updateProjectionMatrix();
  145. renderer.setClearColor( loaded.bgColor.hex, loaded.bgAlpha );
  146. }
  147. function onDocumentMouseMove(event) {
  148. mouseX = ( event.clientX - windowHalfX );
  149. mouseY = ( event.clientY - windowHalfY );
  150. }
  151. function createLoadScene() {
  152. var result = {
  153. scene: new THREE.Scene(),
  154. camera: new THREE.Camera( 65, window.innerWidth / window.innerHeight, 1, 1000 )
  155. };
  156. result.camera.position.z = 100;
  157. var object, geometry, material, light, count = 100, range = 150;
  158. material = new THREE.MeshLambertMaterial( { color:0xffffff } );
  159. geometry = new Cube( 5, 5, 5 );
  160. for( var i = 0; i < count; i++ ) {
  161. object = new THREE.Mesh( geometry, material );
  162. object.position.x = ( Math.random() - 0.5 ) * range;
  163. object.position.y = ( Math.random() - 0.5 ) * range;
  164. object.position.z = ( Math.random() - 0.5 ) * range;
  165. object.rotation.x = Math.random() * 6;
  166. object.rotation.y = Math.random() * 6;
  167. object.rotation.z = Math.random() * 6;
  168. result.scene.addObject( object );
  169. }
  170. light = new THREE.PointLight( 0xffffff );
  171. result.scene.addLight( light );
  172. light = new THREE.DirectionalLight( 0x111111 );
  173. light.position.x = 1;
  174. result.scene.addLight( light );
  175. return result;
  176. }
  177. function loop() {
  178. camera.position.x += ( mouseX - camera.position.x ) * .001;
  179. camera.position.y += ( - mouseY - camera.position.y ) * .001;
  180. renderer.render( scene, camera );
  181. stats.update();
  182. }
  183. function log( text ) {
  184. var e = $("log");
  185. e.innerHTML = text + "<br/>" + e.innerHTML;
  186. }
  187. </script>
  188. </body>
  189. </html>
粤ICP备19079148号