svg2stl
This repository provides a script which takes as input an SVG such as this one:
It outputs an STL file like this one:
You can also see an interactive version here.
The resulting solid is a cuboid with holes in it. It essentially adds a third dimension to the SVG file. The purpose of the output STL is to be fed into a 3D printer. The end goal is to make a physical stencil for artistic purposes.
Installation
git clone https://github.com/MaxHalford/svg2stl
cd svg2stl
pip install -r requirements.txt
Usage
You can generate an STL with the same name as the input file like this:
python svg2stl.py example.svg --thickness 4
You can also show what this looks like in a GUI:
python svg2stl.py example.svg --thickness 4 --show
How it works
- The SVG file is parsed into a sequence of steps thanks to
svg.path
. - Each step is turned into 2D geometric coordinates by sampling from each step's parametric equation with
numpy
. - Each coordinate is duplicated so that there are top and bottom coordinates.
- The coordinates are stitched together to define panes: a floor, a ceiling, and many walls.
pygmsh
does the heavy lifting. It generates a mesh of triangles from the panes through constrained Delaunay triangulation.
Motivation
There are some websites out there that already do this. Like this, this, and this. But they're websites, and sometimes it's nice to be able to do this from the command line. Especially if you want to process many SVGs.
License
The MIT License (MIT). Please see the license file for more information.