CesiumGS / obj2gltf

Convert OBJ assets to glTF
Apache License 2.0
1.7k stars 305 forks source link

Convert gltf with different material on each mesh using command line #190

Open apiatlas9 opened 5 years ago

apiatlas9 commented 5 years ago

Hello,

I have obj file and PBR material files separately. I would like to convert the obj to gilt using command line. The obj might have multiple meshes and each mesh might have different material.

Attached zip file having obj file and all required textures.

There are 2 Meshes in obj. 1) Cylinder001 2) Line004

I am using this command, but it didn’t work.

obj2gltf Cylinder001 --map_Kd diffuse.jpg --map_Ks metalness.jpg --map_Ns roughness.jpg --map_Bump normal.jpg Line004 --map_Kd diffuse2.jpg --map_Ks metalness2.jpg --map_Ns roughness2.jpg --map_Bump normal2.jpg -i model.obj -o model.gltf

obj2gltf.zip

Please advise.

Another alternative : Can we pass custom .mtl file in command line?

lilleyse commented 5 years ago

I don't think this is possible right now. The closest thing is you can pass in a global baseColorTexture, metallicRoughnessOcclusionTexture, etc but there's no way currently to assign it to specific meshes in the obj.

Passing in a custom .mtl file is also not supported but is a good idea.

apiatlas9 commented 4 years ago

@lilleyse May I know, in future, is it possible to convert obj to GLTF file with separate parts with material?

Suppose, we have gltf without material and we would like to assign PBR material on each part. Is it possible using any package or via simple coding?

Here, I am attaching blank GLTF and same with Material for your reference

Sample model GLTFs.zip

lilleyse commented 4 years ago

@apiatlas9 I think your best bet is to assign the materials with some simple coding. If you export the obj with placeholder materials you can convert to glTF and then loop over the materials, filling in the values based on the placeholder material's name.