Skip to content

Commit

Permalink
Also resize the ortho camera when the viewport size changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jul 4, 2023
1 parent d8ed46e commit 66d9c6c
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/components/model-viewer/ModelViewerInternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,17 @@ async function initialize(
group.add(await buildOverlayAnnotation(textureManager, annotation));
}

const camera = new THREE.OrthographicCamera(
-viewportWidth / 2,
viewportWidth / 2,
viewportHeight / 2,
-viewportHeight / 2,
0,
30000
);
const camera = new THREE.OrthographicCamera();
camera.near = 0;
camera.far = 30000;

const updateCamera = (width: number, height: number) => {
camera.left = -width / 2;
camera.right = width / 2;
camera.top = height / 2;
camera.bottom = -height / 2;
};
updateCamera(viewportWidth, viewportHeight);

// group.position.copy(sceneCenter.negate());

Expand Down Expand Up @@ -221,8 +224,10 @@ async function initialize(
resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
if (entry.contentBoxSize) {
const size = entry.contentBoxSize[0];
renderer.setSize(size.inlineSize, size.blockSize);
const { inlineSize: width, blockSize: height } =
entry.contentBoxSize[0];
renderer.setSize(width, height);
updateCamera(width, height);
}
}
});
Expand Down

0 comments on commit 66d9c6c

Please sign in to comment.