Skip to content

Commit 2cb9218

Browse files
committed
Examples: Use InstancedMesh in webgl_clipping_advanced.
1 parent 142144a commit 2cb9218

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

examples/webgl_clipping_advanced.html

+8-6
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,20 @@
208208
clipShadows: true
209209
} );
210210

211-
object = new THREE.Group();
212-
211+
const count = 5 * 5 * 5;
213212
const geometry = new THREE.BoxGeometry( 0.18, 0.18, 0.18 );
213+
object = new THREE.InstancedMesh( geometry, clipMaterial, count );
214+
object.castShadow = true;
215+
216+
let i = 0;
217+
const matrix = new THREE.Matrix4();
214218

215219
for ( let z = - 2; z <= 2; ++ z )
216220
for ( let y = - 2; y <= 2; ++ y )
217221
for ( let x = - 2; x <= 2; ++ x ) {
218222

219-
const mesh = new THREE.Mesh( geometry, clipMaterial );
220-
mesh.position.set( x / 5, y / 5, z / 5 );
221-
mesh.castShadow = true;
222-
object.add( mesh );
223+
matrix.setPosition( x / 5, y / 5, z / 5 );
224+
object.setMatrixAt( i ++, matrix );
223225

224226
}
225227

0 commit comments

Comments
 (0)