Mouse Picking w/o Mouse3D Event Handler?

Software: Away3D 4.x

OEGInc, Newbie
Posted: 11 April 2014 02:35 PM   Total Posts: 27

I’ve got examples of getting mouse picking to work with 3D objects in a scene where you assign a MouseEvent3D.CLICK event listener, and then when someone clicks the object it registers the event, etc..  It works, just not in my particular case.

I essentially need to have the same functionality, but with a function I can call manually passing in the mouseX and mouseY coordinates and getting back a Vector3D of the first mesh/bounding box the ray would hit coming from the camera.

I’m sure this has been done a million times, I just can’t seem to find an example anywhere.  (Maybe it hasn’t since Away3D provides such a nice interface to begin with ?).

Thanks!
—Rob

   

John Brookes, Moderator
Posted: 11 April 2014 03:35 PM   Total Posts: 732   [ # 1 ]

Use the RayCastPicker.as, its what the mouse picking uses and has a few handy functions.

   

OEGInc, Newbie
Posted: 11 April 2014 05:05 PM   Total Posts: 27   [ # 2 ]
JohnBrookes - 11 April 2014 03:35 PM

Use the RayCastPicker.as, its what the mouse picking uses and has a few handy functions.

Thanks John!

With your guidance I was able to solve this problem using the RayCastPicker as follows (for anyone else who needs to do this).

1. Make whatever objects you want to be able to click “mouseEnabled” by setting the “mouseEnabled” property to true on the object’s mesh.

2. I used the following to find the object that was clicked at the MouseX, MouseY position…

var raycastPicker:RaycastPicker = new RaycastPicker(true);
var 
collisionObject:PickingCollisionVO raycastPicker.getViewCollision(mouseXmouseYview3D);

if (
collisionObject)
{
    
// At this point "collisionObject.entity" is your object's mesh
    // And you can find out it's position by checking "collisionObject.entity.scenePosition

Thanks again!
—Rob

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X