For a few polygons more…

These days, when i can find some time, i like to experiment with Molehill, the next big flash player update, with fully hardware accelerated 3D. So when my collegues told me I should participate in TheBattleofTheBit, I really wanted to try somme stuff.

Because TheBattleOfTheBit is supposed to raise interest for our AndTheBitGoesOn festival, I began thinking about ways to make music in a innovative way. So came the idea of using physical machines that played sound sample. At first the idea was to have something like 16 different machines, all fully configurable ( tempo, sound, effects, etc. ).

I recently stumbled upon AS3SFXR which i thought i could use to generate sound on the fly with a lot of tweakable parameters. It was fully in line with the retro feel i wanted to give to my app. I began testing, but i quickly realized that this library was kinda CPU intensive, and even using its sound caching capabilities, i would never really be able to play a lot of different sample at the same time.

So in the end i had to fall back to mostly playing some mp3 sample, and only one fully configurable “sound”, wich generation is greatly inspired by this bit-101 sound synthesis class

For physics simulation, I didn’t want something too heavy, not knowing exactly what CPU power the 3D graphics would leave me. So i decided for a 2D engine, and when you talk about actionscript 2d physics engine, there’s really not much of a debate as far as I know. Box2DAs it was. This engine has great capabilities, is quite fast, and is somewhat well documented.

Still , it’s quite bothersome to implement in my opinion. So I thought about using WCK, a nice physics solution for Flash, with its Alchemy Box2D engine + “world construction kit”, a collection of class and flash IDE components that allow the user to build their physic world directly in the flash IDE. We at IQ12 rarely have the occasion to use physics on our projects, so I wanted to experiment a bit more with it ( last project using a little of WCk was Titeuf ).

So i began trying to build some machines in Flash. After some testing, it became evident that I would never be able to run concurrently 16 machines with each having several balls, sound plates , elevators and walls. It’s simply too much for the engine. So i had to scale back to 4 machines.

I’m not a 3D artist, like at all. I had to keep thing simple. So I modeled some simple elements like spheres, champhered cubes, some slopes and circle arcs. I’m not a texture artist either so i just drew some lines inspired by Jocker’s andTheBitGoesOn logo in a square and slapped that on all my objects.

On the flash side of stuff, i used Away3D always evolving Broomstick version of their engine. I like away3d because it’s very well documented, the community is very active and international, and they update their stuff very regularly. I suppose i could have go the Alternativa3D route, but prefered to go with something I kinda knew, and not in russian. I’ve been using the Away3d engine for quite some time, and for their Broomstick version they tried to stay as close as possible to their existing code, and I thank them for that.

In their Broom stick example they often use SimpleGUI so I used it too. It’s a simple prototyping UI that works with Keith Peters MinimalComps.

So, with all that, i had less that 2 weeks to develop my app and squeeze the developpement time in my work schedule. I was already pretty far from my original idea.

The code is quite simple : on one hand i have a WCK world with my machines set up, each physics object linked to a class. On the other had, i have .obj file containing my 3D objects. I only add to link the two and had some fluff.

So first I load my 3d scene, and for each objects in it I create a away3d mesh, i texture it a set the lighting parameters ( reflection, gloss, shadows, etc. ) . Then I create a new physic world with my WCK class, and i browse the displaylist to create my corresponding 3D objects, populating the various parameters with data from the world ( position, scale, rotation ) . Thoses objects have references to both a 3d mesh and a Box2D body so i can easily update them.

There are some special objects like the sound plates with contact listeners linked to a function that plays a chosen sound when hit and animate their texture a bit.

There is some kind of sound manager static class that loads the mp3, manage the tones creations with 2 sets of frequencies ( the major/minor stuff ) , and plays those sounds.

Add on top of that the UI with some fun parameters , some functions to create/destroy balls dynamically, a nice skybox with the logo and it was done. It took me something like 25/30 hours in total, with a lot of experimenting with broomstick stuff ( mainly ligthing, shadows, filters ), and a LOT of effort trying to get my different machines to be somewhat in synch with each other, problem that was in the end to most time consuming and not really resolved. I tried to get some control over the rythm of each machine, but the physical nature of the engine and its inherent radomness is very messy to work with.

Anyway , i’m happy with how it ended producing some weird relaxation music ( or really gratting noises, depending on the settings ). It really reflects the experimental nature if the thing.

Here are the sources if anyone’s interested. It’s a bit messy and not commented at all, but in the end quite simple.

Leave a comment

Your comment