STL to G-Code Relief Carving

Turn an STL model into 3D carving G-code for a CNC router: a flat end mill roughs out the bulk in Z steps, then a ball nose, tapered ball, flat or V bit follows the surface in a raster. You get the run time, the cusp height, a gouge check and a 3D preview of the simulated cut. Your STL never leaves your browser.

Model

No model loaded yet.

Stock and placement

Z0 is the stock top. The floor is the background around the model; leave it blank to cut the background at the model's base.
The roughing tool also does the cut-out. Feeds: see the CNC Router Feeds & Speeds calculator.
A rectangle around the model plus the margin, cut through the stock with the roughing tool, last.

Machine and output

Load an STL (or the sample) and press Make G-code to see the simulated carving here.

Your Carving Program

Results appear here: run time, cusp height, the gouge check and the G-code files.

How the STL to G-Code Carving Tool Works

A relief carving is a 3D surface cut from the top of a board, like a sign, a plaque or a coin. The tool reads your STL, lays it into the stock with its top at Z0, works out where the cutter can sit at each point without cutting into the model, and joins those points into toolpaths. Then it runs every move through a simulated block of stock and compares the carved result with the model.

The work runs in a Web Worker using a WebAssembly module written in Rust, so the page stays responsive and nothing is uploaded. Seen from above, every point of the model has one height, so this is 3-axis carving only: undercuts and overhangs can't be reached, and the surface under them is cut straight down.

The Method

1. Drop-cutter
tip Z = max over contacts of (zcontact − h(r))
ball: h(r) = R − √(R² − r²)
V bit: h(r) = r ÷ tan(angle ÷ 2)
flat: h(r) = 0
h(r) is the height of the cutter's surface above its tip at distance r from its axis. For each point the cutter is "dropped" onto every nearby triangle: its flat face, its three edges and its corners. The highest touching tip height wins. On a flat face the touching point is found exactly; along an edge a one-dimensional search finds it, which is exact for these convex cutter shapes. Between points, extra points are added wherever the surface rises more than 0.01 mm above the straight move, so the moves don't cut into the model.
2. Cusp height
cusp = h(stepover ÷ 2)
ball: R − √(R² − (s/2)²)
V bit: (s/2) ÷ tan(angle ÷ 2)
Two neighbouring passes on a flat area leave a ridge between them whose height is the cutter's profile at half the stepover. This is the usual scallop-height formula for a ball nose. On slopes the ridges get taller for a ball nose across the slope. A flat end mill leaves no cusp on flat areas but steps on slopes. See the Cusp & Stepover calculator.
3. Roughing
levels Z = −stepdown, −2 × stepdown, … down to the lowest point
cut Z = max(level, drop-cutterR + leave + leave)
The flat end mill clears material in Z levels with a raster, each pass following the model where it is higher than the level. Using a cutter one leave-stock wider and raising it by the leave-stock keeps the real cutter that distance away from the model in every direction. Each pass rapids to 1 mm above the stock top and plunges at the plunge feed.
4. Time and simulation
time = Σ length ÷ feed (cuts) + Σ length ÷ rapid rate
cell height = min(cell height, tip Z + h(r))
The stock is a grid of columns (up to about 400,000 cells). Every move lowers the columns under the cutter to the cutter's shape: level moves are swept exactly and sloping moves are stamped every half cell. The gouge check flags any cell cut more than 0.05 mm below the model surface at that cell.

Worked Examples

The sample panel, metric defaults
  • Load sample (120 × 80 × 11 mm), stock 150 × 100 × 19 mm, fit with a 5 mm margin, relief depth 8 mm
  • Fit: the space is 140 × 90 mm, so the scale is min(140 ÷ 120, 90 ÷ 80) = ×1.125 across and about 8 ÷ 11 = ×0.7274 in Z (the dome peaks at 10.998 mm)
  • Roughing: 6 mm flat end mill, 3 mm stepdown, 0.5 mm leave-stock: 3 levels (Z−3, Z−6 and Z−7.5, the floor plus the leave-stock)
  • Finishing: 3.175 mm (1/8 in) ball nose, 0.3 mm stepover: cusp = 1.5875 − √(1.5875² − 0.15²) = 0.0071 mm
  • Run time at 1500 / 2000 mm/min and 5000 mm/min rapids: roughing 14 min 46 s + finishing 26 min 07 s = 40 min 53 s
  • Simulation: no gouges, 94.8 % of the surface within 0.1 mm of the model, 96.3 cm³ removed, 48,811 lines of GRBL code
Imperial, V-bit finish and a cut-out
  • Sample, stock 4 × 3 × 1/2 in, 0.4 in margin, 0.15 in deep, origin at the stock centre, Fanuc-style, inch output
  • Scale = min(3.2 ÷ 4.724, 2.2 ÷ 3.150) = ×0.6773 (the sample is 4.724 × 3.150 in)
  • Roughing: 1/4 in flat end mill, 0.1 in stepdown, 0.01 in leave: 2 levels, 5 min 34 s at 50 in/min
  • Finishing: 1/4 in 60° V bit, 0.02 in stepover, X then Y, climb only: cusp = 0.01 ÷ tan 30° = 0.0173 in, 30 min 46 s at 60 in/min
  • Cut-out: 0.15 in outside the model, through 0.51 in, two 1/4 in tabs a side, 0.12 in tall: 1 min 41 s
  • Total 38 min 02 s, no gouges, but only 31.2 % of the surface is within 0.1 mm: the V bit's cusps are 0.44 mm tall, so it leaves a textured finish

Tips for Using the Results

  • Pick the stepover from the cusp height. For a smooth finish on wood, aim for a cusp under about 0.01 mm (0.0005 in); that usually means 8 to 10 % of a ball nose's diameter. Halving the stepover doubles the finishing time.
  • Check the gouge check and the comparison view. Compare with model colours the simulated surface: green within 0.1 mm, blue where material is left (narrow gaps the cutter can't reach), red for a gouge. Blue in tight corners is normal; use a smaller or tapered ball to get in.
  • Set Z0 on the stock top. The program assumes Z0 is the top of the board and X0 Y0 is the front left corner (or the centre, if you choose that). The pause between tools is the time to fit the next cutter and set Z0 again.
  • Prove it in the viewer. Open in G-code viewer loads the program into the G-Code Viewer with the stock and tools filled in, where the cut simulation plays back with the timeline and checks for rapids that cut.
  • Feeds and speeds. The defaults are moderate for a hobby router in hardwood. Work out your own chip load with the CNC Router Feeds & Speeds calculator.
  • Big jobs. Very fine stepovers on large stock make millions of points. The page refuses jobs over 8 million finishing points; press Cancel at any time to stop a long job.

Frequently Asked Questions

Binary or ASCII STL files of any size up to 200 MB and 3 million triangles. Pick which way is up and the tool carves what can be seen from above, so reliefs, signs, plaques, terrain and lithophane-style height maps work best. Undercuts and overhangs are ignored: the cutter only reaches what a 3-axis machine can.

From the cusp height you can accept. For a ball nose the cusp is R − √(R² − (stepover ÷ 2)²), so a 3.175 mm (1/8 in) ball at a 0.3 mm stepover leaves 0.0071 mm. A V bit leaves much taller ridges: a 60° V at 0.02 in leaves 0.0173 in. The page shows the cusp height as you type.

A small ball nose taking the full depth in one go would break or burn. The flat end mill removes the bulk in Z levels and leaves an even skin (the leave-stock), so the finishing tool only takes a light cut. For shallow carvings of 2 to 3 mm in soft wood you can turn roughing off.

It adds up every move at its feed rate and every rapid at the rapid rate you enter, without acceleration or tool changes, so treat it as a minimum. 3D carving is made of many short moves, and hobby machines often can't reach full feed on them, so real jobs can take noticeably longer.

GRBL, Mach3 and Mach4, LinuxCNC and generic Fanuc-style controls, in mm (G21) or inches (G20). GRBL has no M6, so the combined file uses a T word and an M0 pause for the tool change; the others use T M6 then M0. LinuxCNC gets G64 path blending, and the Fanuc-style file has an O number, G43 tool length offsets and G28 returns.

Every move is run through a simulated block of stock, and each cell of the result is compared with the model at the same point. A cell cut more than 0.05 mm below the model counts as a gouge. It also counts rapid moves that would cut material. It checks the toolpath, not your machine: it can't see a loose clamp, a wrong Z0 or a tool that's too short.

No. The file is read and machined in your browser by a WebAssembly module, and nothing is sent to a server. Open in G-code viewer passes the program to the viewer inside your own browser.

Limits. 3-axis only, with no undercuts or 4th axis. The raster runs along X and/or Y only, with no waterline or pencil passes. Roughing is a Z-level raster, not an adaptive clearing path. The cut-out is a rectangle around the model. Shank and holder collisions are not checked, so make sure your cutter's flute length covers the relief depth. Always air-cut or dry-run a new program first.

Open-source credits. The engine is written in Rust and uses wasm-bindgen and js-sys (MIT or Apache-2.0) and serde and serde_json (MIT or Apache-2.0). The 3D view uses three.js (MIT) and the page uses Bootstrap (MIT).