Here's another quick and dirty experiment with ActionScript Workers: I've taken two fairly meaty tasks: computational fluid dynamics and rigid body physics and created separate ActionScript Workers for each. The result is a simulation with 75 circle objects managed by Box2D that control an array of density sources that feed into the fluid solver I've used in the past from Oaxoa that runs pretty much in real time.

The PhysicsWorker class handles the Box2D work. I've never used Box2D before, so I took a short cut and almost copy and pasted code from this tutorial at Activetuts+ verbatim. With each physics step, I pass in the current position of the mouse which is used to create an impulse force to attract the circles towards the mouse. Once the physics step is solved, the worker loops through the circles to create DensitySources which are passed back to the main application. 

Simultaneously, the FluidSolverWorker is using the DensitySources from the previous physics step and passing those to the FluidSolver class. 

The rendering of the fluid is handled by a third background worker which is passed the simulated two dimensional densities array from the fluid solver (I've cheated a bit by rendering the circles in the main application).

So, at any one time, this application is doing three things: solving the rigid body physics  solving the fluid dynamics for the density sources generated by the physics solver and rendering the fluid densities generated by the fluid solver.

The application lives here and the source code is available here.

* Thanks to FlashDaily for spotting this: there is a known issue with Flash Player under PPAPI and this may not work properly under Google Chrome. Thibault Imbert and Adobe are aware of this and they are working with Google to fix it ASAP.




0

Add a comment

About Me
About Me
Labels
Labels
Blog Archive
Loading