Skip to content

Parametric: CAM (setups, 2D and 3D toolpaths, simulation, G-code) - #256

Merged
jelveh merged 34 commits into
mainfrom
parcam-nov27/cam
Nov 27, 2026
Merged

jelveh merged 34 commits into
mainfrom
parcam-nov27/cam

Conversation

@jelveh

@jelveh jelveh commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Adds CAM to Parametric: a CAM tab that turns a part into CNC toolpaths, simulates them and writes G-code.

What's in it

Setups. Where the part sits on the machine: the tool direction (any side of the part, from a list or by picking a flat face), a turn about it, the stock (a margin round the part or a fixed block), the work origin (stock top corner or centre, stock bottom corner, or the part origin), G54–G59 and the clearance and retract heights. A second setup defaults to the opposite side.

Tool library. Flat, ball and bull nose end mills, drills and chamfer mills with flutes, speeds and feeds, kept in the part file (doc.cam).

Operations.

  • 2D: Face, 2D Contour (lead-in/out arcs, ramping along the wall, holding tabs), 2D Pocket (picked floors; offset or zigzag; helix, ramp or plunge entry), Drill (G81/G82/G83/G73 on every hole of the drill's size or the picked ones; through holes and counterbores told apart), Bore (helical).
  • 3D: 3D Rough (levels plus the part's flat heights, stock to leave on walls and floors), Parallel and Waterline finishing with ball, bull nose or flat end mills.
  • Climb/conventional, stock to leave, per-operation feeds and speeds. The toolpath previews while you edit, with its machining time. Operations are listed under CAM in the design tree with their state (not generated, out of date after a model change, error, warning), and have Edit, Generate, Move, Duplicate, Suppress, Rename and Delete.

Simulation. Cuts a height map of the stock operation by operation and plays it back with the tool. It's coloured green where finished, amber where material is left and red where the part would be cut. It reports rapid moves through stock and material above the flutes, plus time, removed volume and the most left over the part.

Post processing. Fanuc, Haas, LinuxCNC, Mach3/4 and Grbl, in mm or inches, with fitted arcs (also helical) and canned drilling cycles where the controller has them. Grbl gets no M6/G43/canned cycles and pauses with M0 for tool changes. Preview, copy or download.

How it works

  • src/cam is a pure TypeScript engine running in its own worker, on a fine STL mesh of the part from the kernel, in the setup's work coordinates.
  • dropcutter.ts: drop-cutter for flat, ball, bull and cone cutters. It handles face, edge and corner contacts, closed form for flat and ball edges, and golden-section search where the height along an edge is concave.
  • ops.ts: where the tool can be at height z is where the drop-cutter height is ≤ z. That region's boundary is traced by marching squares, each crossing refined by bisection on the drop-cutter, so walls are exact. Clearing passes are offsets from a distance transform, cut innermost-out (one stepover of engagement), with helix entries inside the ring being entered. Waterlines use the same exact boundaries; parallel passes follow drop-cutter heights.
  • Every generated toolpath is checked against the part with the drop-cutter. A cut into the part becomes a warning on the operation.
  • simulate.ts (z-map), post.ts (dialects and arc fitting), client.ts/worker.ts.
  • UI in src/app/cam. The renderer gained lit, per-vertex-coloured solids for the simulated stock and tool.

Testing

  • tests/cam-engine.test.ts: drop-cutter against exact answers, frames, contours, every operation on hand-built meshes (clear of the part, climb direction, tabs, pocket walls), simulation, arcs, posts per controller, file round trip and damaged data.
  • tests/cam-kernel.test.ts: the example flange and bracket built by OpenCascade. Every operation type, three setup orientations, counterbore boring, all simulated with no gouges and no rapid moves through stock, and G-code for the whole flange program.
  • tests/e2e/cam.spec.ts: the full flow in the browser. Setup, adding a 7 mm drill in the tool library, Drill (6 bolt holes) and Contour, the simulation reporting no collisions, the G-code preview and download, and Undo.
  • Full unit suite and npm run build pass.

The browser run caught two real bugs, both fixed here. A contour lead-in dropped at rapid into uncut stock beside its own slot. Drilling with no facing or roughing first dropped at rapid to just above holes still under stock. Drills, bores, contour leads and finishing passes now feed down from the retract height.

Known limits

  • 3-axis only; no holder or shank collision geometry beyond the flute-length check; no rest machining or adaptive (constant-engagement) clearing yet.
  • Rough and pocket passes inside the wall pass are on the region's distance transform, so they follow it to the grid cell (≈R/5, at most 0.5 mm). The final wall pass and waterlines are exact.

Drills, bores, contour leads and finishing passes feed down from the
retract height (the stock over them may be uncut); helix entries go inside
the pass they enter; counterbores are no longer taken for through holes.
Every toolpath is checked against the part. Toolpath lines are cached,
the first setup or operation is one undo step and the tool library no
longer creates CAM data until OK.
A later setup that used the same tool skipped the move to its start (the
modal X, Y and Z were those of the previous setup's work offset) and ran
straight on in the same work offset without a stop to turn the part.
Long programs with line numbers went past N99999, which most controllers
reject; the numbers now start again at N10.
…ation

They were counted per sample of a move (every half cell), so one rapid
move through the stock was reported as hundreds of moves.
Cuts through the stock (contour breakthrough, drilling) lowered the
height map below the stock, which counted air as removed material and
drew the stock surface below its own bottom.
…ool starts

The first move of every operation was left off the playback timeline,
so the tool was drawn sliding from the previous operation's last point
(through the stock) to the second move.
…a file

Only numeric settings were checked: overriding feeds that were not
numbers reached the G-code as FNaN, a zero stepover or stepdown could
keep the toolpath engine going forever, unknown choices (pattern, cycle,
direction...) and missing tabs went through as they were, and tool
numbers and shape values were not checked.
An arc fitted over a few points on a small radius could end, once
rounded to the output's precision, where it started; controllers run
such a G2/G3 as a full circle.
Haas mills take the G04 dwell in P (milliseconds without a decimal
point); the post wrote the Fanuc G4 X form for them.
…no moves

An operation that generated no moves (a drill finding no holes) marked
the tool's G43 as done, so the next operation with that tool moved
without tool length compensation. Such operations are now left out of
the G-code.
The client dropped the worker's flag for errors written for the user, so
a crash inside the engine ("Cannot read properties of undefined...")
showed as the operation's error as if it were advice. Errors now carry
the flag and internal ones say the CAM engine ran into a problem.
dispose() cleared its requests without settling them, leaving their
callers waiting forever; they now reject with CamCancelled.
A stepover wider than the tool left strips of stock standing between face,
pocket and rough passes (offset passes leave posts in their corners from about
0.85 of the diameter), with no warning. Zero or a negative stepover never
finished zigzag clearing and overflowed the stack in offset clearing.
…g a core

A single helix at the wall of a hole wider than two tools left a core standing
in it, and the move out through the middle then fed sideways into that core
at full depth. Helices now run from the middle out, a tool radius apart.
The breakthrough and drill point were added below a through hole whatever was
under it, so a drill could go on into another wall of the part, and the
toolpath check skips drilling cycles so nothing warned. The point depth now
also comes from the tool's own shape (a chamfer tool without an angle used
118 degrees).
A stepdown of zero or a tiny one counted levels with the clamped value but
placed them with the raw one: thousands of passes at the top, then the whole
depth at once. A negative one put levels above the stock, and a damaged one
gave no levels at all.
…e tool

On a large part the region grid is capped and its cells can be wider than a
small tool. The chord between two refined crossings then cut across the
part's corners: a 0.3 mm tool on a 300 mm plate contoured into all four
corners, the full depth of the wall. Points along long chords where the tool
may not be are now moved out onto the boundary.
…eration is deleted

OK re-added an operation deleted from the design tree while it was being edited.
…ings just chosen

A change still being written was skipped: the previous controller's G-code was saved under the new controller's extension.
…sive

A 1.2 million move program blocked the dialog for about a second on every option change. A change made while a program is still being written stops that one.
… it again

The operation's toolpath vanished from the graphics area while the same toolpath was made a second time.
…ssed state; one speed selected

A pressed "Pause" toggle was announced as paused, and a short program had both "Whole program in 20 s" and "1×" selected, showing 1×.
…ells screen readers which it is

Arrow keys moved the choice out of sight in a long list and nothing was announced; Home and End go to the first and last tool.
…t moved by the changed setup

Turning a setup over drew its old toolpaths in the new placement, floating above the part.
…ntly keeping the old one

Download wrote the previous number with no sign that the typed one was refused.
… not a value

It closed and kept the last valid value, discarding what was typed, where panels show the reason and focus the field.
…onger stops generation

Exit Simulation cancelled the generation worker, stopping toolpaths still being generated.
The panel redrew with the box empty right after the pick; choosing another direction clears it.
…e simulation is open

The panel kept showing the stock cut by the old tools.
@jelveh
jelveh merged commit 00fc570 into main Nov 27, 2026
3 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