Skip to content

Multi-head 1/7: 3MF export and combined-mask meshing - #96

Merged
vycdev merged 4 commits into
vycdev:developfrom
Bjohnson131:mph-split-1-export
Oct 31, 2026
Merged

vycdev merged 4 commits into
vycdev:developfrom
Bjohnson131:mph-split-1-export

Conversation

@Bjohnson131

Copy link
Copy Markdown
Contributor

First of seven stacked PRs splitting up #38 (Multi Print Head Capability) into smaller reviews. This one is independent of the others and targets develop directly.

What

  • 3MF export can write a multi-extruder project: an extruder count, per-layer pause (M600) markers for head swaps, and per-nozzle voxel meshes (voxelMesh.ts) so each head's material is its own object.
  • Smooth mesher gets an optional combinedMask so adjacent color groups move shared boundary vertices identically instead of peeling apart at shared edges.

Nothing calls the new export options yet; the UI wiring arrives in part 5.

Review focus

Slicer-safe topology (no T-junctions, open boundaries, inverted winding, non-manifold edges) in the voxel meshes and the combinedMask path.

Tests

tests/export3mf.test.ts and the new tests/meshingOptions.test.ts. tsc is clean, and the export and meshing tests pass (152).

Stack

  1. This PR: export and meshing
  2. Analysis core (mph-split-2-analysis-core)
  3. Run-based analysis engine (mph-split-3-color-runs)
  4. Head schedule and plan conversion (mph-split-4-schedule-plan)
  5. Worker, UI and export wiring (mph-split-5-ui-wiring)
  6. Docs and diagrams (mph-split-6-docs)
  7. Color grouping mode (mph-split-7-color-grouping)

🤖 Generated with Claude Code

Teach the 3MF exporter to write a multi-extruder project: an extruder
count, per-layer pause (M600) markers for head swaps, and per-nozzle
voxel meshes (voxelMesh) so each head's material is a separate object.
Add a combinedMask option to the smooth mesher so adjacent color groups
move shared boundary vertices identically instead of peeling apart.
Independent of the analysis code; nothing calls it yet.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Bjohnson131
Bjohnson131 marked this pull request as ready for review October 23, 2026 04:43
@Bjohnson131

Copy link
Copy Markdown
Contributor Author

Unit test results for this branch (npm test on mph-split-1-export): 873 tests, 872 passed, 0 failed, 1 skipped. Full output: https://gist.github.com/Bjohnson131/58348b01975e2da17ab1f0eab5c7603f (file test-results-mph-split-1-export.txt).

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated code review

Verdict: Needs changes · Findings: 4 (4 inline)

Scope: this PR's changes against develop; the earlier PRs in this stack are reviewed in their own threads.

The 65 focused export and meshing tests pass, and all three TypeScript configurations pass with incremental caching disabled. Direct checks nevertheless reproduced non-manifold voxel geometry, gaps between smoothed color groups, and loss of transforms and physical filament colors during voxel conversion. These issues need correction before the new paths are wired into the UI.


Reviewed by GPT 6.1 Sol

Comment thread src/lib/voxelMesh.ts Outdated
const vmap = new Map<string, number>();

const addV = (x: number, y: number, z: number): number => {
const key = `${Math.round(x * SNAP)},${Math.round(y * SNAP)},${Math.round(z * SNAP)}`;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[high] Diagonal voxel contacts create non-manifold edges

For a layer mask 10/01, the two voxels touch along a vertical edge. This coordinate map welds that edge into one with four incident triangles; inspectMeshIntegrity reports one non-manifold edge. Edge-only contacts across successive Z layers fail similarly. Resolve these contacts jointly across materials, or preserve independently closed shells through export, and add occupancy-based diagonal topology tests. The new BoxGeometry export fixtures bypass this voxel path.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/meshing.ts
// adjacent groups stay welded instead of each group smoothing them differently.
// Seam vertices interior to the combined solid never enter the graph and map to
// their original grid position in every group.
const solidPixels = combinedMask ?? meshingPixels;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[high] Combined-mask smoothing still leaves gaps at seam junctions

Sharing the coordinate mapper does not share the cap/wall subdivisions. For color rows AB, AB, A., using the same combined mask and skipRepair: true, A emits one right edge from grid (1,0) to (1,3), while B's seam ends at (1,2). Smoothing moves B's endpoint, but A never emits that vertex, leaving a reproduced gap of about 0.36 pixels. Include shared seam junctions in both groups' tessellation before smoothing.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/export3mf.ts
const geom = new THREE.BufferGeometry();
geom.userData.kromacutExportGeometry = { positions, indices, itemSize: 3 };
const mat = new THREE.MeshStandardMaterial({ color: '#' + hex });
const syntheticMesh = new THREE.Mesh(geom, mat);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[medium] Voxel conversion discards scene transforms

The synthetic mesh has an identity matrixWorld, while its vertices are rebuilt from untransformed mask coordinates. A tagged one-pixel mesh translated to (7,8,0) exports at (7,8) normally but at (0,0) with extruderCount: 2; rotations and scales are also lost. Preserve the source transform when rebuilding, or fall back to the original meshes when transforms cannot be represented safely, as the STL compaction path does.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/export3mf.ts
const mat = Array.isArray(mesh.material) ? mesh.material[0] : mesh.material;
let hex = 'FFFFFF';
if ('color' in mat) {
hex = (mat as THREE.MeshStandardMaterial).color.getHexString().toUpperCase();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[medium] Voxel conversion loses physical filament-color overrides

This reads the live preview material and discards the source mesh's physical filament metadata. A blue preview mesh tagged with kromacutFilamentHex: '#FF0000' exports red normally but blue with extruderCount: 2. The original layerFilamentColors indices can also become misaligned after meshes are collapsed and sorted by nozzle. Resolve physical colors on the original meshes before merging, then carry the representative filament color onto each synthetic mesh.

Reviewed by GPT 6.1 Sol

- Preserve indexed voxel surface fans at diagonal contacts and real Z gaps
- Share cap and wall subdivisions before combined-mask smoothing
- Retain transforms and unsupported geometry through safe conversion fallback
- Resolve physical filament colors before nozzle collapse and sorting
- Add occupancy and export regressions; update the unreleased changelog
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fixes for the automated review

Pushed 0d1bfb6 to this branch.

Findings

  • ✅ Diagonal voxel contacts create non-manifold edges: Paired voxel surface faces into separate indexed fans at diagonal contacts and preserved those indices through 3MF export. Added checks for all 255 nonempty 2×2×2 occupancies and serialized multi-material diagonal fixtures.

  • ✅ Combined-mask smoothing still leaves gaps at seam junctions: Subdivided combined-mask cap and wall boundaries at shared grid vertices before smoothing. Added seam-junction regressions for every smoothing strength.

  • ✅ Voxel conversion discards scene transforms: Voxel conversion now falls back to original geometry for transformed scenes. Tests verify translations, rotations, scales, and parent transforms match ordinary export.

  • ✅ Voxel conversion loses physical filament-color overrides: Resolved physical colors from original mesh metadata and original layerFilamentColors indices before collapsing and sorting by nozzle. Synthetic meshes retain the representative physical color.

Also fixed

  • Coordinate snapping welded real Z gaps: Removed coarse voxel-coordinate snapping and canonicalized only abutting planes. Added a regression for a 0.0001 mm gap.

  • Partial voxel conversion dropped unsupported meshes: Scenes containing unsupported meshes or incompatible grids now retain their original geometry instead of being partially replaced.

Verification: 162 meshing/export/voxel tests pass, run outside the sandbox.


Fixed by GPT 6.1 Sol

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated code review: second pass

Verdict: Needs changes · New or remaining findings: 3 (3 inline)

Reviewed head 0d1bfb6, which includes the fixes for the first review. Scope: this PR's changes against develop; the other PRs in this stack are reviewed in their own threads.

All four first-pass findings are resolved. The 162 focused tests, TypeScript check, and targeted ESLint check pass. Additional probes found three remaining defects: non-manifold diagonal color groups, discarded smoothing during multi-head export, and synchronous voxel reconstruction that blocks the UI.

First-pass findings

  • ✅ Resolved: Diagonal voxel contacts create non-manifold edges. Voxel faces now retain separate indexed surface fans, and export preserves those indices. The exhaustive 2×2×2 occupancy checks and serialized diagonal fixtures pass.
  • ✅ Resolved: Combined-mask smoothing still leaves gaps at seam junctions. Cap and wall boundaries now include shared unit-grid subdivisions before smoothing. The reported junction fixture passes for every smoothing strength.
  • ✅ Resolved: Voxel conversion discards scene transforms. Nonidentity world transforms trigger fallback to original geometry. Translation, rotation, scale, and parent-transform export comparisons pass.
  • ✅ Resolved: Voxel conversion loses physical filament-color overrides. Representative colors are resolved from original mesh metadata and original positional overrides before nozzle sorting and collapse. The physical-color regression passes.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/meshing.ts
const startedAt = performance.now();
const meshingPixels = repairBinaryCornerContacts(activePixels, width, height);
const skipBottomCap = options.skipBottomCap ?? false;
const meshingPixels = options.skipRepair

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[high] Preserve separate diagonal shells when skipping repair

For color rows AB/BA, generate A with skipRepair: true and a filled combinedMask. Both meshers still weld the diagonal pixels through their coordinate-based vertex maps, producing a vertical edge with four incident triangles; this reproduces at every smoothing strength. The voxel fix does not protect this meshing path. Preserve independent surface fans here, and assert indexed topology rather than only triangle counts in the skipRepair regression.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/export3mf.ts Outdated
return { mask: data.mask, baseZ: gl.baseZ_world, topZ: data.topZ_world };
});

const { positions, indices } = buildNozzleVoxelMesh(layerRecords, width, height, pixelSize);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[medium] Preserve smoothing when rebuilding nozzle geometry

This reconstruction ignores the source's smoothed positions and rebuilds square voxels from activePixels. A tagged one-pixel Medium mesh at pixel size 1 exports XY bounds approximately 0.34648–0.65352 normally, but 0–1 with extruderCount: 2, while still recording Medium metadata. Multi-head export therefore changes the physical shape and ignores the selected smoothing. Fall back for smoothed sources or preserve their shared smoothing map during reconstruction.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/export3mf.ts Outdated
// eliminates coincident faces at color- and layer-boundaries that cause
// non-manifold geometry in slicers.
if ((options?.extruderCount ?? 0) >= 2) {
const manifoldMeshes = buildNozzleManifoldMeshes(meshes, options?.layerFilamentColors);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[medium] Yield during per-nozzle voxel reconstruction

Mask merging, voxel generation, face pairing, and triangulation all run synchronously before the exporter's existing yields or progress reporting. Exporting one filled 256×256 layer blocked the first timer callback for about 0.7 seconds in a focused probe; larger images increase this UI freeze. Make reconstruction asynchronous with periodic yields and progress updates, or move it into a worker.

Reviewed by GPT 6.1 Sol

- Keep diagonal surface fans separately indexed through meshing and export
- Preserve original smoothed geometry during multi-head export
- Yield and report progress throughout nozzle reconstruction
- Add topology, smoothing, and responsiveness regressions; update changelog
vycdev added a commit to Bjohnson131/Kromacut-mph that referenced this pull request Oct 29, 2026
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fixes for the second automated review

Pushed 40c6d11 to this branch.

Findings

  • ✅ Preserve separate diagonal shells when skipping repair: Both meshers now keep diagonal surface fans separately indexed. Nozzle-tagged sources retain those indices through export. Regressions check indexed edge incidence, winding, and vertex fans across every smoothing strength.

  • ✅ Preserve smoothing when rebuilding nozzle geometry: Smoothed sources retain their original meshes instead of undergoing voxel reconstruction. Tests verify exported geometry matches ordinary export at every smoothing strength, including when strength metadata is omitted.

  • ✅ Yield during per-nozzle voxel reconstruction: Mask merging and voxel reconstruction now yield periodically and report progress. Tests verify timers run during reconstruction, every reconstruction phase yields, and asynchronous output matches synchronous geometry.

Verification: Full unit suite 890/890, tsc -b and lint pass, run outside the sandbox. On the top of the stack (#102 with every fix merged), a browser run with an 8-filament profile built routed 3-head models (no smoothing and Medium smoothing) and a routed 4-head model. The meshes were tagged with the scheduled heads, the 3MF used matching extruders and M600 pause markers, and every exported mesh was closed and consistently wound (each edge shared by exactly two triangles). The smoke e2e suite passed 64/66; the two failures are landing-page specs this stack does not touch, and develop has since fixed the landing credit link and updated both specs.


Fixed by GPT 6.1 Sol

@vycdev
vycdev merged commit 7b18fc6 into vycdev:develop Oct 31, 2026
vycdev added a commit that referenced this pull request Nov 1, 2026
@vycdev vycdev mentioned this pull request Nov 22, 2026
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.

2 participants