1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- THREE.Line = function ( geometry, material, type ) {
- THREE.Object3D.call( this );
- this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
- this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
- this.type = ( type !== undefined ) ? type : THREE.LineStrip;
- };
- THREE.LineStrip = 0;
- 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 );
- THREE.Object3D.prototype.clone.call( this, object );
- return object;
- };
|