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
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.
stl2svg command line is like this:
stl2svg [-x|-y] [-n] [-o<FILE>] [<FILE>]
||Project against the X or Y plane instead of the default Z plane|
||Convert only polygons that are facing up against the projection plane at up to 90º its normal vector (removes hidden polygons)|
||Given a file path
||Read from file instead of stdin|
-z can optionally accept a vector in the form
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
We will be using the following 3D model, one of the samples from OpenSCAD:
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
switches without any argument.
We may also set a custom projection base by defining the
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