Changes
Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user