|
@@ -1,201 +0,0 @@
|
|
|
-<!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;
|
|
|
- }
|
|
|
- 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.js"></script>
|
|
|
-
|
|
|
- <script src="js/libs/stats.min.js"></script>
|
|
|
-
|
|
|
- <script>
|
|
|
-
|
|
|
- var SCREEN_WIDTH = window.innerWidth / 2;
|
|
|
- var SCREEN_HEIGHT = window.innerHeight;
|
|
|
-
|
|
|
- var container, stats;
|
|
|
-
|
|
|
- var camera, scene, webglRenderer;
|
|
|
-
|
|
|
- var mesh, geometry, material;
|
|
|
-
|
|
|
- var directionalLight, pointLight;
|
|
|
-
|
|
|
- var mouseX = 0, mouseY = 0;
|
|
|
-
|
|
|
- var windowHalfX = window.innerWidth / 2;
|
|
|
- var windowHalfY = window.innerHeight / 2;
|
|
|
-
|
|
|
- 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();
|
|
|
- scene.background = new THREE.Color( 0xffffff );
|
|
|
-
|
|
|
- // Spheres
|
|
|
-
|
|
|
- geometry = new THREE.SphereBufferGeometry( 100, 16, 8 );
|
|
|
- material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true, shininess: 0 } );
|
|
|
-
|
|
|
- for ( var i = 0; i < 30; i ++ ) {
|
|
|
-
|
|
|
- mesh = new THREE.Mesh( geometry, material );
|
|
|
- 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
|
|
|
-
|
|
|
- geometry = new THREE.TorusBufferGeometry( 100, 25, 15, 30 );
|
|
|
- mesh = new THREE.Mesh( geometry, material );
|
|
|
- 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();
|
|
|
-
|
|
|
- setTimeout( function () {
|
|
|
-
|
|
|
- scene.add( directionalLight );
|
|
|
-
|
|
|
- }, 3000 );
|
|
|
-
|
|
|
- pointLight = new THREE.PointLight( 0xffaa00 );
|
|
|
- scene.add( pointLight );
|
|
|
-
|
|
|
- geometry = new THREE.SphereBufferGeometry( 100, 8, 4 );
|
|
|
- material = new THREE.MeshBasicMaterial( { color: 0xffaa00 } );
|
|
|
- mesh = new THREE.Mesh( geometry, material );
|
|
|
- mesh.scale.set( 0.05, 0.05, 0.05 );
|
|
|
- pointLight.add( mesh );
|
|
|
-
|
|
|
- webglRenderer = new THREE.WebGLRenderer();
|
|
|
- webglRenderer.setPixelRatio( window.devicePixelRatio );
|
|
|
- webglRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
|
- webglRenderer.domElement.style.position = "relative";
|
|
|
- container.appendChild( webglRenderer.domElement );
|
|
|
-
|
|
|
-
|
|
|
- stats = new Stats();
|
|
|
- container.appendChild( stats.dom );
|
|
|
-
|
|
|
- //
|
|
|
-
|
|
|
- window.addEventListener( 'resize', onWindowResize, false );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- function onWindowResize() {
|
|
|
-
|
|
|
- SCREEN_WIDTH = window.innerWidth / 2;
|
|
|
- SCREEN_HEIGHT = window.innerHeight;
|
|
|
-
|
|
|
- camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
|
|
|
- camera.updateProjectionMatrix();
|
|
|
-
|
|
|
- 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();
|
|
|
-
|
|
|
- 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;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- var r = clock.getElapsedTime();
|
|
|
-
|
|
|
- pointLight.position.x = 200 * Math.cos( r );
|
|
|
- pointLight.position.z = 200 * Math.sin( r );
|
|
|
-
|
|
|
- webglRenderer.render( scene, camera );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- </script>
|
|
|
-
|
|
|
- </body>
|
|
|
-</html>
|