Răsfoiți Sursa

Points: Replace boundingBox check with boundingSphere check. See #7710.

Mr.doob 9 ani în urmă
părinte
comite
84438e47d9
1 a modificat fișierele cu 12 adăugiri și 6 ștergeri
  1. 12 6
      src/objects/Points.js

+ 12 - 6
src/objects/Points.js

@@ -20,6 +20,7 @@ THREE.Points.prototype.raycast = ( function () {
 
 
 	var inverseMatrix = new THREE.Matrix4();
 	var inverseMatrix = new THREE.Matrix4();
 	var ray = new THREE.Ray();
 	var ray = new THREE.Ray();
+	var sphere = new THREE.Sphere();
 
 
 	return function raycast( raycaster, intersects ) {
 	return function raycast( raycaster, intersects ) {
 
 
@@ -27,14 +28,19 @@ THREE.Points.prototype.raycast = ( function () {
 		var geometry = object.geometry;
 		var geometry = object.geometry;
 		var threshold = raycaster.params.Points.threshold;
 		var threshold = raycaster.params.Points.threshold;
 
 
-		inverseMatrix.getInverse( this.matrixWorld );
-		ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
+		// Checking boundingSphere distance to ray
 
 
-		if ( geometry.boundingBox !== null ) {
+		if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
 
 
-			if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
+		var matrixWorld = this.matrixWorld;
 
 
-		}
+		sphere.copy( geometry.boundingSphere );
+		sphere.applyMatrix4( matrixWorld );
+
+		if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
+
+		inverseMatrix.getInverse( matrixWorld );
+		ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
 
 
 		var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
 		var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
 		var localThresholdSq = localThreshold * localThreshold;
 		var localThresholdSq = localThreshold * localThreshold;
@@ -47,7 +53,7 @@ THREE.Points.prototype.raycast = ( function () {
 			if ( rayPointDistanceSq < localThresholdSq ) {
 			if ( rayPointDistanceSq < localThresholdSq ) {
 
 
 				var intersectPoint = ray.closestPointToPoint( point );
 				var intersectPoint = ray.closestPointToPoint( point );
-				intersectPoint.applyMatrix4( object.matrixWorld );
+				intersectPoint.applyMatrix4( matrixWorld );
 
 
 				var distance = raycaster.ray.origin.distanceTo( intersectPoint );
 				var distance = raycaster.ray.origin.distanceTo( intersectPoint );