Category Archives: Software

Slicing STL files in POV-Ray


We have been using POV-Ray to create 3D models and render bitmap slices that can be printed with the CandyFab 4000, our home-built 3D sugar fabricator. One thing that we could do to extend the usefulness of this procedure is to be able to take STL files as input, because STL is the de facto standard file format for 3D fab shops and the machines that do the fabrication. So, here’s how to do it: STL files can be converted to POV-Ray format, and from there we can use our usual bag of tricks to render the set of bitmap slices.


In this article, we explain that process in more detail: We’ll take an STL file, import it into POV-Ray using the stl2pov utility, and then set it up to render a series of slices. Our example file is the sculpture Metatron by Bathsheba Grossman, who has released the STL file for it into the public domain (with some interesting results). The picture above shows Metatron, as rendered in POV-Ray.


The first step is to get and install the stl2pov utility from the author’s page. It’s a cross-platform command line program. (Mac/Linux/Unix users, follow the instructions to compile the source. Windows users, go ahead and download the compiled binary.)


Next, we need an STL file to convert. If you have your own, you can certainly use that. To follow along using the Metatron STL file, go to http://www.bathsheba.com/downloads/ and download the file metatron.zip, a 3.1 MB .ZIP file. After decompressing, that yields metatron.stl, which weighs in at 6.6 MB.

Since we have the utility and the source STL file, we’re ready to perform the conversion. The output file after the conversion will be a large text file that can be awkward to work with. A solution that makes things easier is instead to make it into a POV-Ray .inc (include) file, so that we can simply edit a small POV-Ray wrapper that calls the included file that describes our complex object. To perform the conversion at the command line, execute the following code in the directory with metatron.stl:



stl2pov -s metatron.stl > metatron.inc

The “-s” option turns on smoothing, an option that I have found to increase reliability, and the command saves the converted output to a new file called “metatron.inc”. Unless your computer is really fast, go get some coffee and come back in ten minutes– the conversion can take a while. My file ended up at 28 MB — large enough that you may want to edit it in a dedicated text editor (emacs, vi, AlphaTK….), not the editor built into POV-Ray.


The contents of the new metatron.inc consist of a single definition of a POV-Ray mesh object made out of smooth triangles. It looks like this:

#declare m_Rhinoceros_Binary_STL___Jun_15_2005__ = mesh {
smooth_triangle { // #1
<-1.56964, 0.774161, -0.360695>, <-0.898199, 0.389497, -0.20379>,
<-1.59137, 0.732853, -0.338752>, <-0.910102, 0.368279, -0.189959>,
<-1.57298, 0.776465, -0.341074>, <-0.903134, 0.383962, -0.192153>
}
smooth_triangle { // #2
<-1.58513, 0.728167, -0.377533>, <-0.910933, 0.36028, -0.200995>,
<-1.56964, 0.774161, -0.360695>, <-0.898199, 0.389497, -0.20379>,
<-1.56618, 0.771805, -0.379959>, <-0.892874, 0.395758, -0.214829>
}

[Snip! Insert 28 MB of the same right here…]

smooth_triangle { // #138379
<0.486637, 0.670353, 0.431943>, <0.678163, 0.482259, 0.554546>,
<0.451365, 0.691581, 0.456294>, <0.669205, 0.482143, 0.565423>,
<0.480983, 0.649411, 0.456491>, <0.678073, 0.468723, 0.56614>
}
smooth_triangle { // #138380
<0.451365, 0.691581, 0.456294>, <0.669205, 0.482143, 0.565423>,
<0.427022, 0.675693, 0.497914>, <0.659582, 0.482502, 0.576319>,
<0.456994, 0.655713, 0.480073>, <0.669431, 0.473142, 0.572712>
}
} // end of mesh m_Rhinoceros_Binary_STL___Jun_15_2005__



The #declare statement in the .inc file tells us that it defines a POV-Ray mesh object called “m_Rhinoceros_Binary_STL___Jun_15_2005__”, and it is up to us to use it. Minimally, we need to call #include “metatron.inc” to get the file, and then place the object somewhere. Here is a complete code example, for a POV-Ray file (let’s call it “metatronSimple.pov”) that can draw the Metatron, given that the metatron.inc file is present:

//metatronSimple.pov

#include “metatron.inc”

background{color rgb 1 }

object{ m_Rhinoceros_Binary_STL___Jun_15_2005__
rotate 90*x

texture{ pigment{ color rgb <1,0.5,0> }
finish { ambient 0.15
diffuse 0.85
specular 0.3 } } }

light_source { <-20,100,20> color rgb 2}

camera {
perspective
angle 35
right x*image_width/image_height
location <-3,7,15>
look_at y*0.25
}



Since we can now render the sculpture, are we done? Note quite. There’s one little detail to worry about which is that the mesh object does not really have a defined inside or outside, which becomes a problem when you want to start slicing it up with boolean operations. The solution to this is to define what’s called an “inside vector” that tells POV-Ray where the inside of the sculpture is.
The vector is added just before the closing bracket of the #declare statement, at the very end of metatron.inc, like so:



inside_vector <-0.5, 0.68, 0.5>
} // end of mesh m_Rhinoceros_Binary_STL___Jun_15_2005__


With that modification, you can now use full constructive solid geometry operations on the imported STL object, including slicing it. As we described in the article about the CandyFab 4000, it’s a matter of rendering an animation in POV-Ray to automatically generate the slices. For each frame of the animation, we take the intersection of the object of interest with a thin, flat rectangle, which is raised up a little bit higher with each successive frame:



#if (overview)
object { m_Rhinoceros_Binary_STL___Jun_15_2005__ rotate 90*x }
#else
intersection {
object { m_Rhinoceros_Binary_STL___Jun_15_2005__ rotate 90*x }
box { < -50, 0, -50>, < 50, .10833, 50>
translate y*frame_number*0.10833 }
}
#end // end if


As you can see, we’ve also added a code “switch” (“#if (overview)”) that determines whether we’re slicing the object or just displaying it. Also note that the slice thickness can be chosen however you like; our 3D slices are 0.10833″ thick right now, so that’s the value that’s displayed here.

Of course, if you’re just displaying the object (not slicing), you might want to make it look a bit nicer. The rendering at the top of this article was made by adding a background, some texture, lighting, moving the camera, and was otherwise gussied in ways that you don’t want if you’re slicing up the object. These are all controlled by the same software switch (overview) which is at the beginning of this POV-Ray file, which is called “metatron.pov”. You can download this code example (along with metatronSimple.pov) here (3 kB .ZIP file).


Setting overview = 0 instead, we can now render the slices. Turn on animation, i.e., the clock variable, in POV-Ray, and set it to render 58 frames. You can use the lowest quality setting (Quality 1) and antialiasing should be turned off. Running that produces 58 separate bitmap image files; here is what a selection of four of those slices looks like:


Just looking at a few slices doesn’t really give you a flavor of what the whole object looks like, however. One trick to visualize it is to scan rapidly through the image slice files like a flip book. You can watch this little quicktime movie (53 kB) of doing just that to get the idea. If you watch a few times, it can give you good intuition into how the structure actually fits together.


So are we planning to render Metatron in sugar? Yes, but not yet– it’s a detailed sculpture and we need to improve our effective resolution (or total build size) before going there. We have, however, previously used the technique we’ve described here to fabricate Soliton, which is another one of Bathsheba Grossman’s sculptures.

Laying out printed circuit boards with open-source tools

There has historically been, and still is, a lack of good, free MacOS native EDA (electronic design automation) software. The situation has somewhat improved in the past few years because the X11 layer in Mac OS X allows graphical unix applications to run natively on the Mac, concurrently with other programs. I recently learned to use some of these tools in the gEDA suite to lay out printed circuit boards. These (loosely, if at all, organized) notes should be helpful to anyone that wants to get started making PCBs using a mac, linux, or other unix-like system.
Continue reading Laying out printed circuit boards with open-source tools

Reminder: POV-Ray class this Saturday

We posted earlier about (Evil, Mad) classes that we’re teaching at TechShop, the SF Bay Area’s public-access workshop. The first of these, Technical Graphics with POV-Ray is this Saturday afternoon, 3/31.

POV-Ray is free software that can make genuinely impressive 2D and 3D graphics and animations (examples), but the learning curve is such that it can be difficult to get started on your own. So, drop in and learn how to make it look easy!

LabVIEW routines for the MAKE Controller

MakeController

As evidenced by a growing collection of projects, the MAKE Controller has great potential as a hardware platform enabling computers to really do things.

We won a MAKE Controller for our set of Halloween projects this year, and we’re just starting to play around with it. Having spent some pondering how best to communicate with the board, it’s clear that one of the barriers to more widespread use of this and other embedded systems is the lack, or perceived lack at least, of user-friendly software for programming and communication.

A number of open-source software packages, such as processing and Ruby, can communicate with the MAKE Controller using its OSC interface. However, there has been a noticeable absence of a suitable interface to LabVIEW, a program that is commonly used for interfacing to other similar types of hardware.

So, we wrote one. It’s a simple LabVIEW “vi” routine for issuing (most) simple commands and queries to the MAKE controller. We’ve also included some example routines to help you get your blinky lights going a few minutes sooner.
Continue reading LabVIEW routines for the MAKE Controller

Fixing a bad frequency fuse bit on an AVR

ATtiny2313

This is a quick note on AVR programming with the AVRISP MkII programmer, with which it is possible to foul up your clock fuse bits. =)

(This might be plain as day to some out there, but *I* didn’t know about it, so I thought I’d jot it down.)

Minor problem: I was programming some AVRs when I thought I might try to change the clock fuse bits to use one of the low-frequency internal oscillators. Apparently, it is possible to change the clock frequency low enough that the ISP interface can no longer program the flash– at which point it *seems* as though the chip is lost. These are inexpensive chips, (around $2 each), but the cost can add up quickly if you don’t fix the broken ones. Besides, they’re made of plastic, so you can’t even recycle them into a trivet.
Continue reading Fixing a bad frequency fuse bit on an AVR

Programming the Atmel ATtiny2313 in Mac OS X

avrdevboard

For a recent project, I needed to control sixteen or seventeen LEDs with a microprocessor. The one that I chose was the Atmel ATtiny2313, because it has 20 pins, with up to eighteen outputs, can run without an external oscillator, and is fairly inexpensive at around $2.00 per piece.

Since I’ve got a Mac laptop and no real serial or parallel port, I opted to go with a USB-based programming solution. Furthermore, I wanted to program in C, not assembler, and use open source development tools. Since I was (eventually) successful in all of these goals, I thought that I should write up a few notes about it.
Continue reading Programming the Atmel ATtiny2313 in Mac OS X

Make a Video Feedback Screen Saver in Quartz Composer

Quartz Composer is an easy to use tool that lets you create amazing digital art, even interactive digital art, without writing a single line of code. You might already have it: Quartz Composer is included as part of developer tools package (Xcode) that comes with Mac OS 10.4 Tiger. In this tutorial, I’ll show how to get started with Quartz Composer. No prior programming experience is required. As an example, we’ll build a video feedback screen saver that can take input from an iSight camera.
Continue reading Make a Video Feedback Screen Saver in Quartz Composer