diff --git a/src/components/three/ModelViewer.tsx b/src/components/three/ModelViewer.tsx index 5ca093f..71e4772 100644 --- a/src/components/three/ModelViewer.tsx +++ b/src/components/three/ModelViewer.tsx @@ -61,15 +61,9 @@ function SceneRefCapture() { return () => { if (sceneRef.current === scene) sceneRef.current = null; }; }, [scene]); useEffect(() => { - // Expose the main camera to the ViewCube bus - // (lazy-imported to avoid circular deps) - import('./viewCubeBus').then(({ mainCameraRef }) => { - mainCameraRef.current = camera; - }); + mainCameraRef.current = camera; return () => { - import('./viewCubeBus').then(({ mainCameraRef }) => { - if (mainCameraRef.current === camera) mainCameraRef.current = null; - }); + if (mainCameraRef.current === camera) mainCameraRef.current = null; }; }, [camera]); return null; @@ -79,18 +73,17 @@ function SceneRefCapture() { function ViewCubeAnimator() { const { camera } = useThree(); useFrame((_state, delta) => { - // Eager require to avoid async stalling per-frame - const bus = require('./viewCubeBus'); - const anim = bus.viewAnim; - if (!anim.active) return; - anim.t = Math.min(1, anim.t + delta / anim.duration); - const k = anim.t < 0.5 ? 2 * anim.t * anim.t : 1 - Math.pow(-2 * anim.t + 2, 2) / 2; - camera.position.lerpVectors(anim.startPos, anim.endPos, k); - camera.up.lerpVectors(anim.startUp, anim.endUp, k).normalize(); - const controls = bus.mainControlsRef.current; + if (!viewAnim.active) return; + viewAnim.t = Math.min(1, viewAnim.t + delta / viewAnim.duration); + const k = viewAnim.t < 0.5 + ? 2 * viewAnim.t * viewAnim.t + : 1 - Math.pow(-2 * viewAnim.t + 2, 2) / 2; + camera.position.lerpVectors(viewAnim.startPos, viewAnim.endPos, k); + camera.up.lerpVectors(viewAnim.startUp, viewAnim.endUp, k).normalize(); + const controls = mainControlsRef.current; if (controls?.target) camera.lookAt(controls.target); controls?.update?.(); - if (anim.t >= 1) anim.active = false; + if (viewAnim.t >= 1) viewAnim.active = false; }); return null; }