satguru Posted June 18, 2018 Share Posted June 18, 2018 Looks like the obj loader is not finished loading material when the BABYLON.SceneLoader.ImportMesh() onSuccess function is called. see https://github.com/BabylonJS/Babylon.js/blob/master/loaders/src/OBJ/babylon.objFileLoader.ts#L231 I need to make changes to the mesh material after the mesh is loaded by the obj loader. How would i know when the obj loader is done loading the material? what is the most reliable method for doing that? Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 18, 2018 Share Posted June 18, 2018 I can't tell without a PG example. This is simple to troubleshoot if you simply load your OBJ into the playground. You may need to edit your OBJ and/or material file, or perhaps there's not time to load the texture - however this is rare. DB Is your OBJ, MTL, and image file int the same directory? Are you using power of 2 texturing? EDIT - In looking further at your code, I can see allot of declarations that perhaps won't allow the mapping of a texture. I haven't figured out why you're addressing UVs, but the OBJ importer is simple yet fickle if you make one error. Also, if the issue is not the texture and it is the material, then edit your OBJ file to remove reference to the material, and reference in the MTL file to a texture if necessary. Eliminating the reference to the MTL file in the OBJ file will provide a very nice default texture - which could be your issue depending on how the OBJ was generated and if you already applied any materials. Quote Link to comment Share on other sites More sharing options...
satguru Posted June 18, 2018 Author Share Posted June 18, 2018 Here's a PG example. http://www.babylonjs-playground.com/#UKNERM#11 This loads a small obj file "TallWall.obj". The obj file has a small mtl file "TallWall.mtl". No textures, just colors. The files are located here https://github.com/ssatguru/obj-samples In the PG example I print "mesh.material" from two places 1) from inside the ImportMesh() OnSuccess method and 2) outside it after waiting 2 secs. Inside I get undefined , outside, after 2 sec, I get the material Quote Link to comment Share on other sites More sharing options...
brianzinn Posted June 18, 2018 Share Posted June 18, 2018 I've ran into this before as well. The comment that it's loaded syncronously (Calls synchronously the MTL file attached to this ob) was what confused me last time I checked - I found it to be async. https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.tools.ts#L634 Check here as well: https://github.com/BabylonJS/Babylon.js/blob/master/loaders/src/OBJ/babylon.objFileLoader.ts#L860 Notice the onSuccess() just attaches the material and if I recall correctly the onSucess() you are working with is just that the OBJ file loaded, where material is async. I don't see a way to wire into material loading except manually checking in a loop (2 seconds is not a guarantee on a slower connection) or updating the loader itself to trigger (additional) events. One easy solution is to switch from OBJ... I'm using OBJ files, but not MTL materials. Other standards include material in original file. edit: If you want to work on the loader to delay onSuccess until materials are loaded, it could be added as an option. ie: { onSuccessWithMaterials: true }, which defaults to false. I think you need to get importMesh(...) to not return until materials are loaded, probably not done as it could block for a while. Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 19, 2018 Share Posted June 19, 2018 As stated previously, edit out the mtl file and create you're own, or follow the correct protocol. DB Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 19, 2018 Share Posted June 19, 2018 https://github.com/BabylonJS/Babylon.js/issues/4571 Issue submitted, I agree that it should be async and not sync. satguru 1 Quote Link to comment Share on other sites More sharing options...
satguru Posted June 19, 2018 Author Share Posted June 19, 2018 Nice. Thanks Quote Link to comment Share on other sites More sharing options...
Sebavan Posted June 19, 2018 Share Posted June 19, 2018 This should be all deployed in a minute. brianzinn 1 Quote Link to comment Share on other sites More sharing options...
satguru Posted June 20, 2018 Author Share Posted June 20, 2018 Works fine now Thanks 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.