Browse Source

Fix world space intersection point calculation

Garrett Johnson 5 năm trước cách đây
mục cha
commit
3d420b115b
1 tập tin đã thay đổi với 6 bổ sung5 xóa
  1. 6 5
      examples/js/lines/LineSegments2.js

+ 6 - 5
examples/js/lines/LineSegments2.js

@@ -155,10 +155,12 @@ THREE.LineSegments2.prototype = Object.assign( Object.create( THREE.Mesh.prototy
 				line.at( param, closestPoint );
 
 				// check if the intersection point is within clip space
-				var zPos = MathUtils.lerp( start.z, end.z, param );
+				var zPos = THREE.Math.lerp( start.z, end.z, param );
 				var isInClipSpace = zPos >= -1 && zPos <= 1;
 
-				if ( isInClipSpace && ssOrigin3.distanceTo( closestPoint ) < lineWidth * 0.5 ) {
+				var isInside = ssOrigin3.distanceTo( closestPoint ) < lineWidth * 0.5;
+
+				if ( isInClipSpace && isInside ) {
 
 					line.start.fromBufferAttribute( instanceStart, i );
 					line.end.fromBufferAttribute( instanceEnd, i );
@@ -167,10 +169,9 @@ THREE.LineSegments2.prototype = Object.assign( Object.create( THREE.Mesh.prototy
 					line.end.applyMatrix4( matrixWorld );
 
 					var pointOnLine = new THREE.Vector3();
-					line.at( param, pointOnLine );
-
 					var point = new THREE.Vector3();
-					ray.closestPointToPoint( pointOnLine, point );
+
+					ray.distanceSqToSegment( line.start, line.end, point, pointOnLine );
 
 					intersects.push( {