Skip to content

Multi-head 5/7: worker, UI and export wiring - #100

Merged
vycdev merged 16 commits into
vycdev:developfrom
Bjohnson131:mph-split-5-ui-wiring
Nov 1, 2026
Merged

vycdev merged 16 commits into
vycdev:developfrom
Bjohnson131:mph-split-5-ui-wiring

Conversation

@Bjohnson131

Copy link
Copy Markdown
Contributor

Fifth of seven PRs splitting up #38 (Multi Print Head Capability). This is the part users see.

Depends on #96, #97, #98 and #99. Until they merge, this diff also shows those parts (the branch merges #96's branch). The new wiring is multiHead.worker.ts, useMultiHeadWorker.ts, useSwapPlan.ts and the Auto-paint, 3D controls, Print Instructions and App.tsx changes.

What

  • A Multi-head mode in the Auto-paint tab: head count (2-8) and search depth (Fast/Balanced/Thorough). The analysis runs in a background worker so the UI stays responsive.
  • Building generates a Head Schedule in Print Instructions (initial head load and each swap checkpoint), and 3MF export writes the extruder count and those checkpoints as pause (M600) markers so it works on an ordinary single-nozzle printer.
  • If the analysis cannot produce a usable plan (worker error, or no layout that beats the normal stack), the build falls back to a normal single-head model and shows a notice, rather than exporting a multi-head 3MF with guessed head assignments.
  • Multi-head mode and Flat Paint are mutually exclusive.
  • Settings persist with the rest of the auto-paint setup.

Known limitation

The 3D preview still shows the flat auto-paint colors. Per-pixel color mixing and per-nozzle mesh tagging are not ported to the layered build yet (marked TODO in ThreeDView.tsx); exported pause markers are unaffected.

Tests

No new unit tests of its own: the hooks and UI logic here are not unit-tested yet. tsc is clean and the full unit suite passes (978 tests, 0 failures, 1 skipped).

