diff --git a/src/components/three/ModelViewer.tsx b/src/components/three/ModelViewer.tsx index d7dd672..e886e3e 100644 --- a/src/components/three/ModelViewer.tsx +++ b/src/components/three/ModelViewer.tsx @@ -27,6 +27,18 @@ export function elementKey(modelId: string, el: THREE.Object3D): string { return `${modelId}:${id}`; } +/** Globally accessible ref to the active R3F scene (set by SceneRefCapture). */ +export const sceneRef: { current: THREE.Scene | null } = { current: null }; + +function SceneRefCapture() { + const { scene } = useThree(); + useEffect(() => { + sceneRef.current = scene; + return () => { if (sceneRef.current === scene) sceneRef.current = null; }; + }, [scene]); + return null; +} + function LoadingFallback() { return (