MTLLoader 'mapTexelToLinear' : no matching overloaded function found

I’m loading an .obj file and it’s .mtl file with this function (it’s es6 but it is mostly copied from here https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_obj_mtl.html).


export function loadObjWithMtl(objs_path, obj_filename, mtl_filename){
    let p = new Promise((resolve, reject) => {
        let mtlLoader = new MTLLoader();
        mtlLoader.setPath(objs_path);
        mtlLoader.load(mtl_filename,
                       (materials)=> {
                           materials.preload();
                           let objLoader = new THREE.OBJLoader();
                           objLoader.setMaterials(materials);
                           objLoader.setPath(objs_path);
                           objLoader.load(obj_filename,
                                          (model)=>{
                                              resolve(model);
                                          },
                                          (xhr)=>{
                                              console.log(xhr.loaded);
                                          },
                                          (err)=>{ reject(err);}
                                         );
                       },
                       (xhr)=>{
                           console.log(xhr.loaded);
                       },
                       (err)=>{ reject(err);}
                      );
    });
    return p;
}

I’m calling it like this let carObj = loadObjWithMtl('obj/A/','hoverCraft_A_textured.obj','hoverCraft_A_textured.mtl');

If I comment the line “objLoader.setMaterials(materials);” the mesh is showing in the scene without any material, as expected. If I leave that line I receive this error message:

THREE.WebGLShader: gl.getShaderInfoLog() fragment ERROR: 0:939: 'mapTexelToLinear' : no matching overloaded function found
ERROR: 0:939: '=' : dimension mismatch
ERROR: 0:939: 'assign' : cannot convert from 'const mediump float' to 'highp 4-component vector of float'

Before to open an issue on github, I want to be sure that I’m not doing something wrong.

It seems likely a texture file is not being loaded correctly. Can you try setting material.map = null for each material and see if that helps?

Hey @looeee, thanks for your answer.
Actually, a Texture is present in the material

But as you see, the currentSrc value is a blob, and not an address to a texture location (like, for exampe http://localhost/img/text.jpg).
Setting material.map=null removes the error. But it removes the texture too.
I do not see any documentation that tells me that I’m doing something wrong, so, I suppose it is a bug.

Are the all the texture files present in the same directory as the .mtl file? As far as I know textures can’t be embedded in the .mtl format.

yes, they are, this is the content of my obj/A/ folder:

hoverCraft.png
hoverCraft_A_textured.mtl
hoverCraft_A_textured.obj

Is there any particular things that I should take care of when exporting obj file from blender?

I’m not sure, I don’t use blender. But can you double check that the references to hoverCraft.png are correct in hoverCraft_A_textured.mtl and that there are no other texture files referenced?

Yes, it is referenced

# Blender MTL File: 'hoverCraft_A_2Materials_davide.blend'
# Material Count: 1

newmtl hoverCraft
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 0.936709
illum 1
map_Kd hoverCraft.png

Hello edap,

Is there a special reason why you don’t want export your work in JSON from Blender?

Well, there are 2 reasons:

  • The first one is that I’ve received the files as .mtl and .obj from a 3d artist, I want to simply import them. I can play around with Blender and maybe find a way to do it, but if threejs supports mtl and obj, why should not work?
  • The second one is that I use threejs quite a lot, and if something does not work as expected it should probably be an issue on the github page of threejs. If nobody would report broken things, we probably would not have such a nice library :wink:

As stated above, if you have a choice to export from Blender, use the JSON format, it is a solid base to work with. If there is an obj-Blender export issue, it needs to be specific for people working hard on the module to improve upon.

Secondly, please don’t expect people to dive into unknow waters and answer questions you are not able to resolve. This discourse is by no mean here to challenge people, it is here to let people work together for greater goods.

Why do you misuse promise call in the first place? new MTLLoader is already asynchronous! It is nice to push the envelop, but promise call + ES6 syntax + basket case obj import! Come on what do you expect, a miracle? In 6 month, 4 years from now, yes it will be a breath, but today it is pushing the envelop too far. Please, break the envelop on your own, come back and share your findings, but do not expect genuine people to indirectly do R&D for you.

Anyways, just do the basic steps to debug your issue:

  1. try to import the obj file alone (if it works, then it is the misused promise call causing the issue, if it doesn’t, post a Blender-obj export/import bug finding)
  2. If 1 works, test the ES6 syntax
  3. if 1&2 are ok, then you are done !

If you want to use promise calls, rewrite the new MTLLoader class, post a PR and help everyone…

Haha! I was going to say something a little less… direct… regarding your use of Promise. But yes, the next step in testing this is probably to remove the promise, and try using the code from this example as is, to see if that fixes your issue. If the simplest case works then you can try getting fancy with promises…

Hello @INF1N1T, thank you for taking your time to answering my question. I will simply try to take the mtlloader example in threejs and try to use my model instead the defined on. A few things that needs to be pointed out:

  1. No one is expecting that people “dive into unknown waters”, my tone was not pretentious, read the thread again from the beginning if you are in doubt.
  2. To me, answering “use json” when someone has problem loading mtl, is like to say “use nginx” when someone has difficulties configuring apache. I will definitely try it out, but my problem was with the MTLLoader.
  3. Before judging other people technical solutions, think why they use it first. Think that may have adopted a codebase that they did not write from scratch, think that maybe that promise goes together chained with other promises, maybe using Promise.all. Then, if you still want to answer with this tone, go for it, but do not expect nothing, at least from me.

@edap those are good points.

Still, have you tried loading the model using the simpler non-promise method from the example to see if works that way?

File format has nothing to do with webservers, I am not sure what you are trying to say?

The point that needs to be clear is when an issue occurs, try to get a solid working base and build upon it.

For your case scenario, when using Blender, the recommended solid base is to export in JSON format which is the closest format to a future file standard, it is natif to the web and it has the most people maintening it. The obj format is not natif to blender and by doing so you add a layer of complexity that could trigger errors on the blender side.

THREE.js loaders are asynchronous to allow for parallel processing. Taking an asynchronous process and making it synchronous with promise call does not make any sense.

The loaders have events (onLoadComplete,…) which triggers exaclty when needed. Why don’t you use these events and get a solid working base to build upon?

Hello @looeee. Yes, the problem persists also after using the example code. At this point I think that it has something to do with the model. I’ve read that when you export obj from blender, with a texture, you have to check certain things before to export. I’m going to ask this to the modeller first.

And, of course, i will try out the JSON exporter