4 <title>three.js webgl - lights - point lights</title>
6 <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
9 background-color: #000;
16 top: 0px; width: 100%;
19 font-family: Monospace;
26 text-decoration: none;
36 <div id="container"></div>
38 <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - point lights WebGL demo.<br />
39 Walt Disney head by <a href="http://davidoreilly.com/post/18087489343/disneyhead" target="_blank" rel="noopener">David OReilly</a>
42 <script src="../build/three.js"></script>
44 <script src="js/loaders/BinaryLoader.js"></script>
46 <script src="js/Detector.js"></script>
50 if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
52 var camera, scene, renderer,
54 light1, light2, light3, light4,
57 var clock = new THREE.Clock();
64 var container = document.getElementById( 'container' );
66 camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
67 camera.position.z = 100;
69 scene = new THREE.Scene();
71 loader = new THREE.BinaryLoader();
73 var callback = function( geometry ) {
75 object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { color: 0x555555, specular: 0x111111, shininess: 50 } ) );
76 object.scale.x = object.scale.y = object.scale.z = 0.80;
81 loader.load( "obj/walt/WaltHead_bin.js", callback );
83 var sphere = new THREE.SphereGeometry( 0.5, 16, 8 );
85 light1 = new THREE.PointLight( 0xff0040, 2, 50 );
86 light1.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xff0040 } ) ) );
89 light2 = new THREE.PointLight( 0x0040ff, 2, 50 );
90 light2.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x0040ff } ) ) );
93 light3 = new THREE.PointLight( 0x80ff80, 2, 50 );
94 light3.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x80ff80 } ) ) );
97 light4 = new THREE.PointLight( 0xffaa00, 2, 50 );
98 light4.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xffaa00 } ) ) );
101 renderer = new THREE.WebGLRenderer();
102 renderer.setPixelRatio( window.devicePixelRatio );
103 renderer.setSize( window.innerWidth, window.innerHeight );
104 container.appendChild( renderer.domElement );
108 window.addEventListener( 'resize', onWindowResize, false );
112 function onWindowResize() {
114 camera.aspect = window.innerWidth / window.innerHeight;
115 camera.updateProjectionMatrix();
117 renderer.setSize( window.innerWidth, window.innerHeight );
125 requestAnimationFrame( animate );
133 var time = Date.now() * 0.0005;
134 var delta = clock.getDelta();
136 if( object ) object.rotation.y -= 0.5 * delta;
138 light1.position.x = Math.sin( time * 0.7 ) * 30;
139 light1.position.y = Math.cos( time * 0.5 ) * 40;
140 light1.position.z = Math.cos( time * 0.3 ) * 30;
142 light2.position.x = Math.cos( time * 0.3 ) * 30;
143 light2.position.y = Math.sin( time * 0.5 ) * 40;
144 light2.position.z = Math.sin( time * 0.7 ) * 30;
146 light3.position.x = Math.sin( time * 0.7 ) * 30;
147 light3.position.y = Math.cos( time * 0.3 ) * 40;
148 light3.position.z = Math.sin( time * 0.5 ) * 30;
150 light4.position.x = Math.sin( time * 0.3 ) * 30;
151 light4.position.y = Math.cos( time * 0.7 ) * 40;
152 light4.position.z = Math.sin( time * 0.5 ) * 30;
154 renderer.render( scene, camera );