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.
Here, 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.
Bravo!
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).