Fast animation in Alternativa3D

If you ever played with Alternativa3D, you should know that animation does not come easy with this engine. Why? Basically, because correct sorting requires some computations, and those computations need some time to complete. It is important to understand that this is not some problem unique to Alternativa engine; a very same thing applies to Papervision, for example – to quote Andy Zupko on count of recently added corrective z-sorting, “this is a feature that everyone wants but isn’t the miracle cure they hoped for; while a very cool feature – it can destroy your CPU“.

So, what can be done about it atm? Basically, you have two choices: you could a) precalculate, and b) trade sorting accuracy for speed. Neither option is immediately available in current API, but then there would be no fun in this, right? I have implemented option a) before, and it’s no longer fun. An idea for option b) was around since summer, but only with recent 5.5.0 update – namely, introduction of sprites – it became feasible.

fast3d1Here, every moving object is actually placed in its own scene – until 6.0 release this is the only way to give objects their own isolated BSP trees. In evey scene, objects are kept static, and camera is moved around to avoid BSP regeneration (this trick restricts available transformations somewhat, but you probably will not notice) Finally, every scene is rendered into view object which is then inserted back into original scene in place of moving object as a sprite. Phew! But the result is worth of it, though – the demo above would not be possible to make at all in straightforward manner (btw, press any key to change its animation mode).

While this was fairly complex to do, it is not complex to use (hopefully). I have put all of this together in single SubView class for anyone who wants it. With this class, where you would normally write:

var obj:Object3D = thing.clone ();
scene.root.addChild (obj);

you now put this:

var subView:SubView = new SubView (thing.clone (), view);
scene.root.addChild (subView.sprite);

That’s it. As a bonus, you have ability to do all kinds of per-object operations, such as setting filters, as it’s done in above demo:

subView.view.filters = [ new GlowFilter (0xFFFFFF *
    Math.random (), 1, 60, 60) ];

As always, there are full project sources. Hope it helps someone banging their head against the wall in their search for few extra frames per second.

4 Responses to “Fast animation in Alternativa3D”

  1. 2 makc3d November 4, 2008 at 20:27

    I have uploaded a bit heavier car model, it’s not so fast now :) serves well to test engine limits; it can’t be any faster than this (except for in low stage quality mode).

  2. 3 RR404 April 23, 2010 at 16:12

    2 years later .. is there a glance of solution that would not involve those kind of tricks ?

    I’m just trying to change the Z position of cubes places inline accorindg to a COS(phase+their order in array)

    and the fps just dies when there are more than 10 cubes moving … :/

Ask a Question

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Old stuff

November 2008
« Oct   Dec »

Oh, btw…

%d bloggers like this: