Display away3D view on top of 2D sprite?

I have a problem with away3D. It seems that the away3D View3D is always rendered in background, even if it is the last child added to a Sprite.
For exemple, if I have 2 sprites, one wich is a simple 2D colored square and another wich is the away3D View3D.
Whatever I do:

The colored_square is always rendered on top of the away_view…

So, how can I do to render my away_view in foreground? (I need to render some 3D over some 2D content)

I think its because it uses Stage3D, Stage3D in Flash is always below your 2D content, I believe. I wonder if there’s another solution to this (that keeps the Flash compatibility if we can)

OK. But I tested it on windows (cpp) target and the behaviour is the same (the away3D view is always rendered in background). So this is not restricted to flash.
Anyway, it seems to be possible to add 2D content directly into the stage3D sprite (As according to the flash api doc: > The Stage3D class provides a display area and a programmable rendering context for drawing 2D and 3D graphics. So I guess it means any 2D content can be handeled by stage3D but maybe I am wrong). In wich case it is probably possible to add some 2D content and then, to display some 3D over it. The problem is I use haxeflixel wich render all flixel elements into a single 2D sprite (called FlxGame) if I understood well. And I would like to render some 3D over the haxeflixel 2D background interface. So maybe it is possible to add the flixel FlxGame sprite into the away3D view3D sprite and then to add some 3D content to it…
Has anyone ever tried this?

EDIT: I tested away_view.addChildAt(colored_square, 0) rather than adding the colored_square to the same parent as away_view but the colored_square is still in foreground compared to the away_view 3D content. So away3D view3D seems to always render its 3D content before the 2D and sprite childs hierarchy is actually ignored…

EDIT2: I just read this: http://www.adobe.com/devnet/flashplayer/articles/how-stage3d-works.html and at the section “Stage3D: The stage behind the Stage” it is explained that the stage3D will always render behind 2D content :frowning: (even if, what is strange, StageVideo appears to also be behind Stage (2D) whereas it is actually possible to render video in front of some 2D in flash…). So I guess I would have to deal with this and render my 2D background as a texture mapped on a plan, or something like that, in order to render it behind some real 3D…
Thanks anyway

Currently, the CPP stage3D implementation does try to behave like flash and doesn’t allow anything behind it. e.g. Stage3D always sits behind/underneath the Flash DisplayList.

However, as the implementation of Stage3D is in OpenFL for CPP/HTML targets it utilises the OpenGLView code.

When a new Context3D is created, the OpenGLView it creates is added to the stage at the bottom :

I’ve not tried but you could alter that line to simple be an addChild call (not at 0) and see what happens. I’m not sure though if a transparent background to the OpenGLView layer is currently supported in Away3D. Might be worth playing with if you feel like it :wink:

Hope that helps somewhat and maybe is something that should be added to the non-Flash targets to make it far more flexible.

BTW. No standard 2D display list items can’t be added to Stage3D in Flash - you need to use something like Starling for that.


1 Like