1

I have an export of some .obj files and corresponding .mtl files. Textures are in .tga format in the same folder.

Here is the code I use to load all my .obj:

function addCar(modelPath, modelName) {
  var mtlLoader = new THREE.MTLLoader();
  mtlLoader.setPath(modelPath);

  for (var i = 0; i <= 2; i++) {
    loadObject(mtlLoader, modelPath, modelName, i);
  }
}

function loadObject(loader, path, name, i) {
  var objectName = name + i + '.obj';

  loader.load(name + i + '.mtl', function (materials) {
    materials.preload();

    var objLoader = new THREE.OBJLoader();
    objLoader.setMaterials(materials);
    objLoader.setPath(path);
    objLoader.load(objectName, function (object) {
      scene.add(object);
    }, function (xhr) {
      onProgress(xhr, objectName)
    }, onError);
  });
}

The car is loaded, but not the textures. It appears all white, and there is no error in the console. I tried to add

  mtlLoader.setTexturePath(modelPath);

but it didn't change anything.

I also tried to add

THREE.Loader.Handlers.add( /\.tga$/i, new THREE.TGALoader() );

before to call addCar function. When I do that, some warning appears in the console, but texture still doesn't appear. enter image description here

In all examples I saw, textures are loaded automatically when using OBJLoader and MTLLoader, but I didn't any example using OBJLoader and MTLLoader with TGA textures. So I'm wondering if there is something to do to get it worked.

Any help would be appreciated.

PS: the files (.obj, .mtl and .tga) are exported from 3D max).

Mat
  • 185
  • 1
  • 11
  • Possible duplicate of [WebGL importing models using the OBJMTLoader in three.js fails](http://stackoverflow.com/questions/19401151/webgl-importing-models-using-the-objmtloader-in-three-js-fails) – Damjan Pavlica Dec 31 '16 at 13:52
  • MTLLoader uses the TextureLoader class to load the images, which afaik does not support TGA images (which also explains why there is a specific class for loading TGA images) – 2pha Feb 04 '17 at 17:22

2 Answers2

1

You'll have to use the TGALoader to load .tga files. You can find it here.

See the webgl_materials_texture_tga source for an example.

Is there a reason why you are using a .tga texture instead of .png? For most purposes they will give identical results, and .png will generally be smaller and can be natively decoded by the browser so you'll get better performance.

Lewy Blue
  • 452
  • 3
  • 16
-2

If the number of files is not very big: change the mtl file's content, make 'tga' to 'jpg', then I use photoshop to make every tga file to jpg file.

Ali Beadle
  • 4,486
  • 3
  • 30
  • 55