Hand-printing a 3d bunny | part 2
The project so far
For best results, read part one first!
We want to slice the bunny horizontally into cross sections that correspond to our existing foam sheets so later on we can cut the foam into the shape of the bunny, layer by layer.
Terms defined
- Maya: a 3d program in the likes of Blender, 3dsMax, and Cinema4D. Think of it as a 3d sculpting and animation tool that allows users to make digital representations of 3d objects.
- Mesh: a polygonal object comprised of faces, edges, and vertices. For example, a cube mesh would have 6 faces, 12 edges, and 8 vertices (corners).
- MEL: Maya Embedded Language. This is a scripting language native to Maya that corresponds 1:1 with many tasks.
Strategy
Overall plan
- import the Stanford bunny.obj mesh (the bunny can be found on Stanford’s website)
- scale the bunny so that each 1 unit in Maya roughly corresponds to 1 inch in real life for an easy conversion factor, and such that the broadest cross section of the bunny can still fit on the largest pieces of foam I have
- slice the bunny into 1/8 inch cross sections (my foam sheets are 1/8 inch thick)
- isolate each cross section visually by layer for easy visibility toggling
Execution
Need for automation
Slicing the mesh repeatedly into cross sections was daunting. After making about 10 cuts by hand on the bunny and needing over 100 more, I was ready to turn to scripting. By hand, for each cut you need to:
- select the bunny
- select the Multi-Cut Tool
- click the bunny
- adjust the Multi-Cut Tool to slice the bunny at the right height (1/8 inch intervals)
- go into component mode
- double click a face on the slice to select the entire slice (aka the face loop)
- separate the slice from the bunny
This might not look so bad, but each cut would take me at least 30 sec. That’s about 1 hour for the mundane and repetitive work of 120 cuts, which is enough to make me want to try scripting it instead.
Bunny slicing
I decided to try out MEL for this automation, and after googling some examples figured out this script to do all the cuts along the entire height of the bunny (essentially, steps 1–4):
Separating the slices
Now that I had a bunch of slices, I wanted them separated from each other into separate objects. In Maya, different objects can be added to layers, and it’s easy to toggle layer visibility on and off, something I would find useful once cutting foam one layer at a time.
After having a rough time with MEL data structures (and the script running slowly), I decided to do this part in Python. My strategy was to look at the highest and lowest point of each face and use that to determine what slice it belonged to.
I was in the middle of converting my psuedo-code into real code, then I realized that the polySeparate command does exactly what I wanted when applied to the whole object itself. Oops.
// does what I wanted this large script to do
polySeparate -constructionHistory 1 bunnyMesh;
Filling out the slices
The bunny started off as a hollow shell, and the slices themselves ended up being these hollow rings. Since the thickness of the shell walls are virtually zero, when viewed from above the actual slice is hard to see. Thus, I wanted to fill in the gaps caused by my earlier slicing with faces.
Thankfully, Maya has a polyCloseBorder command that takes care of this in a jiffy:
Assigning to layers
With how I separated the slices from the main bunny mesh, sometimes multiple objects would result from a single slice (example — the slice along the ears would lead to two oval disks)
In the case of multiple objects per slice, I prefer to have them combined into a single object, leading to the code here:
Code that assigned each slice to its own layer:
Slicing results
I finally dipped my toes into Maya scripting! It’s been something I was curious about, but without feeling much cause to pursue, so I’m glad this project forced my hand, in a way. All in all, I’d say it went pretty smoothly.
Here’s a fun slinky-like animation I coded up with the rabbit slices:
Thanks for joining me on this adventure! Until part 3…