interactive 2D content with Away 3D 4

Software: Away3D 4.x

hiroalex, Newbie
Posted: 21 October 2011 08:41 PM   Total Posts: 15

Hi there,

I have a problem (and actually I am pretty sure I am not the only one having the same problem), I need to display an interactive 2D content - lets say a dialog box with a button that display some text - that always faces the camera (like Sprite3D) in my 3D world, and so far, I don’t really know how to do this with Away 3D 4 based on Molehill. With the previous versions of Away 3D, it was rather easy, but it seems complicated now with the separation of the stages…

Anyways here are my thoughts to accomplishing it :

1. Use Starling to create the 2D content and display it in Away3D 4. Do you guys have ever done such a thing? I am not sure if it is possible to do it right now, but is it a feature that will be implemented in the next versions of Away 3D 4?

2. Make a hybrid version of my project, using 2 synchronized engines : Away3D 3.X for displaying interactive 2D content, and Away 3D 4 for displaying all the 3D stuff. What do you think about that?

Do you have any other solution or idea for making such a thing?
Thanks in advance,

And thanks for the good job you do with Away3D!

Alex

   

hiroalex, Newbie
Posted: 21 October 2011 08:56 PM   Total Posts: 15   [ # 1 ]

Actually I have another idea which is just taking Away 3D 3.X and replace all the Flash classes by the Starling classes… it may seem a bit silly but it may work. Do you guys think it is a good idea? (at least, if it works, it is a cheap way to achieve what I want to do with taking advantage of Molehill)

   

hiroalex, Newbie
Posted: 21 October 2011 09:52 PM   Total Posts: 15   [ # 2 ]
hiroalex - 21 October 2011 08:56 PM

Actually I have another idea which is just taking Away 3D 3.X and replace all the Flash classes by the Starling classes… it may seem a bit silly but it may work. Do you guys think it is a good idea? (at least, if it works, it is a cheap way to achieve what I want to do with taking advantage of Molehill)

I have just downloaded Starling, and… it is not what I expected, a lot of properties and methods are missing in comparaison to the Flash objects, actually it is not surprising… anyways, it is not possible to replace Flash classes by Starling Classes as I said before, so that solution will not work… damn!

   

Avatar
Jeff, Newbie
Posted: 22 October 2011 03:24 PM   Total Posts: 30   [ # 3 ]

I don’t think you can use Starlight on same Stade3D than Away3D without creating conflits, but on a different stade3D it works fine.

Sprite3D face always the camera but if you translate the camera it will not work anymore.

You can create a specific object with a fixed translation. Create a new class, let’s say Sprite2D, in entities folder that extends Sprite3D.

Set constructor / destructor, override thepushModelViewProjection method, apply a different matrix that set translation.

...
comps = mvp.decompose();
//** Translation ( Do not depend on Camera position )
comps[0].setTo( x, y, 20); // Z = lens.near
//** Rotation ( Always face the camera )
comps[1].setTo(0, 0, 0);
mvp.recompose(comps); 
...

Here you have a real 2D behaviors inside a fully 3D scene, and you can move your object with x and y coordinates, z will act as a z-index ( layer ) properties.

Be aware that x and y will be relative to z, depending on z value, object position on screen will be different.

I will post an add on to solve this = use real x / y screen coordinate and internally calculate relative one depending on z.

   

hiroalex, Newbie
Posted: 24 October 2011 06:19 PM   Total Posts: 15   [ # 4 ]

Hi,

Thank you very much for your answer, but my main concern is more about the ability to add (or to fake adding) an interactive flat displayObject (from flash or starling) in my 3D world (as it was possible before with Away 3D 3.X)
Is this possible with Away 3D4?

Thank you,

Alex

   

Avatar
Jeff, Newbie
Posted: 26 October 2011 12:20 AM   Total Posts: 30   [ # 5 ]

No, “displayobject” have no meaning in Away3D 4.

Stage3D have no relationship with classic flash displayobject. You can add interactivity with 3d objects but you have to create these interactivity yourself. Lot’s of things are possible but no out of the box as usual wink

   

Avatar
SasMaster, Sr. Member
Posted: 26 October 2011 09:21 AM   Total Posts: 127   [ # 6 ]

Well guys ,because I recently “decompiled” Starling for my own uses here ar e a few things you should know.Starling only IMITATES the Flash 2d display list.It has nothing to do with 2d generic Stage.At its base it is a Stage3D engine which discards the third dimension and uses only an orthographic projection to cancel out the perspective distortion.That means it will help you to solve you 2d GUI integration issue the same way Away4 would do -which means it won’t.Event in Away3D 3.x that a real problem to get Flex components ,for instance , being interactive inside Away3D because of their “FLEXY” nature.So practically speaking the only thing you can do about it at this time would be make some Matrix based distortions (some math work) on your 2D GUI elements while overlaying them above your 3d world.

 Signature 

This looks like a job for superman
http://blog.alladvanced.net

   

laurent, Newbie
Posted: 24 November 2011 03:11 PM   Total Posts: 29   [ # 7 ]

For those who are still interesting in blending away3d and starling, I am proposing a dirty hack in starling Forum:

Has somebody a better approach?
What are the limitations of not letting away3d call Context3d.present itself?

   

Spencer1up, Newbie
Posted: 17 January 2012 01:38 AM   Total Posts: 2   [ # 8 ]

What would be the best camera position and attributes, and best position for the 3D plane to best replicate the 3D plane as a mock 2D canvas?

   

Avatar
theMightyAtom, Sr. Member
Posted: 17 January 2012 10:22 AM   Total Posts: 669   [ # 9 ]

This is achievable in Away4, just needs a little effort.
1.Create your 2D interface (off stage), draw it into a bitmapData and use that in a material on a plane.
2. Set the plane to mouseEnabled = true and m.mouseDetails = true;
3. Add mouse events to the plane.
4. Read the output and you can work out the position of the mouse in relation to texture. This can effect the appearance of the 2D interface and the material updated.

private function readOutput(evt:MouseEvent3D):void {
   
var m:Mesh = (evt.currentTarget as Mesh);
   
trace(m.name "," evt.uv.toString() ) 
  

Note that the UV coordinates are “normalised”, ie. between 0 and 1.
To find the “mouseX” and “mouseY” in you 2D interface, multiply by width and height.

 

   

DinkMcDinkleman, Newbie
Posted: 10 April 2012 11:09 PM   Total Posts: 30   [ # 10 ]

I’ve seen a post out there about combining Genome2D or Starling with Away3D and it seems like an awesome way to do things but no one has detailed a basic setup.

Is there anyone willing to post code and how-to?  It would be greatly appreciated, I’m sure not just by myself but many in the community.

Thank you!

   

DinkMcDinkleman, Newbie
Posted: 20 April 2012 08:44 PM   Total Posts: 30   [ # 11 ]

http://forum.starling-framework.org/topic/away3d-compatibility

For anyone interested in making it work, some helpful info there.  I’m still trying to make heads or tails of it, but once I do I’ll gladly share.

   

afrosquared, Newbie
Posted: 01 May 2012 08:01 AM   Total Posts: 5   [ # 12 ]

With the workaround posted in the Starling forum, one has to comment the Context3D.present() in View3D.as and RendererBase.as to get it to work and call .present() in Starling.  Unfortunately it is creating depth problems in Away3D. It’s almost like the z-order is reversed. When I add 2 planes, one behind the other, and move the camera around, it puts the plane that should be further back in front (or on the top most depth) and vice-versa when spun around.  Any ideas on how to re-calculate depth without Context3D.present()?

Mixing Starling and Away3D gives us some pretty amazing capabilities with GPU rendering.  Great work!

   

afrosquared, Newbie
Posted: 02 May 2012 05:08 PM   Total Posts: 5   [ # 13 ]

Found depth problem.  It was in Starling and enableDepthAndStencil.  Answer posted to Starling forum.

   

DinkMcDinkleman, Newbie
Posted: 03 May 2012 11:50 AM   Total Posts: 30   [ # 14 ]

I’ve posted my own attempt at getting this to work in the support section.  Unfortunately this forum seems to think including a URL means my post must be spam, so I can’t - but it’s at the top of the search forum list now.

The biggest problem is that a call to Starling ‘hands off’ control to another class.  When this happens, all the Away3D variables become useless as they are out of scope.  I tried instantiating them within the class Starling hands off to, but can’t seem to reference the correct class/object/context to add the view to.

Any ideas?

   

netphreak, Newbie
Posted: 10 September 2012 04:09 PM   Total Posts: 10   [ # 15 ]

Could you please make a example method, as i can’t quite figure out how to place the Displayobject on top of the plane with correct rotation etc.

theMightyAtom - 17 January 2012 10:22 AM

This is achievable in Away4, just needs a little effort.
1.Create your 2D interface (off stage), draw it into a bitmapData and use that in a material on a plane.
2. Set the plane to mouseEnabled = true and m.mouseDetails = true;
3. Add mouse events to the plane.
4. Read the output and you can work out the position of the mouse in relation to texture. This can effect the appearance of the 2D interface and the material updated.

private function readOutput(evt:MouseEvent3D):void {
   
var m:Mesh = (evt.currentTarget as Mesh);
   
trace(m.name "," evt.uv.toString() ) 
  

Note that the UV coordinates are “normalised”, ie. between 0 and 1.
To find the “mouseX” and “mouseY” in you 2D interface, multiply by width and height.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X