If you haven’t seen it yet, Andy Zupko just released QuadTree for Papervision3D! He also released a more indepth look at using the new features on his blog. A big huge thanks to the Away3D team for their code and brilliance! Andy was able to port it over to work with Papervision3D rather well and we’ve added some features that I think everyone will want to take advantage of.



So, what is QuadTree? Well, in simple terms, its corrective z sorting for a 3D scene. Say wha? In other words, when you have 2 triangles who’s size is bigger than the distance between them, you will sometimes see sorting issues depending on the angle the camera is to the triangles.

It makes this:

Look like this:

How do I use it?

Now, this is very easy to use with Papervision3D. Instead of creating a BasicRenderEngine, you’d now use the new QuadrantRenderEngine object instead:

var renderer:QuadrantRenderEngine = new QuadrantRenderEngine(QuadrantRenderEngine.CORRECT_Z_FILTER);

You’ll notice that there’s one argument about which type of filter to use. On the sample I’ve created, I used the CORRECT_Z_FILTER which is the faster filter of the 3 options. It simply takes care of z sorting of triangles.

Two new features added for speed

There’s also 2 other options worth mentioning. One is the ability to tell QuadTree that any particular DO3D is not to be tested on each render (DisplayObject3D.testQuad:Boolean=true). The default setting is true, but you can set it to false. The second option is the maxLevel setting. This controls the regions of the QuadTree. Having less does NOT mean better performance. You have to find a nice balance between the # of tri’s you have and how many regions gives you the best bang for the buck.

You might be asking yourself “why would I only want certain objects to be tested for z sorting fixes?”. Well, the example I’ve created shows you just a instance that you *would* choose to be very picky about what QuadTree does and doesn’t test on. This example is using the 3D object I’d made for my Mom’s site. When you first load the sample, it is *not* including the big white mass in the middle (under the panels) in the QuadTree testing. To activate it, hit the “s” key on the keyboard, and you’ll notice a decrease in performance. In this particular type of demo, not testing the biggest object in the scene pays off as the panels above it are still corrected. That’s a substantial savings.

Also, if you want to see how maxLevel affects performance, use the Q and A buttons to increase and decrease the maxLevel. As I said earlier, a lower number does not equal better performance. You just have to find a nice middle ground. The default value, btw, is 4 and my demo seemed to run better set to 3.

Try it out here

My point, all along, is proven true 😉

Now, this all leads me to a point that I’ve been making since this topic and request for corrective z sorting came up a long time ago. My point has been: If you have the 3D model, fix the sorting yourself – its FAR faster performance-wize than QuadTree could ever be. And my example here proves my point.

In the pictures below, I have the original version of my 3D object, and then a new version with the Panels much closer to the surface of the main structure. The only difference between the 2 visually, is JUST that: the panels are simply closer to the main structure.

Original:

The new QuadTree enhanced version:

When you run my sample, just hit “T” to switch between the QuadTree enhanced version and my original model. You’ll see a huge difference in performance. Yes, there are still some sorting issues in my model, but I could very easily go in and split the triangles by hand to fix those minor issues. And I’d still have a very fast presentation. While I would agree that having the panels closer to the main object looks a bit nicer, it’s not “nice enough” to justify the CPU/performance.

Now don’t go and take this as “John thinks QuadTree is useless” – I don’t think that, but I do think it’s uses are very confined given the speed we all live with in Flash 3D. It’s awesome to see it working, and I would love to see good samples of it in production for sure, but if speed is what you need, you’ll likely end up fixing your sorting issues by hand in a good editor. Of course, I haven’t talked about triangles colliding, which is something QuadTree deals with as well. But for more information on that, head over to Andy’s blog for a full explanation 😉

Conclusion

Corrective Z sorting is a very cool feature to have indeed and, btw, the most requested. But so was shaders before they came out. Now ask yourself, “how much do I use shaders these days?” I’d venture a guess that your answer is hardly ever – if ever. I think we’ll see more need for QuadTree than shaders, but I don’t think that QuadTree is the miracle pill we’ll all be able to leverage very often to fix our sorting issues. That will most likely STILL fall on the hands of the 3D modeler 95% of the time I would bet.

Advertisements