MousePicking an imported object

Software: Away3D 4.x

Bill7745, Newbie
Posted: 17 December 2015 07:23 PM   Total Posts: 22

Hi I’m trying to move an imported object that I exported from PreFab2 as an as3 class with the mouse on a map for a war game. I tried enabling the mouse,
(_soldier.mouseEnabled = true;),
and using a MouseEvent3D,(_soldier.addEventListener(MouseEvent3D.MOUSE_DOWN,_soldierOnMouseDown);,
but I can’t select the object.

What do I need to do to select the imported object so I can move it around on a map?

   

veggieman25, Newbie
Posted: 03 February 2016 10:12 AM   Total Posts: 12   [ # 1 ]

Hi all new to away3d, running Away3D 4.1.6

I am having the same issue with MousePicking on an imported object (awd file).
The mouse event is not working, any ideas?

   

rdoi, Member
Posted: 03 February 2016 04:35 PM   Total Posts: 86   [ # 2 ]

You may be setting the event in the container, not in the mesh itself.

Post the code where you setup the event listeners.

 

   

veggieman25, Newbie
Posted: 03 February 2016 09:41 PM   Total Posts: 12   [ # 3 ]

The texture is embeded in the awd file;

Parsers.enableAllBundled();
var 
modelLoaderLoader3D = new Loader3D();
modelLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
modelLoader.addEventListener(LoaderEvent.LOAD_ERRORonLoadError);
modelLoader.load(new URLRequest('box.awd'));

modelLoader.mouseEnabled true;
modelLoader.addEventListener(MouseEvent3D.CLICKf_modelLoader);

function 
onResourceComplete(evLoaderEvent): void
{
 trace
("onResourceComplete");
 
modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
 
modelLoader.removeEventListener(LoaderEvent.LOAD_ERRORonLoadError);
 
_view.scene.addChild(modelLoader);
}

function onLoadError(evLoaderEvent): void
{
 trace
("onLoadError");
 
modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
 
modelLoader.removeEventListener(LoaderEvent.LOAD_ERRORonLoadError);
 
modelLoader null;
}

function f_modelLoader(eventMouseEvent3D): void
{
 trace
("hit");
   

rdoi, Member
Posted: 04 February 2016 02:02 PM   Total Posts: 86   [ # 4 ]

Well you ARE setting the listener in the container.

Maybe you just need to set .mouseChildren= true;

If for some reason, mouse events on v4.x are not bubbled to containers, you will have to set the events in all internal meshes of your “box.awd”.

You can achieve this by looping all container’s children or by listening for loader’s AssetComplete event and assign a mouse listener when the asset type is a mesh.

 

   

veggieman25, Newbie
Posted: 04 February 2016 11:43 PM   Total Posts: 12   [ # 5 ]

Thank you this worked

AssetLibrary.enableParser(AWD2Parser);
var 
modelLoaderLoader3D = new Loader3D();
modelLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
modelLoader.addEventListener(LoaderEvent.LOAD_ERRORonLoadError);
modelLoader.addEventListener(AssetEvent.ASSET_COMPLETEf_onAssetComplete);
modelLoader.load(new URLRequest('box.awd'));

function 
f_onAssetComplete(eventAssetEvent): void
{
 
if (event.asset.assetType == AssetType.MESH)
 
{
  
var newMeshMesh event.asset as Mesh;
  
newMesh.mouseEnabled true;
  
newMesh.mouseChildren true;
  
newMesh.addEventListener(MouseEvent3D.CLICKf_modelLoader);
  
newMesh.geometry.scale(7);
  
_view.scene.addChild(newMesh);
 
}//end if
}//end f_onAssetComplete
function onResourceComplete(evLoaderEvent): void
{
 trace
("onResourceComplete");
 
modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
 
modelLoader.removeEventListener(LoaderEvent.LOAD_ERRORonLoadError);
}

function onLoadError(evLoaderEvent): void
{
 trace
("onLoadError");
 
modelLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
 
modelLoader.removeEventListener(LoaderEvent.LOAD_ERRORonLoadError);
 
modelLoader null;
}
function f_modelLoader(eventMouseEvent3D): void
{
 trace
("hit");
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X