Monday, August 26, 2013

Voronoi-tesselated Tetrahedron

I'm enjoying playing with mathematical objects and printing them. Yesterday I created a Voronoi-tesselated tetrahedron. Halfway through the print I dropped some bells into the central cavity to make a baby-rattle. The object is now on Thingiverse if you want to make one.

My starting point was a blog post showing how to do Voronoi Tesselations in MeshlabHowever, Meshlab is a bit crashy, so I had to do some experimentation. Here is the general procedure I came up with -- hope it helps you create some nice objects.

Launch Meshlab

Make sure Selected Face Rendering is on.. It's the icon with red in it to the right of the light bulb icon.

File > Import Mesh to import your nice fine WATERTIGHT mesh (otherwise, expect bad things to happen), or Filters > Create Mesh Layer > ... to start with a primitive (like the Tetrahedron)

Before you go further, you need to make sure that your object is properly aligned to the XY plane. Click the Wireframe icon (next to the dots icon, then rotate the model (left-click drag it) until there are 3 points that you want to be on the base of your model located where you can drag a marquee over just those points, then click the Select Points icon (next to the Rabbit icon) and do just that.  Then use Filters > Normals... > Transform: Rotate to fit on a plane, check both options and apply.

If you don't have enough vertexes (100-300k is good), use Filters > Remeshing > Subdivision: Midpoint (for primitives) or Filters > Remeshing > Sudivision: Butterfly (for more complex objects) to add triangles. Always set Iterations to 1, you don't want to get too many triangles. Also Edge Threshold to 0.

Click Layers icon (looks like a stack of paper) to show layers.

Filters > Sampling > Poisson-disk Sampling. Number of Samples = 50 to 60. Click Apply, and a new layer will appear in the layers list.

Click on your mesh object in the Layers list so that it is hilighted in yellow. After the sampling, it won't be.

Filters > Color Creation > Voroni Vertex Coloring. Check BackDistance. Click Apply. Your object will get nicely colored with Voroni cells.

Render > Color > None. The colors will disappear. You do this so that the next step is easier to see.

Filters > Selection > Select Faces by Vertex Quality. Check Preview. Slide Max Quality all the way to the right. Slide Min Quality left until you get nice thin borders -- but not too thin. Click Apply.

If the lines are not GREY, use Filters > Selection > Invert Selection. Click Apply. Lines will go grey, areas between them will be red.

Filters > Selection > Delete selected Faces. Now you have a holed, but flat, object.

Filters > Smoothing > Laplacian Smooth with Iterations = 3 to 5 will give you much smoother lines.

This is good place to save a checkpoint. File > Export Mesh AS... NOT File > Export Mesh, which will copy over your old file!!! Save it as a .stl.

Filters > Remeshing > Uniform Mesh Resampling. Precision 1%, Offset 53%, check Absolute Distance. Now wait a bit, and you'll get your thick version of the object. If Meshlab crashes, you probably had a bad initial mesh, it's quirky -- and you're screwed.

In the Layers panel, click on the eyes next to your original object and your Poisson samples to turn them off. You'll only see your new offset mesh.

Filters > Remeshing > Quadric Edge Collapse Decimation. Set the target to be .75 of the original number of vertexes. This smooths things out.

Repeatedly apply Filters > Remeshing > Curvature Flipping Optimization until the object is not getting any better (it may settle down to toggling between two states).

Now you want to increase the number of triangles and make them smooth. Alternate between these two:

Filters > Remeshing > Subdivision: Butterfly, Iterations = 1, Edge Threshold = 0.


Filters > Smoothing > Taubin Smooth

When you get to the number of vertices you think you need, Export As... and save your STL.

Oh, in the case of primitives, they will only be 1mm in size, so use Filters > Normals... > Transform: Scale to make them bigger before saving. The limit is 10x, so maybe do a 10x and a 2x = 20x.