diff --git a/src/objects/Line.js b/src/objects/Line.js index 32e281fa19b27ac467dcc38f87baf136b040aad3..1f7235126971114b5f19fee975d6368e25f5cbf9 100644 --- a/src/objects/Line.js +++ b/src/objects/Line.js @@ -101,7 +101,6 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), { return function raycast( raycaster, intersects ) { var precision = raycaster.linePrecision; - var precisionSq = precision * precision; var geometry = this.geometry; var matrixWorld = this.matrixWorld; @@ -112,6 +111,7 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), { sphere.copy( geometry.boundingSphere ); sphere.applyMatrix4( matrixWorld ); + sphere.radius += precision; if ( raycaster.ray.intersectsSphere( sphere ) === false ) return; @@ -120,6 +120,9 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), { inverseMatrix.getInverse( matrixWorld ); ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix ); + var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ); + var localPrecisionSq = localPrecision * localPrecision; + var vStart = new Vector3(); var vEnd = new Vector3(); var interSegment = new Vector3(); @@ -146,7 +149,7 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), { var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment ); - if ( distSq > precisionSq ) continue; + if ( distSq > localPrecisionSq ) continue; interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation @@ -178,7 +181,7 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), { var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment ); - if ( distSq > precisionSq ) continue; + if ( distSq > localPrecisionSq ) continue; interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation @@ -212,7 +215,7 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), { var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment ); - if ( distSq > precisionSq ) continue; + if ( distSq > localPrecisionSq ) continue; interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation