Преглед на файлове

InstancedMesh: Optimize `raycast()`. (#25606)

Michael Herzog преди 2 години
родител
ревизия
3ddaae1cc9
променени са 1 файла, в които са добавени 11 реда и са изтрити 0 реда
  1. 11 0
      src/objects/InstancedMesh.js

+ 11 - 0
src/objects/InstancedMesh.js

@@ -136,6 +136,17 @@ class InstancedMesh extends Mesh {
 
 
 		if ( _mesh.material === undefined ) return;
 		if ( _mesh.material === undefined ) return;
 
 
+		// test with bounding sphere first
+
+		if ( this.boundingSphere === null ) this.computeBoundingSphere();
+
+		_sphere.copy( this.boundingSphere );
+		_sphere.applyMatrix4( matrixWorld );
+
+		if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
+
+		// now test each instance
+
 		for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
 		for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
 
 
 			// calculate the world matrix for each instance
 			// calculate the world matrix for each instance