From 2f3e98a22feda3fa9eefdcc9b8e56ee0c4a24b67 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 7 Feb 2024 21:55:41 -0600 Subject: [PATCH] chore(web): correct ordering of camera updates in map viewer animation loop --- .../src/components/core/MapViewer/index.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/spelunker-web/src/components/core/MapViewer/index.jsx b/packages/spelunker-web/src/components/core/MapViewer/index.jsx index 6b80478..2f6b7ce 100644 --- a/packages/spelunker-web/src/components/core/MapViewer/index.jsx +++ b/packages/spelunker-web/src/components/core/MapViewer/index.jsx @@ -93,16 +93,21 @@ const MapViewer = ({ map: { id, filename } }) => { const animate = () => { const delta = clock.getDelta(); - mapManager.setTarget(camera.position.x, camera.position.y); - setCurrentPosition({ x: camera.position.x, y: camera.position.y, z: camera.position.z }); - controls.update(delta); - mapManager.update(delta, camera); // Adjust far clip (reduce draw calls by matching frustum to fog distance) camera.far = mapManager.cameraFar; camera.updateProjectionMatrix(); + // Ensure camera world matrices are up-to-date before camera is used in culling or bone + // matrix calculations + camera.updateMatrixWorld(); + + mapManager.setTarget(camera.position.x, camera.position.y); + setCurrentPosition({ x: camera.position.x, y: camera.position.y, z: camera.position.z }); + + mapManager.update(delta, camera); + renderer.setClearColor(mapManager.clearColor); renderer.render(scene, camera);