Skip to content

Commit 480bb42

Browse files
committed
Math: Reverted code refactorings.
1 parent 15ab0e6 commit 480bb42

File tree

4 files changed

+96
-96
lines changed

4 files changed

+96
-96
lines changed

src/math/Box3.js

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,5 @@
11
import { Vector3 } from './Vector3.js';
22

3-
const _points = [
4-
/*@__PURE__*/ new Vector3(),
5-
/*@__PURE__*/ new Vector3(),
6-
/*@__PURE__*/ new Vector3(),
7-
/*@__PURE__*/ new Vector3(),
8-
/*@__PURE__*/ new Vector3(),
9-
/*@__PURE__*/ new Vector3(),
10-
/*@__PURE__*/ new Vector3(),
11-
/*@__PURE__*/ new Vector3()
12-
];
13-
14-
const _vector = /*@__PURE__*/ new Vector3();
15-
16-
const _box = /*@__PURE__*/ new Box3();
17-
18-
// triangle centered vertices
19-
20-
const _v0 = /*@__PURE__*/ new Vector3();
21-
const _v1 = /*@__PURE__*/ new Vector3();
22-
const _v2 = /*@__PURE__*/ new Vector3();
23-
24-
// triangle edge vectors
25-
26-
const _f0 = /*@__PURE__*/ new Vector3();
27-
const _f1 = /*@__PURE__*/ new Vector3();
28-
const _f2 = /*@__PURE__*/ new Vector3();
29-
30-
const _center = /*@__PURE__*/ new Vector3();
31-
const _extents = /*@__PURE__*/ new Vector3();
32-
const _triangleNormal = /*@__PURE__*/ new Vector3();
33-
const _testAxis = /*@__PURE__*/ new Vector3();
34-
35-
function satForAxes( axes, v0, v1, v2, extents ) {
36-
37-
for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
38-
39-
_testAxis.fromArray( axes, i );
40-
// project the aabb onto the seperating axis
41-
const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
42-
// project all 3 vertices of the triangle onto the seperating axis
43-
const p0 = v0.dot( _testAxis );
44-
const p1 = v1.dot( _testAxis );
45-
const p2 = v2.dot( _testAxis );
46-
// actual test, basically see if either of the most extreme of the triangle points intersects r
47-
if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
48-
49-
// points of the projected triangle are outside the projected half-length of the aabb
50-
// the axis is seperating and we can exit
51-
return false;
52-
53-
}
54-
55-
}
56-
57-
return true;
58-
59-
}
60-
613
class Box3 {
624

635
constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) {
@@ -550,4 +492,62 @@ class Box3 {
550492

551493
Box3.prototype.isBox3 = true;
552494

495+
const _points = [
496+
/*@__PURE__*/ new Vector3(),
497+
/*@__PURE__*/ new Vector3(),
498+
/*@__PURE__*/ new Vector3(),
499+
/*@__PURE__*/ new Vector3(),
500+
/*@__PURE__*/ new Vector3(),
501+
/*@__PURE__*/ new Vector3(),
502+
/*@__PURE__*/ new Vector3(),
503+
/*@__PURE__*/ new Vector3()
504+
];
505+
506+
const _vector = /*@__PURE__*/ new Vector3();
507+
508+
const _box = /*@__PURE__*/ new Box3();
509+
510+
// triangle centered vertices
511+
512+
const _v0 = /*@__PURE__*/ new Vector3();
513+
const _v1 = /*@__PURE__*/ new Vector3();
514+
const _v2 = /*@__PURE__*/ new Vector3();
515+
516+
// triangle edge vectors
517+
518+
const _f0 = /*@__PURE__*/ new Vector3();
519+
const _f1 = /*@__PURE__*/ new Vector3();
520+
const _f2 = /*@__PURE__*/ new Vector3();
521+
522+
const _center = /*@__PURE__*/ new Vector3();
523+
const _extents = /*@__PURE__*/ new Vector3();
524+
const _triangleNormal = /*@__PURE__*/ new Vector3();
525+
const _testAxis = /*@__PURE__*/ new Vector3();
526+
527+
function satForAxes( axes, v0, v1, v2, extents ) {
528+
529+
for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
530+
531+
_testAxis.fromArray( axes, i );
532+
// project the aabb onto the seperating axis
533+
const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
534+
// project all 3 vertices of the triangle onto the seperating axis
535+
const p0 = v0.dot( _testAxis );
536+
const p1 = v1.dot( _testAxis );
537+
const p2 = v2.dot( _testAxis );
538+
// actual test, basically see if either of the most extreme of the triangle points intersects r
539+
if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
540+
541+
// points of the projected triangle are outside the projected half-length of the aabb
542+
// the axis is seperating and we can exit
543+
return false;
544+
545+
}
546+
547+
}
548+
549+
return true;
550+
551+
}
552+
553553
export { Box3 };

