stl2svg -- An STL to SVG converter
stl2svg
is a program that takes an STL 3D model, projects it orthographically
against a given plane, and generates an SVG document with the visible polygons.
stl2svg
is available on its source code repository
By default, stl2svg
will read STL data from stdin and write an SVG document
to stdout, projecting all polygons, regardless of visibility, into the Z
plane. With different options this behaviour can be changed.
Basic stl2svg
command line is like this:
stl2svg [-x|-y] [-n] [-o<FILE>] [<FILE>]
Option | Description |
---|---|
-x -y |
Project against the X or Y plane instead of the default Z plane |
-n |
Convert only polygons that are facing up against the projection plane at up to 90º its normal vector (removes hidden polygons) |
-o |
Given a file path <FILE> write SVG output to it instead of stdout |
<FILE> |
Read from file instead of stdin |
-x
-y
and -z
can optionally accept a vector in the form X:Y:Z
where
X/Y/Z are decimal numbers, for example -z0.0:0.0:-1.0
as to allow changing
the projection matrix with a custom one. This is not required for most use
cases.
Basic examples
We will be using the following 3D model, one of the samples from OpenSCAD:
Running stl2svg
with the default settings, would give us an SVG document
that looks like this:
We can change the projection plane from z to x or y by using the -x
-y
switches without any argument.
Advanced example
We may also set a custom projection base by defining the -x
-y
and -z
vectors of an algebraic base, which will be used to project the 3D model
against its z plane. For example, the following command line:
stl2svg -x0.71:0.71:0 -y0:-0.71:-0.71 -z-0.71:0:-0.71
Would give a tilted-camera projection of the figure instead of dead on x/y/z projection.
Notice the vector given are normalized (unitary length) if the vectors given are not unitary, the projection matrix will perform like a transformation matrix. This may be used on purpose to apply affine transforms if desired. For example, running with this arguments will perform scaling transform when run:
stl2svg -x0.71:0.71:0 -y0:-3.71:-3.71 -z-0.71:0:-0.71