algorithmic modeling for Rhino

For another project I have been working with metaball scalar fields, and I thought it would be fun to have a go at meshing them using Paul Bourke's marching tetrahedra methods.  I know that Daniel Piker has done a little of this before more generally, and that there is an excellent implementation of the marching cubes algorithm as a part of Millipede...this is really just more specifically set up for generating metaball meshes.

On its own, the marching tetrahedra algorithm as outlined by Paul Bourke produces some odd results for metaballs...basically, the points that drive the mesh are assigned along the edges of the tetrahedra according to a linear interpretation of the iso value...what this means is that if you have an "ideal" iso value say of 0.29, and the sample points at each end of your tetrahedron edge return values of 0.2 and 0.3, the point will be located along that edge at 10% of the length away from the point with the 0.3 sample.  In general, this works fine, except (from what it appears to me at least...could be wrong here) that the metaball field itself isn't really linear, and the tetrahedra used for sampling are carved from cubes such that the lengths of each edge differ that there are a few spikes and dips here and there.  Sampling resolution has a lot to do with these results as well.  I address this issue here by embedding laplacian smoothing as a part of the process, and also by an additional field value sampling run for each mesh vertex after the initial mesh has been constructed.

So the inputs are your metaball centers (as a list), their radii (also as a list, which is the location at which their isosurface value contribution is 0), the iso level threshold, the grid resolution for sampling (here a lower number produces a higher resolution...basically is the rough size of the grid in the x, y and z directions), and the number of smoothing passes run after the mesh is generated.  The outputs include the metaball meshes as well as the bounding box that's used, as well as the centers of the sample cells (both of these last are superfluous but perhaps interesting).  I'd suggest starting with a low resolution (higher res value) for sketching, as it works pretty quickly...then if you want, you can increase the the sampling density (and incur the resulting exponential slowdown).

I've used a couple of tricks for reducing the number of sampled points (nothing so sophisticated as an octree subdivision), but there are also definitely inefficiencies in points shared between sampling cells having their fields calculated multiple times.  There's really plenty of room for improvement...this is just a rough pass really, but I figured some people might have some fun with it and it seems that every now and again the issue of making metaball meshes comes up, and I figured that it'd be useful to have a quick way of building (relatively) clean meshes laying about.

Also, probably lots of bugs everywhere...feel free to point them out...and the code's pretty ugly, but poke around, take it, do what you will with it.

Views: 19201


You need to be a member of Grasshopper to add comments!

Join Grasshopper

Comment by David Stasiuk on February 1, 2015 at 3:58am

Hi Rodion-

If you're going to try to adapt a script, I would actually suggest using this later implementation: It's much faster, more flexible, and overall better organized.

These scripts are all built off of the development work of Paul Bourke. For example, all of the lookup tables that define edge and face topologies are supplied directly from him...I'm afraid that there really isn't an easy answer to any of this. Is there any reason you can't use the code as it is?

Comment by Kailey O'Farrell on October 17, 2014 at 10:52pm

Hey David,

Thanks! I don't know why I was trying to make the mesh the way I was...your definition made it really easy. Thank you!!

Comment by David Stasiuk on October 17, 2014 at 1:55am

Hi Kailey-

Cool...I would highly recommend using my updated metaball definition, which allows for the integration of multiple input geometries (points, but also curves and breps). There is also some limited control in varying the charge levels along each of the any event, have a look. I would also suggest that you couple it with Mesh Machine, which Daniel Piker created and is available as a component in kangaroo, and which will remesh the marching cubes algorithm into a better mesh.

Comment by Kailey O'Farrell on October 16, 2014 at 4:35pm

Hey David,

I am trying to mesh some metaballs along curves to make a fluid or more organic structure that will eventually deform, so distributing metaballs over the curves works well because I can control the threshold. So the output is isocurves, which is great to visualize what it would look like but I need to make them into a mesh surface. I took a look at this definition which you uploaded which is great! but I havent been able to successfully integrate it into my definition. If you have some time to take a look and help me that would be great!! Thank you!!

Comment by Ewa Kus on August 27, 2014 at 12:03pm


Comment by h on February 22, 2014 at 12:05pm

oh this is great work!

Comment by Andrea Graziano on August 16, 2013 at 3:25am

Thank you David ... it works really well!

Comment by SIMON ESCABI SANTOS on August 1, 2013 at 2:38pm

Thankyou! This was very usefull! 

Comment by Danny Andrés Osorio Gaviria on July 28, 2013 at 2:18pm

Beautiful David!!!... Thank you for share your knowledge!!!...

Comment by David Stasiuk on July 26, 2013 at 9:46am

If you downloaded this already and it's telling you you're missing assemblies, then download the link again.  I had a couple of assemblies in there from earlier, and have removed them, so it should be good now.





  • Add Photos
  • View All

© 2021   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service