@floless/app 0.144.0 → 0.145.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -580,6 +580,40 @@ export function revitObjectBounds(objects, includeHidden = false) {
580
580
  return box;
581
581
  }
582
582
 
583
+ /** How much nearer than a snap point a surface must be to hide it, in model millimetres. */
584
+ export const REVIT_SNAP_OCCLUSION_TOLERANCE_MM = 0.5;
585
+ const occlusionBoxes = new WeakMap();
586
+
587
+ /**
588
+ * Is `point` hidden from `origin` by a visible, un-clipped surface nearer than `tolerance` (render
589
+ * units) short of it? Only meshes whose world box the sight segment crosses are raycast, one at a time,
590
+ * and the answer is given at the first hit that counts — the same visibility rule as the surface pick.
591
+ */
592
+ export function revitSnapPointOccluded(point, origin, meshes, planes = [], tolerance = 0) {
593
+ if (!Array.isArray(origin) || !Array.isArray(point) || !meshes?.length) return false;
594
+ const from = new THREE.Vector3().fromArray(origin); const to = new THREE.Vector3().fromArray(point);
595
+ const length = from.distanceTo(to); const far = length - Math.max(0, tolerance);
596
+ if (!(far > 0)) return false;
597
+ const probe = new THREE.Raycaster(from, to.clone().sub(from).divideScalar(length), 0, far);
598
+ const entry = new THREE.Vector3(); const hits = [];
599
+ for (const mesh of meshes) {
600
+ if (!mesh?.visible) continue;
601
+ // World box cached per mesh, rebuilt when the mesh moves (its world matrix changes).
602
+ let cached = occlusionBoxes.get(mesh);
603
+ if (!cached || !cached.matrix.equals(mesh.matrixWorld)) {
604
+ if (!mesh.geometry.boundingBox) mesh.geometry.computeBoundingBox();
605
+ cached = { matrix: mesh.matrixWorld.clone(), box: mesh.geometry.boundingBox.clone().applyMatrix4(mesh.matrixWorld) };
606
+ occlusionBoxes.set(mesh, cached);
607
+ }
608
+ const box = cached.box;
609
+ const crossing = box.containsPoint(from) ? from : probe.ray.intersectBox(box, entry);
610
+ if (!crossing || from.distanceTo(crossing) > far) continue;
611
+ hits.length = 0; mesh.raycast(probe, hits);
612
+ if (hits.some((hit) => hit.distance <= far && planes.every((plane) => plane.distanceToPoint(hit.point) >= -1e-7))) return true;
613
+ }
614
+ return false;
615
+ }
616
+
583
617
  export function createRevitViewport({ canvas, onSelect = () => {}, onOutlineBuild = () => {}, formatDistance = (valueMm) => `${Math.round(valueMm)} mm`, includeHiddenSelectionBounds = false }) {
584
618
  if (typeof formatDistance !== 'function') throw new TypeError('Model viewport distance formatter must be a function.');
585
619
  const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: false }); renderer.setPixelRatio(Math.min(devicePixelRatio || 1, 2)); renderer.setClearColor(0x020817, 1); renderer.localClippingEnabled = true;
@@ -1297,6 +1331,32 @@ export function createRevitViewport({ canvas, onSelect = () => {}, onOutlineBuil
1297
1331
  side: mesh.material.side, metalness: mesh.material.metalness, roughness: mesh.material.roughness,
1298
1332
  })),
1299
1333
  pickSurface,
1334
+ // Where the pick ray through this pointer starts (the eye, or the near plane when orthographic), in
1335
+ // the same frame as pickSurface's hit. Snapping covers the sightline between the two (#1747).
1336
+ pointerRayOrigin(clientX, clientY) { return setRayAt(clientX, clientY)?.origin.toArray() ?? null; },
1337
+ // Snapping follows exactly what the surface pick follows (ownerHitsAt): only visible meshes, and
1338
+ // only what the section planes keep. An element is skipped whole when hidden or when its envelope
1339
+ // lies entirely on the cut-away side of a plane; a single point is kept only on the kept side.
1340
+ snapVisibility() {
1341
+ const planes = activeRenderPlanes;
1342
+ return {
1343
+ element(mesh, min, max) {
1344
+ if (!mesh?.visible) return false;
1345
+ return planes.every((plane) => {
1346
+ const n = plane.normal;
1347
+ return n.x * (n.x >= 0 ? max[0] : min[0]) + n.y * (n.y >= 0 ? max[1] : min[1]) + n.z * (n.z >= 0 ? max[2] : min[2]) + plane.constant >= -1e-7;
1348
+ });
1349
+ },
1350
+ point(point) {
1351
+ return planes.every((plane) => plane.normal.x * point[0] + plane.normal.y * point[1] + plane.normal.z * point[2] + plane.constant >= -1e-7);
1352
+ },
1353
+ // Hidden behind something nearer the eye? See revitSnapPointOccluded; the tolerance is a fixed
1354
+ // half millimetre of model length, whatever the viewing distance.
1355
+ occluded(point, origin, meshes) {
1356
+ return revitSnapPointOccluded(point, origin, meshes, planes, REVIT_SNAP_OCCLUSION_TOLERANCE_MM / geometryFrame.millimetresPerRenderUnit);
1357
+ },
1358
+ };
1359
+ },
1300
1360
  projectPoint(point) { const value = new THREE.Vector3().fromArray(point).project(camera); const rect = canvas.getBoundingClientRect(); return { x: rect.left + (value.x * .5 + .5) * rect.width, y: rect.top + (-value.y * .5 + .5) * rect.height, visible: value.z >= -1 && value.z <= 1 }; },
1301
1361
  // xeoRVT GLB millimetres cross the render boundary as metres (root scale 0.001). Convert only
1302
1362
  // the measured display value back here; persisted provider coordinates remain untouched.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.144.0",
3
+ "version": "0.145.0",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {