Skip to content

Give each Auto-paint color its own filament stack for better colors and thinner Flat Paint (#151) - #223

Merged
vycdev merged 12 commits into
developfrom
feat/issue-151-region-stacks
Nov 23, 2026
Merged

vycdev merged 12 commits into
developfrom
feat/issue-151-region-stacks

Conversation

@vycdev

@vycdev vycdev commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #151.

Auto-paint gives every color the first layers of one shared filament sequence. So if one color needs an unusual stack, every color above it prints those layers too, and colors that need unrelated stacks can't both be served well. In Flat Paint, the slab is as thick as the deepest prefix any color needs.

A new opt-in Per-region stacks option, off by default, gives each color its own stack instead:

  • Every stack starts on the shared foundation and adds up to three runs of any loaded filament.
  • Stacks are scored with the same appearance model, calibration evidence and CIEDE2000 as the shared sequence.
  • Every stack, the shared prefix included, pays the same small cost per run and layer. The search also tries just the top layers of each shared prefix, so long prefixes whose deeper layers no longer change the color are cut to their visible top. No color is predicted more than 0.1 ΔE worse, and a color that gets slightly worse must still look within 0.5 ΔE of its old color.
  • Max filaments per layer (2–16, default 4) caps how many filaments one layer may hold. Among near-equal choices, the search prefers stacks that reuse filaments already on a layer.

It works in relief, where each column ends at its own height, and in both Flat Paint orientations, where shorter stacks are padded with foundation. In Flat Paint the cap never drops below what the plain layout already needs, because every face sits on the same layer.

Measured on test palettes:

Case Shared sequence Per-region stacks
Flat Paint, 16 colors 14.0 ΔE, 189 tool changes 6.2 ΔE, 163 tool changes
Flat Paint, 64 colors 15.7 ΔE, 202 tool changes 5.8 ΔE, 194 tool changes
Relief, 6-color e2e image 42 layers 20 layers
Relief, 6 / 16 / 64 colors 6 / 7 / 7 tool changes 66 / 70 / 44 tool changes

Relief gets better colors, but needs more tool changes than the shared sequence.

How it fits together

  • src/lib/regionStacks.ts holds the planner. It is React-free and runs in a worker at build time, taking about 0.5 s for 128 colors.
  • buildFlatPaintLayout is generalized into buildStackLayout. Plain Flat Paint now goes through it with unchanged output, and all existing Flat Paint, mesher and multi-head geometry tests pass.
  • Region stacks mesh through the existing slicer-safe createFlatPaintMesher and export as 3MF only, one object per filament.
  • Print Instructions show multi-material guidance. Layer Preview steps by physical layer, and the build warning counts the planned layers.
  • The option can't be combined with Multi-head, and height dithering doesn't apply to it. With Preserve color separation on, every color it keeps apart stays within its limit and never ends up closer to another kept color than on the shared sequence, up to 3 ΔE.
  • Up to 128 colors are planned, fewer on very large images to keep mask memory bounded. Colors with zero regional weight still get their own stack. Above the limit, or if planning fails, the build uses the shared sequence and shows a notice.
  • Exports are grouped by filament ID, so two filaments with the same color stay separate 3MF objects with distinct names. Part names are XML-escaped in both 3MF files.
  • UI strings and a new Auto-paint guide section are localized into all 12 languages.

Tests

  • Planner: shared-prefix predictions match Auto-paint, no target gets worse, the cap holds in both alignments, the incremental counting is fuzzed against a full recount, and results are deterministic.
  • Layout: every pixel gets the right filament on every layer in relief, face-up and face-down.
  • Export: closed-shell 3MF objects at None and Medium smoothing.
  • New @smoke browser test: relief and Flat Paint builds and exports, mode exclusion, and persistence.
  • npm test, lint and check:i18n pass.
  • test:e2e:all: every suite passed except 4 Display P3 cases in image-decode-reuse.spec.ts. Those fail on unchanged develop too (3 of 4 there), which is the known flake image-decode-reuse smoke tests lose clicks after a swatch drag #183.

Council review

Rounds: 7. Members: Claude Opus 5.5 and GPT-6.2 Sol at high effort. No third provider was available here: Gemini, Grok and the others are disabled.

Delegate Round 1 Round 2 Round 3 Round 4 Round 5 Round 6 Round 7
Claude Opus 8.5/10 9/10 9/10 9/10 9/10 9.5/10 not run
GPT Sol 6/10 7/10 7.5/10 8.5/10 8.5/10 9/10 9.5/10

Fixed after review

  • Mask memory, including the large-image budget.
  • Same-color filaments in 3MF.
  • The published shared baseline.
  • Exclusion with Preserve color separation.
  • Cancelling planning on an image change.
  • Cap input.
  • Zero-weight colors.
  • XML escaping.
  • Unique part names.
  • Unambiguous stack and optics-cache keys.
  • The carrier-mask slowdown in plain Flat Paint.
  • The localized progress label.

Declined

  • A strict per-layer cap in Flat Paint. Every face is on one layer, so the cap is floored at what plain Flat Paint already needs. This is documented in the guide.
  • Limiting shared prefixes to 3 runs. They are today's stacks.
  • UI display of tool changes. That's a separate feature.
  • Names that differ only by tab vs space.

Changes after the council (from hands-on testing, reviewed with sol-loop below)

  • Long shared prefixes are cut to their visible top. On a real 27-color image with 8 translucent filaments, Flat Paint drops from 43 to 17 layers and from 142 to 58 estimated tool changes. Overall error improves from 6.46 to 6.08 ΔE.
  • Preserve color separation now works together with per-region stacks instead of being turned off.

Known, not changed here: slab previews (plain Flat Paint too) show a depth-precision speckle on top faces at some angles. The exported geometry is clean: no overlapping coplanar faces.

Proof:

  • Unit tests, lint, typecheck, i18n, and the per-region and Flat Paint Playwright specs.
  • Regression tests that fail on the earlier planners.
  • A replay of the owner's real build (K image, 27 colors, 8 filaments).
  • A headless app build with separation on, plus screenshots comparing normal, per-region and plain Flat Paint renders.

Reviewed with sol-loop: 2 rounds with GPT-6.2 Sol on high. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code, reviewed by Claude Opus 5.5 and GPT-6.2 Sol.

🤖 Generated with Claude Code

vycdev and others added 12 commits November 23, 2026 18:26
Add a React-free planner that gives each Auto-paint target color its own
stack: the shared foundation plus up to three runs of any loaded filament,
scored with the same appearance model and CIEDE2000 as the shared sequence.
Each target's shared prefix stays a candidate, so no color is predicted
worse. A greedy search enforces a per-layer filament cap (relief stacks
align at the plate, Flat Paint stacks at the face) and prefers stacks that
reuse filaments already on a layer.

Not wired into the app yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Generalize the Flat Paint layout into buildStackLayout, which takes each
class's own bottom-up filament stack. Plain Flat Paint now builds its
classes from prefixes of the shared sequence and produces the same parts.
The new relief orientation keeps each column on the plate at its own
height.

Add region labels for pixels and buildRegionStackLayout, with tests that
check every pixel's filament on every layer in all three orientations and
that the meshes export as closed shells, one 3MF object per filament.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Wire the region stack planner into the app as an opt-in Auto-paint
option with a per-layer filament cap (2-16, default 4). Building plans
the stacks in a worker and meshes them through the shared slab path in
relief and both Flat Paint orientations, exporting one 3MF object per
filament. The option persists with Auto-paint settings, excludes
Multi-head, shows multi-material print instructions, steps Layer
Preview by physical layer, and counts planned layers in the build
warning.

Localize the controls, notices, instructions, and a new Auto-paint
guide section into all 12 languages, and add a browser smoke test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Score each shared prefix with the color Auto-paint published for it,
  so the never-worse baseline doesn't depend on re-predicting it.
- Fall back to the shared sequence above 128 target colors or if a plan
  can't fit the cap, and give colors with identical stacks one mesh
  class, bounding mask memory.
- Group parts by filament ID, so two filaments with the same color stay
  separate 3MF objects.
- Make Per-region stacks exclusive with Preserve color separation, cancel
  planning when the image changes, and let the cap field accept 10-16
  while typing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Plan colors Auto-paint dropped for zero regional weight, so their
  pixels keep their own stack instead of the nearest planned color's.
- Bound per-stack mask memory by image size, and allocate masks only
  for classes present in the crop.
- Name same-colored filaments apart in 3MF part names.
- Score the shared baseline from its published uint8 color, like the
  alternatives, and load conflicting saved toggles with Per-region
  stacks off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- XML-escape 3MF object names, so profile names with characters such as
  `&` keep the model file valid.
- Fall back to the filament ID when same-colored filaments also share a
  profile name.
- Note in the Auto-paint guide (all 12 languages) that very large images
  plan fewer than 128 colors, and clarify the changelog that colors may
  keep their shared prefix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Escape part names in model_settings.config with escapeXmlAttribute,
  so control characters in profile names can't break the file.
- Use filament IDs for every same-colored filament when any final part
  tag would collide.
- Build the face-down carrier mask in each caller's pixel pass instead
  of rescanning the image per class.
- Localize the per-region mesh progress label in all 12 languages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Key stacks with an unambiguous JSON encoding, since imported filament
  IDs may contain any text, so distinct stacks never merge into one
  mesh class.
- Check part-name uniqueness after XML normalization, so names that
  differ only by forbidden characters fall back to filament IDs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Imported filament IDs may contain any character, including NUL, so a
joined string key could hand one filament pair another pair's optics.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The planner built new stacks bottom-up and exempted each color's shared
prefix from the run and layer cost, so a 40-layer, 11-run prefix whose
deeper layers no longer change the color beat a 6-layer stack that
looks the same. Most colors kept their long shared stacks, and the
filaments-per-layer cap had nothing to act on.

Now every stack pays the same cost, the search also tries the
foundation plus the top k layers of each shared prefix, and a stack
counts as matching its prefix within 0.1 ΔE. On a real 27-color image
with 8 translucent filaments, a Flat Paint slab drops from 43 to 17
layers and from 142 to 58 estimated tool changes, with overall color
error improving from 6.46 to 6.08 ΔE.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Per-region stacks no longer turn Preserve color separation off. With
separation on, every color it keeps apart must stay within its ΔE limit
and may not move closer to another kept color than their shared colors
were, up to 3 ΔE. The search starts from the shared prefixes, which
meet this by construction, and rejects any move that breaks it, so two
separated colors can't collapse onto the same or a near-identical stack.

The settings come from the Auto-paint result the planner already
receives. The note, guide, and changelog are updated in all 12
languages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The 0.1 ΔE tolerance bounded only how much worse a stack matched its
target, so a trimmed stack could move about 3 ΔE away from the color the
shared prefix printed. A stack may now be up to 0.1 ΔE less accurate
only while its color stays within 0.5 ΔE of the published shared color;
stacks at least as accurate stay free to look different. On the owner's
27-color image this leaves layer counts and tool changes unchanged.

Also fix a duplicate test swatch that never printed and document that
trims of a shared prefix are exempt from maxRuns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vycdev
vycdev merged commit e817b28 into develop Nov 23, 2026
14 checks passed
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.

1 participant