Series

  1. Export and meshing (Multi-head 1/7: 3MF export and combined-mask meshing #96)
  2. Analysis core (Multi-head 2/7: window analysis core #97)
  3. Run-based analysis engine (Multi-head 3/7: run-based analysis engine #98)
  4. Head schedule and plan conversion (Multi-head 4/7: head schedule and plan conversion #99)
  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

Bjohnson131 and others added 3 commits October 22, 2026 23:33
Add a Multi-head mode to the Auto-paint tab (head count 2-8, search
depth) that runs the analysis in a background worker, falls back to a
normal single-head build with a notice when no usable plan is found,
and is mutually exclusive with Flat Paint. Builds generate a Head
Schedule in Print Instructions, and 3MF export writes the extruder
count and swap checkpoints as pause markers. Settings persist with the
rest of the auto-paint setup. The 3D preview still shows flat
auto-paint colors; per-pixel mixing and per-nozzle mesh tagging are not
ported to the layered build yet (see TODO in ThreeDView).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Also drop the docs-page sentence from the Multi-head changelog entry; the
docs page lands in a later PR.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Bjohnson131

Copy link
Copy Markdown
Contributor Author

Unit test results for this branch (npm test on mph-split-5-ui-wiring): 978 tests, 977 passed, 0 failed, 1 skipped. Full output: https://gist.github.com/Bjohnson131/58348b01975e2da17ab1f0eab5c7603f (file test-results-mph-split-5-ui-wiring.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: only what this PR adds on top of #96 + #99; the earlier PRs in this stack are reviewed in their own threads.

The worker, controls, persistence and schedule wiring are present, but multi-head exports can use incorrect head assignments. The asynchronous build and fallback instructions also have correctness issues, and the required translation check fails. TypeScript checks and ESLint passed; npm test reported 977 passes and one failure in the unchanged Windows file-association test. Local export and render reproductions confirmed incorrect extruder routing and hidden fallback instructions.


Reviewed by GPT 6.1 Sol

Comment thread src/App.tsx Outdated
builtModelState.autoPaintFilamentSwatches
)?.map((s) => s.hex)
: undefined,
extruderCount: multiHeadExportReady

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] Multi-head exports use material order instead of head assignments

This enables multi-extruder export after a successful analysis, but ThreeDView never consumes the new filament/nozzle maps or sets mesh.userData.nozzleIndex. The exporter therefore assigns matIdx + 1, clamped to the head count. In a two-head model with several layer colors, later layers are assigned to head 2 even when the Head Schedule requires head 1; per-pixel filament assignments are also discarded. Generate and tag the geometry using the actual filament/nozzle assignments before enabling this export path, or retain a valid single-head fallback.

Reviewed by GPT 6.1 Sol

Comment thread src/components/AutoPaintTab.tsx Outdated
htmlFor="multi-head-mode"
className="text-xs font-semibold text-foreground cursor-pointer"
>
Multi-head mode

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] New UI strings fail the mandatory build check

node scripts/check-i18n-ui.mjs exits with coverage errors for the new Multi-head controls and Head Schedule text. Because npm run build starts with npm run check:i18n, these additions block builds and deployment despite TypeScript passing. Add translation keys and catalog entries, and render the new text through t/Trans, including the additions in PrintInstructions.tsx.

Reviewed by GPT 6.1 Sol

hex: s.hex,
count: (s as { count?: number }).count,
}));
activeResult = await runMultiHead({

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] An analysis can apply an obsolete image snapshot after the image changes

Nothing invalidates this awaited build when imageSrc changes. The controls remain mounted when switching to 2D, and the worker only terminates on another run or unmount. Start analysis for image A, switch to 2D and upload image B, then let analysis finish: this callback applies A's result and printableFeaturePixels to B. For equal-sized images, ThreeDView uses that stale pixel buffer, so the exported model can contain A's artwork. Associate the build with an image revision and discard or cancel obsolete work before calling onChange.

Reviewed by GPT 6.1 Sol

Comment thread src/components/ThreeDControls.tsx Outdated
<PrintInstructions
swapPlan={swapPlan}
multiHeadPlan={multiHeadPlan}
multiHeadMode={multiHeadMode && paintMode === 'autopaint'}

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] Single-head fallback builds hide their swap instructions

When analysis fails or finds no improving layout, the built snapshot correctly stores multiHeadMode: false, but the local toggle remains true. Passing that requested mode here makes PrintInstructions show “Build 3D Model” when multiHeadPlan is null, hiding the fallback model's valid start color and swaps even after a successful build. Derive the instruction mode from builtState when a built model exists, and reserve the pending-schedule prompt for an unbuilt model.

Reviewed by GPT 6.1 Sol

- Generate routed multi-head regions with shared topology and physical nozzle tags
- Match 3MF extruders, filament colors, and pauses to the built Head Schedule
- Preserve single-head fallback instructions and cancel obsolete analyses
- Settle worker failures and analyze the cleaned printable palette
- Localize controls and guides and add routing, export, topology, and lifecycle regressions
- Translate build errors without rebuilding the model on language changes
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fixes for the automated review

Pushed 8864f81 to this branch.

This branch also merges the fixed lower layers (#96 and #99), so it builds on the corrected code.

Findings

  • ✅ Multi-head exports use material order instead of head assignments: Successful plans now generate per-color, per-layer geometry with simulated preview colors, physical filament metadata, and 1-based nozzle tags. Shared tessellation preserves closed, joined regions across all smoothing strengths. Export uses the selected head count and Head Schedule swap checkpoints; failed or unusable analyses retain the single-head fallback.

  • ✅ New UI strings fail the mandatory build check: Localized controls, notices, schedule display, copied instructions, and diagnostics in all 12 catalogs. Updated all localized Auto-paint guides; i18n, translation, release-note, and diagram checks pass.

  • ✅ An analysis can apply an obsolete image snapshot after the image changes: Retained image-scoped build revisions, worker cancellation, and stale-result guards. Regression coverage includes equal-sized image replacements, cancellation, and unmount invalidation.

  • ✅ Single-head fallback builds hide their swap instructions: Instructions use the built snapshot’s mode, schedule, and filaments. Tests verify fallback start colors and swaps remain visible, and successful schedules remain independent of pending settings.

Also fixed

  • Handle synchronous worker failures: Worker construction and postMessage exceptions settle requests and clear busy state, allowing the promised fallback.

  • Analyze the same colors used by printable geometry: Multi-head analysis now receives the cleaned printable palette and frequencies used by Auto-paint, keeping routing aligned with the actual pixel snapshot.

Behavior change vs. the PR description: the "Known limitation" no longer applies. Successful analyses now build routed per-color geometry, the 3D preview shows the routed colors, and the 3MF writes the head count as extruders plus M600 markers at the Head Schedule's swap checkpoints. The single-head fallback (with its notice) is kept only for failed or non-improving analyses. One small follow-up edit was made on top of Codex's work so a language switch does not rebuild the 3D model.

Verification: Full unit suite 1,019/1,019 passes. E2E smoke specs pass (Flat Paint, height dithering, browser export flow, printable detail, smoothing strengths). A browser run with an 8-filament profile built a routed 3-head model: meshes tagged with heads 1-3, a 3MF using extruders 1-3 and 3 M600 pause markers; at 2 heads it fell back to the normal model with the fallback notice.


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: 2 (2 inline)

Reviewed head 8864f81, which includes the fixes for the first review. Scope: only what this PR adds on top of #96 + #99; the other PRs in this stack are reviewed in their own threads.

The four original findings are resolved. Two new edge cases still prevent valid multi-head builds: selecting more heads than available filaments, and printable colors with zero regional weight. TypeScript, i18n, and documentation checks passed; 1,018/1,019 unit tests passed, with only the documented NSIS sandbox failure.

First-pass findings

  • ✅ Resolved: Multi-head exports use material order instead of head assignments. Successful builds now generate geometry from per-color filament paths and attach physical filament metadata and 1-based nozzle tags. Export tests verify assignments, geometry, colors, and schedule pauses.
  • ✅ Resolved: New UI strings fail the mandatory build check. The controls, schedules, notices, and copied instructions use localized messages across all 12 catalogs. npm run check:i18n passes.
  • ✅ Resolved: An analysis can apply an obsolete image snapshot after the image changes. Image changes and unmount invalidate the build revision and cancel the worker. The awaited analysis checks that revision before publishing its snapshot.
  • ✅ Resolved: Single-head fallback builds hide their swap instructions. Instruction mode and routing data now follow the built snapshot. Fallback rendering tests confirm that the original start color and swaps remain visible.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/multiHeadBuild.ts
patchedSliceData.swatches.length !== layerCount ||
nozzleAssignments.length !== multiHeadWindows.length ||
windowRunFilaments.length !== multiHeadWindows.length ||
nozzleAssignments.some((heads) => heads.length !== multiHeadCount) ||

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] Valid plans are rejected when head count exceeds filament count

The analyzer clamps its head slots to Math.min(n, filaments.length, MAX_MULTI_HEAD_HEADS), but this validator compares their length against the unchanged selected count. I reproduced an improving two-filament analysis that builds successfully with 2 selected heads but falls back with the default 4, reporting that no improving layout exists. Pad nozzle assignments and non-windowed ranges with unused slots up to the selected physical head count before validation, so the schedule and export can retain those EMPTY heads.

Reviewed by GPT 6.1 Sol

(data[source + 1] << 8) |
data[source + 2];
const height = targets.get(key);
if (height === undefined) throw new Error(translate('printing:multiHead.invalidPlan'));

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] Handle printable colors omitted from weighted target mappings

Regional weighting can give a printable color zero weight, and final-stack generation omits those target mappings. For example, with edge priority, a color occurring only at the image's center has zero weight. I reproduced a successful routed analysis for such an image, but this lookup returns undefined and aborts the geometry build. Resolve missing colors through the same printable-palette fallback used by the analyzer's buildPixelData, and add regression coverage for zero-weight colors.

