mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-24 12:03:48 +01:00
380 lines
8.3 KiB
HTML
Executable File
380 lines
8.3 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js webgl - io - scene loader</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
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;
|
|
}
|
|
|
|
.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; }
|
|
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="info">
|
|
<a href="http://threejs.org">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>
|
|
</center>
|
|
</div>
|
|
|
|
<script src="../build/three.min.js"></script>
|
|
|
|
<script src="js/loaders/DDSLoader.js"></script>
|
|
|
|
<script src="js/loaders/ctm/lzma.js"></script>
|
|
<script src="js/loaders/ctm/ctm.js"></script>
|
|
<script src="js/loaders/ctm/CTMLoader.js"></script>
|
|
|
|
<script src="js/loaders/deprecated/SceneLoader.js"></script>
|
|
<script src="js/loaders/BinaryLoader.js"></script>
|
|
<script src="js/loaders/OBJLoader.js"></script>
|
|
<script src="js/loaders/VTKLoader.js"></script>
|
|
<script src="js/loaders/STLLoader.js"></script>
|
|
<script src="js/loaders/ColladaLoader.js"></script>
|
|
<script src="js/loaders/UTF8Loader.js"></script>
|
|
<script src="js/loaders/MTLLoader.js"></script>
|
|
|
|
<script src="js/Detector.js"></script>
|
|
<script src="js/libs/stats.min.js"></script>
|
|
|
|
<script>
|
|
|
|
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
|
|
|
|
var SCREEN_WIDTH = window.innerWidth;
|
|
var SCREEN_HEIGHT = window.innerHeight;
|
|
|
|
var container,stats;
|
|
|
|
var camera, scene, loaded;
|
|
var renderer;
|
|
|
|
var mouseX = 0, mouseY = 0;
|
|
|
|
var windowHalfX = window.innerWidth / 2;
|
|
var windowHalfY = window.innerHeight / 2;
|
|
|
|
var rotatingObjects = [];
|
|
var morphAnimatedObjects = [];
|
|
|
|
var clock = new THREE.Clock();
|
|
|
|
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
|
THREE.DefaultLoadingManager.onProgress = function ( item, loaded, total ) {
|
|
|
|
console.log( item, loaded, total );
|
|
|
|
};
|
|
|
|
init();
|
|
animate();
|
|
|
|
function $( id ) {
|
|
|
|
return document.getElementById( id );
|
|
|
|
}
|
|
|
|
function init() {
|
|
|
|
container = document.createElement( 'div' );
|
|
document.body.appendChild( container );
|
|
|
|
var loadScene = createLoadScene();
|
|
|
|
camera = loadScene.camera;
|
|
scene = loadScene.scene;
|
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
renderer.domElement.style.position = "relative";
|
|
container.appendChild( renderer.domElement );
|
|
|
|
renderer.gammaInput = true;
|
|
renderer.gammaOutput = true;
|
|
|
|
stats = new Stats();
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.top = '0px';
|
|
stats.domElement.style.right = '0px';
|
|
stats.domElement.style.zIndex = 100;
|
|
container.appendChild( stats.domElement );
|
|
|
|
var callbackProgress = function( progress, result ) {
|
|
|
|
var bar = 250,
|
|
total = progress.totalModels + progress.totalTextures,
|
|
loaded = progress.loadedModels + progress.loadedTextures;
|
|
|
|
if ( total )
|
|
bar = Math.floor( bar * loaded / total );
|
|
|
|
$( "bar" ).style.width = bar + "px";
|
|
|
|
}
|
|
|
|
var callbackFinished = function ( result ) {
|
|
|
|
loaded = result;
|
|
|
|
$( "message" ).style.display = "none";
|
|
$( "progressbar" ).style.display = "none";
|
|
|
|
result.scene.traverse( function ( object ) {
|
|
|
|
if ( object.userData.rotating === true ) {
|
|
|
|
rotatingObjects.push( object );
|
|
|
|
}
|
|
|
|
if ( object instanceof THREE.MorphAnimMesh ) {
|
|
|
|
morphAnimatedObjects.push( object );
|
|
|
|
}
|
|
|
|
if ( object instanceof THREE.SkinnedMesh ) {
|
|
|
|
if ( object.geometry.animation ) {
|
|
|
|
var animation = new THREE.Animation( object, object.geometry.animation );
|
|
animation.play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
//
|
|
|
|
$( "progress" ).style.display = "none";
|
|
|
|
camera = loaded.currentCamera;
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
scene = loaded.scene;
|
|
|
|
}
|
|
|
|
$( "progress" ).style.display = "block";
|
|
|
|
THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
|
|
|
|
var loader = new THREE.SceneLoader();
|
|
|
|
loader.addGeometryHandler( "binary", THREE.BinaryLoader );
|
|
loader.addGeometryHandler( "ctm", THREE.CTMLoader );
|
|
loader.addGeometryHandler( "vtk", THREE.VTKLoader );
|
|
loader.addGeometryHandler( "stl", THREE.STLLoader );
|
|
|
|
loader.addHierarchyHandler( "obj", THREE.OBJLoader );
|
|
loader.addHierarchyHandler( "dae", THREE.ColladaLoader );
|
|
loader.addHierarchyHandler( "utf8", THREE.UTF8Loader );
|
|
|
|
loader.callbackProgress = callbackProgress;
|
|
|
|
loader.load( "scenes/test_scene.js", callbackFinished );
|
|
|
|
//
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
}
|
|
|
|
function onWindowResize() {
|
|
|
|
windowHalfX = window.innerWidth / 2;
|
|
windowHalfY = window.innerHeight / 2;
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
}
|
|
|
|
function onDocumentMouseMove( event ) {
|
|
|
|
mouseX = ( event.clientX - windowHalfX );
|
|
mouseY = ( event.clientY - windowHalfY );
|
|
|
|
}
|
|
|
|
function createLoadScene() {
|
|
|
|
var result = {
|
|
|
|
scene: new THREE.Scene(),
|
|
camera: new THREE.PerspectiveCamera( 65, window.innerWidth / window.innerHeight, 1, 1000 )
|
|
|
|
};
|
|
|
|
result.camera.position.z = 100;
|
|
result.scene.add( result.camera );
|
|
|
|
var object, geometry, material, light, count = 500, range = 200;
|
|
|
|
material = new THREE.MeshLambertMaterial( { color:0xffffff } );
|
|
geometry = new THREE.BoxGeometry( 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;
|
|
|
|
object.matrixAutoUpdate = false;
|
|
object.updateMatrix();
|
|
|
|
result.scene.add( object );
|
|
|
|
}
|
|
|
|
result.scene.matrixAutoUpdate = false;
|
|
|
|
light = new THREE.PointLight( 0xffffff );
|
|
result.scene.add( light );
|
|
|
|
light = new THREE.DirectionalLight( 0x111111 );
|
|
light.position.x = 1;
|
|
result.scene.add( light );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
|
|
render();
|
|
stats.update();
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
var delta = clock.getDelta();
|
|
|
|
camera.position.x += ( mouseX - camera.position.x ) * .001;
|
|
camera.position.y += ( - mouseY - camera.position.y ) * .001;
|
|
|
|
camera.lookAt( scene.position );
|
|
|
|
// update skinning
|
|
|
|
THREE.AnimationHandler.update( delta * 0.75 );
|
|
|
|
for ( var i = 0; i < rotatingObjects.length; i ++ ) {
|
|
|
|
var object = rotatingObjects[ i ];
|
|
|
|
if ( object.userData.rotateX ) object.rotation.x += 1 * delta;
|
|
if ( object.userData.rotateY ) object.rotation.y += 0.5 * delta;
|
|
|
|
}
|
|
|
|
for ( var i = 0; i < morphAnimatedObjects.length; i ++ ) {
|
|
|
|
var object = morphAnimatedObjects[ i ];
|
|
|
|
object.updateAnimation( 1000 * delta );
|
|
|
|
}
|
|
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|