From 6b16009b5bca6819b648bc729e628cdffbb38e9f 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 17:11:54 +0000 Subject: [PATCH] Changes Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com> --- src/components/three/ModelViewer.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/three/ModelViewer.tsx b/src/components/three/ModelViewer.tsx index 81200d6..24e460e 100644 --- a/src/components/three/ModelViewer.tsx +++ b/src/components/three/ModelViewer.tsx @@ -10,15 +10,35 @@ 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. */ +function isPickableModelMesh(obj: THREE.Object3D): obj is THREE.Mesh { + if (!(obj instanceof THREE.Mesh)) return false; + if (obj.userData.__edgeLine) return false; + if (obj.geometry instanceof THREE.SphereGeometry) return false; + if (obj.geometry instanceof THREE.RingGeometry) return false; + if (obj.geometry instanceof THREE.PlaneGeometry) return false; + return true; +} + +/** Walk up the parent chain until we find a node tagged as `ifcElement`. + * Falls back to the clicked mesh so older/demo GLBs without IFC metadata + * still support selection/highlight. */ export function findElementRoot(obj: THREE.Object3D | null): THREE.Object3D | null { + const fallback = isPickableModelMesh(obj as THREE.Object3D) ? obj : null; let cur: THREE.Object3D | null = obj; while (cur) { if (cur.userData?.ifcElement) return cur; cur = cur.parent; } - return null; + return fallback; +} + +function hasIfcAncestor(obj: THREE.Object3D): boolean { + let cur = obj.parent; + while (cur) { + if (cur.userData?.ifcElement) return true; + cur = cur.parent; + } + return false; } /** Stable key for an element across reloads: prefers ifcId, falls back to name. */