|
@@ -37,11 +37,16 @@ Object.assign( Ray.prototype, {
|
|
|
|
|
|
},
|
|
|
|
|
|
- at: function ( t, optionalTarget ) {
|
|
|
+ at: function ( t, target ) {
|
|
|
|
|
|
- var result = optionalTarget || new Vector3();
|
|
|
+ if ( target === undefined ) {
|
|
|
|
|
|
- return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
|
|
|
+ console.warn( 'THREE.Ray: .at() target is now required' );
|
|
|
+ target = new Vector3();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -67,19 +72,26 @@ Object.assign( Ray.prototype, {
|
|
|
|
|
|
}(),
|
|
|
|
|
|
- closestPointToPoint: function ( point, optionalTarget ) {
|
|
|
+ closestPointToPoint: function ( point, target ) {
|
|
|
+
|
|
|
+ if ( target === undefined ) {
|
|
|
+
|
|
|
+ console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
|
|
|
+ target = new Vector3();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ target.subVectors( point, this.origin );
|
|
|
|
|
|
- var result = optionalTarget || new Vector3();
|
|
|
- result.subVectors( point, this.origin );
|
|
|
- var directionDistance = result.dot( this.direction );
|
|
|
+ var directionDistance = target.dot( this.direction );
|
|
|
|
|
|
if ( directionDistance < 0 ) {
|
|
|
|
|
|
- return result.copy( this.origin );
|
|
|
+ return target.copy( this.origin );
|
|
|
|
|
|
}
|
|
|
|
|
|
- return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
|
|
|
+ return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -244,7 +256,7 @@ Object.assign( Ray.prototype, {
|
|
|
|
|
|
var v1 = new Vector3();
|
|
|
|
|
|
- return function intersectSphere( sphere, optionalTarget ) {
|
|
|
+ return function intersectSphere( sphere, target ) {
|
|
|
|
|
|
v1.subVectors( sphere.center, this.origin );
|
|
|
var tca = v1.dot( this.direction );
|
|
@@ -267,10 +279,10 @@ Object.assign( Ray.prototype, {
|
|
|
// test to see if t0 is behind the ray:
|
|
|
// if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
|
|
|
// in order to always return an intersect point that is in front of the ray.
|
|
|
- if ( t0 < 0 ) return this.at( t1, optionalTarget );
|
|
|
+ if ( t0 < 0 ) return this.at( t1, target );
|
|
|
|
|
|
// else t0 is in front of the ray, so return the first collision point scaled by t0
|
|
|
- return this.at( t0, optionalTarget );
|
|
|
+ return this.at( t0, target );
|
|
|
|
|
|
};
|
|
|
|
|
@@ -309,7 +321,7 @@ Object.assign( Ray.prototype, {
|
|
|
|
|
|
},
|
|
|
|
|
|
- intersectPlane: function ( plane, optionalTarget ) {
|
|
|
+ intersectPlane: function ( plane, target ) {
|
|
|
|
|
|
var t = this.distanceToPlane( plane );
|
|
|
|
|
@@ -319,7 +331,7 @@ Object.assign( Ray.prototype, {
|
|
|
|
|
|
}
|
|
|
|
|
|
- return this.at( t, optionalTarget );
|
|
|
+ return this.at( t, target );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -349,7 +361,7 @@ Object.assign( Ray.prototype, {
|
|
|
|
|
|
},
|
|
|
|
|
|
- intersectBox: function ( box, optionalTarget ) {
|
|
|
+ intersectBox: function ( box, target ) {
|
|
|
|
|
|
var tmin, tmax, tymin, tymax, tzmin, tzmax;
|
|
|
|
|
@@ -414,7 +426,7 @@ Object.assign( Ray.prototype, {
|
|
|
|
|
|
if ( tmax < 0 ) return null;
|
|
|
|
|
|
- return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
|
|
|
+ return this.at( tmin >= 0 ? tmin : tmax, target );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -438,7 +450,7 @@ Object.assign( Ray.prototype, {
|
|
|
var edge2 = new Vector3();
|
|
|
var normal = new Vector3();
|
|
|
|
|
|
- return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
|
|
|
+ return function intersectTriangle( a, b, c, backfaceCulling, target ) {
|
|
|
|
|
|
// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
|
|
|
|
|
@@ -507,7 +519,7 @@ Object.assign( Ray.prototype, {
|
|
|
}
|
|
|
|
|
|
// Ray intersects triangle.
|
|
|
- return this.at( QdN / DdN, optionalTarget );
|
|
|
+ return this.at( QdN / DdN, target );
|
|
|
|
|
|
};
|
|
|
|