Is there a way to trace or get the background color of my Mesh object?

Software: Away3D 4.x

Josh, Newbie
Posted: 17 July 2012 07:30 AM   Total Posts: 24

Hi,

  In new to away3d, i like to ask, if there’s a way to trace or get the background color of my mesh object?
Kindly refer on my code below. Thanx.

case AssetType.MESH:
    
_mesh = new Mesh();
    
_mesh evt.asset as Mesh;
    
_mesh.mouseEnabled true;
    
_mesh.addEventListener(MouseEvent3D.CLICKonMouseClick);
    
_mesh.addEventListener(MouseEvent3D.MOUSE_OUTonMouseOut);
    
_mesh.addEventListener(MouseEvent3D.MOUSE_OVERonMouseOver);

    
trace("Mesh: " _mesh.name);
    
trace("Submesh:" _mesh.subMeshes.length);
    
    for 
each(var sg:SubGeometry in _mesh.geometry.subGeometries)
    
{
     sg
.autoDeriveVertexNormals true;
     
sg.autoDeriveVertexTangents true;
    
}
    
    
for each(var sm:SubMesh in _mesh.subMeshes)
    
{
     _material 
= new ColorMaterial(0xFFFFFF Math.random());
     
     
sm.material _material;
     
_mesh.material _material;
     
     
sm.material.lightPicker _staticLightPicker;
    
}
   
break; 
   

Richard Olsson, Administrator
Posted: 17 July 2012 09:58 AM   Total Posts: 1192   [ # 1 ]

What do you mean by the “background color” of your mesh? You are configuring your material to be randomly colored, so your code is already controlling the color. Isn’t that the color that you’re after?

   

Josh, Newbie
Posted: 17 July 2012 10:31 AM   Total Posts: 24   [ # 2 ]

I have a MouseEvent3D, that when i click the specific mesh on the stage. I want to get the backgroundColor value in hexadecimal format.
 
  For example.
 
  When i click the cellphone Mesh object with white background Color.
I want to trace the color of if and show on my output tab.  “0xFFFFFF”.
Hope you can help me.

Thanx,

Best Regards,
Josh

   

Richard Olsson, Administrator
Posted: 20 July 2012 12:43 PM   Total Posts: 1192   [ # 3 ]

Listen for a mouse event, when the event fires, cast the event.currentTarget object to a Mesh, and cast it’s material to a ColorMaterial, and retrieve the color property from there.

myMesh.addEventListener(MouseEvent3D.CLICKonClick);

function 
onClick(ev MouseEvent3D) : void
{
  
var mesh Mesh Mesh(ev.currentTarget);
  var 
mat ColorMaterial ColorMaterial(mesh.material);
  
trace(mat.color);

The color property contains the numeric representation of the color (i.e. the hexadecimal value that you passed into your material constructor). If you really care about it being a hexadecimal string representation, you can use Number.toString() for that.

   

Josh, Newbie
Posted: 24 July 2012 07:25 AM   Total Posts: 24   [ # 4 ]

Thanx for the reply

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X