@McFunkyPants: If the Loader3D container is empty after RESOURCE_COMPLETE then that's a bug. Can you send in the file that you're loading for me to test? E- mail it straight to me using the e-mail address that you can find by clicking my username (if you're using the Google Groups web interface.)
@John: You should _never_, regardless of the file, try to access anything within the Loader3D instance straight after a parseData() or load() operation. They are both asynchronous and if it ever works for you then it's just pure luck. The only thing you should ever do before receiving events is addChild() the loader to the scene (if you want to.) Then wait until the RESOURCE_COMPLETE for all assets to have been loaded, or for the ASSET_COMPLETE event which is dispatched once per asset, before trying to change any materials or anything. Cheers /R On Jun 1, 1:57 am, McFunkypants <[email protected]> wrote: > Hello, > > Firstly, thanks guys for being such a wonderful, hard-working team. I > have what I believe to be an ultra-simple conundrum. > > I would like to change the material of a Loader3D asset. I'm stumped! > > Using the most recent GIT version of away3d 4 broomstick, I am > successfully loading an embedded mesh into my scene and it properly > parses and triggers a LoaderEvent.RESOURCE_COMPLETE event. No errors: > it parses perfectly. It renders just fine in my scene, by the way - > just with a black and white checkered default material. > > This object has zero for the numChildren property and so I cannot use: > > private function onResourceRetrieved_tree(e:LoaderEvent) : void > { > for (var i : int = 0; i < tree1.numChildren; ++i) // has no > children! > { > mesh = Mesh(tree1.getChildAt(i)); > mesh.material = treematerial; > } > > } > > I also cannot seem to cast a Loader3D to be a Mesh nor does it have a > material property, so neither of these two attempts works if added to > the above function: > > Mesh(tree1).material = treematerial; > ObjectContainer3D(tree1).material = treematerial; > > Just to help, here's the code that loads this tree mesh. I've tried > both 3ds and obj. > > tree1 = new Loader3D(false); > tree1.addEventListener(LoaderEvent.LOAD_ERROR, > onResourceLoadingError_tree); > tree1.addEventListener(LoaderEvent.RESOURCE_COMPLETE, > onResourceRetrieved_tree); > tree1.parseData(new treedata(), new OBJParser(),new > AssetLoaderContext(false),null); > view.scene.addChild(tree1); > treematerial = new BitmapMaterial(new treeimage().bitmapData,true); > treematerial.lights = [mylight]; > treematerial.ambientColor = 0x777777; > // I also tried AssetLoaderContext and mapUrlToData with no errors but > nothing happens. > > This stuff really shouldn't be so hard. =( I feel pretty stupid > wasting 4 hours on this. Oh model loader code, why art thou so > complex and counterintuitive? I sure would like Loader3D.material = > to just automagically work. > > I would be most grateful for any hints on setting the material of a > completely embedded model file that has no children meshes but renders > just fine. What prop lets me access the mesh in this case? > > What I really want is a way to either cast Loader3D to Mesh or > ObjectContainer3D, or some way to change the material of a Loader3D > object. > > THANK YOU VERY MUCH! I'm really grateful for any help.
