|
15 | 15 | import { GUI } from './jsm/libs/lil-gui.module.min.js'; |
16 | 16 | import { OrbitControls } from "./jsm/controls/OrbitControls.js"; |
17 | 17 |
|
18 | | - let camera, scene, renderer, stats; |
| 18 | + let camera, scene, renderer, controls, stats; |
19 | 19 |
|
20 | 20 | let mesh; |
21 | 21 | const amount = parseInt( window.location.search.substr( 1 ) ) || 10; |
|
25 | 25 | const mouse = new THREE.Vector2( 1, 1 ); |
26 | 26 |
|
27 | 27 | const color = new THREE.Color(); |
| 28 | + const white = new THREE.Color().setHex( 0xffffff ); |
28 | 29 |
|
29 | 30 | init(); |
30 | 31 | animate(); |
|
37 | 38 |
|
38 | 39 | scene = new THREE.Scene(); |
39 | 40 |
|
40 | | - const light1 = new THREE.HemisphereLight( 0xffffff, 0x000088 ); |
41 | | - light1.position.set( - 1, 1.5, 1 ); |
42 | | - scene.add( light1 ); |
43 | | - |
44 | | - const light2 = new THREE.HemisphereLight( 0xffffff, 0x880000, 0.5 ); |
45 | | - light2.position.set( - 1, - 1.5, - 1 ); |
46 | | - scene.add( light2 ); |
| 41 | + const light = new THREE.HemisphereLight( 0xffffff, 0x888888 ); |
| 42 | + light.position.set( 0, 1, 0 ); |
| 43 | + scene.add( light ); |
47 | 44 |
|
48 | 45 | const geometry = new THREE.IcosahedronGeometry( 0.5, 3 ); |
49 | | - const material = new THREE.MeshPhongMaterial(); |
| 46 | + const material = new THREE.MeshPhongMaterial( { color: 0xffffff } ); |
50 | 47 |
|
51 | 48 | mesh = new THREE.InstancedMesh( geometry, material, count ); |
52 | 49 |
|
|
86 | 83 | renderer.setSize( window.innerWidth, window.innerHeight ); |
87 | 84 | document.body.appendChild( renderer.domElement ); |
88 | 85 |
|
89 | | - new OrbitControls( camera, renderer.domElement ); |
| 86 | + controls = new OrbitControls( camera, renderer.domElement ); |
| 87 | + controls.enableDamping = true; |
| 88 | + controls.enableZoom = false; |
| 89 | + controls.enablePan = false; |
90 | 90 |
|
91 | 91 | stats = new Stats(); |
92 | 92 | document.body.appendChild( stats.dom ); |
|
118 | 118 |
|
119 | 119 | requestAnimationFrame( animate ); |
120 | 120 |
|
121 | | - render(); |
122 | | - |
123 | | - } |
124 | | - |
125 | | - function render() { |
| 121 | + controls.update(); |
126 | 122 |
|
127 | 123 | raycaster.setFromCamera( mouse, camera ); |
128 | 124 |
|
|
132 | 128 |
|
133 | 129 | const instanceId = intersection[ 0 ].instanceId; |
134 | 130 |
|
135 | | - mesh.setColorAt( instanceId, color.setHex( Math.random() * 0xffffff ) ); |
136 | | - mesh.instanceColor.needsUpdate = true; |
| 131 | + mesh.getColorAt( instanceId, color ); |
| 132 | + |
| 133 | + if ( color.equals( white ) ) { |
| 134 | + |
| 135 | + mesh.setColorAt( instanceId, color.setHex( Math.random() * 0xffffff ) ); |
| 136 | + |
| 137 | + mesh.instanceColor.needsUpdate = true; |
| 138 | + |
| 139 | + } |
137 | 140 |
|
138 | 141 | } |
139 | 142 |
|
140 | | - renderer.render( scene, camera ); |
| 143 | + render(); |
141 | 144 |
|
142 | 145 | stats.update(); |
143 | 146 |
|
144 | 147 | } |
145 | 148 |
|
| 149 | + function render() { |
| 150 | + |
| 151 | + renderer.render( scene, camera ); |
| 152 | + |
| 153 | + } |
| 154 | + |
146 | 155 | </script> |
147 | 156 | </body> |
148 | 157 | </html> |
0 commit comments