Repository navigation
Description
Problem or motivation
Context. #1208 added repairWallTJunctions (packages/viewer/src/systems/wall/wall-t-junctions.ts), called from finishWallFaces in wall-system.tsx. It closes the T-junctions that CSG cuts, finish-band splits and terrain-fill seams leave on wall faces. As the PR says, they look closed at full float precision and only crack open into dotted light leaks once a GLB bake quantizes positions. The repair itself is sound: it never invents a vertex and keeps each piece's material group.
Problem. The repair runs on every wall build, including every live rebuild while drawing and editing. It is a sizeable share of the build, and nothing on screen needs it: the live renderer draws unquantized positions.
Measurements (Apple M-series, Bun 1.4.4, three r187, machine shared with other jobs, so medians of alternated runs):
| What | Repair on every build | Repair deferred | Note |
|---|---|---|---|
generatePlacedWall, 60 walls with a door and a window (one third curved, half the doors arched), 12 alternated pairs |
median 372 ms | median 284 ms | the repair is about 24% of the build |
| Same benchmark, earlier session | 271–309 ms | 212–239 ms | 20–25% |
| One-off repair at export time, same 60 walls (repair, normals, planar UVs) | — | median 122 ms | about 2 ms per wall, paid once per export |
Browser frame time for «send wall» (rAF, steady-state p50 in ms, editor dev build, our fork before the 1.0.7 merge versus after the merge with the deferred repair; medians of three alternated pairs, machine load 10–13). The numbers swing up to 3–5× between runs of the same build, so only large repeated differences mean something:
| Scene / view | Before the 1.0.7 merge | After, repair deferred |
|---|---|---|
| demo / plan | 134 | 80 |
| large (500 walls) / plan | 382 | 243 |
| large / plan + 3D side by side | 1403 | 1382 |
| demo / plan + 3D side by side | 114 | 154 |
With the repair on every rebuild (an earlier session) the same «send wall» was 20–26% slower than before the merge in demo/plan and large/side-by-side. The side-by-side 3D view is still slower than before the merge for reasons unrelated to this proposal (in our fork, mostly the retired solid look).
Proposed solution
Let callers choose when the repair runs. A minimal version of what we ship in our fork:
/** `repaired` (default) removes the T-junctions on every build. `deferred` leaves them and marks the geometry. */
export type WallTJunctionMode = 'repaired' | 'deferred'
export function generateExtrudedWall(
/* …existing parameters… */
tJunctions: WallTJunctionMode = 'repaired',
): THREE.BufferGeometryfinishWallFacesclassifies the faces as today; withdeferredit skipsrepairWallTJunctionsand setsgeometry.userData.wallTJunctions = 'deferred'.- The live
WallSystem(updateWallGeometry, and the collision mesh) passesdeferred. - A new
repairDeferredWallTJunctions(mesh)runs the same repair on a marked mesh (position and groups, then the same face-reason remap, normals and level-relative planar UVs as the live build), and drops the mark. - Export preparation (
startSceneExportPreparationinpackages/editor/src/lib/glb-export.ts, shared by GLB, USDZ, STL and 3MF) calls it on every cloned wall mesh, so every export is still crack-free. The live mesh is not touched: export works on its own clone. - Every other caller keeps today's behaviour, because the default is
repaired. The golden hashes and the existing T-junction tests are unchanged.
A test we added builds a T of two walls (one with a window) through runWallBuildFrame, exports it with prepareSceneForExport, writes a GLB with GLTFExporter and reads it back with GLTFLoader. The live mesh keeps its T-junctions, and the exported GLB has none (107 without the export hook, 0 with it). Area, UVs, normals and the per-triangle wallSurfaceAssignments are kept.
Alternatives considered
A module-level switch (setWallTJunctionRepair('export-only')) would have the same effect, but an explicit parameter keeps the default visible to every caller.
Additional context
Related small fix (already in our fork). Welding at 1e-6 m can merge two dense vertices of an arched or curved cut, which leaves a zero-area triangle. The section readers (readWallSurfaceMesh) reject it, so those walls dropped out of sections. In emit, a triangle without edge points that is degenerate after welding is now skipped (isDegenerate, exact cross product). Five hashes in wall-finish-plain-golden.json change; volume, bounds and per-material area do not.
We are happy to open a PR with both changes if that helps.
Reporter: Pietro Ditroia (Arkimensor).
Activity