mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 21:47:59 +01:00
267 lines
6.7 KiB
HTML
Executable File
267 lines
6.7 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js webgl - io - CTM 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 {
|
|
font-family: Monospace;
|
|
background-color: #000;
|
|
color: #fff;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
#info {
|
|
color: #fff;
|
|
position: absolute;
|
|
top: 10px;
|
|
width: 100%;
|
|
text-align: center;
|
|
z-index: 100;
|
|
display:block;
|
|
}
|
|
|
|
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
|
|
|
|
#stats { position: absolute; top:0; left: 0 }
|
|
#stats #fps { background: transparent !important }
|
|
#stats #fps #fpsText { color: #aaa !important }
|
|
#stats #fps #fpsGraph { display: none }
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="info">
|
|
<a href="http://threejs.org" target="_blank">three.js</a> -
|
|
<a href="http://openctm.sourceforge.net/" target="_blank">CTM format</a> loader test -
|
|
using <a href="http://code.google.com/p/js-openctm/">js-openctm</a> -
|
|
models from <a href="http://www.sci.utah.edu/~wald/animrep/" target="_blank">The Utah 3D Animation Repository</a>,
|
|
<a href="http://www.ir-ltd.net/infinite-3d-head-scan-released/" target="_blank">Lee Perry-Smith</a>,
|
|
<a href="http://davidoreilly.com/post/18087489343/disneyhead" target="_blank">David OReilly</a>
|
|
</div>
|
|
|
|
<script src="../build/three.min.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/Detector.js"></script>
|
|
<script src="js/libs/stats.min.js"></script>
|
|
|
|
<script>
|
|
|
|
var SCREEN_WIDTH = window.innerWidth;
|
|
var SCREEN_HEIGHT = window.innerHeight;
|
|
|
|
var container, stats;
|
|
|
|
var camera, scene, 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();
|
|
animate();
|
|
|
|
|
|
function init() {
|
|
|
|
container = document.createElement( 'div' );
|
|
document.body.appendChild( container );
|
|
|
|
camera = new THREE.PerspectiveCamera( 20, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 2000 );
|
|
camera.position.z = 800;
|
|
|
|
scene = new THREE.Scene();
|
|
scene.fog = new THREE.Fog( 0x050505, 800, 2000 );
|
|
|
|
var path = "textures/cube/SwedishRoyalCastle/";
|
|
var format = '.jpg';
|
|
var urls = [
|
|
path + 'px' + format, path + 'nx' + format,
|
|
path + 'py' + format, path + 'ny' + format,
|
|
path + 'pz' + format, path + 'nz' + format
|
|
];
|
|
|
|
reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
|
|
|
|
// LIGHTS
|
|
|
|
var ambient = new THREE.AmbientLight( 0x080808 );
|
|
//scene.add( ambient );
|
|
|
|
var light = new THREE.SpotLight( 0xffeedd, 1.2, 650, Math.PI/2, 3 );
|
|
light.position.set( 0, -100, 500 );
|
|
|
|
light.castShadow = true;
|
|
light.shadowMapWidth = 2048;
|
|
light.shadowMapHeight = 2048;
|
|
light.shadowCameraFov = 45;
|
|
//light.shadowCameraVisible = true;
|
|
|
|
scene.add( light );
|
|
|
|
|
|
// RENDERER
|
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer.setClearColor( scene.fog.color );
|
|
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;
|
|
|
|
renderer.shadowMapEnabled = true;
|
|
|
|
// STATS
|
|
|
|
stats = new Stats();
|
|
container.appendChild( stats.domElement );
|
|
|
|
// EVENTS
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
// LOADER
|
|
|
|
var c = 0, s = Date.now();
|
|
|
|
function checkTime() {
|
|
|
|
c ++;
|
|
|
|
if ( c === 3 ) {
|
|
|
|
var e = Date.now();
|
|
console.log( "Total parse time: " + (e-s) + " ms" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var loader = new THREE.CTMLoader();
|
|
|
|
loader.load( "models/ctm/ben.ctm", function( geometry ) {
|
|
|
|
var material = new THREE.MeshLambertMaterial( { color: 0xffaa00, map: THREE.ImageUtils.loadTexture( "textures/UV_Grid_Sm.jpg" ), envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.3 } );
|
|
callbackModel( geometry, 450, material, 0, -200, 0, 0, 0 );
|
|
checkTime();
|
|
|
|
}, { useWorker: true } );
|
|
|
|
loader.load( "models/ctm/WaltHead.ctm", function( geometry ) {
|
|
|
|
var material1 = new THREE.MeshLambertMaterial( { color: 0xffffff } );
|
|
var material2 = new THREE.MeshPhongMaterial( { color: 0xff4400, specular: 0x333333, shininess: 100 } );
|
|
var material3 = new THREE.MeshPhongMaterial( { color: 0x00ff44, specular: 0x333333, shininess: 100 } );
|
|
|
|
callbackModel( geometry, 5, material1, -200, 0, -50, 0, 0 );
|
|
callbackModel( geometry, 2, material2, 100, 0, 125, 0, 0 );
|
|
callbackModel( geometry, 2, material3, -100, 0, 125, 0, 0 );
|
|
|
|
checkTime();
|
|
|
|
}, { useWorker: true } );
|
|
|
|
loader.load( "models/ctm/LeePerry.ctm", function( geometry ) {
|
|
|
|
geometry.computeTangents();
|
|
|
|
var material = new THREE.MeshPhongMaterial( {
|
|
|
|
specular: 0x303030,
|
|
shininess: 50,
|
|
map: THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ),
|
|
specularMap: THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Map-SPEC.jpg" ),
|
|
normalMap: THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" ),
|
|
normalScale: new THREE.Vector2( 0.8, 0.8 ),
|
|
wrapRGB: new THREE.Vector3( 0.75, 0.5, 0.5 ),
|
|
wrapAround: true
|
|
|
|
} );
|
|
|
|
callbackModel( geometry, 1300, material, 200, 50, 0, 0, 0 );
|
|
checkTime();
|
|
|
|
}, { useWorker: true } );
|
|
|
|
}
|
|
|
|
function callbackModel( geometry, s, material, x, y, z, rx, ry ) {
|
|
|
|
var mesh = new THREE.Mesh( geometry, material );
|
|
|
|
mesh.position.set( x, y, z );
|
|
mesh.scale.set( s, s, s );
|
|
mesh.rotation.x = rx;
|
|
mesh.rotation.z = ry;
|
|
|
|
mesh.castShadow = true;
|
|
mesh.receiveShadow = true;
|
|
|
|
scene.add( mesh );
|
|
|
|
}
|
|
|
|
//
|
|
|
|
function onWindowResize( event ) {
|
|
|
|
SCREEN_WIDTH = window.innerWidth;
|
|
SCREEN_HEIGHT = window.innerHeight;
|
|
|
|
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
|
|
camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
|
|
camera.updateProjectionMatrix();
|
|
|
|
}
|
|
|
|
function onDocumentMouseMove( event ) {
|
|
|
|
mouseX = ( event.clientX - windowHalfX );
|
|
mouseY = ( event.clientY - windowHalfY );
|
|
|
|
}
|
|
|
|
//
|
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
|
|
render();
|
|
stats.update();
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
camera.position.x += ( mouseX - camera.position.x ) * .05;
|
|
camera.position.y += ( - mouseY - camera.position.y ) * .05;
|
|
|
|
camera.lookAt( scene.position );
|
|
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|