Grasshopper

algorithmic modeling for Rhino

Marching Cubes: Curve Wrapping & More Metaballs

UPDATE: 30-Jan-2014

140130_marching_cubes.gh

I have added breps as an input for wrapping geometry (it also can take lines now), as in the above definition. It has been updated for some efficiencies...now you can taper a curve at both ends if you choose, you only need to feed one radius, although you can feed as many as you like (it acts like the longest list component). The definition uses kangaroo, weaverbird and nudibranch, although I ahve also included some internalized geometry...but I highly recommend playing with those! Kangaroo and weaverbird are better-known essentials, but nudibranch is really fantastic too. Enjoy!

Some of the work posted lately by Nick Tyrer has gotten me thinking about marching cubes again...I had done some stuff with marching tetrahedra and cubes a ways back, and with some new inspiration (and a little time I could carve out today) I figured I'd take a stab at trying to make it more flexible and robust. There was a lot of room for improvement...certainly there still is. This is really a work in progress, so all caveats apply to the script...it can probably break, hasn't been thoroughly tested, etc. But I probably won't be able to do too much more with it for a bit, so I figured I'd put it out there if anyone wants to play with it.

The short of it is that the inputs can take any combination of points and curves, along with variable radii of influence for each geometry object. Also, if you're using curves, and want to "taper" the effect of it over its length (from start to finish) you can do so. For example, an untapered curve versus a tapered curve:

The marching cube stuff is derived from the amazing Paul Bourke's work. I'm calculating fields around points and curves using a standard metaball fall-off function. The trick to its (relative) quickness is in using rTrees to determine which sample points should have their fields updated by various geometry objects, and also in ensuring that points aren't sampled more often than they need to be. The use of the rTree has some up-front computational expense, but with larger geometry sets it saves a ton of time.

The definition has some examples in it, as well as a description of the inputs...but here there are again anyway:

G = A list of base Geometry, which can be any combination of curves or points

R = Radius...this is a list of the radius of influence for each geometry object. The number of elements in this HAS TO BE EQUAL to the number of elements in the geometry list

res = resolution...the edge length of each sampling cube, so smaller numbers reflect higher resolutions. Watch out...the lower this number is, it exponentially increases the calculation time!

iso = iso value for cutting the surface...the lower the number, the bigger the mesh will be

smooth = an integer equal to the number of smoothing passes you want to do on the mesh(es) after they've been created

taper = a boolean...if you're using curves, and want the mesh that wraps around the end of the curve to be tapered smaller, then set this equal to true

ratio = the taper ratio, a double between 0 and 1...this is how much of your base radius you want your tapered edge to be...so if your taper = 1, then your tapered edge should have the same radius as the beginning, 0.5 then it'll be half, etc.

run = a boolean to execute the code...it still can be pretty slow with a lot of geometry, so you can toggle this off to adjust your settings

Anyway, I hope you enjoy!

140120_marching_cubes.gh

Views: 63303

Comment

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

Comment by Andrew Clark on March 5, 2021 at 4:57pm

Hello, I am trying to achieve something very similar but generating a shape based on a curve's proximity to itself like in the example here. Can anyone lend a hand? 

Comment by Ralph Zoontjens on September 10, 2018 at 3:44am

Lu, if you toggle 'Run' on the Visual Basic script components it will work and generate your metaballs. It may have to do with the version of Rhino you are running whether these components will work well. You also need the vbscript.dll library. Otherwise post a screenshot of where your definition runs into an error, I will have a look at it.

Comment by Lu Yang on September 9, 2018 at 10:29pm

Hi David, could you please teach me how did you make this model? I downloaded the gh file and some component from kangaroo got lost, maybe a screenshot of your gh could help? Thanks a lot! 

Comment by Ralph Zoontjens on February 6, 2018 at 9:28am

Works like a champ! You can make the definition more efficient by reducing the gene pools a lot.

We managed to make a rock generator. Thanks!

Comment by Chris Beffa on August 31, 2017 at 2:08am

Hey David, I'm trying to get a result similar to your erosion effect above, but Marching Cubes seems to no longer be working (OUTPUT PARAMETER CHUNK IS MISSING; ARCHIVE IS CORRUPT) and I'm unable to get the same effect using Cocoon.  Any suggestions?

Comment by David Stasiuk on March 17, 2017 at 2:06pm

You may want to try the plug-in Cocoon.

Comment by Jan on January 20, 2017 at 3:35am

Hi guys!

Maybe you can help me. Im trying to test marching cubes on mac. Unfortunately the VB script doesn't work. Do you think it's because grasshopper for mac is still not finished.

Comment by Scott Finlayson on October 23, 2016 at 5:44am

Hi David is this a topic relevant to the query below;

http://www.grasshopper3d.com/forum/topics/help-with-a-modelling-con...

Comment by Tim on September 25, 2016 at 8:08am

Woooo, "fingery" looks spooky, thanks.

Comment by GuangYang on September 25, 2016 at 1:45am

thanks for sharing!

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service