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

  • Arend

    Amazing work, thanks for sharing!

  • djordje

    Yep, definitively cool.

  • Nick Tyrer

    Hey David

    Really Cool work! And thanks for the credit.

    I also have been thinking about the 'taper' but i haven't spent much time on it. haven't got much further than globally affecting the field values.

  • Daniel González Abalde

    Cool, thanks David!

  • Christian Schmidts

    definitely the fastest and cleanest marching cube implementation so far here on the gh community

    also nice approach to script the genepool..

    one suggestion for further development would be to able to have also negative values for the radii - these points /curves could act like a kind of voids which are pushing away the isosrf with variable strength. I have no idea how complicated it would be to achieve with the marching cube or if its possible but I think this could lead to quite interesting forms..

    anyway great work and thank you for sharing!

  • David Stasiuk

    Thanks Christian...interesting idea on the negative points/curves. Intuitively, it seems like it could work...they would just adjust the iso value in the other direction. There may be some funny stuff with the threshold, but I'll try to look into it. I'm hoping sometime over the next weeks to package it as a GHA along with an Exoskeleton reboot, but we'll see.

    Glad you saw the genepool bit in there :)

  • Atsuo Nakajima

    Amazing! What a beautiful program!

    Thank you for sharing.

  • Christian Schmidts

    Hello David, great to hear that you will look into..

    I think that it could lead to interesting forms especially because the algorithm is capable to handle a quite big amount of points. I imagine things like impressioning forms to others or even define a kind of boundaries which could limit the isosurf locally.

    I hope it will happen with the gha - both really great tools!

  • Thomas J. Mrokon

    really nice - thanks for sharing....

  • Tudor Cosmatu

    Sweet!

  • jozze

    wicked!

  • Pieter Segeren

    Awesome work David! Love it. And thank you for sharing it.

  • mahmoud fathi

    good work

  • jozze

    Hey David,

    very cool stuffs. I am trying to get similar "sponge like" effects somehow through a python script based in your 140130 (VB script) marching cubes definition. I wonder if you could roughly explain the logic behind that code..actually I´m getting a bit lost.. I´d really appreciate it. Thank you.

  • Pirouz Nourian

    Amazing work! Thanks for sharing. 

  • Ralf

    Hi David, at first, thanks a lot for this great piece of code. I was used to work with the millipede geom wrapper, but I cant explain how much faster your script is.

    Now I think I am pushing this script to its limits, but maybe not - I am really not sure, so I would appreciate your help.

    I am using your definition for getting geometry out of curves - these curves are resulting out of tracked boid's. I attached a pic from my succeeded wrap - there are about 700 curves and it took itself about 18 minutes computing time. I think that is very okay. So I thought, no problem for this definition, let's do it with 2000 curves (because at least, I have to do it with 4000 curves). But at this point, there is something it does not like, and I don't get it because at this time I'am not really into vb scripting.

    I tried to tweak it from the outside, with scaling, brep r and all this things, but show's most of the time a problem in the line 255, or line 172.

    Sorry for this big question, maybe you got some hints for me :) thanks!

  • Jenny Salvatore

    problem here... the VB-component for the Vase seems to not output any data for (mc) that goes into the weaverbird component... panel says <null> ...since everybody here loves the definition i assume you all found the solution? : ) please let me know

  • mohamed fawzy mohamed

    wow can u send to me solution or GH file :) thx

  • Esteban Pacheco

    Mannnnn This is Awesome!

  • Luca Borro

    Hi,

    your work is wonderful! Thanks a lot.
    I take your work for excercise...and I want to obtain a single value for RADIUS (example: 2mm, 3mm, 4mm, 5mm, ecc....) Is it possible?
    Thanks
    L

  • Oliver Tessin

    I cant run the first definition "...30..."

    Downloading the latest Kangaroo (can't find 0.94) doesnt solve the problem. I get this error message and screen.

    Object: MeshMachineComponent3 (level 1)
    {
    Ein Aufrufziel hat einen Ausnahmefehler verursacht.
    TargetInvocationException
    }

    Object: MeshMachineComponent3 (level 2)
    {
    Die Datei oder Assembly "Plankton, Version=0.3.0.0, Culture=neutral, PublicKeyToken=null" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
    FileNotFoundException
    }

    Object: KangarooA (level 1)
    {
    Ein Aufrufziel hat einen Ausnahmefehler verursacht.
    TargetInvocationException
    }

    Object: KangarooA (level 2)
    {
    Die Datei oder Assembly "KangarooLib, Version=0.0.9.9, Culture=neutral, PublicKeyToken=null" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
    FileNotFoundException
    }

    Object: KangarooZombie (level 1)
    {
    Ein Aufrufziel hat einen Ausnahmefehler verursacht.
    TargetInvocationException
    }

    Object: KangarooZombie (level 2)
    {
    Die Datei oder Assembly "KangarooLib, Version=0.0.9.9, Culture=neutral, PublicKeyToken=null" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
    FileNotFoundException
    }

    Many thanks,

    Oliver

  • David Stasiuk

    Hi...yes it's an older version by now. It defnitely won't work with Kangaroo version 2+, but it should work with 0.99, which I think is available for download. You'll also need Nudibranch. But I also included the base geometry input of curves and breps internalized so that you don't need to do any initial form-find to see the marching cubes output for this particular input. What are you looking to do with the script?

  • Oliver Tessin

    Hi David,

    I uninstalled Kangaroo 2 before I posted. Your scripts works fine. I already got some nice results. 

    My main opbjective is to create a fibrous structure based on agent-behaviour design regarding stresslines and strand thickning through load values. I posted earlier about it http://www.grasshopper3d.com/forum/topics/extract-fem-volumetric-po...

    Btw, might their be another way to solve the uneven srf than cranking up the res and smooth values? I'm already using mesh subdivision and smooth with weaverbird. It's lots of geometry, I know, and it will get much more, but I was wondering if I could improve something. Can't find an attach button for the file here...

  • David Stasiuk

    Hi Oliver...this is one of those things that I really wish I had more time to update...the smooth that I built into the script in is a very basic Laplacian operation, and the topology that results from the MC algorithm isn't well suited to being nicely smoothed from this. What I really should do is one final pass post-Laplacian smooth that reevaluates each vertex in the iso-field and relocates it. This should produce a much smoother result, especially after a WB loop sub-D pass.

    Daniel Piker started up a very interesting approaching using a small library he built called Æther that may be worth looking at. Unfortunately, I am just in the middle of a lot of things, so won't have time to code up these (and other) desired changes for improving this MC implementation, probably for a few months yet.

  • Oliver Tessin

    I understand. So any further smoothing attempt of the output isn't really proportional to its effort...

    I'll have a look into that library you mentioned later. Many thanks for the hint!

    And should you find the time to refine your MC... I would highly appreciate it!
  • Neo

    Hi David, 

    Your Job is awesome. but I am not clear how "iso" this parameter influence the final result. As I tried to increase the number then I found these spheres getting smaller.Can you explain a little bit on how does it work?? Thanks 

  • Neo

    Thank you Nik, I know the marching cube algorithm but what is the relationship between marching cube and iso value??

  • Neo

    Hi Nik, "it samples the eight corners of each sample cube in a big XYZ grid around your object for the overall field value at each of those eight points" here, is the sample cube similar to the bounding box?  "by summing the contribution of all geometric objects or at least the closest point to each one"  is the geometric objects a cube unit or a object ? I don't understand it clearly. Thanks

  • Neo

    Thanks for your patients Nik, I tried to figure out all these terminology . so "iso" just means one certain surface because within one 3D field, there is a lot of surfaces where all the value at this surface are the same. just like the electric field, at different distance from the center charge there is always a Gaussian Surface where the field strength is the same. so the value only means which surface to choose. am I right?

  • Neo

    Thanks for your help Nik, I learned a lot from your post. 

  • Henrique F

     thanks for sharing!

  • Artc Quang

    GOOD JOB!

  • GuangYang

    thanks for sharing!

  • Tim

    Woooo, "fingery" looks spooky, thanks.

  • Scott Finlayson

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

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

  • Jan

    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.

  • David Stasiuk

    You may want to try the plug-in Cocoon.

  • Chris Beffa

    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?

  • Ralph Zoontjens

    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!