|
@@ -5,6 +5,8 @@ import { Vector3 } from './Vector3.js';
|
|
|
* @author bhouston / http://clara.io
|
|
|
*/
|
|
|
|
|
|
+var _vector1, _vector2, _normalMatrix;
|
|
|
+
|
|
|
function Plane( normal, constant ) {
|
|
|
|
|
|
// normal is assumed to be normalized
|
|
@@ -45,24 +47,24 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
},
|
|
|
|
|
|
- setFromCoplanarPoints: function () {
|
|
|
+ setFromCoplanarPoints: function ( a, b, c ) {
|
|
|
|
|
|
- var v1 = new Vector3();
|
|
|
- var v2 = new Vector3();
|
|
|
+ if ( _vector1 === undefined ) {
|
|
|
|
|
|
- return function setFromCoplanarPoints( a, b, c ) {
|
|
|
+ _vector1 = new Vector3();
|
|
|
+ _vector2 = new Vector3();
|
|
|
|
|
|
- var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
|
|
|
+ }
|
|
|
|
|
|
- // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
|
|
|
+ var normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
|
|
|
|
|
|
- this.setFromNormalAndCoplanarPoint( normal, a );
|
|
|
+ // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
|
|
|
|
|
|
- return this;
|
|
|
+ this.setFromNormalAndCoplanarPoint( normal, a );
|
|
|
|
|
|
- };
|
|
|
+ return this;
|
|
|
|
|
|
- }(),
|
|
|
+ },
|
|
|
|
|
|
clone: function () {
|
|
|
|
|
@@ -125,50 +127,46 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
},
|
|
|
|
|
|
- intersectLine: function () {
|
|
|
-
|
|
|
- var v1 = new Vector3();
|
|
|
+ intersectLine: function ( line, target ) {
|
|
|
|
|
|
- return function intersectLine( line, target ) {
|
|
|
+ if ( _vector1 === undefined ) _vector1 = new Vector3();
|
|
|
|
|
|
- if ( target === undefined ) {
|
|
|
-
|
|
|
- console.warn( 'THREE.Plane: .intersectLine() target is now required' );
|
|
|
- target = new Vector3();
|
|
|
-
|
|
|
- }
|
|
|
+ if ( target === undefined ) {
|
|
|
|
|
|
- var direction = line.delta( v1 );
|
|
|
+ console.warn( 'THREE.Plane: .intersectLine() target is now required' );
|
|
|
+ target = new Vector3();
|
|
|
|
|
|
- var denominator = this.normal.dot( direction );
|
|
|
+ }
|
|
|
|
|
|
- if ( denominator === 0 ) {
|
|
|
+ var direction = line.delta( _vector1 );
|
|
|
|
|
|
- // line is coplanar, return origin
|
|
|
- if ( this.distanceToPoint( line.start ) === 0 ) {
|
|
|
+ var denominator = this.normal.dot( direction );
|
|
|
|
|
|
- return target.copy( line.start );
|
|
|
+ if ( denominator === 0 ) {
|
|
|
|
|
|
- }
|
|
|
+ // line is coplanar, return origin
|
|
|
+ if ( this.distanceToPoint( line.start ) === 0 ) {
|
|
|
|
|
|
- // Unsure if this is the correct method to handle this case.
|
|
|
- return undefined;
|
|
|
+ return target.copy( line.start );
|
|
|
|
|
|
}
|
|
|
|
|
|
- var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
|
|
|
+ // Unsure if this is the correct method to handle this case.
|
|
|
+ return undefined;
|
|
|
|
|
|
- if ( t < 0 || t > 1 ) {
|
|
|
+ }
|
|
|
|
|
|
- return undefined;
|
|
|
+ var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
|
|
|
|
|
|
- }
|
|
|
+ if ( t < 0 || t > 1 ) {
|
|
|
|
|
|
- return target.copy( direction ).multiplyScalar( t ).add( line.start );
|
|
|
+ return undefined;
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- }(),
|
|
|
+ return target.copy( direction ).multiplyScalar( t ).add( line.start );
|
|
|
+
|
|
|
+ },
|
|
|
|
|
|
intersectsLine: function ( line ) {
|
|
|
|
|
@@ -206,26 +204,26 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
},
|
|
|
|
|
|
- applyMatrix4: function () {
|
|
|
+ applyMatrix4: function ( matrix, optionalNormalMatrix ) {
|
|
|
|
|
|
- var v1 = new Vector3();
|
|
|
- var m1 = new Matrix3();
|
|
|
+ if ( _normalMatrix === undefined ) {
|
|
|
|
|
|
- return function applyMatrix4( matrix, optionalNormalMatrix ) {
|
|
|
+ _normalMatrix = new Matrix3();
|
|
|
+ _vector1 = new Vector3();
|
|
|
|
|
|
- var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
|
|
|
+ }
|
|
|
|
|
|
- var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
|
|
|
+ var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
|
|
|
|
|
|
- var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
|
|
|
+ var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
|
|
|
|
|
|
- this.constant = - referencePoint.dot( normal );
|
|
|
+ var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
|
|
|
|
|
|
- return this;
|
|
|
+ this.constant = - referencePoint.dot( normal );
|
|
|
|
|
|
- };
|
|
|
+ return this;
|
|
|
|
|
|
- }(),
|
|
|
+ },
|
|
|
|
|
|
translate: function ( offset ) {
|
|
|
|