Reviewed by GPT 6.1 Sol

- Pad unused physical head slots before validating routed plans
- Resolve omitted target colors through printable-palette matching
- Cover unused heads, zero-weight colors, dithering, and routed geometry
- Update the unreleased Multi-head changelog entry
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 1e2dbd8 to this branch.

This branch merges the second-round fixes from the lower layers (#96 and #99), so it builds on the corrected code.

Findings

  • ✅ Valid plans are rejected when head count exceeds filament count: Padded window assignments and non-windowed ranges before validation. Tests verify 2, 4, and 8 selected heads preserve EMPTY slots, schedule entries, and export head counts without mutating analysis results.

  • ✅ Handle printable colors omitted from weighted target mappings: Added the analyzer-equivalent printable-palette fallback to geometry height mapping. Regression coverage verifies zero-weight color heights, existing mappings, dithering, filament routing, and closed geometry.

Verification: After the merges: full unit suite 1,032/1,032, tsc -b, lint and check:i18n pass. 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 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

Multi-head fixes merged in

Pushed b9fdc69 to this branch. It merges the fixes from #98 (windows when heads outnumber color runs) and #99 (per-color rendering without fitted optics). There are no other changes in this PR.

Verification: after the merge, full unit suite 1,034/1,034, tsc -b, lint and check:i18n pass.


Fixed by Claude Opus 5.5

@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Search fix merged in

Pushed ce8b5d0 to this branch. It merges the #98 sampling fix, so large windows keep the reorders that smaller windows find. There are no other changes in this PR.

Verification: after the merge, full unit suite 1,036/1,036, tsc -b, lint and check:i18n pass.


Fixed by Claude Opus 5.5

- Pass the final stack's appearance model to per-color rendering, so routed
  previews use the same calibration evidence as single-head builds
- Fall back to the normal stack when the predicted usage-weighted mean
  CIEDE2000 gain is below 0.25, since small gains do not justify head swaps
- Make test fixtures' predicted colors describe their own stacks
- Test the fallback, usage weighting, and corrected preview colors
vycdev added a commit to Bjohnson131/Kromacut-mph that referenced this pull request Oct 31, 2026
…o mph-split-6-docs

# Conflicts:
#	CHANGELOG.md
@vycdev

vycdev commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Note

🤖 Claude Opus 5.5 responding on behalf of Victor Sandu

Routed previews now use the full appearance model, and builds fall back when the predicted gain is too small to justify the head swaps. Pushed 1c206ad, on top of a merge of the #99 fix.

  • Preview: multiHeadBuildSnapshot passes the final stack's appearance model to per-color rendering, so routed colors use the same calibration evidence as single-head builds.
  • Gain check: a build falls back unless its predicted gain over the normal stack is at least MIN_MULTI_HEAD_PREDICTED_GAIN, measured as usage-weighted mean CIEDE2000. The existing fallback notice is shown. The value, 0.25, is a judgment call rather than a measured limit.

Which tested head counts route:

Test Layer-based (default) Color-based
Rocco, no proofs 2, 3, 7, 8 (falls back at 4–6) 2, 3, 4, 7
cats, real proofs 4 (falls back at 2, 3, 6) 4 (falls back at 2, 3)
Rocco palette, real proofs none of 2–4 none of 2–4

In the last row, the layouts the search picked at 3 and 4 heads are predicted to be worse than single-head by 0.13 to 2.69; at 2 heads it finds no window. Those builds used to route. Rocco Layer-based at 4–6 heads falls back because CIEDE2000 barely moves, even though CIE76 improves by 3–4.5, so default-mode users will see the fallback more often. Better search results are tracked in #113.

The test fixtures changed too: their predicted colors now describe their own stacks.

Verified: after the merge, unit suite 1,041/1,041, tsc -b, lint and check:i18n pass. Browser results are on #102, which contains this change.

@vycdev
vycdev merged commit 0e666f1 into vycdev:develop Nov 1, 2026
vycdev added a commit that referenced this pull request Nov 1, 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