Jump to content

Materials not applied on .obj model


Recommended Posts


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.


Am I missing someting?



Link to comment
Share on other sites


So i have recreated the situation with a sample model. 


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!

Link to comment
Share on other sites

Maybe we should add this:

		var matTimer = setInterval(function() {
			if (typeof(mesh.material) != "undefined") {
				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

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.

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.


  • Recently Browsing   0 members

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