|
63 | 63 |
|
64 | 64 | scene = new THREE.Scene();
|
65 | 65 |
|
66 |
| - camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 ); |
| 66 | + camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 1000 ); |
67 | 67 | scene.add( camera );
|
68 | 68 |
|
69 | 69 | crosshair = new THREE.Mesh(
|
|
77 | 77 | crosshair.position.z = - 40;
|
78 | 78 | camera.add( crosshair );
|
79 | 79 |
|
80 |
| - var light = new THREE.DirectionalLight( 0xffffff, 1 ); |
| 80 | + var mesh = new THREE.Mesh( |
| 81 | + new THREE.BoxGeometry( 200, 200, 200, 10, 10, 10 ), |
| 82 | + new THREE.MeshBasicMaterial( { color: 0x202020, wireframe: true } ) |
| 83 | + ); |
| 84 | + scene.add( mesh ); |
| 85 | + |
| 86 | + scene.add( new THREE.AmbientLight( 0x202040 ) ); |
| 87 | + |
| 88 | + var light = new THREE.DirectionalLight( 0xffffff ); |
81 | 89 | light.position.set( 1, 1, 1 ).normalize();
|
82 | 90 | scene.add( light );
|
83 | 91 |
|
84 |
| - var geometry = new THREE.BoxGeometry( 20, 20, 20 ); |
| 92 | + var geometry = new THREE.BoxGeometry( 3, 3, 3 ); |
85 | 93 |
|
86 | 94 | for ( var i = 0; i < 200; i ++ ) {
|
87 | 95 |
|
88 | 96 | var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
|
89 | 97 |
|
90 |
| - object.position.x = Math.random() * 800 - 400; |
91 |
| - object.position.y = Math.random() * 800 - 400; |
92 |
| - object.position.z = Math.random() * 800 - 400; |
| 98 | + object.position.x = Math.random() * 100 - 50; |
| 99 | + object.position.y = Math.random() * 100 - 50; |
| 100 | + object.position.z = Math.random() * 100 - 50; |
93 | 101 |
|
94 | 102 | object.rotation.x = Math.random() * 2 * Math.PI;
|
95 | 103 | object.rotation.y = Math.random() * 2 * Math.PI;
|
|
99 | 107 | object.scale.y = Math.random() + 0.5;
|
100 | 108 | object.scale.z = Math.random() + 0.5;
|
101 | 109 |
|
| 110 | + object.userData.velocity = new THREE.Vector3(); |
| 111 | + object.userData.velocity.x = ( Math.random() - 0.5 ) * 0.1; |
| 112 | + object.userData.velocity.y = ( Math.random() - 0.5 ) * 0.1; |
| 113 | + object.userData.velocity.z = ( Math.random() - 0.5 ) * 0.1; |
| 114 | + |
102 | 115 | scene.add( object );
|
103 | 116 | cubes.push( object );
|
104 | 117 |
|
|
183 | 196 |
|
184 | 197 | controls.update();
|
185 | 198 |
|
| 199 | + for ( var i = 0; i < cubes.length; i ++ ) { |
| 200 | + |
| 201 | + var cube = cubes[ i ]; |
| 202 | + |
| 203 | + cube.position.add( cube.userData.velocity ); |
| 204 | + |
| 205 | + if ( cube.position.x < 100 ) cube.position.x += 200; |
| 206 | + if ( cube.position.y < 100 ) cube.position.y += 200; |
| 207 | + if ( cube.position.z < 100 ) cube.position.z += 200; |
| 208 | + |
| 209 | + if ( cube.position.x > 100 ) cube.position.x -= 200; |
| 210 | + if ( cube.position.y > 100 ) cube.position.y -= 200; |
| 211 | + if ( cube.position.z > 100 ) cube.position.z -= 200; |
| 212 | + |
| 213 | + cube.rotation.x += 0.01; |
| 214 | + |
| 215 | + } |
| 216 | + |
186 | 217 | effect.render( scene, camera );
|
187 | 218 |
|
188 | 219 | }
|
|
0 commit comments