No description
Find a file
2021-12-22 18:53:10 +01:00
example.png give some love 2021-12-22 18:49:31 +01:00
example.stl give some love 2021-12-22 18:49:31 +01:00
example.svg fix example.svg by removing first path 2021-12-22 18:53:10 +01:00
LICENSE give some love 2021-12-22 18:49:31 +01:00
README.md image links 2021-12-22 18:50:11 +01:00
requirements.txt init 2021-12-22 12:16:31 +01:00
svg2stl.py fix example.svg by removing first path 2021-12-22 18:53:10 +01:00

svg2stl

This repository provides a script which takes as input an SVG such as this one:

example.svg

It outputs an STL file like this one:

example.png

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.