Jump to content

[Solved] How to edit the material in an imported mesh


Juncheng
 Share

Recommended Posts

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);
}

596fb0956a0dd_ScreenShot2017-07-19at12_15_08PM.png.42f21c6c557ed50ab4934c865304d545.png

596fb09464479_ScreenShot2017-07-19at12_16_31PM.thumb.png.d91c0f4093966e0e78d689d894ea61f1.png

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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");
    });
}:

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...