mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 21:47:59 +01:00
225 lines
5.4 KiB
HTML
Executable File
225 lines
5.4 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js misc - lights - point + directional</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:#fff;
|
|
padding:0;
|
|
margin:0;
|
|
overflow:hidden;
|
|
font-family:georgia;
|
|
text-align:center;
|
|
}
|
|
h1 { }
|
|
a { color:skyblue }
|
|
canvas { pointer-events:none; z-index:10; }
|
|
|
|
#d { text-align:center; margin:1em 0 -11.4em 0; z-index:0; position:relative; display:block }
|
|
.button { background:#000; color:#fff; padding:0.2em 0.5em; cursor:pointer }
|
|
.inactive { background:#999; color:#eee }
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script src="../build/three.min.js"></script>
|
|
|
|
<script src="js/renderers/Projector.js"></script>
|
|
<script src="js/renderers/CanvasRenderer.js"></script>
|
|
|
|
<script src="js/libs/stats.min.js"></script>
|
|
|
|
<script>
|
|
|
|
var SCREEN_WIDTH = window.innerWidth / 2;
|
|
var SCREEN_HEIGHT = window.innerHeight;
|
|
var FLOOR = -250;
|
|
|
|
var container, stats;
|
|
|
|
var camera, scene, canvasRenderer, webglRenderer;
|
|
|
|
var mesh, zmesh, geometry;
|
|
var materialSpheres, materialTorus;
|
|
|
|
var directionalLight, pointLight;
|
|
|
|
var mouseX = 0, mouseY = 0;
|
|
|
|
var windowHalfX = window.innerWidth / 2;
|
|
var windowHalfY = window.innerHeight / 2;
|
|
|
|
var lightAdded = false;
|
|
|
|
var clock = new THREE.Clock();
|
|
|
|
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init() {
|
|
|
|
container = document.createElement('div');
|
|
document.body.appendChild(container);
|
|
|
|
camera = new THREE.PerspectiveCamera( 75, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 100000 );
|
|
camera.position.z = 500;
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
// Spheres
|
|
|
|
var geometry = new THREE.SphereGeometry( 100, 16, 8 );
|
|
materialSpheres = new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading, overdraw: 0.5 } );
|
|
|
|
for ( var i = 0; i < 30; i ++ ) {
|
|
|
|
mesh = new THREE.Mesh( geometry, materialSpheres );
|
|
mesh.position.x = 500 * ( Math.random() - 0.5 );
|
|
mesh.position.y = 500 * ( Math.random() - 0.5 );
|
|
mesh.position.z = 500 * ( Math.random() - 0.5 );
|
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.25 * ( Math.random() + 0.5 );
|
|
scene.add( mesh );
|
|
|
|
}
|
|
|
|
// Torus
|
|
|
|
materialTorus = new THREE.MeshLambertMaterial( { color: 0xffffff, overdraw: 0.5 } );
|
|
mesh = new THREE.Mesh( new THREE.TorusGeometry( 100, 25, 15, 30 ), materialTorus );
|
|
scene.add( mesh );
|
|
|
|
// Lights
|
|
|
|
var ambient = new THREE.AmbientLight( 0x101010 );
|
|
scene.add( ambient );
|
|
|
|
directionalLight = new THREE.DirectionalLight( 0xffffff );
|
|
directionalLight.position.set( 0, -70, 100 ).normalize();
|
|
//scene.add( directionalLight );
|
|
|
|
pointLight = new THREE.PointLight( 0xffaa00 );
|
|
scene.add( pointLight );
|
|
|
|
var mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0xffaa00 } ) );
|
|
mesh.scale.set( 0.05, 0.05, 0.05 );
|
|
pointLight.add( mesh );
|
|
|
|
canvasRenderer = new THREE.CanvasRenderer();
|
|
canvasRenderer.setClearColor( 0xffffff );
|
|
canvasRenderer.setPixelRatio( window.devicePixelRatio );
|
|
canvasRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
container.appendChild( canvasRenderer.domElement );
|
|
|
|
webglRenderer = new THREE.WebGLRenderer();
|
|
webglRenderer.setClearColor( 0xffffff );
|
|
webglRenderer.setPixelRatio( window.devicePixelRatio );
|
|
webglRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
webglRenderer.domElement.style.position = "relative";
|
|
container.appendChild( webglRenderer.domElement );
|
|
|
|
|
|
stats = new Stats();
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.top = '0px';
|
|
stats.domElement.style.zIndex = 100;
|
|
container.appendChild( stats.domElement );
|
|
|
|
//
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
}
|
|
|
|
function onWindowResize() {
|
|
|
|
SCREEN_WIDTH = window.innerWidth / 2;
|
|
SCREEN_HEIGHT = window.innerHeight;
|
|
|
|
camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
|
|
camera.updateProjectionMatrix();
|
|
|
|
canvasRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
webglRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
|
|
}
|
|
|
|
function onDocumentMouseMove( event ) {
|
|
|
|
mouseX = ( event.clientX - windowHalfX );
|
|
mouseY = ( event.clientY - windowHalfY );
|
|
|
|
}
|
|
|
|
//
|
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
|
|
render();
|
|
stats.update();
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
var delta = clock.getDelta();
|
|
var r = clock.getElapsedTime();
|
|
|
|
if ( ! lightAdded && r >= 3.0 ) {
|
|
|
|
scene.add( directionalLight );
|
|
|
|
materialTorus.needsUpdate = true;
|
|
materialSpheres.needsUpdate = true;
|
|
|
|
lightAdded = true;
|
|
|
|
}
|
|
|
|
camera.position.x += ( mouseX - camera.position.x ) * 0.05;
|
|
camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
|
|
|
|
camera.lookAt( scene.position );
|
|
|
|
for ( var i = 0, l = scene.children.length; i < l; i ++ ) {
|
|
|
|
var object = scene.children[ i ];
|
|
|
|
if ( object instanceof THREE.Mesh ) {
|
|
|
|
if ( i % 3 == 1 )
|
|
|
|
object.rotation.z += 1.5 * delta;
|
|
|
|
else if ( i % 3 == 2 )
|
|
|
|
object.rotation.y += 1.5 * delta;
|
|
|
|
else if ( i % 3 == 0 )
|
|
|
|
object.rotation.x += 1.5 * delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
pointLight.position.x = 200 * Math.cos( r );
|
|
pointLight.position.z = 200 * Math.sin( r );
|
|
|
|
canvasRenderer.render( scene, camera );
|
|
webglRenderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|