fix(server-client): canonical origin/geometry_class + compact entity index (#1841)

Merged
LO
4mo ago
+2113-533

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:

  1. Geometry / slab collapse. The geometry pipeline stores MeshData.positions relative to a per-mesh origin, but both parquet serializers dropped origin and geometry_class (no such columns), and the optimized instance table had mesh_index/material_index with 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." convertServerMesh dropped even the fields the server did serialize.
  2. Entity-index V8 ceiling. decodeDataModel built a Map<number, EntityMetadata> (one entry per entity → the ~16.7M 2^24 Map ceiling), which serverDataModel then re-materialized by hand into more per-entity Maps — instead of reusing the canonical CompactEntityIndex.

Fix (upgrade + enforce the canonical contract)

  • Geometry wire: standard + optimized parquet now emit origin (Y-up, world = origin + position) and geometry_class; the optimized path carries origin per instance so deduplicated templates place correctly. Decoders populate MeshData.origin/geometry_class; convertServerMesh (extracted to a pure, unit-tested util) forwards them. Additive + backward-compatible — absent columns decode as origin [0,0,0] / class 0, so world-baked payloads and older caches are byte-identical.
  • Entity index: decodeDataModel decodes into a compact columnar ServerEntityIndex (typed arrays + binary search, Map-compatible read surface, .columns for bulk consumption); serverDataModel reuses the canonical CompactEntityIndex for entityIndex.byId. No giant Map. DataModel.entities type changes Map → 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/parse shipped raw IFC Z-up while parquet shipped Y-up. services::axis is 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_class in the canonical frame. @ifc-lite/server-client had NO tests at all (that is why it could drift); it now has a vitest suite, wired so check-test-wiring keeps it wired. The pure "Arrow tables -> MeshData" half of the decoder is split into parquet-tables.ts so the column contract is testable without booting parquet-wasm, and both builders share one originIsUsable guard so the standard and instanced paths cannot disagree.

Verification

  • Rust: 71 ifc-lite-server tests pass (incl. new axis + contract tests), clippy clean, module-size ratchet green.
  • TS: 20 new @ifc-lite/server-client tests, 1772 viewer tests pass, viewer typecheck 0 errors, check:api-surface matches.
  • Changesets: geometry patch + entity-index minor.

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^24 Map ceiling into the canonical DataStore interface, shared by packages/data, packages/cache and 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 into ProcessingResult.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_class during 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.