Skip to content

Move the color state into the ObjectsManager - #389

Merged
sophiedeziel merged 2 commits into
developfrom
objects_manager_colors
Aug 23, 2026
Merged

sophiedeziel merged 2 commits into
developfrom
objects_manager_colors

Conversation

@sophiedeziel

Copy link
Copy Markdown
Collaborator

Stacked on #380 (which stacks on #311) — the next slice of moving job-derived scene state into the manager.

The problem

The manager owned the materials and performed every recolor, but SceneManager held the source of truth: _extrusionColor, _travelColor, and the per-tool fallback with its warn-once bookkeeping. Every renderPaths call computed each tool's color before handing it over, and clear() only worked because the colors happened to live outside the manager being swapped.

What moves

was is now
extrusion color(s) SceneManager._extrusionColor + fallback logic in renderPaths ObjectsManager.extrusionColor + private colorForTool()
travel color SceneManager._travelColor, passed on every render call ObjectsManager.travelColor; renderTravelLines defaults to it
setExtrusionColor per-tool material mutator (color, toolIndex?) takes the full value (Color | Color[]), stores it, repaints in place
default color SceneManager.defaultExtrusionColor lives on the manager; the SceneManager static stays as an alias

renderExtrusions(paths, toolIndex) now resolves its own color, so renderPaths passes no colors at all, and clear() carries both colors onto the replacement manager like the other settings.

A small robustness win

Repainting tools beyond a shrunken color array now derives the tool list from what is actually drawn (the per-tool materials and the lines' userData.toolIndex) instead of job.toolPaths — the setter no longer needs the job, so it is inherently safe after clear().

Behavior notes (deliberate, minor)

  • The warn-once set for missing tool colors now resets on clear() (it lives on the swapped manager), so a newly loaded file can warn again — arguably more correct, since it may have different tools.
  • SceneManager's public color accessors are unchanged; the demo and DevGUI need no edits.

Tests

The existing color suites were rewritten against the new API — mostly turning spy assertions into state assertions on the actual materials (the fallback tests now check uColor uniforms instead of call arguments). A clear() carry-over test is added. Both files hold their 100% coverage thresholds; 394 tests green.

Assisted by Claude Code - Fable 5

Base automatically changed from objects_manager_volumes to develop August 23, 2026 20:55
The manager owned the materials and did every recolor, but SceneManager
held the source of truth: the extrusion color(s), the travel color, and
the per-tool fallback with its warn-once bookkeeping. renderPaths had to
compute each tool's color before handing it over.

The manager now owns the colors. setExtrusionColor takes the full value
(one color or an array indexed by tool), stores it, and repaints in
place; colorForTool resolves what a tool draws with, including the
fallback. renderExtrusions takes just a tool index, and renderTravelLines
defaults to the stored travel color, so renderPaths passes no colors at
all. SceneManager's accessors delegate, and clear() carries both colors
onto the replacement manager.

Repainting the tools beyond a shrunken color array now derives the tool
list from what is actually drawn (materials and line userData) instead of
job.toolPaths, so the setter no longer needs the job at all.
@sophiedeziel
sophiedeziel force-pushed the objects_manager_colors branch from 8b71d55 to 3c38b3b Compare August 23, 2026 20:56
@github-actions

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 8491d6b):

https://gcode-preview--pr389-objects-manager-colo-vthxbky3.web.app

(expires Tue, 22 Sep 2026 21:10:57 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 59bd114ae4847b32c2bba0b68620b9069a3e3531

@sophiedeziel sophiedeziel added 3.0 Targeted for the 3.0 release refactor Code change that neither fixes a bug nor adds a feature labels Aug 23, 2026
Two renderExtrusions call sites still passed a Color where the new
signature takes a tool index. They ran anyway — vitest strips types and
typeCheck only sees the entry file — and their instanceof-only
assertions kept passing, so nothing caught it.

New assertions close the review's gaps:
- set-then-draw resolves each tool's array entry, in both line and tube
  mode; the whole suite previously survived colorForTool returning the
  array's last entry for every in-bounds tool
- shrinking the color array repaints line-drawn tools, pinning the
  LineSegments2 branch of renderedToolIndices
- renderTravelLines really uses the stored travel color as its default,
  asserted on the drawn material at both unit and scene level
- a missing tool color warns again after clear(), pinning the documented
  decision that the warn-once bookkeeping belongs to the swapped manager
@sophiedeziel
sophiedeziel merged commit f780d78 into develop Aug 23, 2026
7 checks passed
@sophiedeziel
sophiedeziel deleted the objects_manager_colors branch August 23, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0 Targeted for the 3.0 release refactor Code change that neither fixes a bug nor adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant