2016/02/05

Slicers

As an exercise at the Recurse Center, I wrote a slicer  in Python to convert an STL file into layers of PNG files.

At first, I thought I could calculate the lines of the layers from the triangles in the STL file, and then flood fill the closed area. This didn't quite work, because some layers would have 1 pixel features, and the flood fill would cause the whole image to be white.

After some research into how others have done this, I was inspired to compute the amount of times a ray passes through the mesh surface. All my rays were in the x-direction, and each layer would filter the polygon/triangle/facets at its height. The rest was geometry to find the edge points on the xy-plane, and then find the x-coordinate for each row in the layer image.

While my new inspiration took a different high-level approach, I ended up using much of the math I had been using to draw the outlines, particularly my calculation of the triangle edges in the layer. The difference was how I found the interior of the object.

I also added a feature I didn't see in Creation Workshop. I've been frustrated that I cannot see the holes in my lift bed when I place the object in the scene. My slicer takes a mask file that locates those holes, allowing the slicer to find the best placement for the object on the bed automatically.

No comments:

Post a Comment