Pages

Saturday, 9 May 2009

3D particle systems in AS3

Well its my first post so I thought I'd talk about something I've been working on this afternoon. I recently saw an amazing post about a 300,000 particle 3d system created in flash with alchemy. For those who don't know Alchemy allows you to compile C and C++ libraries using flash and there have been some amazing examples floating around including a flash Quake port! Now I don't have alchemy so I thought I'd try and build something comparable using just AS3. 300,000 particles in flash is no mean feat, in fact if each point is described by 3 values, X, Y, and Z then thats just under a million variables which need to be updated each frame, not to mention the calculations needed to transform the particles to 2d space from 3d space.

To be honest I am quite amazed that my attempt managed to get such a high frame rate at 54,000 particles. Flash certainly has improved over the last few years. At 300,000 particles I get a frame rate of about 6fps, and at 1 million particles 1 to 2 which isn't too bad :).

The movie below shows the effect that I managed to achieve. (click the image to start..)

Flash 10 demo

Each particles position is determined when the shape loads then the location of the camera is used to determine the transform to 2d space. Once all particles have been calculated they are drawn using bitmap data! I like the Lorentz Attractors the most.

Enjoy, more to come soon!

No comments:

Post a Comment