Jump to content

Materials not applied on .obj model


Recommended Posts

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!

Link to post
Share on other sites

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!

Link to post
Share on other sites

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

Link to post
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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...