Skip to content

feat: Vortek toolhead HUD for Bambu H2C files - #34

Merged
little-did-I-know merged 6 commits into
mainfrom
feature/vortek-toolhead-hud
Oct 30, 2026
Merged

little-did-I-know merged 6 commits into
mainfrom
feature/vortek-toolhead-hud

Conversation

@little-did-I-know

Copy link
Copy Markdown
Owner

Summary

Bambu H2C (Vortek) files switch between two nozzles and several filaments mid-print. This adds a small HUD to the 3D viewer that shows the active tool (nozzle, filament colour, filament type) for the current layer or simulated move, and flips when the tool changes.

  • Detection: a file counts as Vortek if the header printer_model is an H2C, or it has M620 N plus M632 or M640.8. The toolbar shows a Vortek detected · N changes badge and a "Vortek toolhead" toggle (on by default). Both hide for other files.
  • Parser: builds parser.toolChanges[] (line, layer, x/y/z, from/to filament, from/to nozzle) and parser.vortek. T<n>, OF# and NF# index directly into the header's filament_colour and filament_type lists. The first event comes from the first T<n> H-1, with its nozzle taken from filament_nozzle_map. T1000, T65279 and repeated T<n> H-1 lines are ignored.
  • HUD: a new ToolheadHUD module is purely presentational. It updates in GcodeViewer3D.render() and is skipped for review viewers. It animates only when the tool changes between two known tools, so the first appearance, a re-show and a new file load don't flip.
  • Safety: the colour must match a hex regex before it reaches style.background. The type goes through the existing sanitiser and then textContent. There is no innerHTML path.

Behaviour notes

  • Mid-layer changes: a scrubbed layer shows the tool at the end of the layer, so a mid-layer change shows only the last tool.
  • Play on a change layer: pressing Play flips once at the start, from the end-of-layer tool to the start-of-layer tool.
  • Parse cost: about 6% slower on a 4.3M-line H2C file (5.09 s on main, 5.34 s here). It comes from scanning ;, M and T lines for Vortek markers.
  • Build output: gcode-modifier.html is rebuilt in the commits, as in earlier feature commits.

Test plan

  • npm test: 410 of 410, including 23 parser tests on a new H2C fixture and 10 HUD tests
  • Cube (101 changes): the badge shows 101 changes, the HUD starts at N1, #001489, PETG, and flips once across layer 25 and not on repeats or within a run
  • bridge_base_plate_2_filaments (441 changes): only #F4EE2A PLA and #ADB1B2 PETG appear
  • bridge_base_plate_1_0.6mm (1 change): a static #001489 PETG, the badge says 1 change, and nothing animates
  • Simulation: the HUD flips at the move where the swap happens (layer 25, swap at move 517, flip at 518)
  • Toggle off and on, including hiding mid-flip, does not replay the animation
  • Loading a non-Vortek file after a Vortek one hides the controls and HUD, keeps them hidden across view switches (code, warp, reference, visual), and resets the toggle to on
  • Loading a file with no layers after a Vortek file clears the badge and HUD
  • Light theme styling
  • Not checked: the other four H2C samples (inductive, inductive_blue, different_nozzle, different_nozzle_vortek) were not loaded in the browser. The reviewer ran the parser against all seven.

Commits

  • feat: detect Vortek/H2C files and build tool-change events
  • feat: add ToolheadHUD module
  • feat: render Vortek toolhead HUD in the 3D viewer
  • feat: Vortek toolhead toggle and detection badge
  • fix: clear HUD flip when hidden and keep Vortek controls hidden across view switches
  • fix: reset Vortek badge and HUD when a loaded file has no layers

Not in this PR

src/comparison.js:25 calls p.parse(...), but GcodeParser only has parseAsync, so loading a compare file appears to throw. It was already broken on main and is unrelated to this change.

Parser now flags Bambu H2C / Vortek files (H2C printer_model header, or
M620 N with M632/M640.8), reads per-slot filament colors and types from
the header, and records tool changes from NOZZLE_CHANGE_START
annotations plus the initial T<n> H-1 load. activeToolAt() and
activeToolInLayer() resolve the active tool for a line or a viewer
position. Non-Vortek files stay untouched.
Presentational badge for the active Vortek tool (nozzle, filament swatch,
type). update() diffs against the last tool shown and only reports an
animation when two non-null tools differ; color/type reach the DOM via
textContent and style only.
…s view switches

Hiding the HUD mid-flip left th-flip set (display:none cancels the animation
without animationend), so it replayed on re-show. setView() resets the inline
display of every .preview-toolbar > span, which re-showed #vortekControls on
non-Vortek files; hide it with a class instead.
@little-did-I-know
little-did-I-know merged commit aa78b9d into main Oct 30, 2026
2 checks passed
@little-did-I-know
little-did-I-know deleted the feature/vortek-toolhead-hud branch October 30, 2026 12:41
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