From 95e352830e25a83dd8a8a59479fa5d03e522bbeb 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:42 +0000 Subject: [PATCH] Changes Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com> --- src/components/ViewerControls.tsx | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/components/ViewerControls.tsx b/src/components/ViewerControls.tsx index 5a925e4..c953524 100644 --- a/src/components/ViewerControls.tsx +++ b/src/components/ViewerControls.tsx @@ -31,8 +31,40 @@ export function ViewerControls() { edgeThresholdAngle, setEdgeThresholdAngle, positionMode, setPositionMode, activeModelId, models, + selectionMode, setSelectionMode, + selectedElementKeys, hiddenElementKeys, isolatedElementKeys, + hideSelectedElements, isolateSelectedElements, showAllElements, clearElementSelection, } = useModelStore(); const activeModel = models.find(m => m.id === activeModelId); + const hasSelection = selectedElementKeys.size > 0; + const hasHiddenOrIsolated = hiddenElementKeys.size > 0 || isolatedElementKeys !== null; + + 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 objects: THREE.Object3D[] = []; + const collect = (root: THREE.Object3D) => { + const modelId = root.userData?.modelId as string | undefined; + if (!modelId) { root.children.forEach(collect); return; } + root.traverse((el) => { + if (!el.userData?.ifcElement) return; + if (selectedElementKeys.has(elementKey(modelId, el))) objects.push(el); + }); + }; + if (scene) collect(scene); + if (objects.length === 0) { + toast.error('Não foi possível localizar elementos selecionados. Use IFC para seleção persistente.'); + return; + } + const base = activeModel.fileName.replace(/\.(glb|gltf|ifc|obj|stl)$/i, ''); + await exportObjectsAsGLB(objects, `${base}_selecao_${objects.length}elem.glb`); + toast.success(`GLB exportado com ${objects.length} elemento(s)`); + }, [activeModel, selectedElementKeys]); const handleScreenshot = useCallback(() => { const canvas = document.querySelector('canvas');