Basically what was mentioned here: https://github.com/mrdoob/three.js/issues/16395 .
All I did was to change the model loaded in this: https://threejs.org/examples/?q=obj#webgl_loader_obj2 .
So the resulting code is:
var onLoadMtl = function ( materials ) {
objLoader.setModelName( modelName );
objLoader.setMaterials( materials );
objLoader.setLogging( true, true );
objLoader.load( 'models/obj/my_scans/Model.obj', callbackOnLoad, null, null, null, false );
};
objLoader.loadMtl( 'models/obj/my_scans/Model.mtl', null, onLoadMtl );
But the model will not load. The model will not show up, and no errors come up…
Any ideas ?
PS: The model loads fine in MeshLab
You’ve ran into the following issue (it’s about the ambiguity of the tr
statement):
https://github.com/mrdoob/three.js/issues/12861
You can solve the issue by creating your MTLLoader
like so. This will invert the semantic of the transparency definition.
const materialLoader = new THREE.MTLLoader();
materialLoader.setMaterialOptions( { invertTrProperty: true } )
Result with OBJLoader
:
BTW: One more reason to use glTF
instead of OBJ
. More information about this topic:
https://threejs.org/docs/index.html#manual/en/introduction/Loading-3D-models
Thanks! It worked. I was also using an outdated version of the loader.
Hello, my 3d model is composed of obj file and texture (MTL + JPG), I don’t know how to load JPG.My model is shown in black.Can you share your code?Thank you very much!
Mugen87
December 25, 2019, 9:52am
8
I’ve already shared the code for loading MTL (with textures) here:
Have you actually tried this code? If so, please share your current work of progress as a git repository.
Thank you very much for your careful answer. By changing the value in the MTL file, my model has texture, but the back of my model is still black. I think it may be the problem of setting the light source, but I don’t know how to adjust it.
Mugen87
December 25, 2019, 4:05pm
11
You are just adding an instance of SpotLight
right now. Try to add an ambient light next to your spot light like so:
var ambientLight = new THREE.AmbientLight( 0x404040 ); // soft white light
scene.add( ambientLight );
Thank you very much for your answer. It was very effective and helpful.And then I’m going to have to adjust the axes, hopefully to fit the model.