We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Metaballs (Read 2291 times)
Metaballs
Apr 4th, 2008, 6:25pm
 
I'm just getting started in metaballs, and I understand the basics of how to create them. I made a program which creates metaballs and displays them, based on an example I found somewhere. But its definitely not working well.

Any applet over 100x100 in size will lock my computer up, and I've read that I need to 1) use a threshold constant and 2) avoid divisions and sqrt calls, as they are expensive. However, all the help I've been able to find through Google are made either created for C++/3D, in another language, or strictly mathematical. I get the basic math, but I'm having trouble making the system run well.

Does anyone have some simple code, or pointers or a good website link that I can use to soak up some more information about metaball execution? Thanks!
Re: Metaballs
Reply #1 - Apr 4th, 2008, 9:49pm
 
v3ga's BlobDetection library uses an implementation of metaballs to do it's magic.

He did have another metaballs thing which used to be listed in the Exhibition section but he's redone his site which is probably why it doesn't work.

Here's his current site:

http://www.v3ga.net/blog/

You could always ask if he some metaballs source code available, he was quite helpful to me when I was at school.
Re: Metaballs
Reply #2 - Apr 4th, 2008, 11:47pm
 
Thanks. I read another post here on the Processing Discourse mentioning both v3ga and someone named Koenie as inspirations.

Looks like v3ga's metaball code has been lost in the shuffle with his new site design. I'll msg him later today and see if he can help me out.

Seems like I keep hearing about these Processing all-stars from back when Processing was called Proce55ing. Now, they are all gone / private. We need some Processing heroes again! lol
Re: Metaballs
Reply #3 - Apr 5th, 2008, 1:14am
 
Hey guys.
Phew long time no post on the Processing board.

I zipped some of my Processing sketches and put it online at the following urls :

http://www.v3ga.net/processing/v3ga_processing_sketches_118.zip

The code sources were ported from Alpha to Beta by Martin Antolini (http://www.martinantolini.com/), many thanks to him. The code is flat in one big file, yes all of that was programmed before Processing had tabs Smiley Anyway, you'll find my first implementation of Metaballs (Liquid_balls) and another one called MetaballsWired which is much refined and in 3D too.

Hope this will help. Cheers.
Re: Metaballs
Reply #4 - Apr 5th, 2008, 9:37pm
 
Thanks! Well, I sort of got it working, however the Liquid Balls applet wasn't exactly what I'm looking for. The end effect I'm looking to achieve is more like this:

http://processing.org/discourse/yabb/YaBB.cgi?board=Contribution_Responsive;action=display;num=1068153198

The source code that was linked to by this guy is simple, but nearly indecipherable to me thanks to no documentation and poor variable naming.

Here is what I've managed to come up with so far. There is not as much "viscosity" as I was hoping for, and there is a problem with the equation...still trying to tweak the variables to work together. Anyway, this applet is lagging like crazy unless I turn down the strengths, but I think if the problem is pinned down, I can scale this up much higher strengths.

Main program code:
Code:
import processing.opengl.*;

int ballCount;
Metaball2D[] mbs;

void setup() {
size(300,300,P3D);
background(0);

// initalize metaballs
ballCount = 3;
mbs = new Metaball2D[ballCount];

mbs[0] = new Metaball2D(100,80,1000);
mbs[1] = new Metaball2D(200,100,3000);
mbs[2] = new Metaball2D(50,100,500);

//noLoop();
frameRate(30);
}

void draw() {
background(0);

// move each ball
for(int m=0; m<ballCount; m++) { mbs[m].move(); }


// main rendering
for(int i=0; i<width; i++) {
for(int j=0; j<height; j++) {
float inf = 0.0f;
for(int m=0; m<ballCount; m++) {
inf += mbs[m].getInfluence(i,j);
}

if(inf>.2) {
stroke(inf*75,inf*60,inf*50);
point(i,j);
}
}
}
}




Metaball2D class code:
Code:
class Metaball2D {
float x,y;
float strength;
float xspeed,yspeed;

float dx,dy;

Metaball2D( float _x, float _y, float _strength ) {
x = _x;
y = _y;
strength = _strength;

xspeed = random(1,2);
yspeed = random(1,2);
}

void move() {
x += xspeed;
y += yspeed;

if(x+xspeed>width || x-10<0) xspeed *= -1;
if(y+yspeed>height || y-10<0) yspeed *= -1;
}

// returns a "influence" value, given a single pixel coordinate
float getInfluence(float px, float py) {
dx = (x-px);
dy = (y-py);

return strength/(dx*dx + dy*dy+0.11f);
}
}



So whats making this applet lag? Any help appreciated Smiley
Re: Metaballs
Reply #5 - Apr 6th, 2008, 8:11am
 
Ah ha, I got it working they way I wanted to by gently tweaking threshold values and color computations. Yay! Seems like there ought to be a better way, but it comes down to a delicate balance of variables, it seems.
Re: Metaballs
Reply #6 - Apr 6th, 2008, 9:47am
 
You can also have a gander at some of my old metablobs experiments, which probably require some little tweaking in order to get them to work with recent versions of Processing (these were made 4-5 years ago)

http://toxi.co.uk/p5/blobsInterlace/
http://toxi.co.uk/p5/nodeSpace/
http://toxi.co.uk/p5/base26/

The latter 2 examples are using slices of 2D metaballs to create a 3D structure...

Hth!
Re: Metaballs
Reply #7 - Apr 25th, 2009, 10:55am
 
hi toxi
any news of somebody who had done this tweaking?
really long long pde for a mid-beginner..
if i manage.. ill post it..
anyway thanks a lot.. i love it!  from a long time ago :)


Page Index Toggle Pages: 1