RESOLVED: How to access a global material from ObjectContainer3D?

Software: Away3D 4.x

Qbrain, Member
Posted: 22 November 2011 03:00 PM   Total Posts: 92

Hey everyone,

I’m going fine on my little project, I have one question though.. (for now wink )

I have an object, which is a .obj with an .mtl material on it.

Now, I want to add an eventlistener to this object. is there a possible way to have the eventlistener work with the container instead of the mesh?

I don’t want to add the eventlistener to all the meshes in my object. I need it to only apply on the object itself (since i want to use the outlinemethod in a mouse_over situation)

container.addEventListener does not work though…

any ideas?
thx!

-Q

   

Qbrain, Member
Posted: 24 November 2011 01:51 PM   Total Posts: 92   [ # 1 ]

Alright, I’ll try to make my question more simple.

I have this eagle here. (see attachment) The only thing I would like to create is that if my mouse goes over the eagle, it gets an outline and when it leaves, the outline goes away. Now I can create this type of behavior with the cube shape, but this model is imported as an .obj with .mtl material on it. It is possible to get the outlinemethod on this object with the mouseover event?

Thanks!!

-Q

 

   

Avatar
Fabrice Closier, Administrator
Posted: 24 November 2011 02:13 PM   Total Posts: 1265   [ # 2 ]

you can add a loader.addEventListener(AssetEvent.MESH_COMPLETE, onSomeMeshReady);  and once (testing name) you get the mesh as event.currentTarget being your eagle. Add a mouse event.

 

   

Qbrain, Member
Posted: 24 November 2011 02:17 PM   Total Posts: 92   [ # 3 ]

thanks for the fast reply! Deffinetely makes sense! will try it right now!

-Q

 

   

Qbrain, Member
Posted: 24 November 2011 02:35 PM   Total Posts: 92   [ # 4 ]

doesn’t work yet. I’m probably having a noobish mistake but can’t find it atm..
Here is the source for this object now, minus the imports and other obvious stuff, the loader2 declaration is in my constructor:

var loader2Loader3D = new Loader3D();
   
loader2.load(new URLRequest('objects/eagle/neweagle.obj'));
   
loader2.addEventListener(LoaderEvent.RESOURCE_COMPLETEonBasicSceneComplete);
   
loader2.addEventListener(AssetEvent.MESH_COMPLETE,onBasicMeshScene);

private function 
onBasicSceneComplete(event:LoaderEvent){
   
var container ObjectContainer3D ObjectContainer3D(event.target);
   
_view.scene.addChild(container);

   
//var materia : ColorMaterial = new ColorMaterial(0xfa6c16);
   //materia.lights = [_light];
   
var sceneMesh Mesh
   
// create rigidbody shape
   //var boxShape : AWPBoxShape = new AWPBoxShape(200, 200, 200);
   
   
for (var int 0container.numChildreni++) {
    sceneMesh 
Mesh(container.getChildAt(i));
    
sceneMesh.geometry.scale(20);
    
//sceneMesh.material = materia;
   
}
   
   
   container
.1500;
   
container.rotationY 180;
   
container.= -4700;
   
   
//var sceneBody : AWPRigidBody = new AWPRigidBody(boxShape, sceneMesh, 0);
   //physicsWorld.addRigidBody(sceneBody);
   
   
}

private function onBasicMeshScene(event:AssetEvent){
   
var test:Mesh event.currentTarget as Mesh;
   
test.mouseEnabled true;
   
test.addEventListener(MouseEvent3D.MOUSE_OVER,boxMouseOver);
   
test.addEventListener(MouseEvent3D.MOUSE_OUT,boxMouseOut);
   
   
   
}

private function boxMouseOver(event:MouseEvent3D){
   debugtext2
.text "debugtext2";
   
debugtext.text "mouseoverja";
   
event.target.material.addMethod(standardOutlineMethod);
   
}
  
private function boxMouseOut(event:MouseEvent3D){
   debugtext2
.text "mouseoutja";
   
debugtext.text "debugtext";
   
event.target.material.removeMethod(standardOutlineMethod);
   

 

   

Avatar
Fabrice Closier, Administrator
Posted: 24 November 2011 04:39 PM   Total Posts: 1265   [ # 5 ]

Try set the listener before you do load and a trace in the onBasicMeshScene.

 

   

Qbrain, Member
Posted: 24 November 2011 05:04 PM   Total Posts: 92   [ # 6 ]

Done. event.target and event.currentTarget both trace [Object Loader3D] (logically), but when I trace event.currentTarget as Mesh, it traces null (same for event.target) which somewhere makes sense, however I don’t know how to fix this..

-Q

 

   

Qbrain, Member
Posted: 24 November 2011 05:33 PM   Total Posts: 92   [ # 7 ]

Problem fixed. I looked at the code at this page:

http://away3d.com/forum/viewthread/1433/

what I needed to use was test:Mesh = Mesh(event.asset);

anyway,
thanks for the help with the loaders etc!

-Q

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X