Skip to content

Commit 3ddaae1

Browse files
authored
InstancedMesh: Optimize raycast(). (#25606)
1 parent edb16f9 commit 3ddaae1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/objects/InstancedMesh.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ class InstancedMesh extends Mesh {
136136

137137
if ( _mesh.material === undefined ) return;
138138

139+
// test with bounding sphere first
140+
141+
if ( this.boundingSphere === null ) this.computeBoundingSphere();
142+
143+
_sphere.copy( this.boundingSphere );
144+
_sphere.applyMatrix4( matrixWorld );
145+
146+
if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
147+
148+
// now test each instance
149+
139150
for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
140151

141152
// calculate the world matrix for each instance

0 commit comments

Comments
 (0)