Recently, to do a little bit of 3D modeling, I wanted to try my hand at making a modular back cover for my iPhone. Yes, there’s too many 3D printable models of iPhone covers, but sometimes, we reinvent wheels not to have more wheels, but to have more inventors. To do something a bit more organic, my concept was to have a pattern of leaf veins for my iPhone backcover, Graftleaf.
However, instead of drawing a leaf pattern myself, I generated the pattern from an image using free tools. That’s what the rest of this tutorial will help you do, and what I learned.
First, I had to go find a creative commons image of some leaf veins. I need something that was CC-BY, which allowed derivative works. I also needed the image to be sharp (damn you, tilt-shift) with high contrast. I used flickr’s advanced search, so you can look for CC images.
Next, I fired up GIMP, an open source alternative to Photoshop. After you open up GIMP, then open up the leaf vein picture above through File -> Open.
Now we want to convert it to grayscale. Image -> Mode -> Grayscale.
However, the colors are inverted. We want the veins to be black. Colors -> Level.
Move switch the positions of the black and white arrows in “Output Levels”
Now, we want to make the veins a solid black and white. Choose Colors -> Threshold. Adjust it until it the veins are thick, but there aren’t too many spots in the cells between the veins.
Lastly, we want to crop the image to make the details more visible, as well as reducing the complexity of the image, so the PNG to DXF conversion won’t take a long time.
Now that our image is edge detected, and we can now save it to a file as a PNG. Now, we’ll use an open source tool for vector drawings, called Inkscape, to convert the PNG to DXF.
This is where OpenSCAD gets a little finicky. It can’t read all types of DXF files, so we need to install an Inkscape extension that allows us to save DXF files in a format OpenSCAD can read. Go download the extension. To install it in Inkscape, copy the *.py and *.inx files (in the zip file of the extension) to your Inkscape extensions folder. Where the extensions folder is located depends on what system you’re using.
- Linux: ~/.config/inkscape/extensions/
- Mac OS X: /Applications/Inkscape.app/Contents/Resources/extensions/
- Windows: C:\Program Files\Inkscape\share\extensions\
(If you’re all-pro, you can use git to clone the extension into the inkscape extension folder.)
Once you have that installed, open up Inkscape and load up the leaf PNG we just saved. When it asks you if you want to link or embed, choose embed.
Next, we want to trace the bitmap we have as a path. First select the bitmap by clicking on it. Then Path -> Trace Bitmap. I just used the default options, but you can play around with things then click update to see what it would look like.
Now you have two objects on the canvas. One is a vector path of the leaf veins, overlaid on top of the bitmap of the leaf veins. Move the vector path out of the way by dragging and dropping it. Then select the bitmap and delete it. Then move the vector path back.
Now, we can save it to DWF using the extension we installed earlier. File -> Save As. Make sure you select “OpenSCAD DXF Output (*.DXF)” as the file type to save as.
We finally have our DXF file that we can use in OpenSCAD, as you can see all the assets.
Now, we can use it in our OpenSCAD! We can write the OpenSCAD snippet:
linear_extrude(height = 4)
In making Graftleaf, I actually did the additional step of compiling with CGAL (F6 in OpenSCAD), and then exporting the result to STL. Then using the STL in the final model, for faster renders.
If you found this more advanced OpenSCAD tutorial helpful, let me know! I’ll write more. Have a great week!