src/math/Matrix4.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import { Vector3 } from './Vector3.js';
22

3-
const _v1 = /*@__PURE__*/ new Vector3();
4-
const _m1 = /*@__PURE__*/ new Matrix4();
5-
const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
6-
const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
7-
const _x = /*@__PURE__*/ new Vector3();
8-
const _y = /*@__PURE__*/ new Vector3();
9-
const _z = /*@__PURE__*/ new Vector3();
10-
113
class Matrix4 {
124

135
constructor() {
@@ -882,4 +874,12 @@ class Matrix4 {
882874

883875
Matrix4.prototype.isMatrix4 = true;
884876

877+
const _v1 = /*@__PURE__*/ new Vector3();
878+
const _m1 = /*@__PURE__*/ new Matrix4();
879+
const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
880+
const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
881+
const _x = /*@__PURE__*/ new Vector3();
882+
const _y = /*@__PURE__*/ new Vector3();
883+
const _z = /*@__PURE__*/ new Vector3();
884+
885885
export { Matrix4 };

src/math/Vector3.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { MathUtils } from './MathUtils.js';
22
import { Quaternion } from './Quaternion.js';
33

4-
const _vector = /*@__PURE__*/ new Vector3();
5-
const _quaternion = /*@__PURE__*/ new Quaternion();
6-
74
class Vector3 {
85

96
constructor( x = 0, y = 0, z = 0 ) {
@@ -718,4 +715,7 @@ class Vector3 {
718715

719716
Vector3.prototype.isVector3 = true;
720717

718+
const _vector = /*@__PURE__*/ new Vector3();
719+
const _quaternion = /*@__PURE__*/ new Quaternion();
720+
721721
export { Vector3 };

src/objects/Sprite.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,6 @@ const _uvA = /*@__PURE__*/ new Vector2();
2626
const _uvB = /*@__PURE__*/ new Vector2();
2727
const _uvC = /*@__PURE__*/ new Vector2();
2828

29-
function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
30-
31-
// compute position in camera space
32-
_alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
33-
34-
// to check if rotation is not zero
35-
if ( sin !== undefined ) {
36-
37-
_rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
38-
_rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
39-
40-
} else {
41-
42-
_rotatedPosition.copy( _alignedPosition );
43-
44-
}
45-
46-
47-
vertexPosition.copy( mvPosition );
48-
vertexPosition.x += _rotatedPosition.x;
49-
vertexPosition.y += _rotatedPosition.y;
50-
51-
// transform to world space
52-
vertexPosition.applyMatrix4( _viewWorldMatrix );
53-
54-
}
55-
5629
class Sprite extends Object3D {
5730

5831
constructor( material ) {
@@ -178,4 +151,31 @@ class Sprite extends Object3D {
178151

179152
Sprite.prototype.isSprite = true;
180153

154+
function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
155+
156+
// compute position in camera space
157+
_alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
158+
159+
// to check if rotation is not zero
160+
if ( sin !== undefined ) {
161+
162+
_rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
163+
_rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
164+
165+
} else {
166+
167+
_rotatedPosition.copy( _alignedPosition );
168+
169+
}
170+
171+
172+
vertexPosition.copy( mvPosition );
173+
vertexPosition.x += _rotatedPosition.x;
174+
vertexPosition.y += _rotatedPosition.y;
175+
176+
// transform to world space
177+
vertexPosition.applyMatrix4( _viewWorldMatrix );
178+
179+
}
180+
181181
export { Sprite };

0 commit comments

Comments
 (0)