-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GlobeControls limit Frustum with horizon for performance (#483)
* GlobeControls limit Frustum with horizon * add custom Frustum * fix obb intersectsFrustum false positive * revert mistake change * fix obb planes * document new ellippsoid methods * make obb more readable * Ellipsoid fix getPositionElevation * add comment to explain horizon edge cases * clean PR * Small style changes --------- Co-authored-by: Garrett Johnson <[email protected]>
- Loading branch information
1 parent
5d15614
commit f46d417
Showing
7 changed files
with
210 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Frustum, Matrix3, Vector3 } from 'three'; | ||
|
||
const _mat3 = new Matrix3(); | ||
|
||
// Solve a system of equations to find the point where the three planes intersect | ||
function findIntersectionPoint( plane1, plane2, plane3, target ) { | ||
|
||
// Create the matrix A using the normals of the planes as rows | ||
const A = _mat3.set( | ||
plane1.normal.x, plane1.normal.y, plane1.normal.z, | ||
plane2.normal.x, plane2.normal.y, plane2.normal.z, | ||
plane3.normal.x, plane3.normal.y, plane3.normal.z | ||
); | ||
|
||
// Create the vector B using the constants of the planes | ||
target.set( - plane1.constant, - plane2.constant, - plane3.constant ); | ||
|
||
// Solve for X by applying the inverse matrix to B | ||
target.applyMatrix3( A.invert() ); | ||
|
||
return target; | ||
|
||
} | ||
|
||
class ExtendedFrustum extends Frustum { | ||
|
||
constructor() { | ||
|
||
super(); | ||
this.points = Array( 8 ).fill().map( () => new Vector3() ); | ||
|
||
} | ||
|
||
setFromProjectionMatrix( m, coordinateSystem ) { | ||
|
||
super.setFromProjectionMatrix( m, coordinateSystem ); | ||
this.calculateFrustumPoints(); | ||
|
||
} | ||
|
||
calculateFrustumPoints() { | ||
|
||
const { planes, points } = this; | ||
const planeIntersections = [ | ||
[ planes[ 0 ], planes[ 3 ], planes[ 4 ] ], // Near top left | ||
[ planes[ 1 ], planes[ 3 ], planes[ 4 ] ], // Near top right | ||
[ planes[ 0 ], planes[ 2 ], planes[ 4 ] ], // Near bottom left | ||
[ planes[ 1 ], planes[ 2 ], planes[ 4 ] ], // Near bottom right | ||
[ planes[ 0 ], planes[ 3 ], planes[ 5 ] ], // Far top left | ||
[ planes[ 1 ], planes[ 3 ], planes[ 5 ] ], // Far top right | ||
[ planes[ 0 ], planes[ 2 ], planes[ 5 ] ], // Far bottom left | ||
[ planes[ 1 ], planes[ 2 ], planes[ 5 ] ], // Far bottom right | ||
]; | ||
|
||
planeIntersections.forEach( ( planes, index ) => { | ||
|
||
findIntersectionPoint( planes[ 0 ], planes[ 1 ], planes[ 2 ], points[ index ] ); | ||
|
||
} ); | ||
|
||
} | ||
|
||
} | ||
|
||
export { ExtendedFrustum }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters