Hey Ian only the root Object3D (the instance returned by the loader.handle property after a file is loaded) will have its materialLibrary set. for obj files this should be the case but appears not to be at present because the container of an obj file can be either an objectcontainer3d or a mesh, depending on the contents of the file. for now you can still grab the materialLibrary from the obj parser instance, but the failure to pass this over to the created object3d instance should be fixed in an update - please can you log the issue in our issue tracker here: http://code.google.com/p/away3d/issues/list
cheers Rob On Tue, May 4, 2010 at 1:17 AM, tictox <[email protected]> wrote: > Hi All , > > I was searching on replacing materials for loaded obj models ,I didnt > find much and had a look into the API again to see how it all works. > > I found a materialLibrary property in Object3D and the comments above > the declaration states it is populated via Obj loaders etc.. but this > never happens , it traces as null on all files I tested, SO I set the > reference now in Loader3D notifySuccess method : > > "_result.materialLibrary = materialLibrary" > > and added it in the clone method of Object3D as well : > > "object3D.materialLibrary = materialLibrary" > > This worked well , but then I had problems calling "getMaterial" > method on MaterialLibrary class and found another weird problem.. > > when "addMaterial" is called in MaterialLibrary , the "name" > argument's value is coming through with hidden "\n" characters. > > I fixed this now by adding some string manipulation into the > prepareData method on the Obj class : > > <code> > > for (var ii:int = 0; ii < trunk.length; ii++) { > trunk[ii] = > trunk[ii].split("\n").join("").split("\r").join("").split("\n > \r").join("") > } > > </code> > > So now its all working and im able to call getMaterial on the > MaterialLibrary of all models to return the MaterialData object and > set its material propery to any new material. > > IM using CS4 , Away3D fp10 branch and models are exported via > lightwave .. here are the obj and mtl files.. > > http://www.prezencenewmedia.com/ian/away3d/new_08split.obj > http://www.prezencenewmedia.com/ian/away3d/new_08split.mtl > > the only other means I found to access the bitmaps of the loaded > models was to loop Object3D.geometry.materialDictionary but this was > not an as good a solution as having materialLibrary property working > which seems to be the logical means to do it. > > Why is the materialLibrary property on the Object3D never set? Is this > a bug? > > Thanks > Ian > > > > I > > > > > > > > > > > -- Rob Bateman Flash Development & Consultancy [email protected] www.infiniteturtles.co.uk www.away3d.com
