Skip to content

Fix orthographic camera near and far parameters #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
26 changes: 25 additions & 1 deletion packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,24 @@ export class MainView extends React.Component<IProps, IStates> {
);
}

// Update near and far for orthographic camera if applicable
if (this._camera instanceof THREE.OrthographicCamera) {
const near = Math.max(this._refLength / 20, 0.01);
const far = this._refLength * 20;

const distance = this._camera.position.distanceTo(
this._controls.target
);
const zoomFactor = 1000 / distance;
this._camera.zoom = zoomFactor;

console.log(near, far);

this._camera.near = near;
this._camera.far = far;
this._camera.updateProjectionMatrix();
}

// Update clip plane size
this._clippingPlaneMeshControl.geometry = new THREE.PlaneGeometry(
this._refLength * 10,
Expand Down Expand Up @@ -1756,11 +1774,17 @@ export class MainView extends React.Component<IProps, IStates> {
const distance = position.distanceTo(target);
const zoomFactor = 1000 / distance;

const refLength = this._refLength ?? 1000; // Fallback value if undefined
const near = Math.max(refLength / 20, 0.01);
const far = refLength * 20;

this._camera = new THREE.OrthographicCamera(
width / -2,
width / 2,
height / 2,
height / -2
height / -2,
near,
far
);
this._camera.zoom = zoomFactor;
this._camera.updateProjectionMatrix();
Expand Down
Loading