My .obj model is white even though I attached an .mtl file to it

1.9k Views Asked by At

I'm working on three.js and I'm trying to import a .obj file with its corresponding mtl file. The textures the mtl file was referencing were .bmp so I tweaked the mtl file to point to all .dds files and converted all my assests to dds. Problem is that its just rendering white texture. I'm not sure its related but it said that PVRTC compressed textures are not supported. Here is the code I used for the obj/mtl loader:

var onProgress = function(xhr) {
  if (xhr.lengthComputable) {
    var percentComplete = xhr.loaded / xhr.total * 100;
    console.log(Math.round(percentComplete, 2) + '% downloaded');
  }
};
var onError = function(xhr) {};
THREE.Loader.Handlers.add(/\.dds$/i, new THREE.DDSLoader());
var loader = new THREE.OBJMTLLoader();
loader.load('assets/FirstPersonExampleMap.obj', 'assets/FirstPersonExampleMap.mtl', function(object) {
  object.position.y = 0;
  scene.add(object);
}, onProgress, onError);

And here is an example of my tweaked .mtl file:

newmtl assets/M_WhiteEditQuarter_M_WhiteEditQuarter
 map_Kd M_WhiteEditQuarter_M_WhiteEditQuarter_D.dds
 map_Ks M_WhiteEditQuarter_M_WhiteEditQuarter_S.dds
 bump M_WhiteEditQuarter_M_WhiteEditQuarter_N.dds

1

There are 1 best solutions below

6
On BEST ANSWER

The references to your textures in the .mtl directory should be with respect to where your html file is. So the .mtl should look like this:

newmtl M_WhiteEditQuarter_M_WhiteEditQuarter
    map_Kd assets/M_WhiteEditQuarter_M_WhiteEditQuarter_D.dds
    map_Ks assets/M_WhiteEditQuarter_M_WhiteEditQuarter_S.dds
    bump assets/M_WhiteEditQuarter_M_WhiteEditQuarter_N.dds

the newmtl is just a name so it does not have to prefixed with assets. The rest are actual paths to your textures.

Update 1

General comments: Your model is huge. That is one thing. The other is that you are using a lot of 1x1 textures. Why? There is a lot of delay caused by them. The third issue is that your textures are also very big. For your diffuse textures that is ok? but your normal maps do not have such detail to warrant the space they take.

Back to the issue

Looking at your bmp version; Your .obj and .mtl files need fixing. As I said newmtl is just a name so it does not have to be path prefixed. But there is an inconsistency between your .obj and .mtl files. In one file newmtl is path prefixed and in the other it is not. So when .obj loads it will never find the materials. So once I fixed that I got the textures to appear.

Also in one case an mtl definition FirstPersonExampleMap_FirstPersonExampleMap_PersistentLevel_SkySphereBlueprint_Sky Sphere mesh_MaterialInstanceDynamic_3 has spaces in it. I am not sure this is valid.

The tool I am using to see the changes is http://www.finalmesh.com/

Note: It seems that the is a big sphere around your world and also there are elements around your church that are actually white. I had to zoom in a lot until I got material to show.

https://i.stack.imgur.com/Z4iZT.jpg

https://i.stack.imgur.com/xhVUH.jpg