Roland's homepage

My random knot in the Web

py-stl / stl2pov

Note

The Python version of this program has been renamed to stltools. The version on this page is therefore out of date.

The C version is still current, although it has limited functionality compared with the Python version.

Introduction

The origin of this software was found in the desire of the author to render 3D CAD models using the POV-ray raytracer. Next to geometric primitives, POV-ray can also use meshes. One obvious way to generate those from CAD software is to use the STereoLithography (“stl”) file format.

History

The first effort produced the stl2pov program, written in C. This went through the usual evolution of fixing bugs and adding features. And it reached a point where the original design ran into its limits; it ran very slow on large files because it tried to detect and correct errors (like e.g. gaps or degenerate facets) in the STL file. This turned out to be very hard to do correctly. The key problem is that only the program that generates the STL file has the geometric information and context to produce a correct STL file.

Later the author converted that program to Python as a learning experience and to easy portability. This resulted in a more re-usable version of the software to parse STL files as a Python module. This paved the way for more programs to use it.

Design

The current version is written in python, and requires version 2.x. Additionally, the stl2pdf program requires the cairo library and its python bindings.

The module stl.py reads both text and binary StereoLithography (“stl”) files and creates stl.Surface objects. The actual interpreting is done in a generator method, so it is possible to read large stl files without blocking the program. The module xform.py handles coordinate transforms and projections.

The programs stl2pov, stl2ps, stl2pdf and stlinfo use this library to convert stl files to POV-ray meshes, PostScript and PDF files respectively, and to provide human readable information.

Programs

stl2pov

This is a refactoring of the C version 2.x. Version 2 was too slow, basically because it tried to do too much. This version is a straight translator. It produces a POV-ray mesh declaration that you can use in your scenes. N.B.: you have to instantiate the mesh as an object, give it material properties, define a light and a camera &c.

stl2ps

This is a new script that produces a view of the STL object looking down parallel to the positive Z-axis on the centre of the object. Rotating the object is supported. Currently the output uses only greyscale and a very simple shading algorithm. It does not draw facets that point away from the viewer. The remaining facets are sorted back to front by average depth of their vertices. The removal of completely occluded surfaces has been tested and dropped as too expensive. Shadows and more sophisticated lighting effects are not planned, but patches are welcome.

stl2pdf

This is basically a variant of stl2ps using the cairo library to generate PDF output directly.

stlinfo

print human readable information about the STL file or a human readable (text) version of the STL file.

Download

source:py-stl-3.1.zip
GPG signature:
——-BEGIN PGP SIGNATURE——-
Version: GnuPG v2.0.22 (FreeBSD)

iQIcBAABAgAGBQJTEzjbAAoJEED21dyjijPgntMQAJFXnZRbQJ+JQHS7XHCZMlrK
PlSK9M4iwzg4TiHub87P9BevF4NKn270cJbOHq0vHEInkEVPmTLrgb1AC3Sv0ZZK
ijaHLFfBd+D62jZrY5+uzNIhtp5NbQ2vYnlzaHkUY33beUFdP7ZK4I0Cl/w5ShqM
wKZFrK/dCod6CCmTDk6PeF7/HbR0CBd0W5XFJS3DcEjdNzV9tDuzyD6JAKKApSLf
PP4yhTWwdzvCeIwUh7jwrOW8YzXhCI/Rm9sn6ZX9kq/hjyLpTzDoYzf1u3Ij7WYr
LknECl4vOX6L1hoMgbElePSmXlWaUqnljIgRKRHWe3HU3fIOQsIFS/XGAlZVVQ2J
4TM8a/JxUWN5KZYzfwNUrZ1lKSaTn7j1MBKYFzI4pMLDtzLe+/oUMrh+kF/wX4x7
piULok5Q1azw5FasTZ71U9TI1Eo/URVlCgxxM+u8ewf/x2XkccOdnhyGZuvJfXHS
lE/NFxI7GzGxcl0M+8gOXumkCrl+g6KqEsXYRnaOCDL+UvU1imsZQioruG+R6tFw
Y7iNiK217YMR9BuFjPVB0JhwB1PZ15uoVq00gF3s2ssQf/y0Wbl1mBYKXI5AgS/e
0jA5zOoZZhBgci1X3HYDXpRD/IHsRaruH5CAneL6bobWd5vVHMqIyZxt6rP+iSYp
jqseajfHUV5SqJC7aaq0
=MI/J
——-END PGP SIGNATURE——-
SHA256 hash:d5a2eccbd627d05b28d3b6d619202d3a55b4d94dbf21a63b68109688ebc8e929
Requirements:python, cairo

For those who do not want to use Python, below is the latest version written in C. This only contains the stl2pov program!

source:stl2pov-2.5.0.tar.gz
GPG signature:
——-BEGIN PGP SIGNATURE——-
Version: GnuPG v2.0.22 (FreeBSD)

iQIcBAABAgAGBQJTEzj2AAoJEED21dyjijPg2qUP/inBgcFzAebDPQnKr66Vw5ah
/U1zvzYnxSDZsuLKW/S6pK1HbSLQnY1LSnsnlGQ2VwSVu7zlGjxVZrDVXwcoiNwA
BBbrVruKRRTn8Y3csBWksOW68It7K3cqrAk7xHdXJ8YSimdPZakQ3GJ0DL54b323
IJtQpTgpHuhnD1siF41gDrJjvLbdt6mShFVydV/K6u4wP6lAou7QDBUW6iqY3zsV
9nlRTBI3xCaELHK+bQUxDLoSDzcwXBB6Ap4FL4cO6JCfP6EYJUZHSRD/0l+k4NDY
DR2xoXD4RpaZrxs9/eciy9NJJ0Ayw6izXmjwI9rlH8jIhUds2rNMrjmNkCrYCvS8
Co3McQNTaijWL5ZkWpxGcAVPLouNH3cV3otJbQ5WuNAf4MS/mbcBarn+f+cidsCa
b6dl7SviYh2fiIP+YNHoZqe4OnGiMS3F4VZ8SeZadfuv5xU5ZbAq/dOklzmC1E9g
uL5M+qzqBsg6jkgJ0jUe9Si2/m+uCpNk79Dnvfj0/YJCnTBIkGsQGiXJ7PzBo6il
xdT/9U3NxpDwQ4KJZLKWXljgVWvxa4HkYu/1MwMehdV9XqDAp9jYQVLgcVgSTSfO
7CUGhkoYTwqjrmiBX/9fUO9VdGwoBx99WdQCTV5/6HNDYLlGLbg/e/Ja+6OiCrbY
XT+PcV1dzrpLxKuHfPLN
=GEp8
——-END PGP SIGNATURE——-
SHA256 hash:6a22915b7577db1166b03805ceb1aa01d2aa4afff67267fd4ef0246b701e3ab2
Requirements:C development environment, make.

Update: 2014-03-02 (new signature)
Update: 2014-06-16 (redirect to renamed version)

For comments, please send me an e-mail.


Related articles


←  lamprop dxftools  →