diff --git a/src/pages/XRSession.tsx b/src/pages/XRSession.tsx index 7abd1b7..436ad82 100644 --- a/src/pages/XRSession.tsx +++ b/src/pages/XRSession.tsx @@ -359,10 +359,11 @@ function XRSnapHandler() { // ─── XR Grid ─────────────────────────────────────────── function XRGrid() { const showGrid = useModelStore((s) => s.showGrid); + const gridY = useModelStore((s) => s.gridY); if (!showGrid) return null; return ( s.models); + const { scene } = useThree(); + useEffect(() => { + if (!useModelStore.getState().gridAutoFollow) return; + const id = setTimeout(() => { + if (!useModelStore.getState().gridAutoFollow) return; + const box = new THREE.Box3(); + let has = false; + scene.traverse((obj) => { + if (obj instanceof THREE.Mesh && obj.geometry) { + if (obj.geometry instanceof THREE.SphereGeometry) return; + if (obj.geometry instanceof THREE.RingGeometry) return; + if (obj.userData.__edgeLine) return; + obj.updateWorldMatrix(true, false); + const b = new THREE.Box3().setFromObject(obj); + if (isFinite(b.min.y)) { + if (!has) { box.copy(b); has = true; } + else box.union(b); + } + } + }); + if (has) useModelStore.setState({ gridY: box.min.y - 0.005 }); + }, 150); + return () => clearTimeout(id); + }, [models, scene]); + return null; +} + // ImageTrackingAnchor removed — replaced by XRHitTestPlacement // ─── XRSession Page ────────────────────────────────────