Page 1 of 1

More pseudo-fluids, this time with python with pymunk

Posted: Sun Mar 30, 2008 5:10 pm
by viblo
After reading maximiles post here: http://www.slembcke.net/forums/viewtopic.php?f=6&t=78 I felt inspired to create something similar but use the python chipmunk wrapper pymunk (found at http://pymunk.googlecode.com/) instead to see if it at all is possible to create something that demanding in realtime from the python wrapper. The balls are rendered as metaballs to create a more watery effect than just spheres. r,g,s seen in the video is metaball constants, l is the number of balls in the scene. The radius of the balls is 3 to 6. The gray value is the FPS but as I recorded with fraps it doesnt say much about the performance without recording..
In the second video, the simulation is rendered in 5 fps and then adjusted afterwards. On my computer, a P4 3GHz, the scenes are realtime (30+fps) up to about 800 balls when I don't record.

The videos can be seen here:
http://video.google.com/videoplay?docid ... 4855944985
and
http://video.google.com/videoplay?docid ... 3312119261

Re: More pseudo-fluids, this time with python with pymunk

Posted: Sun Mar 30, 2008 6:03 pm
by slembcke
Very cool. Out of curiosity, how fast is it without rendering?

Also, you should give your line segments a bevel radius to help prevent balls from escaping.

Re: More pseudo-fluids, this time with python with pymunk

Posted: Mon Mar 31, 2008 3:59 pm
by viblo
In a scene with a bix box with the water in the bottom like in the end of the second video:
~1000 balls: about 10-15 fps with rendering, 20-25 without.
~800 balls: about 25-30fps with rendering, 150+ without.
There are a big drop between ~800 and ~1000 balls as you can see from the numbers.. If the balls are in the air/moving/more free the fps is higher.

Re: More pseudo-fluids, this time with python with pymunk

Posted: Mon Mar 31, 2008 4:13 pm
by slembcke
Did you edit the hash parameters?

I think the table size for the spatial hash defaults to 1000 slots. That might be the issue.

Re: More pseudo-fluids, this time with python with pymunk

Posted: Mon Mar 31, 2008 5:26 pm
by viblo
Yep, I do a cpSpaceResizeActiveHash(self._space, dim=15, count=10000) in the start of the simulation. I remember that when I tested my way to this value it didn't seem to matter that much how big count is.
I did some new tests after having read you post:
dim 10, count 10 give 7 fps for 1030 balls no rendering
dim 10, count 1000 give 19 fps for 1030 balls no rendering
dim 15, count 10000 give 20-21 fps for 1030 balls no rendering
and with different dimensions:
dim 1, count 10000 ~2.5 fps
dim 10, count 10000 ~18 fps
dim 15, count 10000 20-21 fps
dim 100, count 10000 ~15 fps

Re: More pseudo-fluids, this time with python with pymunk

Posted: Mon Mar 31, 2008 10:38 pm
by maximile
Looks really nice. I like the metaball rendering.