Skip to main content

A package to help you convert a SVG file to a 3D STL file

Project description

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:

example.png

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

The thickness is the distance between the solid's bottom and top.

An SVG is a sequence of geometric lines. When these lines are not straight, then points are interpolated along their trajectory. You can choose how many points to interpolate as so:

python svg2stl.py example.svg --definition 12

In addition to saving the result, you can show what the rendered solid looks like in a GUI:

python svg2stl.py example.svg --thickness 4 --show

Some SVGs have bogus instructions at the beginning of their path definition. For instance, the first shape of example_bogus.svg is bogus and cause the rendering to fail. Skipping it does the trick:

python svg2stl.py example_bogus.svg --skip 1

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

svg2stl-0.0.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

svg2stl-0.0.3-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file svg2stl-0.0.3.tar.gz.

File metadata

  • Download URL: svg2stl-0.0.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for svg2stl-0.0.3.tar.gz
Algorithm Hash digest
SHA256 86a59cd4efd5abc97ca73e81319478d9ada7aecd3992e94f989e6032c17db992
MD5 eb6f6e6f2fe57246788d2186e012907a
BLAKE2b-256 22efbad54bd422d8b3e24e206285fa93baba465d4f2955a1d8fb7c530899111e

See more details on using hashes here.

File details

Details for the file svg2stl-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: svg2stl-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for svg2stl-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f4bd16fb14a17ce90ff4aca0204ac3b43ee98bf58f07c03e1390fb0ae02305e1
MD5 13eebce021491488762f432604cf958a
BLAKE2b-256 4f777fd655c4fe37cf06802203cf6864d98749f271f48b742d94d7dba599ee38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page