|
@@ -18,6 +18,75 @@ THREE.LinePieces = 1;
|
|
|
|
|
|
THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
|
|
|
|
|
|
+THREE.Line.prototype.raycast = ( function () {
|
|
|
+
|
|
|
+ var inverseMatrix = new THREE.Matrix4();
|
|
|
+ var ray = new THREE.Ray();
|
|
|
+ var sphere = new THREE.Sphere();
|
|
|
+
|
|
|
+ return function ( raycaster, intersects ) {
|
|
|
+
|
|
|
+ var precision = raycaster.linePrecision;
|
|
|
+ var precisionSq = precision * precision;
|
|
|
+
|
|
|
+ var geometry = this.geometry;
|
|
|
+
|
|
|
+ if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
|
|
|
+
|
|
|
+ // Checking boundingSphere distance to ray
|
|
|
+
|
|
|
+ sphere.copy( geometry.boundingSphere );
|
|
|
+ sphere.applyMatrix4( this.matrixWorld );
|
|
|
+
|
|
|
+ if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
|
|
|
+
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ inverseMatrix.getInverse( this.matrixWorld );
|
|
|
+ ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
|
|
|
+
|
|
|
+ /* if ( geometry instanceof THREE.BufferGeometry ) {
|
|
|
+
|
|
|
+ } else */ if ( geometry instanceof THREE.Geometry ) {
|
|
|
+
|
|
|
+ var vertices = geometry.vertices;
|
|
|
+ var nbVertices = vertices.length;
|
|
|
+ var interSegment = new THREE.Vector3();
|
|
|
+ var interRay = new THREE.Vector3();
|
|
|
+ var step = this.type === THREE.LineStrip ? 1 : 2;
|
|
|
+
|
|
|
+ for ( var i = 0; i < nbVertices - 1; i = i + step ) {
|
|
|
+
|
|
|
+ var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
|
|
|
+
|
|
|
+ if ( distSq > precisionSq ) continue;
|
|
|
+
|
|
|
+ var distance = ray.origin.distanceTo( interRay );
|
|
|
+
|
|
|
+ if ( distance < raycaster.near || distance > raycaster.far ) continue;
|
|
|
+
|
|
|
+ intersects.push( {
|
|
|
+
|
|
|
+ distance: distance,
|
|
|
+ // What do we want? intersection point on the ray or on the segment??
|
|
|
+ // point: raycaster.ray.at( distance ),
|
|
|
+ point: interSegment.clone().applyMatrix4( this.matrixWorld ),
|
|
|
+ face: null,
|
|
|
+ faceIndex: null,
|
|
|
+ object: this
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+}() );
|
|
|
+
|
|
|
THREE.Line.prototype.clone = function ( object ) {
|
|
|
|
|
|
if ( object === undefined ) object = new THREE.Line( this.geometry, this.material, this.type );
|