|
1 | 1 | import { Vector3 } from './Vector3.js'; |
2 | 2 |
|
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 | | - |
61 | 3 | class Box3 { |
62 | 4 |
|
63 | 5 | constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) { |
@@ -550,4 +492,62 @@ class Box3 { |
550 | 492 |
|
551 | 493 | Box3.prototype.isBox3 = true; |
552 | 494 |
|
| 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 | + |
553 | 553 | export { Box3 }; |
0 commit comments