Juncheng Posted July 19, 2017 Share Posted July 19, 2017 Hi Guys, I am Juncheng. I am new to Babylon.js. I imported a model through OBJ loader, then I failed to modify the properties of its material. modelGoldTop.onSuccess = function (task) { m = task.loadedMeshes[0]; m.scaling = new BABYLON.Vector3(12,12,12); var material = m.material; console.log("Material: " + material); // material.backFaceCulling = false; // m.material = material; console.log(m); } I tried to log the material and mesh object. The material shows undefined, but if you dive into the mesh, you can find the mesh has its material. Why? I am confused. How to edit the material? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 20, 2017 Share Posted July 20, 2017 Hey! Material is loaded asynchronously for.obj file as they are in a separate.mtl file You should use this to be called when material is ready : Mesh.onMaterialChangedObservable.add(function(){ }); Quote Link to comment Share on other sites More sharing options...
Juncheng Posted July 20, 2017 Author Share Posted July 20, 2017 16 hours ago, Deltakosh said: Hey! Material is loaded asynchronously for.obj file as they are in a separate.mtl file You should use this to be called when material is ready : Mesh.onMaterialChangedObservable.add(function(){ }); Thank you, Deltakosh. I kind of understood what you were doing right here. I tried to listen to the change from the material with my mesh m, but nothing happened. modelGoldTop.onSuccess = function (task) { m = task.loadedMeshes[0]; m.onMaterialChangedObservable.add(function(){ console.log("Material loaded"); }); }; Is there any documentation for this? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 21, 2017 Share Posted July 21, 2017 This should work https://www.babylonjs-playground.com/#HW3HF0 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted July 21, 2017 Share Posted July 21, 2017 22 hours ago, Juncheng said: Thank you, Deltakosh. I kind of understood what you were doing right here. I tried to listen to the change from the material with my mesh m, but nothing happened. modelGoldTop.onSuccess = function (task) { m = task.loadedMeshes[0]; m.onMaterialChangedObservable.add(function(){ console.log("Material loaded"); }); }; Is there any documentation for this? Putting this in assetsManager.onFinish can be m.onMaterialChangedObservable.add(function(){ console.log("Material loaded"); }); Exemple : var m; modelGoldTop.onSuccess = function (task) { m = task.loadedMeshes[0]; }; assetsManager.onFinish = function() { m.onMaterialChangedObservable.add(function(){ console.log("Material loaded"); }); }: Quote Link to comment Share on other sites More sharing options...
Juncheng Posted July 21, 2017 Author Share Posted July 21, 2017 @Deltakosh @Dad72 Hey guys, both of your methods worked. I found the problem for me that I am using an older version v3.0 from Balylon-master. I think onMaterialChangedObservable only available in Balylon v3.1-alpha. I switched to v3.1-alpha now. It worked. Cheers! GameMonetize 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.