I am still in the middle of adding object/face/material interactivity into the Agile3D although the idea and even the implementation is pretty easy as you already know i am too much of an optimization freak to go with the first implementation.
Soon i will be posting all the research i did in this subject but i wanted to write some of the things i discovered on display object stacking that will be further used in the forementioned post. During face rendering in normal conditions, meaning interactivity is disabled, we render all the triangles inside one graphics instance there is not much display objects in this scenario actually there is only one so not a problem. But once we decide to enable interactivity first thing that comes to mind is making each face a separate display object instance for easier manipulation. There are other options than creating multiple display objects but i will talk about those in the next post.
First lets look at the type of display object, logically we’ll start with Sprite since it extends InteractiveObject and therefore supports mouse events. However this is also the slowest option, creating even small number of Sprites will drop framerate noticeably even without any interactivity and once you start moving over them with the mouse the framerate drop will go further due to event processing. The only other option seems to be Shape, its faster since its not an InteractiveObject and also it consumes way less memory than Sprites mainly due not being a DisplayObjectContainer however since shapes don’t support mouse events directly you will need to find other solution for handling those, i will be talking on this topic in the next post.
Next we need to play with the method how to stack em. There were not many options how to do that again we are stuck with two. Majority of people use addChild which seems the most logical and also the fastest way to add display objects. Surprisingly it isn’t, i did a couple of tests outside of Agile3D as well as within Agile3D and discovered that the 2nd option is way faster. I am talking about addChildAt which seems to be almost 2-2.5 times faster than addChild. The only problem is that we must be adding children in reverse order since we will be using addChildAt(child, 0) which adds child at the beginning of the array instead of the end.
Thats all folks, as i said there will be future posts maybe even more than one about mouse interactivity in 3D scene. But since this post was about stacking display objects in general and affects everybody that wants to optimize his display tree handling, i decided to post it separately.