I published a quick post on the Phenomblue blog yesterday about ND3D, the stripped down AS3 3D engine.
Categories
- Actionscript 3.0 (10)
- Flex 3.0 (2)
- Papervision (4)
- Tutorials (3)
- Utilities (6)
I published a quick post on the Phenomblue blog yesterday about ND3D, the stripped down AS3 3D engine.
With the great reviews from [draw.logic], the dudes at the Papervison3D dev blog and just the response from the community I figured it was time to set this thing in stone, metaphorically speaking. I went ahead and revised it (adding a camera is a little different now), included all the libraries (SWCs) you need and put it all on google code.
And yes, we do have a Microsoft Surface machine at Phenomblue. I’m not gonna lie, it’s pretty sextacular.
WARNING! This post is totally nerdcore. If you have a heart condition, increased risk of an anurism or have difficulties counting your fingers then this is not for you!
I’ve been scouring the Papervison 2 code over the past couple days and I noticed that they use a lot of Dictionaries in the very heart of the library. Every single vertex has one, there are a bunch created on the fly for organizing (i.e. merging verticies). I had always thought that Dictionaries were more resource intensive than arrays. So I decided to do some benchmarking.
Although I only did one test per senario (I really should do multiple tests for a more complete statistical model), I’m sure it’s not too far from a true statistical analysis.
For the primiative tests I just used a uint. For the object tests I used this simple class:
package { import flash.events.EventDispatcher; public class ValueObject extends EventDispatcher { public var x:Number; public var y:Number; public var z:Number; public function ValueObject(x:Number=0, y:Number=0, z:Number=0) { super(); this.x = x; this.y = y; this.z = z; } override public function toString():String { return "[ValueObject x:\"" + this.x + "\" y:\"" + this.y + "\" z:\"" + this.z + "\"]"; } } }
The first part of the test was seeing how long it takes to fill the objects. All I used was a simple “for” loop to fill each object to any given size.

To test retrival of data it was a simple matter of using a position for the Array and the actual primative/object for the Dictionaries. The test was run grabbing a value that was added halfway through the filling test (i.e. size / 2).
Looping is where things change a bit. To loop through the Dictionaries I used a “for each” loop and just a regular old “for” loop on the Array.
When dealing with primatives Dictionaries will perform better than Arrays when dealing with amounts of data over 50,000. The results aren’t shown here because the graphs would be too skewed to get any real value out of them.
The real difference between Dictionaries and Arrays comes out when you fill them with objects and start looping. Arrays outperform Dictionaries in those tests so much that it almost doesn’t seem real.
Of course, the real value of a Dictionary is in it’s retrieval abilities since you can retrive data using any value object as opposed to a linear position. To do something similar using an Array would be a more expensive process.
One of the more recent updates to Papervision3D 2 was the introduction of Google SketchUp support. So, I decided to prod this new functionality with a stick. Turns out it still has some growing to do. Never the less the basic functionality is there and waiting for a sprinkling of Miracle Grow.
First we need a SketchUp model. Just so happens that KMZ files are just ZIP files. Also, MKZ version 4 files already contain a DAE file. Perfect. So all you have to do is:
If you don’t wanna make your own I’ve included one that I made for testing at the end of this post.
I like to embed my DAE files (you don’t have to, it’s just XML), so that’s what we’re gonna do first:
[Embed(source="../../../../../embedded/skull.dae", mimeType="application/octet-stream")] private static const daeSkull:Class;
Not a big deal, just like embedding any other file. Now all we have to do is instantiate it and add it to a scene:
var collada:SketchupCollada = new SketchupCollada(XML(new SketchUpView.daeSkull()), null, 0.01); this.scene.addChild(collada);
That’s pretty much all there is to it. You’ll probably notice a few things right off the bat like: “Where the f are all my materials?” Well, they’re not there, and you can’t apply new ones at runtime. At least, that’s how it stands as of the 709 build.
Here’s the example (click and drag to orbit the camera around the model):
PV3DDebug is great because now you can view critical stuff without having trace a ton of stuff out and constantly recompile to get stuff to look correct. The main thing is the camera control, since setting up cameras tends to be a huge time-sink.
Here’s an example of PV3DDebug in action:
Enjoy!