* Returns `true` if the given triangle intersects with this bounding box. * * @param {Triangle} triangle - The triangle to test. * @return {boolean} Whether the given triangle intersects with this bounding box.
( triangle )
| 524 | * @return {boolean} Whether the given triangle intersects with this bounding box. |
| 525 | */ |
| 526 | intersectsTriangle( triangle ) { |
| 527 | |
| 528 | if ( this.isEmpty() ) { |
| 529 | |
| 530 | return false; |
| 531 | |
| 532 | } |
| 533 | |
| 534 | // compute box center and extents |
| 535 | this.getCenter( _center ); |
| 536 | _extents.subVectors( this.max, _center ); |
| 537 | |
| 538 | // translate triangle to aabb origin |
| 539 | _v0.subVectors( triangle.a, _center ); |
| 540 | _v1.subVectors( triangle.b, _center ); |
| 541 | _v2.subVectors( triangle.c, _center ); |
| 542 | |
| 543 | // compute edge vectors for triangle |
| 544 | _f0.subVectors( _v1, _v0 ); |
| 545 | _f1.subVectors( _v2, _v1 ); |
| 546 | _f2.subVectors( _v0, _v2 ); |
| 547 | |
| 548 | // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb |
| 549 | // 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 |
| 550 | // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned) |
| 551 | let axes = [ |
| 552 | 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y, |
| 553 | _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x, |
| 554 | - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0 |
| 555 | ]; |
| 556 | if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) { |
| 557 | |
| 558 | return false; |
| 559 | |
| 560 | } |
| 561 | |
| 562 | // test 3 face normals from the aabb |
| 563 | axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]; |
| 564 | if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) { |
| 565 | |
| 566 | return false; |
| 567 | |
| 568 | } |
| 569 | |
| 570 | // finally testing the face normal of the triangle |
| 571 | // use already existing triangle edge vectors here |
| 572 | _triangleNormal.crossVectors( _f0, _f1 ); |
| 573 | axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ]; |
| 574 | |
| 575 | return satForAxes( axes, _v0, _v1, _v2, _extents ); |
| 576 | |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Clamps the given point within the bounds of this box. |
no test coverage detected