|
17 | 17 |
|
18 | 18 | var camera, scene, renderer, stats;
|
19 | 19 |
|
20 |
| - var mesh, geometry; |
21 |
| - var amount = parseInt( window.location.search.substr( 1 ) ) || 3; |
| 20 | + var mesh; |
| 21 | + var amount = parseInt( window.location.search.substr( 1 ) ) || 10; |
22 | 22 | var count = Math.pow( amount, 3 );
|
23 |
| - var object = new THREE.Object3D(); |
24 | 23 |
|
25 |
| - var intersection; |
26 | 24 | var raycaster = new THREE.Raycaster();
|
27 | 25 | var mouse = new THREE.Vector2( 1, 1 );
|
28 | 26 |
|
|
36 | 34 |
|
37 | 35 | function init() {
|
38 | 36 |
|
39 |
| - camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1000 ); |
| 37 | + camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 100 ); |
40 | 38 | camera.position.set( amount, amount, amount );
|
41 | 39 | camera.lookAt( 0, 0, 0 );
|
42 | 40 |
|
43 | 41 | scene = new THREE.Scene();
|
44 | 42 |
|
45 |
| - geometry = new THREE.TorusKnotBufferGeometry( 0.5, 0.2, 16, 4, 2, 3 ); |
46 |
| - geometry.scale( 0.5, 0.5, 0.5 ); |
| 43 | + var light = new THREE.HemisphereLight( 0xffffff, 0x000088 ); |
| 44 | + light.position.set( - 1, 1.5, 1 ); |
| 45 | + scene.add( light ); |
47 | 46 |
|
48 |
| - var material = new THREE.MeshNormalMaterial( { flatShading: true } ); |
| 47 | + var light = new THREE.HemisphereLight( 0xffffff, 0x880000, 0.5 ); |
| 48 | + light.position.set( - 1, - 1.5, - 1 ); |
| 49 | + scene.add( light ); |
| 50 | + |
| 51 | + var geometry = new THREE.SphereBufferGeometry( 0.5 ); |
| 52 | + var material = new THREE.MeshPhongMaterial( { flatShading: true } ); |
49 | 53 |
|
50 | 54 | mesh = new THREE.InstancedMesh( geometry, material, count );
|
51 | 55 |
|
52 | 56 | var i = 0;
|
53 |
| - var offset = amount / 2; |
| 57 | + var offset = ( amount - 1 ) / 2; |
| 58 | + |
| 59 | + var transform = new THREE.Object3D(); |
54 | 60 |
|
55 | 61 | for ( var x = 0; x < amount; x ++ ) {
|
56 | 62 |
|
57 | 63 | for ( var y = 0; y < amount; y ++ ) {
|
58 | 64 |
|
59 | 65 | for ( var z = 0; z < amount; z ++ ) {
|
60 | 66 |
|
61 |
| - object.position.set( offset - x, offset - y, offset - z ); |
62 |
| - |
63 |
| - object.updateMatrix(); |
| 67 | + transform.position.set( offset - x, offset - y, offset - z ); |
| 68 | + transform.updateMatrix(); |
64 | 69 |
|
65 |
| - mesh.setMatrixAt( i ++, object.matrix ); |
| 70 | + mesh.setMatrixAt( i ++, transform.matrix ); |
66 | 71 |
|
67 | 72 | }
|
68 | 73 |
|
|
82 | 87 | renderer.setSize( window.innerWidth, window.innerHeight );
|
83 | 88 | document.body.appendChild( renderer.domElement );
|
84 | 89 |
|
85 |
| - var orbitControls = new OrbitControls( camera, renderer.domElement ); |
| 90 | + new OrbitControls( camera, renderer.domElement ); |
86 | 91 |
|
87 | 92 | stats = new Stats();
|
88 | 93 | document.body.appendChild( stats.dom );
|
|
122 | 127 |
|
123 | 128 | raycaster.setFromCamera( mouse, camera );
|
124 | 129 |
|
125 |
| - intersection = raycaster.intersectObjects( scene.children ); |
| 130 | + var intersection = raycaster.intersectObject( mesh ); |
126 | 131 |
|
127 | 132 | if ( intersection.length > 0 ) {
|
128 | 133 |
|
|
0 commit comments