rpajo Posted May 11, 2017 Share Posted May 11, 2017 Hello I am still somewhat new to Babylon and i'm having the following problem. I am loading an .obj model into my scene and I wish to apply a standard material onto the meshes, after the model has loaded. But my problem is, that the materials are not applied in the success callback. I have a button to maually apply the materials and it works fine. document.getElementById("applyMaterials").addEventListener("click", function(e) { var meshMaterial = new BABYLON.StandardMaterial("meshMaterial", scene); meshMaterial.backFaceCulling = false; meshesGlobal.forEach(function(element) { element.material = meshMaterial; }, this); }); I have tried my code in the playground with the skull.babylon model and it works fine. http://www.babylonjs-playground.com/index.html#EAY2GH Am I missing someting? Thanks! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 11, 2017 Share Posted May 11, 2017 can you save your .obj somewhere so you can reference it in the PG? It's gonna be easier to help if we can see the bug Quote Link to comment Share on other sites More sharing options...
Raggar Posted May 11, 2017 Share Posted May 11, 2017 does meshesGlobal contain All the meshes from the imported file? If you use the blender exporter, I think index 0 of the array is a root mesh without any geometry. Quote Link to comment Share on other sites More sharing options...
rpajo Posted May 12, 2017 Author Share Posted May 12, 2017 Hey! So i have recreated the situation with a sample model. http://www.babylonjs-playground.com/index.html#EAY2GH#1 I have found that only importing models with mtl files are affected by this. I have also added a button to apply the materials manualy, as I have mentioned. Are the any problems that I am missing with applying materials on models with mtl files? Thanks for the help! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 12, 2017 Share Posted May 12, 2017 Ok I know why this is because the loading of .obj is done in 2 steps: first the obj is loaded and the callback is called Then the mtl is loaded and material is applied. If you are only interested by geometry I suggest removing the reference to the .mtl file in the .obj file Quote Link to comment Share on other sites More sharing options...
rpajo Posted May 13, 2017 Author Share Posted May 13, 2017 Oh, I understand. Thanks for celaring this up Cheers Quote Link to comment Share on other sites More sharing options...
ozRocker Posted May 14, 2017 Share Posted May 14, 2017 Maybe we should add this: var matTimer = setInterval(function() { if (typeof(mesh.material) != "undefined") { clearTimeout(matTimer); var mat = mesh.material; //Do stuff to material } }, 50); to the OBJ Loader documentation 'cos a lot of people encounter this problem first time when trying to access .OBJ materials rpajo 1 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.