Skip to content

viewer,editor: defer wall T-junction repair to export preparation - #1309

Open
kruschdev wants to merge 1 commit into
pascalorg:mainfrom
kruschdev:perf/defer-wall-t-junction-repair
Open

kruschdev wants to merge 1 commit into
pascalorg:mainfrom
kruschdev:perf/defer-wall-t-junction-repair

Conversation

@kruschdev

@kruschdev kruschdev commented Nov 23, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes #1273

Previously, finishWallFaces ran repairWallTJunctions on every wall geometry build, including every live rebuild during drawing and editing. The repair exists to prevent dotted light leaks once quantized by GLB/export bakes, while the live renderer draws full-precision float geometry.

I updated @pascal-app/viewer and @pascal-app/editor so live wall rebuilds defer T-junction repair and export preparation runs it on demand on cloned meshes:

  • Explicit repair mode (packages/viewer/src/systems/wall/wall-system.tsx, packages/viewer/src/index.ts): Added export type WallTJunctionMode = 'repaired' | 'deferred' and an optional trailing tJunctions: WallTJunctionMode = 'repaired' parameter on generateExtrudedWall (threaded through finishWallFaces and mergeWallTerrainFill). Because the default stays 'repaired', every existing caller, golden hash, and T-junction test keeps its existing behavior.
  • Deferred live rebuilds (updateWallGeometry): Both the live render wall mesh and its collision-mesh pass 'deferred', skipping repairWallTJunctions during interactive editing and marking geometry.userData.wallTJunctions = 'deferred'.
  • On-demand export repair (repairDeferredWallTJunctions, packages/editor/src/lib/glb-export.ts): Exported repairDeferredWallTJunctions(mesh), which runs repairWallTJunctions on marked meshes, preserves material groups and non-marker userData, recomputes normals and level-relative planar UVs (applyWorldPlanarWallUVs), refreshes bounds, and clears userData.wallTJunctions. finishSceneExportPreparation (shared across GLB, USDZ, STL, 3MF, and viewer bakes) invokes it on cloned deferred wall meshes (cloning first if a geometry is shared) so exports remain crack-free without mutating live viewer meshes.
  • Tests: Extended packages/viewer/src/systems/wall/wall-t-junctions.test.ts to verify deferred marking and repairDeferredWallTJunctions, and added packages/editor/src/lib/glb-export-wall-t-junctions.test.ts building a T-junction of walls with a window through runWallBuildFrame, exporting via prepareSceneForExport + GLTFExporter, and parsing back with GLTFLoader to verify live meshes stay deferred while exported GLB meshes have 0 T-junctions and preserved area, normals, and UVs.

How to test

  1. Run bunx biome check packages/viewer/src/systems/wall/wall-system.tsx packages/viewer/src/systems/wall/wall-t-junctions.test.ts packages/viewer/src/index.ts packages/editor/src/lib/glb-export.ts packages/editor/src/lib/glb-export-wall-t-junctions.test.ts.
  2. Run bunx turbo run build check-types --filter=@pascal-app/viewer --filter=@pascal-app/editor.
  3. Run bun test packages/viewer/src/systems/wall/wall-t-junctions.test.ts packages/viewer/src/systems/wall/wall-finish-geometry.test.ts packages/viewer/src/systems/wall/wall-opening-cutout.test.ts packages/editor/src/lib/glb-export-wall-t-junctions.test.ts packages/editor/src/lib/glb-export.test.ts (90 pass, 0 fail).

Screenshots / screen recording

N/A (geometry build and export-preparation optimization; live wall rendering and committed golden hashes are unchanged).

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

Note

Medium Risk
Changes wall geometry timing and export preparation for all baked formats, but defaults remain 'repaired' for non-live callers and export still enforces zero T-junctions.

Overview
Live wall rebuilds now skip repairWallTJunctions during interactive editing by threading a new WallTJunctionMode ('repaired' | 'deferred') through generateExtrudedWall, finishWallFaces, and mergeWallTerrainFill. updateWallGeometry passes 'deferred' for render and collision meshes, stamping geometry.userData.wallTJunctions = 'deferred' instead of splitting triangles every drag.

Export runs repair only on cloned meshes: repairDeferredWallTJunctions (re-exported from viewer) fixes T-junctions, restores normals/UVs, and clears the marker; finishSceneExportPreparation walks the export scene, cloning shared geometries before repair so live viewer meshes stay untouched.

Tests cover deferred build + on-demand repair in the viewer and a T-junction GLB round-trip via prepareSceneForExport.

Reviewed by Cursor Bugbot for commit b063e9c. Bugbot is set up for automated code reviews on this repo. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Walls: run the T-junction repair on demand (export only), not on every rebuild

1 participant