diff --git a/src/components/ViewerControls.tsx b/src/components/ViewerControls.tsx index 7b867e4..4cfa60c 100644 --- a/src/components/ViewerControls.tsx +++ b/src/components/ViewerControls.tsx @@ -41,12 +41,8 @@ export function ViewerControls() { const handleExportSelection = useCallback(async () => { if (!activeModel || selectedElementKeys.size === 0) return; - const canvas = document.querySelector('canvas') as HTMLCanvasElement | null; - if (!canvas) { toast.error('Canvas não encontrado'); return; } - // Walk the global scene to find selected element nodes - const scene = (canvas as unknown as { __r3f?: { fiber?: { scene?: THREE.Scene } } }).__r3f?.fiber?.scene - ?? (window as unknown as { __r3fScene?: THREE.Scene }).__r3fScene; - // Fallback: scan via DOM-attached three scene exposed by drei? Use traversal of stored models — use document approach + const scene = sceneRef.current; + if (!scene) { toast.error('Cena 3D não disponível'); return; } const objects: THREE.Object3D[] = []; const collect = (root: THREE.Object3D) => { const modelId = root.userData?.modelId as string | undefined; @@ -56,7 +52,7 @@ export function ViewerControls() { if (selectedElementKeys.has(elementKey(modelId, el))) objects.push(el); }); }; - if (scene) collect(scene); + collect(scene); if (objects.length === 0) { toast.error('Não foi possível localizar elementos selecionados. Use IFC para seleção persistente.'); return;