|
@@ -5,14 +5,14 @@ import { Vector3 } from './Vector3.js';
|
|
|
* @author WestLangley / http://github.com/WestLangley
|
|
|
*/
|
|
|
|
|
|
-var points;
|
|
|
-var vector;
|
|
|
+var _points;
|
|
|
+var _vector;
|
|
|
|
|
|
-var v0, v1, v2;
|
|
|
-var f0, f1, f2;
|
|
|
-var center;
|
|
|
-var extents;
|
|
|
-var triangleNormal;
|
|
|
+var _v0, _v1, _v2;
|
|
|
+var _f0, _f1, _f2;
|
|
|
+var _center;
|
|
|
+var _extents;
|
|
|
+var _triangleNormal;
|
|
|
|
|
|
function Box3( min, max ) {
|
|
|
|
|
@@ -116,9 +116,9 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
setFromCenterAndSize: function ( center, size ) {
|
|
|
|
|
|
- if ( vector === undefined ) vector = new Vector3();
|
|
|
+ if ( _vector === undefined ) _vector = new Vector3();
|
|
|
|
|
|
- var halfSize = vector.copy( size ).multiplyScalar( 0.5 );
|
|
|
+ var halfSize = _vector.copy( size ).multiplyScalar( 0.5 );
|
|
|
|
|
|
this.min.copy( center ).sub( halfSize );
|
|
|
this.max.copy( center ).add( halfSize );
|
|
@@ -222,7 +222,7 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
expandByObject: function ( object ) {
|
|
|
|
|
|
- if ( vector === undefined ) vector = new Vector3();
|
|
|
+ if ( _vector === undefined ) _vector = new Vector3();
|
|
|
|
|
|
var i, l;
|
|
|
|
|
@@ -241,10 +241,10 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
for ( i = 0, l = vertices.length; i < l; i ++ ) {
|
|
|
|
|
|
- vector.copy( vertices[ i ] );
|
|
|
- vector.applyMatrix4( object.matrixWorld );
|
|
|
+ _vector.copy( vertices[ i ] );
|
|
|
+ _vector.applyMatrix4( object.matrixWorld );
|
|
|
|
|
|
- this.expandByPoint( vector );
|
|
|
+ this.expandByPoint( _vector );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -256,9 +256,9 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
for ( i = 0, l = attribute.count; i < l; i ++ ) {
|
|
|
|
|
|
- vector.fromBufferAttribute( attribute, i ).applyMatrix4( object.matrixWorld );
|
|
|
+ _vector.fromBufferAttribute( attribute, i ).applyMatrix4( object.matrixWorld );
|
|
|
|
|
|
- this.expandByPoint( vector );
|
|
|
+ this.expandByPoint( _vector );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -329,13 +329,13 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
intersectsSphere: function ( sphere ) {
|
|
|
|
|
|
- if ( vector === undefined ) vector = new Vector3();
|
|
|
+ if ( _vector === undefined ) _vector = new Vector3();
|
|
|
|
|
|
// Find the point on the AABB closest to the sphere center.
|
|
|
- this.clampPoint( sphere.center, vector );
|
|
|
+ this.clampPoint( sphere.center, _vector );
|
|
|
|
|
|
// If that point is inside the sphere, the AABB and sphere intersect.
|
|
|
- return vector.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
|
|
|
+ return _vector.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -388,23 +388,23 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
intersectsTriangle: function ( triangle ) {
|
|
|
|
|
|
- if ( v0 === undefined ) {
|
|
|
+ if ( _v0 === undefined ) {
|
|
|
|
|
|
// triangle centered vertices
|
|
|
|
|
|
- v0 = new Vector3();
|
|
|
- v1 = new Vector3();
|
|
|
- v2 = new Vector3();
|
|
|
+ _v0 = new Vector3();
|
|
|
+ _v1 = new Vector3();
|
|
|
+ _v2 = new Vector3();
|
|
|
|
|
|
// triangle edge vectors
|
|
|
|
|
|
- f0 = new Vector3();
|
|
|
- f1 = new Vector3();
|
|
|
- f2 = new Vector3();
|
|
|
+ _f0 = new Vector3();
|
|
|
+ _f1 = new Vector3();
|
|
|
+ _f2 = new Vector3();
|
|
|
|
|
|
- center = new Vector3();
|
|
|
- extents = new Vector3();
|
|
|
- triangleNormal = new Vector3();
|
|
|
+ _center = new Vector3();
|
|
|
+ _extents = new Vector3();
|
|
|
+ _triangleNormal = new Vector3();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -415,28 +415,28 @@ Object.assign( Box3.prototype, {
|
|
|
}
|
|
|
|
|
|
// compute box center and extents
|
|
|
- this.getCenter( center );
|
|
|
- extents.subVectors( this.max, center );
|
|
|
+ this.getCenter( _center );
|
|
|
+ _extents.subVectors( this.max, _center );
|
|
|
|
|
|
// translate triangle to aabb origin
|
|
|
- v0.subVectors( triangle.a, center );
|
|
|
- v1.subVectors( triangle.b, center );
|
|
|
- v2.subVectors( triangle.c, center );
|
|
|
+ _v0.subVectors( triangle.a, _center );
|
|
|
+ _v1.subVectors( triangle.b, _center );
|
|
|
+ _v2.subVectors( triangle.c, _center );
|
|
|
|
|
|
// compute edge vectors for triangle
|
|
|
- f0.subVectors( v1, v0 );
|
|
|
- f1.subVectors( v2, v1 );
|
|
|
- f2.subVectors( v0, v2 );
|
|
|
+ _f0.subVectors( _v1, _v0 );
|
|
|
+ _f1.subVectors( _v2, _v1 );
|
|
|
+ _f2.subVectors( _v0, _v2 );
|
|
|
|
|
|
// test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
|
|
|
// make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
|
|
|
// axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
|
|
|
var axes = [
|
|
|
- 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
|
|
|
- f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
|
|
|
- - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
|
|
|
+ 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
|
|
|
+ _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
|
|
|
+ - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
|
|
|
];
|
|
|
- if ( ! satForAxes( axes, v0, v1, v2, extents ) ) {
|
|
|
+ if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
|
|
|
|
|
|
return false;
|
|
|
|
|
@@ -444,7 +444,7 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
// test 3 face normals from the aabb
|
|
|
axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
|
|
|
- if ( ! satForAxes( axes, v0, v1, v2, extents ) ) {
|
|
|
+ if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
|
|
|
|
|
|
return false;
|
|
|
|
|
@@ -452,10 +452,10 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
// finally testing the face normal of the triangle
|
|
|
// use already existing triangle edge vectors here
|
|
|
- triangleNormal.crossVectors( f0, f1 );
|
|
|
- axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
|
|
|
+ _triangleNormal.crossVectors( _f0, _f1 );
|
|
|
+ axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
|
|
|
|
|
|
- return satForAxes( axes, v0, v1, v2, extents );
|
|
|
+ return satForAxes( axes, _v0, _v1, _v2, _extents );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -474,9 +474,9 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
distanceToPoint: function ( point ) {
|
|
|
|
|
|
- if ( vector === undefined ) vector = new Vector3();
|
|
|
+ if ( _vector === undefined ) _vector = new Vector3();
|
|
|
|
|
|
- var clampedPoint = vector.copy( point ).clamp( this.min, this.max );
|
|
|
+ var clampedPoint = _vector.copy( point ).clamp( this.min, this.max );
|
|
|
|
|
|
return clampedPoint.sub( point ).length();
|
|
|
|
|
@@ -484,7 +484,7 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
getBoundingSphere: function ( target ) {
|
|
|
|
|
|
- if ( vector === undefined ) vector = new Vector3();
|
|
|
+ if ( _vector === undefined ) _vector = new Vector3();
|
|
|
|
|
|
if ( target === undefined ) {
|
|
|
|
|
@@ -495,7 +495,7 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
this.getCenter( target.center );
|
|
|
|
|
|
- target.radius = this.getSize( vector ).length() * 0.5;
|
|
|
+ target.radius = this.getSize( _vector ).length() * 0.5;
|
|
|
|
|
|
return target;
|
|
|
|
|
@@ -524,9 +524,9 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
applyMatrix4: function ( matrix ) {
|
|
|
|
|
|
- if ( points === undefined ) {
|
|
|
+ if ( _points === undefined ) {
|
|
|
|
|
|
- points = [
|
|
|
+ _points = [
|
|
|
new Vector3(),
|
|
|
new Vector3(),
|
|
|
new Vector3(),
|
|
@@ -543,16 +543,16 @@ Object.assign( Box3.prototype, {
|
|
|
if ( this.isEmpty() ) return this;
|
|
|
|
|
|
// NOTE: I am using a binary pattern to specify all 2^3 combinations below
|
|
|
- points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
|
|
|
- points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
|
|
|
- points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
|
|
|
- points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
|
|
|
- points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
|
|
|
- points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
|
|
|
- points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
|
|
|
- points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
|
|
|
+ _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
|
|
|
+ _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
|
|
|
+ _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
|
|
|
+ _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
|
|
|
+ _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
|
|
|
+ _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
|
|
|
+ _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
|
|
|
+ _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
|
|
|
|
|
|
- this.setFromPoints( points );
|
|
|
+ this.setFromPoints( _points );
|
|
|
|
|
|
return this;
|
|
|
|
|
@@ -575,23 +575,23 @@ Object.assign( Box3.prototype, {
|
|
|
|
|
|
} );
|
|
|
|
|
|
-var testAxis;
|
|
|
+var _testAxis;
|
|
|
|
|
|
function satForAxes( axes, v0, v1, v2, extents ) {
|
|
|
|
|
|
- if ( testAxis === undefined ) testAxis = new Vector3();
|
|
|
+ if ( _testAxis === undefined ) _testAxis = new Vector3();
|
|
|
|
|
|
var i, j;
|
|
|
|
|
|
for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
|
|
|
|
|
|
- testAxis.fromArray( axes, i );
|
|
|
+ _testAxis.fromArray( axes, i );
|
|
|
// project the aabb onto the seperating axis
|
|
|
- var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
|
|
|
+ var r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
|
|
|
// project all 3 vertices of the triangle onto the seperating axis
|
|
|
- var p0 = v0.dot( testAxis );
|
|
|
- var p1 = v1.dot( testAxis );
|
|
|
- var p2 = v2.dot( testAxis );
|
|
|
+ var p0 = v0.dot( _testAxis );
|
|
|
+ var p1 = v1.dot( _testAxis );
|
|
|
+ var p2 = v2.dot( _testAxis );
|
|
|
// actual test, basically see if either of the most extreme of the triangle points intersects r
|
|
|
if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
|
|
|
|