From adeab0acd1c1d2f76b88c11cc9fa3136eedcd1de 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:51:00 +0000 Subject: [PATCH] Changes Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com> --- src/components/three/ModelViewer.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/components/three/ModelViewer.tsx b/src/components/three/ModelViewer.tsx index 3d2a9f1..30429f1 100644 --- a/src/components/three/ModelViewer.tsx +++ b/src/components/three/ModelViewer.tsx @@ -10,6 +10,24 @@ interface ModelViewerProps { url?: string; // legacy, ignored — uses store.models } +/** Walk up the parent chain until we find a node tagged as `ifcElement`, + * or the model root. Returns null if neither found. */ +export function findElementRoot(obj: THREE.Object3D | null): THREE.Object3D | null { + let cur: THREE.Object3D | null = obj; + while (cur) { + if (cur.userData?.ifcElement) return cur; + cur = cur.parent; + } + return null; +} + +/** Stable key for an element across reloads: prefers ifcId, falls back to name. */ +export function elementKey(modelId: string, el: THREE.Object3D): string { + const id = el.userData?.ifcId ?? el.name ?? el.uuid; + return `${modelId}:${id}`; +} + + function LoadingFallback() { return (