XML to load 3D object?

Software: Away3D 4.x

gOzaru, Newbie
Posted: 23 April 2013 05:48 PM   Total Posts: 13

Hi,
I have known how to combine AS3 and XML, but I don’t know how to make a function which able to read 3D object I drag onto scene?
Should I assign its variable like this:

//solider ant texture
  
[Embed(source="soldier_ant.jpg")]
  
public static var AntTexture:Class;
  
  
//solider ant model
  
[Embed(source="soldier_ant.3ds",mimeType="application/octet-stream")]
  
public static var AntModel:Class; 

And add function to load 3D object:

_loader = new Loader3D();
   
_loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   
_loader.loadData(new AntModel(), assetLoaderContext); 

What MouseEvent3D should i use when I want to drag it over my stage3d?
Any help please!

 

   

SuperSam, Sr. Member
Posted: 23 April 2013 11:00 PM   Total Posts: 102   [ # 1 ]

Hi gOzaru,


If I understand your question properly you want to drag a mesh object that is already displayed on stage, right ? If so you need to:


- Enable it to mouse interaction. This is disabled by default for performance reasons.

- Tell Away3D which technique it should use to guess if you clicked on your mesh.

- Have your mesh listen to MouseEvent3D.MOUSE_DOWN and MouseEvent3D.MOUSE_UP

- When mouse is down on the mesh, you can either listen to MouseEvent3D.MOUSE_MOVE or set a boolean to true. The latter is better for performance, possibly better practise too, but less convenient.

- Use the new and previous mouse coordinates to move the mesh along the axes you decide. Since mouse moves in 2D you’ll have to decide yourself if you want to move it along x/z, x/y or z/y. Moving it freely in the 3 axes might need a more complex algorithm or an extra control (for instance mouse wheel could move in the distance). If you decided to use a boolean in the previous step, this step’s code should be called from the main loop method (if boolean is true), otherwise just put it in the MOUSE_MOVE handler function.

- Once MOUSE_UP is fired don’t forget to remove MOUSE_MOVE event listener or set back boolean to false.


Here’s a little starting code to set you on the road. Let’s assume you added your ant as a Mesh instance called “hero” to the scene.

hero.pickingCollider PickingColliderType.AUTO_FIRST_ENCOUNTERED;    // I let Away3D partly decide for your situation since I don't know it myself
hero.mouseEnabled true;
hero.addEventListener(MouseEvent3D.MOUSE_DOWNonMouseDown);
hero.addEventListener(MouseEvent3D.MOUSE_UPonMouseUp); 


You can also directly add _loader to the scene instead of a Mesh, but while _loader has a mouseEnabled property, it doesn’t have a pickingCollider one. I never tried mouse interaction with a Loader3D, I use Mesh instances instead. It’s less straightforward (but better practise), so you can just give a try to Loader3D if you prefer.

   

gOzaru, Newbie
Posted: 23 April 2013 11:10 PM   Total Posts: 13   [ # 2 ]

Hi SuperSam,
thank you for replying.
yeah you were right, I forgot to add its mouseEnabled.
Uhm actually, I want to load 3d object when I drag it from XML list on flash 2D graphics. so when I drop it to stage3d, it will placed on a plane. I just read that MouseEvent3D can not be used to drag item from XML list. So do you know what function should I use to drag it?

Layer 0: XML list -> flash 2D
Layer Stage3D[0]: Plane with physics
Layer Stage3D[1]: 3D Object I drag. (has physics)
Feature: Object rotated 90 degrees.

Anyone know this please email me in .(JavaScript must be enabled to view this email address)
I’ll pay you US$ 50 via bank transfer if I have done my task.
I mean with an example where I can understand. Not just function.

   

gOzaru, Newbie
Posted: 23 April 2013 11:12 PM   Total Posts: 13   [ # 3 ]

This is my friend’s task for flash programming..
She can’t understand english well, so I help her.
Please help me if you can!

   

SuperSam, Sr. Member
Posted: 23 April 2013 11:56 PM   Total Posts: 102   [ # 4 ]

Ahah yeah sounds like I answered the wrong question. Hopefully this time I understood correctly :D


Use flash.events.MouseEvent to interact with the display list (what you call flash 2D). It’s kind of the same process as I described above except it’s totally unrelated to Away3D.

Once you have dragged whatever it is you’re dragging (a graphical representation of an XML node ?) and released the mouse, MouseEvent.MOUSE_UP will fire and you’ll have to catch it and use the data to instantiate an Away3D Mesh that you will pass on to the part of your program that deals with Stage3D. Actually it would be better to instantiate all meshes before hand and just use the data to display and position the correct mesh, because if you wait until the user drags that XML Node to instantiate your mesh, there will be latency in the program.

In the end the mesh should be positioned according to the mouse position and that’s it, except that there might be an issue with transposing the coordinates. You will know that’s the case if the mesh appears in a different spot than where you released the mouse button, or if the mesh doesn’t appear at all but you know it’s added to the Scene3D. (in that case the mesh is off screen)


It sounds like you have 2 Stage3D instances running. It will be a pain if you want your plane to interact with your dragged 3D object… Generally you would be better off using one Stage3D instance unless you really know what you want and what you are doing. smile

   

gOzaru, Newbie
Posted: 24 April 2013 07:04 AM   Total Posts: 13   [ # 5 ]

uhm… I guess you’re right about Stage3D. Physics would not work if the dragged 3D object is not interacting with plane on stage3D[0]. Thank you.
So the problem is latency. I know about this application about it on this website:
http://www.meble.vox.pl/voxbox/
Thank you.

   

SuperSam, Sr. Member
Posted: 24 April 2013 12:50 PM   Total Posts: 102   [ # 6 ]

Nice, I see what you’re doing now smile

If models are not complex like in this app I think the latency is acceptable, provided you have some visual indication that the program is not frozen.

If models are bigger and take longer to instantiate you can either do it when the program initializes (be careful if you have too many models though), or make up a system that loads and displays them progressively as they’re loaded in chunks.


Good luck. Also transforming coordinates might actually be a more annoying issue than it looks. Maybe if you listen to MouseEvent3D.MOUSE_UP on the 3D plane you won’t have that problem ?
In that case Away3D might give you correct 3D coordinates if you select the right PickingColliderType. I didn’t test that though.

   

gOzaru, Newbie
Posted: 24 April 2013 07:59 PM   Total Posts: 13   [ # 7 ]

I see, thank you SuperSam. i am gonna test a lot on PickingColliderType. I will try to apply it with Away3D physics later. Thank you for reading my post and guide me!

   

SuperSam, Sr. Member
Posted: 24 April 2013 08:46 PM   Total Posts: 102   [ # 8 ]

Welcome smile

When you’ll feel slightly more comfortable with Away3D feel free to come back and help other people. I’m not a pro either but this forum seems to be in need of active and helpful users ^_^’

   

gOzaru, Newbie
Posted: 25 April 2013 01:08 AM   Total Posts: 13   [ # 9 ]

Okay. I will.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X