Wednesday, March 25

Final Project Part 1: STL Files

We're now on the home stretch of this Advanced Computer Programming class, so the class is starting to work on final projects. I decided to program a 3D printer from scratch. Should be fun :).

The basic idea is this: the SLA DLP 3D printer (which I'm building on the side) uses a standard computer projector to solidify subsequent layers of light-curable resin. The result is a physical object. So my program needs to take as input an STL file, which represents a 3D mesh of triangles. It then needs to calculate the cross section of the file at each layer height (of which there are many - objects 4" high with 0.1mm accuracy take 1000 layers) and send a corresponding image to the projector. At the same time, it should connect via serial communication to a microcontroller which moves a build platform to change layers.

My focus this week was the basics - just read in and process a binary STL file. I began by downloading some sample files here. Here's a 3D model of part of a pump:

An example STL file.

The STL file format itself is pretty simple: an 80 byte header, a 4 byte uint representing the number of triangles in the file, and then repetitions of a block of data representing each triangle: a surface normal represented by three floats, three points each represented by three more floats, and an extra 2 byte uint.

Result of reading in aforementioned example.
So here's what I came up with after a little tinkering. This file's 80 byte header contained "Uncompressed stl file", there were 178689 triangles in the file, and the object has the bounding box (every triangle fits inside) 1 < x < 5.2646, 1 < y < 8.587, and 0.4 < z < 3.8309. This looks promising!

Having succeeded with my goal for the week, I started to learn Qt, the popular "cross-platform application framework" that should let me easily create a GUI for my project. It's amazingly user-friendly, so I was able to do this with a few hours of work:


As yet, this little window has a fully functional menu ("New", "Open", "Save", "Exit", etc.), a text output panel on the left, and a graphical display panel on the right. The plan is to open an STL file, display its 2D shadow on the right, allow the user to place it anywhere on the printer build platform, and then, well, print. Each of those green square represents a different STL file - I can drag them around. Next up is translating my STL-reading code to Qt language so I can combine the two.

All in all, not a bad week's work!