Dynamically access a face of a cube

Software: Away3D 3.x

lostirc, Newbie
Posted: 01 August 2011 07:40 PM   Total Posts: 5

I’m trying to change the material on the face of a cube on mouse over. Right now I’m creating my cube primitive and adding a mouse over listener

var cube:Cube = new Cube({material:cubeMatwidth:200height:50depth:100});
cube.addOnMouseOver(handleOver); 

Inside my handleOver method I have this

private function handleOver(e:MouseEvent3D):void{
var newColor:uint 0x00B2EE;
   
e.currentTarget.material =  new PhongColorMaterialnewColor,{specular:0.2,shininess:5});

This however changes the entire cube’s material. Is there any way to access the individual face dynamically so I can change it’s material?

 

   

Stephen Hopkins, Sr. Member
Posted: 02 August 2011 12:18 AM   Total Posts: 110   [ # 1 ]

I think Away3D 3.6 or 3.5 has a Cube6 class, that lets you specify the material of each face.

 Signature 

http://www-scf.usc.edu/~shopkins

   

lostirc, Newbie
Posted: 02 August 2011 12:28 AM   Total Posts: 5   [ # 2 ]

I just took a look at Cube6, it looks like that’s in away3dlite.

You can access each edge of the cube using this:

e.currentTarget.cubeMaterials.back 

I just can’t seem to figure out how to access that property dynamically using the event.

   

Stephen Hopkins, Sr. Member
Posted: 02 August 2011 12:39 AM   Total Posts: 110   [ # 3 ]

Hmm, Away3D Cube has the property, cubeMaterials, http://away3d.com/livedocs/3.6.0_lib/away3d/primitives/Cube.html#cubeMaterials

Not sure of the order you add them, though. Can probably figure that out by looking at the source.


This might be a ghetto way to do it, but you can look at the material of the mouseEvent3D, and see which one it matches in the cubeMaterials property, then change that one.

 Signature 

http://www-scf.usc.edu/~shopkins

   

lostirc, Newbie
Posted: 02 August 2011 12:43 PM   Total Posts: 5   [ # 4 ]

A trace of

trace(e.currentTarget.cubeMaterials); //returns [object CubeMaterialsData] 

not sure if that’s useful or not.

Is it possible to assign a name to each face that I can somehow access through the MouseEvent3D?

   

lostirc, Newbie
Posted: 02 August 2011 12:47 PM   Total Posts: 5   [ # 5 ]

I just took a look, it looks like that object is specific to the entire cube. Is there a way to attach listeners to each face individually? It’s not ideal but it could be a workaround

   

Somokon, Member
Posted: 02 August 2011 03:40 PM   Total Posts: 75   [ # 6 ]

Inside the handler function, you could take a look at the event.localX, event.localY, and event.localZ coordinates, and use those to determine which face of the cube has been clicked. 

It’s not perfectly precise, but it works well for me.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X