This Instructable will teach you how to create generative objects with Processing code that can be 3d printed. One of the delights of using generative code to print things is that you can randomize certain elements so that every time you render a piece, it's completely unique. I was heavily inspired by the jewelry of Nervous System, which demonstrates this concept beautifully.
If you've never used Processing before, it may be helpful to look at a beginner tutorial first.
You will be using:
- Modelbuilder, a Processing library*
- Netfabb Basic, a free version of 3d modeling software
- A 3d printer or a 3d printing service, such as Shapeways
*There is a newer version now, Mk2 (however, the code in this tutorial was written before it came out and only works with the original Modelbuilder)
BTW, I'm using a Mac, but you should be able to do it with Windows and Linux too.
Step 1: Setting Up the Environment & Sketch
You should also grab Modelbuilder's source code from Github. In the modelbuilder master folder, navigate to export > Modelbuilder v0007a03. The folder inside there, called modelbuilder, is what you should move into your Processing libraries folder.
Once you've got everything in the right place, open Processing and create a new sketch.
The code here shows the basics of what you need to initiate your model object and bring up a blank canvas. If it throws and error on the first line, make sure your ModelBuilder library is in the right place, and that within it, the 'unlekker' folder exists inside of 'src'.
Step 2: Create a 3d Shape
What kind of shape you decide to make is up to you. You can start with something simple just to wrap your head around making 3D shapes with code, or you can use my code. I decided to make a cluster of hollow pyramids that are set to random heights each time to sketch is run.
Step 3: More Ideas: Get Creative With Your Interface
If you want to go a step further, you can make your sketch interactive by creating an interface that accepts input. For example, you could add sliders to your sketch's interface to adjust the heights of the pyramids, or make the grid size customizable.
The example shown is the interface for another project, where I made my own custom bracelet generating app. I made a program that allows users to design their own pixelated icon on a 16x16 square grid. The program then takes the design and repeats it all around the bracelet, with holes containing Xs filling in the black pixels.
Step 4: Export & Resize in Netfabb
Once you've decided on a shape to make and have previewed it by rendering your sketch, you'll see in the code there's a line to export the model to an STL file (a common 3d format) when you hit the 's' key. That's one of the cool features of ModelBuilder.
Go ahead and test the export function and make yourself an STL file, which you should find in the same folder as your sketch. Then open that file up in Netfabb (Project > Open.).
In Netfabb, you'll first want to adjust the size of your object. Because pixels don't really convert into physical world units, you may find that the shape you exported is way bigger than expected. Make sure your shape is green, indicating that it's selected. The Netfabb interface will show you your object's dimensions in the bottom right, and you can use the Scale Parts tool in the top icon menu bar to resize it. I made the base of the pyramids shape 100x100mm.
Step 5: Repair the Object
You may have noticed a big red exclamation point in the bottom right of the window. This means your object has been diagnosed with a hole that shouldn't be there, or maybe the edges don't quite fit, or something else is wrong, so you need to click the red first aid icon at the top to start fixing it. You'll then see a panel in the bottom right called Status. Play around in the Actions panel (right next to Status), until you have 1 shell (i.e., a single object), and 0 for border edge, invalid orientation, and holes. I managed to repair my object by clicking Close all holes, Stitch triangles, Fix flipped triangles, and Remove double triangles. For more info about repairing, check out the Netfabb wiki and this tutorial by Shapeways.
After you've done that, right/ctrl-click Part Repair on the right side bar, and select Apply Part Repair. In the dialog box that pops up, select "Remove Old Part".
"Your Part (Repaired)" should be selected in the right bar, and there should be no exclamation point indicating your part is error-free, so it's time to export this new and improved version of your object. Select Part > Export Part > As STL. If you get a dialog box that says "Some file formats do not include information. This may result in errors" you should click Optimize, and everything will be good to go.
Step 6: Print Your Object
Now you're ready to send your object to a printer. I used Shapeways, but maybe you have access to a 3d printer somewhere else.
If you are going to use Shapeways, make an account on their site, and follow the instructions on the Design tab at the top of the page to upload your design. You'll see that they tell you how much material your design uses and how much it'll cost, which may make you want to tweak your design to see if you can shave it down a bit.
Here's what I got back, printed in "frosted detail" translucent plastic. My next step is to make a PCB with addressable LEDs to put inside it so I can light up each pyramid and make some sort of tabletop light art object.
Participated in the