| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <!DOCTYPE HTML>
- <html lang="en">
- <head>
- <title>three.js - scene loader test</title>
- <meta charset="utf-8">
- <style type="text/css">
- body {
- background:#000;
- color:#fff;
- padding:0;
- margin:0;
- overflow:hidden;
- font-family:georgia;
- text-align:center;
- }
-
- #info {
- position: absolute;
- top: 0px; width: 100%;
- padding: 5px;
- font-family: Monospace;
- font-size: 13px;
- text-align: center;
- z-index:100;
- }
-
- #progress {
- color:red;
- top:7em;
- width: 100%;
- font-size:3em;
- font-variant:small-caps;
- font-weight:bold;
- position:absolute;
- z-index:100;
- text-align: center;
- text-shadow: #000 0px 0px 10px;
- display:none;
- }
-
- #start {
- color:#fff;
- text-shadow: #000 0px 0px 2px;
- padding:0.1em 0.3em;
- width:3em;
- text-align: center;
- /*
- font-size:0.8em;
- -moz-box-shadow: 0px 0px 5px #000;
- -webkit-box-shadow: 0px 0px 5px #000;
- box-shadow: 0px 0px 5px #000;
- */
- display:none;
- }
-
- .enabled {
- color: lime!important;
- cursor:pointer;
- }
-
- .enabled:hover {
- text-shadow: #0f0 0px 0px 5px !important;
- }
-
- .disabled {
- background:gray;
- cursor:default;
- }
-
- a { color:red }
- canvas { pointer-events:none; z-index:10; }
- #log { position:absolute; top:0; display:block; text-align:left; z-index:1000; pointer-events:none; }
- </style>
- </head>
- <body>
- <div id="info">
- <a href="http://github.com/mrdoob/three.js">three.js</a> - scene loader test
- </div>
- <div id="progress">
- <span id="message">Loading ...</span>
- <center><div id="start" class="disabled">Start</div></center>
- </div>
-
- <pre id="log"></pre>
- <script type="text/javascript" src="../build/ThreeExtras.js"></script>
- <script type="text/javascript" src="js/Stats.js"></script>
- <script type="text/javascript">
- var SCREEN_WIDTH = window.innerWidth;
- var SCREEN_HEIGHT = window.innerHeight;
- var container,stats;
- var camera, scene, loaded;
- var renderer;
- var mesh, zmesh, geometry;
- var mouseX = 0, mouseY = 0;
- var windowHalfX = window.innerWidth / 2;
- var windowHalfY = window.innerHeight / 2;
- document.addEventListener( 'mousemove', onDocumentMouseMove, false );
- init();
- function $( id ) {
-
- return document.getElementById( id );
-
- }
-
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- var loadScene = createLoadScene();
- scene = loadScene.scene;
- camera = loadScene.camera;
-
- renderer = new THREE.WebGLRenderer();
- renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
- renderer.domElement.style.position = "relative";
- container.appendChild( renderer.domElement );
- $( "start" ).addEventListener( 'click', onStartClick, false );
- setInterval( loop, 1000/60 );
- var callback_sync = function( result ) {
-
- /*
- scene = result.scene;
- camera = result.currentCamera;
-
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
-
- renderer.setClearColor( result.bgColor.hex, result.bgAlpha );
-
- */
- }
-
- var callback_async = function( result ) {
-
- loaded = result;
-
- var mat_veyron = result.geometries[ "veyron" ].materials;
-
- mat_veyron[ 0 ][ 0 ] = result.materials[ "interior" ];
- mat_veyron[ 1 ][ 0 ] = result.materials[ "chrome" ];
- mat_veyron[ 2 ][ 0 ] = result.materials[ "darkerchrome" ];
- mat_veyron[ 3 ][ 0 ] = result.materials[ "glass" ];
- mat_veyron[ 4 ][ 0 ] = result.materials[ "chrome" ];
- mat_veyron[ 5 ][ 0 ] = result.materials[ "chrome" ];
-
- $( "message" ).style.display = "none";
- $( "start" ).style.display = "block";
- $( "start" ).className = "enabled";
-
- }
-
- $( "progress" ).style.display = "block";
- SceneUtils.loadScene( "scenes/test_scene.js", callback_sync, callback_async );
- stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.top = '0px';
- stats.domElement.style.zIndex = 100;
- container.appendChild( stats.domElement );
- }
- function setButtonActive( id ) {
-
- $( "start" ).style.backgroundColor = "green";
-
- }
-
- function onStartClick() {
-
- $( "progress" ).style.display = "none";
-
- scene = loaded.scene;
- camera = loaded.currentCamera;
-
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
-
- renderer.setClearColor( loaded.bgColor.hex, loaded.bgAlpha );
-
- }
-
- function onDocumentMouseMove(event) {
- mouseX = ( event.clientX - windowHalfX );
- mouseY = ( event.clientY - windowHalfY );
- }
- function createLoadScene() {
-
- var result = {
-
- scene: new THREE.Scene(),
- camera: new THREE.Camera( 65, window.innerWidth / window.innerHeight, 1, 1000 )
-
- };
-
- result.camera.position.z = 100;
-
- var object, geometry, material, light, count = 100, range = 150;
-
- material = new THREE.MeshLambertMaterial( { color:0xffffff } );
- geometry = new Cube( 5, 5, 5 );
-
- for( var i = 0; i < count; i++ ) {
-
- object = new THREE.Mesh( geometry, material );
- object.position.x = ( Math.random() - 0.5 ) * range;
- object.position.y = ( Math.random() - 0.5 ) * range;
- object.position.z = ( Math.random() - 0.5 ) * range;
- object.rotation.x = Math.random() * 6;
- object.rotation.y = Math.random() * 6;
- object.rotation.z = Math.random() * 6;
- result.scene.addObject( object );
-
- }
-
- light = new THREE.PointLight( 0xffffff );
- result.scene.addLight( light );
- light = new THREE.DirectionalLight( 0x111111 );
- light.position.x = 1;
- result.scene.addLight( light );
- return result;
-
- }
-
- function loop() {
- camera.position.x += ( mouseX - camera.position.x ) * .001;
- camera.position.y += ( - mouseY - camera.position.y ) * .001;
- renderer.render( scene, camera );
- stats.update();
- }
- function log( text ) {
- var e = $("log");
- e.innerHTML = text + "<br/>" + e.innerHTML;
- }
- </script>
- </body>
- </html>
|