Skip to content
28 changes: 27 additions & 1 deletion packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,26 @@ 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;
if (updateCamera) {
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 +1776,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