jackbob Posted November 18, 2016 Share Posted November 18, 2016 Hi, I am rather new to Babylon. I am using the AssetManger to load OBJ/MTL. I am executing my renderloop in the onFinish callback on the AssetManager. I want to make adjustments to the material created when the MTL-file was loaded (adjust the emissive color). However, it appears that the materials are not yet created when onFinish is called (i.e. they are still undefined). How do I know when the materials have been properly created so that I can make my adjustments? I have something along the lines of this, const scene = createScene(); // Setup camera etc. const loader = new BABYLON.AssetsManager(scene); const model = loader.addMeshTask("model", "", "source/", "Model.obj"); model.onSuccess = (t) => { t.loadedMeshes.forEach((m) => { m.position.x = 0; m.position.y = 0; m.position.z = 0; }); }; loader.onFinish = (task) => { // task[0].loadedMeshes[0].material is undefined... engine.runRenderLoop(() => { scene.render(); }); }; loader.load(); Best, Bob Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 19, 2016 Share Posted November 19, 2016 Hi bob! Sorry about the problems. No errors seen on console network areas... like "404" for the .mtl file? Wouldn't the texture be loaded separately with a textureTask? Not sure. I'm not very experienced with .obj and .mtl loading, but I found this monster playground demo... with all sorts of object-loader crap. In fact, it might contain the entire obj loader SYSTEM. I don't know who coded it or what its purpose, but take a look http://www.babylonjs-playground.com/#1S9WC2#5 Material/Texture .isReady might not be activating, but maybe the mtl isn't even loading correctly. Check your stuff... and I'll keep thinking. Sorry for the slow and bad reply. I'll do some studying. Quote Link to comment Share on other sites More sharing options...
jackbob Posted November 19, 2016 Author Share Posted November 19, 2016 Thank you for your suggestions Wingnut. It does not appear to be an issue with fetching the resources from the server. Everything loads nicely, both the OBJ and MTL files are loaded and rendered appropriately. However, I don't know where I should hook in my logic to alter the materials that were automatically created from the MTL file? I would think there would be a way to observe the material state and wait till it is ready (and the textures loaded etc.) and then make modifications to the material properties, but I am not sure how. I have browsed the documentation and currently I am going through the sourcecode of the file loader. It appears to be the way material loading has been implemented in the _parseSolid method in babylon.objFileLoader.ts where the materials are loaded async while the function returns as soon as the meshes have loaded (leaving the material callback hanging without anyway to know when it is done...). See this file on Github. Can anybody confirm this? (The code snippet you referred to, Wingnut, appears to be an (early?) implementation of the obj loader). Quote Link to comment Share on other sites More sharing options...
Nabroski Posted November 19, 2016 Share Posted November 19, 2016 hm interessting:http://www.babylonjs-playground.com/#28YUR5#135@Wingnut also an interesting task to get the material from onfinish function http://www.babylonjs-playground.com/#28YUR5#136 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.