feat(viewer,lists): location zones — classify elements by user-defined 3D zone boxes (#1810)
What the issue asked for, and how much this delivers
#1810 (from discussion #1763) asks to split/assign model elements by custom 3D zones (construction sections, takt areas): define volumes, figure out which volume(s) each element falls into, handle boundary-crossers by either geometric splitting or a per-zone quantity breakdown, support several zone sets at once, and end with a filterable/exportable per-element property. Louis's comment adds: it must work across multiple loaded models at once.
Delivered (v1):
- User-defined 3D zones as oriented boxes (Y-axis rotation only): numeric editing, 3D drag gizmo (move/resize/rotate), auto-generation from building storeys, JSON export/import + localStorage auto-persist.
- Per-element classification across every loaded (federated) model at once, recomputed automatically as models load/unload and zones change.
- Multiple independent zone sets ("Sections" AND "Takt areas") that never interfere.
- A
zonecolumn/condition source in@ifc-lite/lists(filter, group, CSV-export by zone), zone membership in the Properties panel, and "select everything in this zone".
Not delivered (honest gaps vs the ask): no geometric splitting at zone boundaries, and no pro-rated per-zone quantity breakdown for boundary-crossing elements — a straddler is flagged (straddles, with every touched zone listed) but its quantities are not apportioned. Zone volumes are boxes only (no arbitrary prisms / imported volumes), and the assignment is not written back into the IFC as a pset. Hence Refs #1810, not Closes.
Design
apps/viewer/src/lib/zones/— pure, unit-tested core: OBB math (geometry.ts), assignment engine (assignment.ts), storey generation (storey-generation.ts), versioned JSON persistence (persistence.ts,version: 1+ strict validation, migrations required for future shape changes).zonesSliceholds zone-set CRUD + the computed assignment cache;useZoneAssignmentSyncgathers world-space element AABBs from the rendererScene(which already foldsMeshData.origin, so local-frame elements far from the origin are correct) and runs the pure engine, debounced 200ms.- Scene mesh ids are federated global ids (
mesh.expressId + idOffsetat upload), so assignments are namespaced per model; unloading a model removes its entries on the next recompute, andresetViewerStatenow drops the assignment cache so a newly loaded model can't briefly read the old model's zone membership through colliding ids. - All coordinates are the viewer's world frame (Y-up, metres regardless of the source file's units — unit scaling happens in the geometry pipeline), so the fixed epsilons are scale-correct.
- Storey generation reuses the canonical
spatialHierarchy.storeyElevations(metres, the single storey-elevation channel consolidated in #1857) plus the hierarchy tree'selevationKey0.5m merge so a storey split across federated files yields ONE zone. It does not add anotherfindStoreyByElevationimplementation.
Zone-assignment semantics (plain terms)
- An element's home zone is the zone containing its AABB centroid.
- An element touches a zone only when its box really penetrates it by > 1mm (
STRADDLE_PENETRATION_M) — implemented as a negative epsilon on the SAT overlap test. This is deliberate: takt areas / sections tile the building sharing exact boundary planes, and a wall ending exactly at a shared boundary must not be flagged as straddling with zero actual overlap (that was the bug the last commit fixed; the flag would have flooded on precisely the models this feature targets). straddles= touches more than one zone, or touches a zone without its centroid being in any.- Geometry is never split; the flag + touched-zone list is informational.
Adversarial testing done
- Boundary/penetration edges: element ending exactly on a shared boundary (no straddle — tested), element penetrating 5cm past it (straddles — tested), degenerate zero-thickness AABB exactly on a boundary (unassigned, documented + tested), thin element deep inside a zone (still assigned — the negative-eps SAT only penalizes faces within 1mm of a zone face, not thin extents; verified by hand-tracing the interval math), huge AABB fully containing a zone (counts as touching; straddle when it spans several), rotated-zone false-positive corner case (SAT-exact, tested), zero-size and negative-size zones (negative sizes rejected on import, clamped to 0.05m minimum in both the panel and the gizmo; a degenerate zone matches nothing rather than crashing).
- Mutation check: flipped the negative epsilon back to positive (reverting the essence of the last commit) —
assignment.test.tsfails 2 tests; restored. The tests test behaviour, not the implementation. - Local-frame origin: verified
Scene.getEntityBoundingBoxaddspiece.originper piece (scene.ts) and caches instanced-occurrence AABBs at upload, so element bounds and zone boxes are compared in the same world space. - Multi-model: verified the upload path offsets mesh ids into the federated global-id space before the scene sees them; assignments are fully replaced on every recompute keyed off the
modelsmap reference +geometryUpdateTick, so unloading a model leaves no stale entries. Found and fixed the model-RESET hole (new commit):resetViewerStatecleared every other model-derived cache but keptzoneAssignments. - Lists multi-valued semantics: zero zones ->
nullcell; straddler -> touched names joined", "(same convention as the material source), soequals "Section A"intentionally excludes straddlers (usecontains);Straddlesis a separate boolean column; providers without zone data resolve tonull(backward compatible, tested). - Persistence: versioned (
version: 1), strict field validation, wrong-version/corrupt files fail loudly with a message instead of silently dropping zones (tested). Future shape changes must bump + migrate (documented intypes.ts).
Gates (actual results)
pnpm typecheck— 33/33 tasks successful.pnpm --filter @ifc-lite/viewer test— 1878 pass, 0 fail, 2 skipped.pnpm --filter @ifc-lite/lists test— 112 pass (5 files).node scripts/check-test-wiring.mjs— pass.node scripts/check-api-surface.mjs— pass (37 packages, 3945 exports; no new top-level exports, only members inside existing@ifc-lite/liststypes).pnpm docs:check-samples— 246 snippets clean.- Changeset:
.changeset/zone-column-source-1810.md,@ifc-lite/listsminor (additive on a 1.x package).docs/guide/lists.mdupdated in this PR.
Known limitations
- Straddlers are flagged, not split or quantity-apportioned (the biggest remaining piece of the original ask).
- Rotation gizmo drag is screen-space-approximate under oblique cameras (exact in top view; numeric field is always exact).
- Elements with no geometry (no scene mesh) are not classified — zone assignment is geometric by design.
- Zone boxes only (no prisms / imported volumes); assignment lives in viewer state + JSON export, not IFC psets.
Refs #1810
🤖 Generated with Claude Code
https://claude.ai/code/session_01M76mvdz8Hz7WHEoxwn694V
Summary by CodeRabbit
- New Features
- Added location zones for grouping model elements into customizable 3D zone sets.
- Create, rename, edit, delete, show, hide, import, and export zones.
- Generate zones automatically from building storeys.
- Select elements within a zone and view zone assignments in the Properties panel.
- Use zone names and straddling status in list columns and filters.
- Documentation
- Documented zone-based list columns, filters, and data-provider behavior.
- Tests
- Added coverage for zone geometry, assignments, persistence, and list integration.