소스 검색

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;
 
+		// 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 ++ ) {
 
 			// calculate the world matrix for each instance