I'm working on a project that loads in 3DS files. I needed to set the material 
of the resulting object, and rather than reaching into the loaded object I 
created a new Traverser that applies a material to every node in a tree of 3D 
objects. The code is at the bottom, but I have two questions:

1: Is there a better way to do this?

2: Would this be an appropriate class to add to Away3D?


Thanks,
Dan



package
{
        import away3d.core.base.Object3D;
        import away3d.core.base.Mesh;
        import away3d.core.traverse.Traverser;
        import away3d.materials.ITriangleMaterial;        

        /**
        * Traverser that sets materials.
        *
        * see away3d.core.traverse.Traverser
        */
        public class MaterialTraverser extends Traverser
        {       
        
                /**
                * Material which is to be applied to nodes
                */
                var material:ITriangleMaterial;
                
                /**
                 * Creates a new <code>MaterialTraverser</code> object.
                 *
                 * @param       material        The material which is to be 
applied to the nodes
                 */
                public function MaterialTraverser(material:ITriangleMaterial)
                {
                        this.material = material;
                }
                
                /**
                 * Sets the current node's material
                 */
                public override function apply(node:Object3D):void
                {       
                        if (node is Mesh) {
                                (node as Mesh).material = material;
                        }
                }

        }
}

-- 
Daniel T. Griscom             [email protected]
Suitable Systems              http://www.suitable.com/
1 Centre Street, Suite 204    (781) 665-0053
Wakefield, MA  01880-2400

Reply via email to