SOLVED: Looping through children in onjectContainer3D (dae) in away3d 3.6

Software: Away3D 3.x

Mr Margaret Scratcher, Sr. Member
Posted: 23 August 2011 03:49 AM   Total Posts: 344

Hi there, trying to achieve this:

private function blockComplete(event Loader3DEvent) : void
  {
   trace 
("DAE loaded");
   
//blockContainer = new Plane();
   
blockContainer event.loader.handle as ObjectContainer3D;
   
blockContainer.scale(100);
    
view.scene.addChild(blockContainer);
    
view.camera.= -1000;
   var 
mesh ObjectContainer3D;
   for (var 
int 0blockContainer.numChildren; ++i
   
{
    mesh 
ObjectContainer3D(blockContainer.getChildAt(i));
    
//var blockMaterials : ColorMaterial = new ColorMaterial(0xff0000);
    
    
var blockMaterials:ShadingColorMaterial = new ShadingColorMaterial(0xFFFFFF{ diffuse:0xFFFFFFspecular:0xFFFFFFalpha:1 } );
    
   
mesh.material blockMaterials;
   
}
   
  } 

Which is partially ported back from away3d V4 - seems like the getChildAt method is not there in 3.6 - how ddo I cycle through and change all the meterials? Or maybe a different method to load the .dae with alternative materials from the start (once object is loaded, materials stay the same, but the material color is specified using flashVars..

here’s the .dae load function:

private function loadBlock() : void
  {
   blockLoader 
Collada.load(flashvars.obj);
   
blockLoader.addEventListener(Loader3DEvent.LOAD_SUCCESS,blockComplete);
  
   

Mr Margaret Scratcher, Sr. Member
Posted: 23 August 2011 05:10 PM   Total Posts: 344   [ # 1 ]

YESSSSSS! I found a solution, so I thought I’d share it here for any one else who’s having the same difficulties:

var blockMaterials:ColorMaterial = new ColorMaterial ();
   
    for 
each(var mesh:Mesh in blockContainer.children)
        
{
        
//mesh.material = blockMaterials;
        //mesh.material = null;
        
for each(var f:Face in mesh.geometry.faces
        
{ f.material blockMaterials
        
        
        } 

The above code works through an imported .dae (and most likely, any other imported format or primitive), and then works through each face of the mesh and changes the material of that face.

   
   
‹‹ model size and scale

X

Away3D Forum

Member Login

Username

Password

Remember_me



X