Skip to content

Commit

Permalink
Set the camera near value based on distance the ellipsoid surface (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson authored Feb 21, 2024
1 parent e899a41 commit 77673af
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/three/controls/GlobeControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ export class GlobeControls extends EnvironmentControls {
}

// update the projection matrix
// interpolate from the 25% radius margin around the globe down to the surface
// so we can avoid z fighting when near value is too far at a high altitude
const largestDistance = Math.max( ...ellipsoid.radius );
camera.near = Math.max( 1, distanceToCenter - largestDistance * 1.25 );
const margin = 0.25 * largestDistance;
const alpha = MathUtils.clamp( ( distanceToCenter - largestDistance ) / margin, 0, 1 );
const minNear = MathUtils.lerp( 1, 1000, alpha );
camera.near = Math.max( minNear, distanceToCenter - largestDistance - margin );

// update the far plane to the horizon distance
const invMatrix = _invMatrix.copy( tilesGroup.matrixWorld ).invert();
Expand Down

0 comments on commit 77673af

Please sign in to comment.