3D MetaBalls

Blitz3D Forums/Blitz3D Programming/3D MetaBalls

Oiduts Studios(Posted 2010) [#1]
I did some googling on fluid dynamics and finally found out what a metaball was. I was wondering if anyone here has any experience with them? Preferably with Blitz? I am more interested in doing 3D metaballs. I know this is crazy stuff that is really out there but I bet someone here has at least attempted this.


Jiffy(Posted 2010) [#2]
http://www.blitzforum.de/forum/viewtopic.php?t=31608&highlight=marching+cubes

Explanations/base here: (If need to convert for marching tetrahedra)
http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/

A15 tile for fluid surface reconstruction (needs marching tetrahedra):
http://www.cs.ubc.ca/~rbridson/docs/brentw_msc.pdf

Have at it.


Oiduts Studios(Posted 2010) [#3]
NICE! I encourage that everyone that hasn't seen this should run it, it is quite amazing. Thank you for this, funny, those Germans really know some cool stuff.




Rroff(Posted 2010) [#4]
I know about metaballs but seeing it running like that in blitz was a bit suprising... I can't even imagine getting my head around programming that :S

Change the number of balls to 10 (from 5 default) and make sure debug is disabled or performance sucks - and the effect is quite freaky :D


Ross C(Posted 2010) [#5]
that e at the end of the codebox you posted. Is it supposed to be there, as it throws an error here.


Ross C(Posted 2010) [#6]
Could it be using voxels?

[EDIT] Oh yeah, it is. The variable right at the beginning says so!


Jiffy(Posted 2010) [#7]
That code is an implementation of the second link- though nicely optimized. Actually- most code I've ever seen is a variant of that one demo.

Voxels is a loose term. Any 3d array that represents a 3d object/scene is 'technically' voxels. This isn't _exactly_ voxels- it's a 'voxelization' of implicit surface data. The voxels are kinda a 'lookup table' to the 'real' data- the sphere function. Also- the sphere has no set _hard_ boundry- it's an approximation- which allows near spheres 'fields' to overlap & merge.

It's kindof a bit of a mess actually. :)

You can throw hard data into the voxel space & get 'proper' voxel behavior- so I guess the point is moot. But there are lots of limits this implementation gives you that a real voxel engine wouldn't.


Nate the Great(Posted 2010) [#8]
goodness... I wish I had the skills to do that even in 2d, thats what im working on now but it is quite a pain. I am thinking of contacting taron to see if he knows a quick way as he seems to be good with graphical things.


Jiffy(Posted 2010) [#9]
2d:
http://www.gamedev.net/reference/programming/features/isometa2d/
Code (C++) @ end- it's mostly math, so it shouldn't be too hard to convert.
http://www.angelcode.com/dev/metaballs/metaballs.asp

There are some principles & links that 3d metaball coders might be interested in @ the end of the 1st article.


Blitzplotter(Posted 2010) [#10]
Oh my, this is trully imprssive to watch. Moot points aside it is bloody impressive. I'd to delete the last 'e' from the codebox for a compile however.

Never heard of a marching tetrahedra before, sounds pretty ominous.

Hope you don't mind, here is a snapshot of the balls slpodging together/apart:-




Jiffy(Posted 2010) [#11]
Marching cubes was patented. Cube as a primitive sold. Someone wrote Marching tetrahedra to get around the patent. Pyramid as a primitive solid. 6 pyramids make a cube I think. There ya go.


Oiduts Studios(Posted 2010) [#12]
Sorry about the "e" guys, I fixed it.


Noobody(Posted 2010) [#13]
Wagh! Stop digging up old codes of mine without telling me :D

As Jiffy already pointed out, I copied the look-up table for the edges and triangles from his second link.

Could it be using voxels?

It is indeed. Internally, samples of the metaball function are stored as voxels in a 3D grid. The marching cubes algorithm is then applied, since it is made for converting voxel data into a polygonal representation.

But there are lots of limits this implementation gives you that a real voxel engine wouldn't.

That depends what you mean by 'real' voxel engine. If you mean volume renderers used in medical apllications, then yes - marching cubes only extracts one surface, whereas volume rendering renders the whole volume, as the name suggests. However, if you mean the voxel rendering techniques used in, e.g., iD tech 6 or the voxel shader I posted a while ago, then no - those renderers also only display one possible surface.

Marching cubes was patented.

True, but fortunately, the patent expired in 2005.

goodness... I wish I had the skills to do that even in 2d

I can upload a 2D metaballs code once I get home (I'm not really supposed to code at work :/ ). You can do it insanely fast with the OpenGL trick I'm using in my SPH code -or- do it all on the CPU, where it'll still run at a decent framerate as long as you optimize it good enough. It all works with precalculation.


I'll check back later and upload a faster version of the program. The marching cubes implementation is already as fast as it goes, but the metaballs calculation is quite unoptimized. I only put it in back then to give a neat example of the use of marching cubes; in fact, I never really intended it to be real-time.


_PJ_(Posted 2010) [#14]
Yeah that code is amazing. Though it looks to be simple in operation, it's way too much for me to understand what's going on :D
The result is brilliant, though. A prime example of German Efficiency :)

That aside, and with nothing particularly important to say on the matter knowing nothing of voxels and marching cubes, I will say., that every time I read Metaballs, I always read it as Meatballs ... Swedish influence I'mn sure.


Noobody(Posted 2010) [#15]
A prime example of German Efficiency :)

I'm Swiss, but thanks ;)

every time I read Metaballs, I always read it as Meatballs

Fun fact: In Japanese universities, they were called meatballs for a while - some of the Japanese researchers spelled it wrong in a paper on metaballs. Since English speaking people were sparse in Japan at that time, nobody realized that meatballs meant something entirely different.


Noobody(Posted 2010) [#16]
I optimized the metaball calculation - precalculation rocks! - and it's now about 6 times faster:



Oiduts Studios(Posted 2010) [#17]
YAY! Now we can put your code and ZJP's code together and Blitz will godlike.


groovylime(Posted 2010) [#18]
Oops... I saw the thread title and got hungry for some meatballs.

Glad I popped in though, as this looks very cool.