Skip to content

Commit

Permalink
set near plane to a value relative to the far plane distance/glTF size
Browse files Browse the repository at this point in the history
  • Loading branch information
UX3D-labode committed Nov 6, 2020
1 parent bc8893f commit c38b8b9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/user_camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { jsToGl, clamp } from './utils.js';
import { getSceneExtends } from './gltf_utils.js';

const VecZero = vec3.create();
const panSpeedDenominator = 1200;
const PanSpeedDenominator = 1200;
const MaxNearFarRatio = 10000;

class UserCamera extends gltfCamera
{
Expand Down Expand Up @@ -87,7 +88,7 @@ class UserCamera extends gltfCamera
fitPanSpeedToScene(min, max)
{
const longestDistance = vec3.distance(min, max);
this.panSpeed = longestDistance / panSpeedDenominator;
this.panSpeed = longestDistance / PanSpeedDenominator;
}

fitViewToScene(gltf, sceneIndex)
Expand Down Expand Up @@ -145,8 +146,8 @@ class UserCamera extends gltfCamera
let zNear = this.zoom - (longestDistance * 0.6);
let zFar = this.zoom + (longestDistance * 0.6);

zNear = Math.max(zNear, Number.EPSILON); // should not be negative
zFar = Math.abs(zFar);
// minimum near plane value needs to depend on far plane value to avoid z fighting or too large near planes
zNear = Math.max(zNear, zFar / MaxNearFarRatio);

this.znear = zNear;
this.zfar = zFar;
Expand Down

0 comments on commit c38b8b9

Please sign in to comment.