Hey Dan

traversers are really only used for scene-wide functions, and it is unlikely
that a scenario would arise where you want to apply the same material to the
entire scene of your view... ;)

i see the reason why you created this class for your 3ds file, however, you
can easily access and reset the materials you need without this by using the
mateiralLibrary property on the objectcontainer produced by the 3ds parser:

3dsObject.mateirialLibrary.getMateiral("myMatName").material = new
BitmapMaterial(myBitmap);

soemthing like that should do the trick, or refer to the Basic_LoadModel
example in the examples folder to see an example of the material being set
on a 3ds file after loading.

cheers

Rob

On Fri, Nov 27, 2009 at 8:37 PM, Daniel Griscom <[email protected]>wrote:

> 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
>



-- 
Rob Bateman
Flash Development & Consultancy

[email protected]
www.infiniteturtles.co.uk
www.away3d.com

Reply via email to