|
1 | | -import { Plane, Vector3, MathUtils, PlaneHelper } from 'three'; |
| 1 | +import { Plane, Vector3 } from 'three'; |
2 | 2 | import { isYProjectedTriangleDegenerate } from './triangleLineUtils.js'; |
3 | 3 |
|
4 | 4 | const EPSILON = 1e-16; |
@@ -35,8 +35,7 @@ export function trimToBeneathTriPlane( tri, line, lineTarget ) { |
35 | 35 | line.delta( _lineDirection ).normalize(); |
36 | 36 | if ( Math.abs( _plane.normal.dot( _lineDirection ) ) < EPSILON ) { |
37 | 37 |
|
38 | | - // if the line is definitely above or on the plane then skip it |
39 | | - if ( ( isStartOnPlane || ! isStartBelow ) && ( isEndOnPlane || ! isEndBelow ) ) { |
| 38 | + if ( isStartOnPlane || ! isStartBelow ) { |
40 | 39 |
|
41 | 40 | return false; |
42 | 41 |
|
@@ -64,20 +63,40 @@ export function trimToBeneathTriPlane( tri, line, lineTarget ) { |
64 | 63 |
|
65 | 64 | } else { |
66 | 65 |
|
67 | | - const t = MathUtils.mapLinear( 0, startDist, endDist, 0, 1 ); |
68 | | - line.at( t, _planeHit ); |
| 66 | + let didHit = _plane.intersectLine( line, _planeHit ); |
| 67 | + if ( ! didHit ) { |
69 | 68 |
|
70 | | - if ( isStartBelow ) { |
| 69 | + if ( isStartOnPlane ) { |
71 | 70 |
|
72 | | - lineTarget.start.copy( line.start ); |
73 | | - lineTarget.end.copy( _planeHit ); |
74 | | - return true; |
| 71 | + _planeHit.copy( line.start ); |
| 72 | + didHit = true; |
75 | 73 |
|
76 | | - } else if ( isEndBelow ) { |
| 74 | + } |
77 | 75 |
|
78 | | - lineTarget.end.copy( line.end ); |
79 | | - lineTarget.start.copy( _planeHit ); |
80 | | - return true; |
| 76 | + if ( isEndOnPlane ) { |
| 77 | + |
| 78 | + _planeHit.copy( line.end ); |
| 79 | + didHit = true; |
| 80 | + |
| 81 | + } |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + if ( didHit ) { |
| 86 | + |
| 87 | + if ( isStartBelow ) { |
| 88 | + |
| 89 | + lineTarget.start.copy( line.start ); |
| 90 | + lineTarget.end.copy( _planeHit ); |
| 91 | + return true; |
| 92 | + |
| 93 | + } else if ( isEndBelow ) { |
| 94 | + |
| 95 | + lineTarget.end.copy( line.end ); |
| 96 | + lineTarget.start.copy( _planeHit ); |
| 97 | + return true; |
| 98 | + |
| 99 | + } |
81 | 100 |
|
82 | 101 | } |
83 | 102 |
|
|
0 commit comments