fix(server-client): canonical origin/geometry_class + compact entity index (#1841)
Merged
LO
4mo ago+2113+2113+0123456789012345678901234567890123456789-533-533-012345678901234567890123456789
Fixes #1841.
Root cause
@ifc-lite/server-client had drifted into a degraded re-implementation of the canonical parser/geometry contract; it only "worked" because the server emitted the lowest-common-denominator representation. Two divergences:
- Geometry / slab collapse. The geometry pipeline stores
MeshData.positionsrelative to a per-meshorigin, but both parquet serializers droppedoriginandgeometry_class(no such columns), and the optimized instance table hadmesh_index/material_indexwith no per-instance transform. So origin-relative geometry collapsed onto the world origin, and deduplicated repeats (e.g. slabs) rendered every occurrence at the shared template coordinates — "N slabs collapse to one."convertServerMeshdropped even the fields the server did serialize. - Entity-index V8 ceiling.
decodeDataModelbuilt aMap<number, EntityMetadata>(one entry per entity → the ~16.7M2^24Map ceiling), whichserverDataModelthen re-materialized by hand into more per-entity Maps — instead of reusing the canonicalCompactEntityIndex.
Fix (upgrade + enforce the canonical contract)
- Geometry wire: standard + optimized parquet now emit
origin(Y-up,world = origin + position) andgeometry_class; the optimized path carries origin per instance so deduplicated templates place correctly. Decoders populateMeshData.origin/geometry_class;convertServerMesh(extracted to a pure, unit-tested util) forwards them. Additive + backward-compatible — absent columns decode as origin[0,0,0]/ class0, so world-baked payloads and older caches are byte-identical. - Entity index:
decodeDataModeldecodes into a compact columnarServerEntityIndex(typed arrays + binary search, Map-compatible read surface,.columnsfor bulk consumption);serverDataModelreuses the canonicalCompactEntityIndexforentityIndex.byId. No giant Map.DataModel.entitiestype changesMap→ServerEntityIndex(minor bump; Map-compatible read surface preserved). - Axis frame: the Z-up -> Y-up swap was open-coded in each parquet serializer and simply MISSING from the JSON route, so
POST /api/v1/parseshipped raw IFC Z-up while parquet shipped Y-up.services::axisis now the single definition and all three transports route through it. The JSON response cache is versioned separately so stale Z-up entries cannot be served. - Enforcement (never again): Rust contract tests pin that the mesh/instance tables carry
origin+geometry_classin the canonical frame.@ifc-lite/server-clienthad NO tests at all (that is why it could drift); it now has avitestsuite, wired socheck-test-wiringkeeps it wired. The pure "Arrow tables -> MeshData" half of the decoder is split intoparquet-tables.tsso the column contract is testable without booting parquet-wasm, and both builders share oneoriginIsUsableguard so the standard and instanced paths cannot disagree.
Verification
- Rust: 71
ifc-lite-servertests pass (incl. new axis + contract tests), clippy clean, module-size ratchet green. - TS: 20 new
@ifc-lite/server-clienttests, 1772 viewer tests pass, viewer typecheck 0 errors,check:api-surfacematches. - Changesets: geometry
patch+ entity-indexminor.
Behaviour change worth calling out
POST /api/v1/parse (the JSON transport) now returns Y-up like every other transport. For the viewer this is strictly a fix, but any external consumer that compensated for the old Z-up output would need to drop that compensation.
Out of scope (flagged for follow-up)
getGlobalIdMap()bakes the same V8 ~2^24Mapceiling into the canonicalDataStoreinterface, shared bypackages/data,packages/cacheand the server path. Fixing it only here would reintroduce the divergence this PR removes. Tracked in #1853.- Server-side instancing (
enable_instancing, default false, never set) would move occurrences intoProcessingResult.instances, which no serializer transports.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ddp5uELykicu1tGSrVmpnK
Summary by CodeRabbit
-
New Features
- Improved support for large models with more compact, efficient entity lookup while keeping familiar map-like access.
- Preserved per-mesh placement details and
geometry_classduring server transfer for consistent viewer rendering.
-
Bug Fixes
- Fixed geometry placement/origin for both standard and optimized (instanced) payloads, aligning all wire formats to the same Y-up conventions.
- Kept backward compatibility when placement metadata is missing, and improved JSON cache versioning to ensure updated responses are served.