CesiumGS / obj2gltf

Convert OBJ assets to glTF
Apache License 2.0
1.71k stars 307 forks source link

Set texture maps even if there is no .mtl file. #141

Open nauman-tintash opened 6 years ago

nauman-tintash commented 6 years ago

If there is no .mtl file with the OBJ, then no texture is set even if we pass individual texture maps as command line params. There should be a feature to add the texture maps (diffuse, normal, etc) to the model directly through params even if there is no material file present.

lilleyse commented 6 years ago

Thanks @nauman-tintash, this is the intended behavior of the command line flags at the bottom of the list but there seems to be a bug where they are getting ignored in certain cases. I should have a fix soon.

nauman-tintash commented 6 years ago

Thanks @lilleyse for letting me know. If you have any clues on why these flags might be getting ignored that you can share, that'd be really helpful. I intend to look at the bug myself as well and would love to contribute.

lilleyse commented 6 years ago

@nauman-tintash awesome!

The problem is the flags are only being considered if loadMtl is called, and that only happens when the obj has an mtl file.

The fix is a bit messier than I was hoping, but one approach is to fix how default materials are handled.

In loadObj there is a function assignDefaultMaterial which usually bails early if there were no materials, but instead it should call loadMtl.getDefaultMaterial and assign that material to each primitive.

loadMtl.getDefaultMaterial will need to be refactored to load the overriding textures. As a result it will need to return a promise, which means assignDefaultMaterial will need to return a promise as well.

Finally createGltf#getMaterial can be changed to no longer check for default materials.

lilleyse commented 6 years ago

Also - if you do plan on contributing make sure to send in a CLA

yosun commented 3 months ago

any updates on this fix