Skip to content

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

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

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
Contributor

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.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Maintainer] LGTM at b063e9c. Thanks @kruschdev, this is a clean implementation of #1273.

What I checked: the new tJunctions: 'repaired' | 'deferred' parameter is trailing with default 'repaired', so every existing caller, golden hash and T-junction test keeps its behavior. Live render and collision meshes pass 'deferred' and stamp geometry.userData.wallTJunctions; mergeWallTerrainFill now carries userData across its toNonIndexed() copy so the marker is not lost. repairDeferredWallTJunctions runs the repair on demand, rebuilds normals and the level-relative planar UVs, drops the marker, and returns whether triangles were split. finishSceneExportPreparation runs it on cloned meshes (cloning first when a geometry is shared, with a ref-count so a shared geometry is repaired once per mesh), so live viewer meshes are never mutated. The end-to-end test (T-junction with a window, export through GLTFExporter, parse back, 0 T-junctions, area/normals/UVs preserved) is exactly the right guard. No security surface.

One thing to double check, not a blocker: any consumer that reads wall geometry outside finishSceneExportPreparation (thumbnail or share-viewer bakes) will now see unrepaired geometry. The description says all bakes go through the shared prepare step; if you have confirmed that, great.

Status: GitHub Actions have not run on this head (fork workflows are waiting for maintainer approval), so it is not merge-ready until CI is green. Fixes #1273 is correct; it will close on merge.

@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks for the LGTM @Aymericr! Confirmed against main: both share-viewer bakes (packages/editor/src/components/editor/bake-exporter.tsx) and user exports (packages/editor/src/components/editor/export-manager.tsx) route through exportSceneToGlb / prepareSceneForExport -> finishSceneExportPreparation, and scene thumbnails (camera-controls:generate-thumbnail) are canvas screenshots rather than geometry bakes. Ready for CI whenever you can trigger it.

@Aymericr Aymericr added the bot:bugs label Dec 2, 2026 — with Cursor
Aymericr added a commit that referenced this pull request Dec 2, 2026
* core: slide door with transom to full opening height on sloped walls

Ported from #1304 (head 4a50d00).

Co-authored-by: kruschdev <249158235+kruschdev@users.noreply.github.com>

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

Ported from #1309 (head b063e9c).

Co-authored-by: kruschdev <249158235+kruschdev@users.noreply.github.com>

* i18n: tighten placeholder, tag, and ICU select validation

Ported from #1344 (head 32ec36e).

Co-authored-by: kruschdev <249158235+kruschdev@users.noreply.github.com>

* core(i18n): apply per-fallback-locale plural rules in PascalI18n

Ported from #1345 (head 03da2d2).

Co-authored-by: kruschdev <249158235+kruschdev@users.noreply.github.com>

* Revert "core(i18n): apply per-fallback-locale plural rules in PascalI18n"

This reverts commit f936404.

Co-authored-by: Aymeric Rabot <Aymericr@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: kruschdev <249158235+kruschdev@users.noreply.github.com>
Co-authored-by: Aymeric Rabot <Aymericr@users.noreply.github.com>

Aymericr commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thanks @kruschdev! This landed on main in #1347 (squash 4047d44), with you credited as co-author. Fork CI couldn't run here, so we ported it to a branch where it could. Closing this one as merged via #1347.

@Aymericr Aymericr closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

2 participants