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 (