, Sr. Member
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_DOWN, onMouseDown);
hero.addEventListener(MouseEvent3D.MOUSE_UP, onMouseUp);
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.