Fabrice, Thanks!
This worked. I did have to run a :
trace (m.name);
to know what to put in the
case "blah"
this was a AWD with a single mesh in it made with PreFab
it went through that recursive function, recognized the
e.loader.handle as an objectcontainer3d, then went through it again as
object children mesh, then the applycustom material function was made.
The AWD was named "aw_0", I guess by default.
The uvs were retained! YAY!
so:
private function applyMyCustomMaterial(m:Mesh):void {
trace ("running the applymycustommaterial function");
trace (m.name);
switch(m.name){
case "aw_0":
m.material = belizeMainlandMat;
trace(m.material);
break;
}
On May 31, 5:14 pm, Fabrice3D <[email protected]> wrote:
> awd, doesn't support materialLibrary.
>
> onSuccess just access the Object3D
> which is correct in your code as event.loader.handle
>
> you need then to check if its a type ObjectContainer3D or Mesh
> a single object is returned in awd as Mesh while more than 1 as
> ObjectContainer3D
>
> if its a Mesh, apply as mesh else access its children
>
> if you have more write a recursive routine like this: (which I just did for
> you :)) )
>
> onSuccess
> parse(loader.handle);
>
> private function parse(object3d:Object3D):void
> {
> if(object3d is ObjectContainer3D){
> var obj:ObjectContainer3D = (object3d as
> ObjectContainer3D);
> for(var i:int =0;i<obj.children.length;++i){
> if(obj.children[i] is
> ObjectContainer3D){
> parse(obj.children[i]);
> } else if(obj.children[i] is Mesh){
>
> applyMyCustomMaterial(obj.children[i] as Mesh);
> }
> }
>
> } else if(object3d is Mesh){
> applyMyCustomMaterial(object3d as Mesh);
> }
> }
>
> in the applyMyCustomMaterial(m.Mesh)
> switch(m.name){
> case "bla":
> m.material = myBlaMaterial;
> break;
>
> Fabrice
>
> On May 31, 2010, at 6:38 PM, KarmaKat wrote:
>
> > My code was a little jumbled there with my adieu mixed in...
> > SInce I can't seem to edit that post here is the code again a little
> > cleaner:
>
> > public function loadMyAWD ():void {
>
> > var loaderAWD:Loader3D = new Loader3D();
>
> > loaderAWD.addEventListener(Loader3DEvent.LOAD_SUCCESS, onSuccess);
>
> > var awd:AWData = new AWData();
>
> > loaderAWD.loadGeometry("assets/belizeMesh.awd", awd);
>
> > }
>
> > public function onSuccess(e:Loader3DEvent):void {
>
> > var myObject3D:Object3D = e.loader.handle;
>
> > var myMesh:Mesh = myObject3D as Mesh;
>
> > trace ( myMesh.material);
>
> > for each (var materialData:MaterialData in
> > myObject3D.materialLibrary)
> > {
>
> > materialData.material = belizeMainlandMat;
>
> > }
>
> > for each (var i:Face in myMesh.faces) {
> > i.material= belizeMainlandMat;
> > }
>
> > myMesh.material = belizeMainlandMat;
>
> > this.view.scene.addChild(myMesh);
> > trace (myMesh.material);
> > }