
# π οΈ CNC Simulator Pro
### Free, browser-based 3-axis CNC milling simulator with real-time G-code animation
Run a real CNC machine in your browser β watch material get cut away in 3D as your G-code executes. No installs, no signups, no fees. **100% client-side.**
[](https://rudra496.github.io/cnc/)
[](./LICENSE)
[](https://github.com/rudra496/cnc/stargazers)
[](https://nextjs.org/)
[](https://threejs.org/)
[](https://www.typescriptlang.org/)
**[π Live Demo](https://rudra496.github.io/cnc/)** Β· **[β Star this repo](https://github.com/rudra496/cnc/stargazers)** Β· **[π Report a Bug](https://github.com/rudra496/cnc/issues)** Β· **[π¬ Discussions](https://github.com/rudra496/cnc/discussions)**
---
> β‘ **TL;DR** β CNC Simulator Pro is a professional-grade, **free and open-source** CNC milling simulator that runs entirely in your browser. It features a high-fidelity 3D machining center, real-time G-code visualization, a shop-style DRO control bar, a feeds & speeds calculator, and a complete learning suite for G-codes, M-codes, and tool management. Perfect for **students, machinists, hobbyists, educators, and anyone learning CNC programming.**
Built with **Next.js 16**, **react-three-fiber**, **Three.js**, **TypeScript**, **Tailwind CSS 4**, and **shadcn/ui**. Deploys to **GitHub Pages** as a static site.
---
## π Table of Contents
- [Why CNC Simulator Pro?](#-why-cnc-simulator-pro)
- [Features](#-features)
- [Tool Library](#-tool-library-8-pre-configured-tools)
- [Material Library](#-material-library-8-materials)
- [Feeds & Speeds Calculator](#-feeds--speeds-calculator)
- [Try It Now](#-try-it-now)
- [Screenshots](#-screenshots)
- [Deploy to GitHub Pages](#-deploy-to-github-pages)
- [Local Development](#-local-development)
- [Keyboard Shortcuts](#-keyboard-shortcuts)
- [Project Structure](#-project-structure)
- [Tech Stack](#-tech-stack)
- [Roadmap](#-roadmap)
- [Contributing](#-contributing)
- [Community & Support](#-community--support)
- [License](#-license)
---
## π‘ Why CNC Simulator Pro?
Commercial CNC simulation software can cost **thousands of dollars** and requires powerful hardware. CNC Simulator Pro is built on the belief that **learning CNC should be free and accessible to everyone**, everywhere.
| | CNC Simulator Pro | Commercial Software |
|---|---|---|
| **Price** | π― Free forever | πΈ $$$ |
| **Install** | None β runs in browser | Heavy desktop app |
| **Platform** | Any device with a browser | Windows/Linux only |
| **Source code** | Open source (MIT) | Closed source |
| **Real 3D machining** | β
Yes | β
Yes |
| **G-code learning** | β
65-code reference | Varies |
**Who is it for?**
- π **Students** learning CNC programming, manufacturing, or mechatronics
- π¨βπ« **Educators** teaching machining, G-code, or CAM concepts
- π§ **Machinists & engineers** prototyping and validating toolpaths
- π οΈ **Hobbyists & makers** exploring CNC before buying a machine
- π» **Developers** studying real-time 3D simulation with Three.js
---
## β¨ Features
### π― 3D Machine & Simulation
- **High-fidelity gantry VMC** β base, table with T-slots, columns, moving bridge (Y), carriage (X), telescoping quill (Z), spindle motor, safety-glass enclosure
- **Real material removal** β a subdivided heightmap workpiece that gets *actually milled* as the tool follows the program
- **Per-tool geometry** β end mills, ball noses, drills, chamfers, face mills, spot drills and reamers each render their real shape and carve with their real diameter
- **Live toolpath** β cyan feed moves + amber dashed rapids, with arc tessellation
- **PBR materials, soft shadows, environment reflections, fog, infinite grid**
- **Camera presets** β Iso / Top / Front / Right / Reset, plus orbit / zoom
### ποΈ Unique Advanced Control Bar
- **LCD-style DRO** β live X / Y / Z coordinates with cutting indicator
- **Status lamps** β spindle RPM, feed rate, active tool, coolant
- **Transport** β reset, step-back, play/pause, step-forward, single-block
- **Machine modes** β **Run** (full cut) / **Dry Run** (no material cut) / **Machine Lock** (toolpath preview only)
- **Optional stop (M01)** and **Block skip (/)** toggles
- **Timeline scrubber** with elapsed / remaining cycle time + block counter
- **Cycle speed** β 0.25Γ to 10Γ presets
- **Override knobs** β Feed / Rapid / Spindle % sliders that genuinely affect timing
- **Keyboard shortcuts** β `Space` play/pause, `β/β` step, `R` reset
### π» Manual G-code Programming
- **Full code editor** with syntax highlighting (color-coded G/M/T/F/S/X/Y/Z/I/J)
- **Line numbers + current-execution-line tracking** (highlights the block running in 3D)
- **Click-a-line-to-seek** β click any line to jump the simulation to that block
- **Parse diagnostics** β errors and warnings shown inline with line numbers
- **26 ready-to-run example programs** (Beginner β Advanced): circle pocket, square pocket, drilling, heart, spiral, "HI" engraving, grid pockets, gear, star, flower, face surfacing, hex pocket, cutter comp, circle bore, peck drill array, slot, island pocket, "CNC" engraving, dovetail, bolt circle, cam lobe, "2024", keyway, star burst, concentric rings, trophy base plate
### π§ Tool Library (8 pre-configured tools)
| T# | Tool | Diameter | Use |
|----|------|----------|-----|
| T1 | End Mill | Γ6 mm | General pockets, slots, profiles |
| T2 | End Mill | Γ10 mm | Roughing bigger features |
| T3 | Drill | Γ3 mm | Holes (G81/G83) |
| T4 | Ball Nose | Γ6 mm | 3D surfacing |
| T5 | Chamfer | Γ10 mm 90Β° | Edge breaking, spotting |
| T6 | Face Mill | Γ50 mm | Surfacing stock flat |
| T7 | Spot Drill | Γ8 mm | Accurate hole spotting |
| T8 | Reamer | Γ5 mm | Precision finished holes |
Each tool renders its real geometry and carves with its real diameter. The **Tools** tab shows all tools, highlights the active one, and marks which tools the current program uses.
### π§± Material Library (8 materials)
Aluminum 6061/7075, Mild Steel, Stainless 304, Brass, Copper, Delrin, Oak β each with recommended surface speed (Vc), chip load (fz), max depth of cut, and coolant recommendation. **Selecting a material changes the workpiece color in the 3D view.**
### π Feeds & Speeds Calculator
Pick a tool + material, adjust axial/radial/feed overrides, and get live:
- **RPM** = (Vc Γ 1000) / (Ο Γ D)
- **Feed** = fz Γ flutes Γ RPM
- **MRR** (material removal rate, cmΒ³/min)
- **Spindle power** estimate (kW)
- **Recommended DOC / WOC**
- Contextual warnings (rubbing risk, RPM cap, work-hardening, etc.)
### πΎ Program Library (save / load / export / import)
- **Save** the current editor content + workpiece to browser `localStorage`
- **Load** any saved program back into the editor
- **Download** a single program as a `.nc` file
- **Export All** / **Import** the entire library as JSON
- **15 code snippets** (header, tool change, circular pocket, drilling cycle, profile, finish pass, surfacing, etc.) β click to insert into the editor
### π Comprehensive Learning
- **Reference tab** β 65 CNC codes (G/M/T/F/S/Z) with descriptions, examples, and tips, fully searchable and category-filtered
- **Guide tab** β how-to steps, G-code primer, coordinate system, programming tips, keyboard shortcuts
---
## π Try It Now
### π [**Open CNC Simulator Pro β**](https://rudra496.github.io/cnc/)
No download, no account, no setup. Pick an example program and hit βΆοΈ Play.
---
## πΈ Screenshots
> _Screenshots coming soon β in the meantime, [try the live demo](https://rudra496.github.io/cnc/) to see the 3D machine, control bar, editor, and material removal in action._
---
## π Deploy to GitHub Pages
This project is configured for **static export** and includes a GitHub Action that builds and deploys automatically.
### Option A β Automatic (recommended)
1. **Create a new GitHub repository** and push this project's source code to it:
```bash
git init
git add .
git commit -m "CNC Simulator Pro"
git branch -M main
git remote add origin https://github.com//.git
git push -u origin main
```
2. **Enable GitHub Pages**: go to your repo β **Settings β Pages β Build and deployment β Source: GitHub Actions**.
3. The included workflow (`.github/workflows/deploy.yml`) will automatically build and deploy on every push to `main`. Wait ~2 minutes, then visit:
```
https://.github.io//
```
> The `basePath` is auto-detected from your repo name β no configuration needed.
### Option B β Manual build
```bash
bun install
# For a project page (username.github.io/REPO):
NEXT_PUBLIC_BASE_PATH="/REPO" bun run build
# For a user page (username.github.io):
bun run build
```
The static site is generated in `out/`. Upload the **contents** of `out/` to your `gh-pages` branch or the root of your GitHub Pages site. The `.nojekyll` file is included automatically.
---
## π§βπ» Local Development
```bash
bun install
bun run dev # http://localhost:3000
bun run lint # ESLint check
```
Requirements: Node 18+ / Bun 1.0+.
---
## β¨οΈ Keyboard Shortcuts
| Key | Action |
|-----|--------|
| `Space` | Play / Pause |
| `β` | Step forward one block |
| `β` | Step back one block |
| `R` | Reset to start |
---
## ποΈ Project Structure
```
src/
βββ app/
β βββ layout.tsx # Root layout + metadata
β βββ page.tsx # Main page (3D viewport + tabbed panel + control bar)
βββ components/
β βββ cnc/
β β βββ CncScene.tsx # 3D machine (react-three-fiber)
β β βββ ControlBar.tsx # Controller console
β β βββ GCodeEditor.tsx # Syntax-highlighted editor
β β βββ ProgramPanel.tsx # Example selector + editor + diagnostics
β β βββ ProgramManager.tsx # Save/load/export/import + snippets
β β βββ ToolManager.tsx # Tool library browser
β β βββ MaterialPanel.tsx # Material library selector
β β βββ FeedsCalculator.tsx # Feeds & speeds calculator
β β βββ CodeReference.tsx # 65-code reference
β β βββ GuidePanel.tsx # Educational guide
β β βββ SceneOverlay.tsx # 3D view toggles + camera presets
β βββ ui/ # shadcn/ui components
βββ lib/
βββ cnc/
βββ parser.ts # G-code interpreter
βββ store.ts # Zustand simulation store
βββ carve.ts # Workpiece carving engine
βββ tools.ts # 8-tool library
βββ materials.ts # 8-material library
βββ feeds.ts # Feeds & speeds math
βββ reference.ts # 65 CNC code entries
βββ examples.ts # 26 example programs
βββ snippets.ts # 15 code templates
βββ programStore.ts # localStorage program manager
βββ viewStore.ts # View/camera options
βββ types.ts # Shared types
```
---
## π¨ Tech Stack
- **Next.js 16** (App Router, static export) Β· **TypeScript 5**
- **react-three-fiber** + **@react-three/drei** + **Three.js** β 3D rendering
- **Tailwind CSS 4** + **shadcn/ui** β UI components
- **Zustand** β simulation state Β· **react-resizable-panels** β layout
- **lucide-react** β icons
---
## πΊοΈ Roadmap
- [x] High-fidelity 3D gantry VMC with real material removal
- [x] 26 example G-code programs (Beginner β Advanced)
- [x] DRO control bar with Run / Dry Run / Machine Lock modes
- [x] Feeds & speeds calculator
- [x] Tool & material libraries
- [x] 65-code G/M-code reference
- [x] Save / load / export programs locally
- [ ] 4th-axis (rotary) simulation
- [ ] STL/STEP stock import
- [ ] G-code export from CAM-style geometry
- [ ] Lathe / turning simulation
- [ ] Mobile-optimized touch controls
> Have an idea? [Open a discussion](https://github.com/rudra496/cnc/discussions) or [request a feature](https://github.com/rudra496/cnc/issues/new?labels=enhancement&template=feature_request.md)!
---
## π€ Contributing
Contributions are welcome and appreciated! Whether it's a bug fix, a new example program, a tool definition, documentation, or a feature β every contribution makes CNC learning more accessible.
1. **Fork** the repository
2. Create a feature branch: `git checkout -b feature/amazing-feature`
3. Commit your changes: `git commit -m 'Add amazing feature'`
4. Push to the branch: `git push origin feature/amazing-feature`
5. Open a **Pull Request**
See [**CONTRIBUTING.md**](./CONTRIBUTING.md) for detailed guidelines, and please read our [**Code of Conduct**](./CODE_OF_CONDUCT.md).
---
## π¬ Community & Support
[](https://github.com/rudra496/cnc/discussions)
[](https://github.com/rudra496/cnc/issues)
[](https://github.com/rudra496/cnc/issues)
- π Found a bug? [Open an issue](https://github.com/rudra496/cnc/issues/new?labels=bug&template=bug_report.md)
- π‘ Have an idea? [Start a discussion](https://github.com/rudra496/cnc/discussions)
- β Like the project? [Star the repo](https://github.com/rudra496/cnc/stargazers) β it helps others discover it!
- π Share it with a machinist, student, or maker who'd love it.
---
## π License
Released under the **MIT License** β see [LICENSE](./LICENSE). Free to use, modify, and share. Built for learning and experimentation.
---
**Enjoy milling!** π
Made with β€οΈ by [**Rudra Sarker**](https://github.com/rudra496)
[π Portfolio](https://rudra496.github.io/site) Β· [π» GitHub](https://github.com/rudra496) Β· [πΌ LinkedIn](https://www.linkedin.com/in/rudrasarker)
If CNC Simulator Pro helped you learn or teach CNC, please consider **β starring** this repository and **sharing** it. It makes a real difference.