123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - lights - point lights</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-color: #000;
- margin: 0px;
- overflow: hidden;
- }
- #info {
- position: absolute;
- top: 0px; width: 100%;
- color: #ffffff;
- padding: 5px;
- font-family: Monospace;
- font-size: 13px;
- text-align: center;
- }
- a {
- color: #ff0080;
- text-decoration: none;
- }
- a:hover {
- color: #0080ff;
- }
- </style>
- </head>
- <body>
- <div id="container"></div>
- <div id="info">
- <a href="http://threejs.org" target="_blank">three.js</a> - point lights WebGL demo
- </div>
- <script src="../build/three.js"></script>
- <script src="js/controls/TrackballControls.js"></script>
- <script src="js/Detector.js"></script>
- <script src="js/libs/stats.min.js"></script>
- <script>
- if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
- var camera, scene, renderer, controls,
- particle1, particle2, particle4, particle4, particle5, particle6,
- light1, light2, light3, light4, light5, light6;
- var FAR = 300;
- var clock = new THREE.Clock();
- init();
- animate();
- function init() {
- var container = document.getElementById( 'container' );
- // CAMERA
- camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, FAR );
- camera.position.set( 0, 15, 150 );
- camera.lookAt( new THREE.Vector3() );
- // SCENE
- scene = new THREE.Scene();
- scene.fog = new THREE.Fog( 0x040306, 10, FAR );
- // CONTROLS
- controls = new THREE.TrackballControls( camera );
- controls.rotateSpeed = 1.0;
- controls.zoomSpeed = 1.2;
- controls.panSpeed = 0.8;
- controls.noZoom = false;
- controls.noPan = false;
- controls.staticMoving = false;
- controls.dynamicDampingFactor = 0.15;
- controls.keys = [ 65, 83, 68 ];
- // TEXTURES
- var textureLoader = new THREE.TextureLoader();
- var texture = textureLoader.load( "textures/disturb.jpg" );
- texture.repeat.set( 20, 10 );
- texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
- texture.format = THREE.RGBFormat;
- // MATERIALS
- var groundMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture } );
- var objectMaterial = new THREE.MeshStandardMaterial( { color: 0xffffff, roughness: 0.5, metalness: 1.0 } );
- // GROUND
- var mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 800, 400, 2, 2 ), groundMaterial );
- mesh.position.y = - 5;
- mesh.rotation.x = - Math.PI / 2;
- scene.add( mesh );
- // OBJECTS
- //var objectGeometry = new THREE.BoxGeometry( 0.5, 1, 1 );
- //var objectGeometry = new THREE.SphereGeometry( 1.5, 16, 8 );
- var objectGeometry = new THREE.TorusGeometry( 1.5, 0.4, 8, 16 );
- for ( var i = 0; i < 5000; i ++ ) {
- var mesh = new THREE.Mesh( objectGeometry, objectMaterial );
- mesh.position.x = 400 * ( 0.5 - Math.random() );
- mesh.position.y = 50 * ( 0.5 - Math.random() ) + 25;
- mesh.position.z = 200 * ( 0.5 - Math.random() );
- mesh.rotation.y = 3.14 * ( 0.5 - Math.random() );
- mesh.rotation.x = 3.14 * ( 0.5 - Math.random() );
- mesh.matrixAutoUpdate = false;
- mesh.updateMatrix();
- scene.add( mesh );
- }
- // LIGHTS
- var intensity = 2.5;
- var distance = 100;
- var decay = 2.0;
- var c1 = 0xff0040, c2 = 0x0040ff, c3 = 0x80ff80, c4 = 0xffaa00, c5 = 0x00ffaa, c6 = 0xff1100;
- var sphere = new THREE.SphereGeometry( 0.25, 16, 8 );
- light1 = new THREE.PointLight( c1, intensity, distance, decay );
- light1.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c1 } ) ) );
- scene.add( light1 );
- light2 = new THREE.PointLight( c2, intensity, distance, decay );
- light2.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c2 } ) ) );
- scene.add( light2 );
- light3 = new THREE.PointLight( c3, intensity, distance, decay );
- light3.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c3 } ) ) );
- scene.add( light3 );
- light4 = new THREE.PointLight( c4, intensity, distance, decay );
- light4.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c4 } ) ) );
- scene.add( light4 );
- light5 = new THREE.PointLight( c5, intensity, distance, decay );
- light5.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c5 } ) ) );
- scene.add( light5 );
- light6 = new THREE.PointLight( c6, intensity, distance, decay );
- light6.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c6 } ) ) );
- scene.add( light6 );
- var dlight = new THREE.DirectionalLight( 0xffffff, 0.05 );
- dlight.position.set( 0.5, 1, 0 ).normalize();
- scene.add( dlight );
- // RENDERER
- renderer = new THREE.WebGLRenderer( { antialias: false } );
- renderer.setClearColor( scene.fog.color );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- container.appendChild( renderer.domElement );
- renderer.gammaInput = true;
- renderer.gammaOutput = true;
- // STATS
- stats = new Stats();
- container.appendChild( stats.dom );
- //
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- controls.handleResize();
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- function render() {
- var time = Date.now() * 0.00025;
- var z = 20, d = 150;
- light1.position.x = Math.sin( time * 0.7 ) * d;
- light1.position.z = Math.cos( time * 0.3 ) * d;
- light2.position.x = Math.cos( time * 0.3 ) * d;
- light2.position.z = Math.sin( time * 0.7 ) * d;
- light3.position.x = Math.sin( time * 0.7 ) * d;
- light3.position.z = Math.sin( time * 0.5 ) * d;
- light4.position.x = Math.sin( time * 0.3 ) * d;
- light4.position.z = Math.sin( time * 0.5 ) * d;
- light5.position.x = Math.cos( time * 0.3 ) * d;
- light5.position.z = Math.sin( time * 0.5 ) * d;
- light6.position.x = Math.cos( time * 0.7 ) * d;
- light6.position.z = Math.cos( time * 0.5 ) * d;
- controls.update( clock.getDelta() );
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|