actionscript-3flashstage3ddepth-bufferaway3d

Away3D Stage3DProxy drawing order


I have a flash application where two 3d Views are sharing the same Stage3DProxy, because I need one to be overlaid/drawn over the other at all times. However, they seem to share the same 3d space/z-buffer(?).

My update function currently looks like this:

private function onEnterFrame(event : Event) : void {   
    stage3DProxy.clear();
    away3DView.render();
    away3DView2.render();
    stage3DProxy.present();
}

Clearly, this is not enough on its own - I read somewhere that the setDepthTest method can be used eg:

stage3DProxy.context3D.setDepthTest(false, Context3DCompareMode.NEVER);

...setting it to different modes between each view's render() call, but I'm not at all clear on how this works, and documentation is very thin on the ground. I've played around, setting it to different things between render calls, but no joy.

The only examples I can find for setting up a Stage3DProxy use one Away3D view and two starling - which isn't what I'm after. I read on their forums a comment which says you have to specify certain setDepthTest settings in about '8 other places', but doesn't elaborate on where they are or what they need to be set to, and this sounds like quite a hack for something which should be pretty basic!

If anyone could help I'd be very grateful, or if anyone knows another way to do this - forcing a particular drawing order seems like it should be a relatively trivial task yet I can find nothing useful about doing it, I want to stick with Away3D as it's good a nice API and feature set, but this is a real obstacle to my current project!

Thanks in advance


Solution

  • After ages trawling for this, the answer was absurdly simple:

    view3D.layeredView = true;

    This will cause the view in question to be rendered at the 'top'. Subsequent renders on the shared proxy will still draw over this, so you need to consider the render order, but it's exactly what I needed.

    I can't believe it was so hard to find, all Stage3DProxy guides talk about sharing with Starling, not another View3D...hope this stops someone else from tearing their hair out!