I’ll be the first to admit, I’m no 3D programmer – but whenever I needed it in Flash, I just used Papervision3D. It seems the default standard these days and the amount of available information, documentation, and tutorials seems endless. For quite some time though, I’ve been wanting to try out Away3D. The folks who use it, swear by it and I’ve seen some really great stuff done using it. Likewise, I’ve also really been wanting to try out Box2DFlash for some 2d physics simulations. The Box2DFlash api, based on its C++ counterpart, always intimidated the hell out of me though, with its crazy use of capitalization and arbitrary class names. But when Tomek Augustyn/Og2t sent me a message on Twitter suggesting I give QuickBox2D a try, that seemed a good sign that the time was ripe to try out these two new (to me) technologies.
And so, inspired by games like the old classic LineRider and the new Red Bull Soapbox Racer, I came up with this pale comparison. To play, use your mouse to draw line segments (left to right) that will become the track. When done, click “begin” and down you go. Okay, so it’s no award winner, but given the fact I’ve never used Away3D or QuickBox2D before and got that put together over the course of a Saturday, it’s not too shabby and speaks volumes about how easy the two libraries are to pick up.
Some good and bad points of each that learned along the way –
Away3D Drawbacks:
- I hate hate hate api’s that rely on “initObjects” in class constructors. It always seems like a good idea and makes for a nice clean interface, but I find myself crippled when deprived of code hints. I would much rather enter default values or nulls into a constructor than selectively decide what properties to instantiate and run the risk of misspelling them or worse yet, not even know what’s available.
- Probably my own stupid fault, but I couldn’t get the SpringCam working at all. I had to devise my own with a TargetCamera3D instance and a bit of simple easing. I’ll look into that further when I have the time.
Away3D Pluses:
- Performance seems fantastic for this initial trial.
- The learning curve (at least coming from PV3D) is pretty freaking low.
- I love the Skybox6 class. So much easier than creating your own cube and trying to size it nicely as is required in PV3D (though making your background image seems a bit tricky and I just used one that comes with the Away3D demos download.
- While I haven’t tried them yet, the Pixel Bender filters that come with the Flash 10 release look freakin’ awesome. I’m sure PV3D X will do something similar, but I can’t wait to have the time to dig into these and see what can be accomplished.
- The materials available are terrific and slightly easier than their PV3D counterparts.
QuickBox2D Points:
Having never used a 2D physics engine before, I can’t make any real comparisons. One thing I loved was how simple it was to pick up. Much easier than diving straight into Box2DFlash. I highly recommend it to anyone getting into 2D physics. One thing that reallyvirked me was when creating a GroupObject containing two CircleObjects (a simple car, e.g.), the CircleObjects won’t rotate – they’ll just slide. I’m sure if I dig further into the Box2D mechanism behind it all, I can figure out a way around that, though.
In any case, both libraries are loads of fun and it was a Saturday well spent…
Your expiriment looks pretty great for a firt try. I was blown away when I clicked ‘begin’.
How does this work? The 2d physics are calculated while away3D makes a 3d representation of this? Or does this box2d thing actually work in 3d?
Hey Niels. thanks for the comments. Seeing as this was my first attempt, I probably did it the hard way, basically what’s happening is, during an enterframe event it’s setting the 3d car’s x, y, and rotationZ properties equal to the x, y, and angle properties of a 2d box (that you can’t see) sliding down some ramps (equal to what you’ve drawn). So, I’ve got a method saying this:
_world3.getCar().x = (_world2.getCar().x * WORLD_SCALE – WIDTH * .5) * SCALE3D;
_world3.getCar().y = ((-_world2.getCar().y * WORLD_SCALE + HEIGHT * .5) * SCALE3D);
_world3.getCar().rotationZ = -_world2.getCar().angle * (180 / Math.PI);
Gotta be a better way, but it works. I’d post the whole script, but it’s a real mess – stuff just thrown in as I thought of/learned it.
Hmmm. Getting
Error: isNaN(sz)
at away3d.cameras.lenses::ZoomFocusLens/project()
at away3d.core.project::MeshProjector/primitives()
at away3d.core.traverse::PrimitiveTraverser/apply()
at away3d.core.base::Object3D/traverse()
at away3d.containers::ObjectContainer3D/traverse()
at away3d.containers::ObjectContainer3D/traverse()
at away3d.containers::View3D/render()
at World3d/render()
when I click on Begin after drawing. I’m on Vista/Firefox 3.5
Ok. Looks like I’m getting this only after drawing a lot of inclined lines.
So it ‘ looks ‘ 3d, but you could not use this method to move into the z-depth? (like make left turn), or is box2d capable of doing this?
I really think these 3d experiments in flash are awsome. You should check out this dude’s blog, he does some amazing stuff too
http://www.neuroproductions.be/
Great first try (although it shows a lot of errors in the debug player). You should use actors to bind your physics world to the graphical output. More info is on the Box2D website.
Hey Devon,
Cool demo… In order to create cars etc… you should look into using joints instead of group objects – group objects will always act like one rigid body, if you want to create a car, you can do so with the use of “revolute joints”…
Hi Devon,
The ‘initObjects’ are entirely optional. You can also set anything using properties :)
J
Thanks for the comments..
@Pradeek & Patrick – I got those errors from time to time testing, but being just a personal project, it didn’t bother me much. Obviously, Away3D is getting some bad info somewhere though and I gotta sit down some time and figure out where exactly. And thanks for the heads up on the actors/graphical binding info.
@Zevan – Thanks for the joint information. I was actually going to come ask that on the actionsnippet site and now I don’t have to!
@Niels – no you can’t do real z depth, but you can fake it very nicely. Check out the Red Bull site I linked to for a prime example.
@Jensa – great news about the initObjects! Did I mention I hate them?
Haha nice one, I am happy to be the messenger and inspire people with another people’s experiments :) btw. Devon, would you shade the rubber cube twist demo code? I am really interested what functions you’ve used to achieve that smooth rubber feel. Tweaked Penner’s equations?
Hey Og2t, Thanks again for the tip..
That cube code was actually posted a couple posts later, here: https://blog.onebyonedesign.com/?p=292 Maybe I should stop being lazy and put the code in the same post…
I’ve used both PV3D and Away3D, and while example code for Away3D is a little harder to find (the web site is not very useful) I’d have to say that Away3D is the better of the two. Still, Papervision just incorporates the coolest Away3D features (like the QuadTreeRenderer) into their own code anyway…
http://bit.ly/1no4G1
Hey, does anyone have any plans to integrate QuickBox2D with Box2D Alchemy from WCK? I’m using Starling and QuickBox2D is about a thousand times easier to integrate than WCK but I would really like to be using the Alchemy port. Unfortunately it’s not as easy as it might be! Just wondering if anyone has seen anything out there already?