Build a 3D Slicer From Scratch
From Mesh to Machine Instructions
Last year I got my first 3D Printer, and like any normal Software Engineer, I quickly found myself fascinated by how the machine transformed a digital 3D Model into something real that I could hold in my hand. But as I dug deeper, I found surprisingly little written on how the software behind the machine actually worked. So, in a less normal fashion, I decided to learn by building my own 3D slicer from scratch!
This series is a culmination of those learnings, going from zero computational geometry background to printing a cube generated from my very own 3D Slicer. We won’t be building anything ready to compete with OrcaSlicer, but this series will ensure you are comfortable with the fundamentals of how slicers work. Furthermore, this isn’t just a theory course, and by the end you’ll get the unique satisfaction of being able to 3D print something that came from your very own slicer! I can tell you from experience that there’s nothing quite as magical as seeing something physical come to life from code you wrote.
What You’ll Learn
In this exploration, you’ll learn:
- What a Slicer Does: Breaking down why we even need Slicers in the first place
- Parsing STL Files: Understanding the lingua franca of the 3D Printing world
- Slicing Models: The basic algorithm for slicing 3D models into printable layers
- Simple Infill Generation: How to add rectilinear infill to give our model support and stability
- Path/Motion/Extrusion Planning: How we convert our slices and infill into printer-ready toolpaths
- G-code Basics & Generation: The language that controls 3D printers, and our final output
Prerequisites
You should have:
- Basic understanding of 3D coordinates and geometry
- Interest in 3D printing and computational geometry (Access to a 3D Printer is highly recommended, but not required for curious-enough minds!)
- Some prior programming experience, but experience in our implementation language of choice (Zig) is not required. I won’t be giving a programming tutorial, but we also won’t be doing anything incredibly advanced and I’ll explain the code as we go.
No prior experience with slicing software internals is required, we’ll build everything from first principles!
Table of Contents
What is a Slicer Even?
Learn what goes on behind the scenes when you slice a model (spoiler: it's a lot!) and the scope of what we'll be building in this series.
Parsing STL Files
Learn how 3D models are represented as triangle meshes in the STL format.
Slicing Models into Layers
Transform your 3D model into 2D cross-sections.
Rectilinear Infill
Fill in our layers with a simple tried-and-true infill type.
Path Planning
Convert our polygons and lines into an efficient path for the printhead to follow.
Motion & Extrusion Planning
Prepare for the real world by converting our paths into a plan for actual printhead movement and filament extrusion.
G-Code Generation
Final command assembly and generation of G-Code that you can run on your very own 3D Printer!