From ce8b92a27b1c5ee72f326a1cb2b949b0a806ce9f Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 21 May 2026 14:52:52 +0000 Subject: [PATCH] Changes Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com> --- src/components/three/ModelViewer.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 (