|
@@ -5,47 +5,45 @@ const _vector1 = new Vector3();
|
|
|
const _vector2 = new Vector3();
|
|
|
const _normalMatrix = new Matrix3();
|
|
|
|
|
|
-function Plane( normal, constant ) {
|
|
|
+class Plane {
|
|
|
|
|
|
- // normal is assumed to be normalized
|
|
|
+ constructor( normal, constant ) {
|
|
|
|
|
|
- this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
|
|
|
- this.constant = ( constant !== undefined ) ? constant : 0;
|
|
|
+ // normal is assumed to be normalized
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
-Object.assign( Plane.prototype, {
|
|
|
+ this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
|
|
|
+ this.constant = ( constant !== undefined ) ? constant : 0;
|
|
|
|
|
|
- isPlane: true,
|
|
|
+ }
|
|
|
|
|
|
- set: function ( normal, constant ) {
|
|
|
+ set( normal, constant ) {
|
|
|
|
|
|
this.normal.copy( normal );
|
|
|
this.constant = constant;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setComponents: function ( x, y, z, w ) {
|
|
|
+ setComponents( x, y, z, w ) {
|
|
|
|
|
|
this.normal.set( x, y, z );
|
|
|
this.constant = w;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setFromNormalAndCoplanarPoint: function ( normal, point ) {
|
|
|
+ setFromNormalAndCoplanarPoint( normal, point ) {
|
|
|
|
|
|
this.normal.copy( normal );
|
|
|
this.constant = - point.dot( this.normal );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setFromCoplanarPoints: function ( a, b, c ) {
|
|
|
+ setFromCoplanarPoints( a, b, c ) {
|
|
|
|
|
|
const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
|
|
|
|
|
@@ -55,24 +53,24 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- clone: function () {
|
|
|
+ clone() {
|
|
|
|
|
|
return new this.constructor().copy( this );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copy: function ( plane ) {
|
|
|
+ copy( plane ) {
|
|
|
|
|
|
this.normal.copy( plane.normal );
|
|
|
this.constant = plane.constant;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- normalize: function () {
|
|
|
+ normalize() {
|
|
|
|
|
|
// Note: will lead to a divide by zero if the plane is invalid.
|
|
|
|
|
@@ -82,30 +80,30 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- negate: function () {
|
|
|
+ negate() {
|
|
|
|
|
|
this.constant *= - 1;
|
|
|
this.normal.negate();
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- distanceToPoint: function ( point ) {
|
|
|
+ distanceToPoint( point ) {
|
|
|
|
|
|
return this.normal.dot( point ) + this.constant;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- distanceToSphere: function ( sphere ) {
|
|
|
+ distanceToSphere( sphere ) {
|
|
|
|
|
|
return this.distanceToPoint( sphere.center ) - sphere.radius;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- projectPoint: function ( point, target ) {
|
|
|
+ projectPoint( point, target ) {
|
|
|
|
|
|
if ( target === undefined ) {
|
|
|
|
|
@@ -116,9 +114,9 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- intersectLine: function ( line, target ) {
|
|
|
+ intersectLine( line, target ) {
|
|
|
|
|
|
if ( target === undefined ) {
|
|
|
|
|
@@ -155,9 +153,9 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
return target.copy( direction ).multiplyScalar( t ).add( line.start );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- intersectsLine: function ( line ) {
|
|
|
+ intersectsLine( line ) {
|
|
|
|
|
|
// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
|
|
|
|
|
@@ -166,21 +164,21 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- intersectsBox: function ( box ) {
|
|
|
+ intersectsBox( box ) {
|
|
|
|
|
|
return box.intersectsPlane( this );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- intersectsSphere: function ( sphere ) {
|
|
|
+ intersectsSphere( sphere ) {
|
|
|
|
|
|
return sphere.intersectsPlane( this );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- coplanarPoint: function ( target ) {
|
|
|
+ coplanarPoint( target ) {
|
|
|
|
|
|
if ( target === undefined ) {
|
|
|
|
|
@@ -191,9 +189,9 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
return target.copy( this.normal ).multiplyScalar( - this.constant );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- applyMatrix4: function ( matrix, optionalNormalMatrix ) {
|
|
|
+ applyMatrix4( matrix, optionalNormalMatrix ) {
|
|
|
|
|
|
const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
|
|
|
|
|
@@ -205,23 +203,25 @@ Object.assign( Plane.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- translate: function ( offset ) {
|
|
|
+ translate( offset ) {
|
|
|
|
|
|
this.constant -= offset.dot( this.normal );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- equals: function ( plane ) {
|
|
|
+ equals( plane ) {
|
|
|
|
|
|
return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
+}
|
|
|
+
|
|
|
+Plane.prototype.isPlane = true;
|
|
|
|
|
|
|
|
|
export { Plane };
|