mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 19:43:48 +01:00
206 lines
4.8 KiB
HTML
Executable File
206 lines
4.8 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js webgl - PLY</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: #000000;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
#info {
|
|
color: #fff;
|
|
position: absolute;
|
|
top: 10px;
|
|
width: 100%;
|
|
text-align: center;
|
|
z-index: 100;
|
|
display:block;
|
|
|
|
}
|
|
|
|
a { color: skyblue }
|
|
.button { background:#999; color:#eee; padding:0.2em 0.5em; cursor:pointer }
|
|
.highlight { background:orange; color:#fff; }
|
|
|
|
span {
|
|
display: inline-block;
|
|
width: 60px;
|
|
float: left;
|
|
text-align: center;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="info">
|
|
<a href="http://threejs.org" target="_blank">three.js</a> -
|
|
PLY loader test by <a href="https://github.com/menway">Wei Meng</a>. Image from <a href="http://people.sc.fsu.edu/~jburkardt/data/ply/ply.html">John Burkardt</a>
|
|
</div>
|
|
|
|
<script src="../build/three.min.js"></script>
|
|
|
|
<script src="js/loaders/PLYLoader.js"></script>
|
|
|
|
<script src="js/Detector.js"></script>
|
|
<script src="js/libs/stats.min.js"></script>
|
|
|
|
<script>
|
|
|
|
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
|
|
|
|
var container, stats;
|
|
|
|
var camera, cameraTarget, scene, renderer;
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init() {
|
|
|
|
container = document.createElement( 'div' );
|
|
document.body.appendChild( container );
|
|
|
|
camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 15 );
|
|
camera.position.set( 3, 0.15, 3 );
|
|
|
|
cameraTarget = new THREE.Vector3( 0, -0.25, 0 );
|
|
|
|
scene = new THREE.Scene();
|
|
scene.fog = new THREE.Fog( 0x72645b, 2, 15 );
|
|
|
|
|
|
// Ground
|
|
|
|
var plane = new THREE.Mesh(
|
|
new THREE.PlaneBufferGeometry( 40, 40 ),
|
|
new THREE.MeshPhongMaterial( { color: 0x999999, specular: 0x101010 } )
|
|
);
|
|
plane.rotation.x = -Math.PI/2;
|
|
plane.position.y = -0.5;
|
|
scene.add( plane );
|
|
|
|
plane.receiveShadow = true;
|
|
|
|
|
|
// PLY file
|
|
|
|
var loader = new THREE.PLYLoader();
|
|
loader.addEventListener( 'load', function ( event ) {
|
|
|
|
var geometry = event.content;
|
|
var material = new THREE.MeshPhongMaterial( { color: 0x0055ff, specular: 0x111111, shininess: 200 } );
|
|
var mesh = new THREE.Mesh( geometry, material );
|
|
|
|
mesh.position.set( 0, - 0.25, 0 );
|
|
mesh.rotation.set( 0, - Math.PI / 2, 0 );
|
|
mesh.scale.set( 0.001, 0.001, 0.001 );
|
|
|
|
mesh.castShadow = true;
|
|
mesh.receiveShadow = true;
|
|
|
|
scene.add( mesh );
|
|
|
|
} );
|
|
loader.load( './models/ply/ascii/dolphins.ply' );
|
|
|
|
// Lights
|
|
|
|
scene.add( new THREE.AmbientLight( 0x777777 ) );
|
|
|
|
addShadowedLight( 1, 1, 1, 0xffffff, 1.35 );
|
|
addShadowedLight( 0.5, 1, -1, 0xffaa00, 1 );
|
|
|
|
// renderer
|
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer.setClearColor( scene.fog.color );
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
renderer.gammaInput = true;
|
|
renderer.gammaOutput = true;
|
|
|
|
renderer.shadowMapEnabled = true;
|
|
renderer.shadowMapCullFace = THREE.CullFaceBack;
|
|
|
|
container.appendChild( renderer.domElement );
|
|
|
|
// stats
|
|
|
|
stats = new Stats();
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.top = '0px';
|
|
container.appendChild( stats.domElement );
|
|
|
|
// resize
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
}
|
|
|
|
function addShadowedLight( x, y, z, color, intensity ) {
|
|
|
|
var directionalLight = new THREE.DirectionalLight( color, intensity );
|
|
directionalLight.position.set( x, y, z )
|
|
scene.add( directionalLight );
|
|
|
|
directionalLight.castShadow = true;
|
|
// directionalLight.shadowCameraVisible = true;
|
|
|
|
var d = 1;
|
|
directionalLight.shadowCameraLeft = -d;
|
|
directionalLight.shadowCameraRight = d;
|
|
directionalLight.shadowCameraTop = d;
|
|
directionalLight.shadowCameraBottom = -d;
|
|
|
|
directionalLight.shadowCameraNear = 1;
|
|
directionalLight.shadowCameraFar = 4;
|
|
|
|
directionalLight.shadowMapWidth = 1024;
|
|
directionalLight.shadowMapHeight = 1024;
|
|
|
|
directionalLight.shadowBias = -0.005;
|
|
directionalLight.shadowDarkness = 0.15;
|
|
|
|
}
|
|
|
|
function onWindowResize() {
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
}
|
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
|
|
render();
|
|
stats.update();
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
var timer = Date.now() * 0.0005;
|
|
|
|
camera.position.x = Math.sin( timer ) * 3;
|
|
camera.position.z = Math.cos( timer ) * 3;
|
|
|
|
camera.lookAt( cameraTarget );
|
|
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|