mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-21 02:45:59 +10:00
298 lines
6.8 KiB
HTML
298 lines
6.8 KiB
HTML
<!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;
|
|
display:none;
|
|
}
|
|
|
|
.shadow {
|
|
-moz-box-shadow: 0px 0px 5px #000;
|
|
-webkit-box-shadow: 0px 0px 5px #000;
|
|
box-shadow: 0px 0px 5px #000;
|
|
}
|
|
|
|
#progressbar {
|
|
text-align: center;
|
|
background: white;
|
|
width: 250px;
|
|
height: 10px;
|
|
}
|
|
|
|
#bar {
|
|
background:#d00;
|
|
width:50px;
|
|
height:10px;
|
|
}
|
|
|
|
.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="progressbar" class="shadow"><div id="bar" class="shadow"></div></div>
|
|
<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_progress = function( progress ) {
|
|
|
|
var bar = 250;
|
|
if ( progress.total_models + progress.total_textures )
|
|
bar = Math.floor( 250 * ( progress.loaded_models + progress.loaded_textures ) / ( progress.total_models + progress.total_textures ) );
|
|
|
|
$( "bar" ).style.width = bar + "px";
|
|
|
|
}
|
|
|
|
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";
|
|
$( "progressbar" ).style.display = "none";
|
|
$( "start" ).style.display = "block";
|
|
$( "start" ).className = "enabled";
|
|
|
|
}
|
|
|
|
$( "progress" ).style.display = "block";
|
|
SceneUtils.loadScene( "scenes/test_scene.js", callback_sync, callback_async, callback_progress );
|
|
|
|
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>
|