Particle-based fluid simulation

January 15th, 2011
by admin

I’ve recently stumbled upon this paper about fluid simulation – “Particle-based Viscoelastic Fluid Simulation by S. Clavet et. al.

This paper just screams “implement me”, because its content lacks of unnecessary formalism and entire idea of particle simulation is explained with a pseudocode. So all I needed to do is just rewrite the pseudocode into an actionScript code…
So this is the demo:

There are bunch of parameters which controls the fluid properties – this is an advantage of using the particle fluid model.
Make/grab option lets you add the particles, as well as grab them (when clicked in the center of the particle )
Yield ratio influences stickyness or “stretchyness”. The lower the value, the stickiness or “stretchyness” is higher (of course if “sticky” or “stretchy” sliders are nonzero).
“Smooth jitter” and “smooth pulse” smoothes fluid velocity field, “smooth jitter” handles fast velocities and the other handles slow velocities respectively.

There are many possibilities of how to optimize this, mainly PixelBender to calculate the distance field and alchemy to optimize some vector operations. I believe that there exists some tricks to optimize the goo rendering – it’s taking 50% of frame evaluation. Another subjects to optimize:
– highly unoptimized collision system
– getting rid of Vector’s splice function in spring adjusting function
Maybe somebody in the future (most probably – me;p) will “pixelbenderize” this thing, mainly because I’m curious how much faster can it be.

Additionally I’ve written a “library” (1000 lines of code, the “library” term is an exaggeration) which lets you create your own goo, main class of the library is instantiated via
var gg:GooGen=new GooGen( stage.stageWidth , stage.stageHeight );
There is a bunch of methods for adding,deleting particles, and most important – for simulating them:

gg.addParticle( x,y ); // add particle at x,y
gg.step(delta); // one step of simulation
gg.drawParticles(); // renders all particles, since GooGen extends Bitmap class
gg.getParticleAtPos(mouseX,mouseY); // gets particle at x,y
gg.addBody( x,y,width,height,rotation); // adds a wall. avoid adding too many walls, or optimize my code ;p

I don’t believe anyone will try to do something using this class, so I saved myself a trouble of writing any documentation :P Wide programmers will always figure out how to use it from the demo source I’m providing:

demo source
GooGen “lib”

Demo uses (as you can see) bit101’s minimal components.

Posted in flash experiments | Comments (3)

3 Responses to “Particle-based fluid simulation”

  1. lab Fluid simulation | Alladin Says:

    […] suwakow, czesc opisalem na blogu: Znajduja sie tam rowniez linki do biblioteki i zrodlo […]

  2. Tweets that mention Teleranek ? Particle-based fluid simulation — Says:

    […] This post was mentioned on Twitter by Mario Klingemann, Vaclav Vancura, Michael Cann, Shaurya Agarwal, Corstiaan Smorenburg and others. Corstiaan Smorenburg said: RT @quasimondo: Those are some nice gooey as3 particles: #googen […]

  3. FlashApplications » Particle-based fluid simulation Says:

    […] KategorienActionScript3, News Tags: AS3, Lab, usefull Kommentare (0) Trackbacks (0) Einen Kommentar schreiben Trackback […]

Leave a Reply