kcoley / gltf2usd

command-line utility for converting glTF 2.0 models to USD
MIT License
263 stars 39 forks source link

Auto Material PBR from GLTF to USDZ #109

Closed enzyme69 closed 5 years ago

enzyme69 commented 5 years ago
screen shot 2018-11-22 at 12 01 42 pm

Wondering what's the best way to properly setup the PBR Material, so that one does not need to dig inside the USDA and tweaking the material mapping manually?

When following Khronos Group PBR Principle Material, I don't see it translates correctly to USDZ.

enzyme69 commented 5 years ago

An interesting example is some downloadable 3D assets from Sketchfab, such as this "Porg":

https://sketchfab.com/models/d5902960a033459cb1966dd064f885d1

192-168-1-10:porg jimmygunawan$ python gltf2usd.py -g scene.gltf -o scene.usdz 
converted usd file extension from .usdz to .usdc: /Users/jimmygunawan/Downloads/porg/scene.usdc
Traceback (most recent call last):
  File "gltf2usd.py", line 806, in <module>
    convert_to_usd(os.path.expanduser(args.gltf_file), os.path.abspath(os.path.expanduser(args.usd_file)), args.fps, args.scale, args.arkit, args.verbose, args.use_euler_rotation, args.optimize_textures)
  File "gltf2usd.py", line 754, in convert_to_usd
    usd = GLTF2USD(gltf_file=gltf_file, usd_file=usd_file, fps=fps, scale=scale, verbose=verbose, use_euler_rotation=use_euler_rotation, optimize_textures=optimize_textures)
  File "gltf2usd.py", line 74, in __init__
    self.convert()
  File "gltf2usd.py", line 724, in convert
    self._convert_materials_to_preview_surface_new()
  File "gltf2usd.py", line 437, in _convert_materials_to_preview_surface_new
    usd_material.convert_material_to_usd_preview_surface(material, self.output_dir)
  File "/Users/jimmygunawan/Downloads/porg/_gltf2usd/usd_material.py", line 22, in convert_material_to_usd_preview_surface
    usd_preview_surface = USDPreviewSurface(self._stage, gltf_material, self, output_directory)
  File "/Users/jimmygunawan/Downloads/porg/_gltf2usd/usd_material.py", line 42, in __init__
    self._initialize_from_gltf_material(gltf_material)
  File "/Users/jimmygunawan/Downloads/porg/_gltf2usd/usd_material.py", line 105, in _initialize_from_gltf_material
    self._set_khr_material_pbr_specular_glossiness(gltf_material)
  File "/Users/jimmygunawan/Downloads/porg/_gltf2usd/usd_material.py", line 172, in _set_khr_material_pbr_specular_glossiness
    self._set_pbr_specular_glossiness_glossiness(pbr_specular_glossiness)
  File "/Users/jimmygunawan/Downloads/porg/_gltf2usd/usd_material.py", line 214, in _set_pbr_specular_glossiness_glossiness
    destination = specular_glossiness_texture.write_to_directory(self._output_directory, GLTFImage.ImageColorChannels.A, "glossiness")
  File "/Users/jimmygunawan/Downloads/porg/_gltf2usd/gltf2/Material.py", line 38, in write_to_directory
    return self._image.write_to_directory(output_directory, channels, texture_prefix)
  File "/Users/jimmygunawan/Downloads/porg/_gltf2usd/gltf2/GLTFImage.py", line 63, in write_to_directory
    img = img.getchannel(channels.value)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 2057, in getchannel
    'The image has no channel "{}"'.format(channel))
ValueError: The image has no channel "A"

What could be the issue in here?

I wonder why with GLTF there is no proper standard or agreement even on PBR Material?

enzyme69 commented 5 years ago

Ok apparently with PBR Export, I think we can use the panel supplied by Khronos Group. Basically a matter of preparing Material, linking the Color, Roughness, Metallic, etc Map and then export. I supposed the Roughness and Metalness got created and separated automatically from RGB.

screen shot 2018-11-29 at 4 56 19 pm screen shot 2018-11-29 at 4 56 15 pm
enzyme69 commented 5 years ago
screen shot 2018-11-30 at 11 33 07 pm

Blender 2.8 currently Beta, actually has GLTF IO from KhronosGroup, still has bug, but it seems like for PBR it can export Normal, Albedo. Something still funky with Metalness and Roughness, not sure how GLTF 2 USDZ handles it, but it seems like it generates and separates Metalness and Roughness autmatically. Metalness tend to get full white plain white color, not sure where it came from.

enzyme69 commented 5 years ago

I am testing something here: https://github.com/KhronosGroup/glTF-Blender-IO/issues/116

enzyme69 commented 5 years ago

So far my solution seems to be to use gltf2usd.py to convert to USDA. And then I get 2 textures output for roughness and metalness, I can then fix that manually.

Haven't tried for multiple material it could be slightly more tedious having to do this manually.

Still curious how you guys handle PBR material export...

enzyme69 commented 5 years ago
screen shot 2018-12-01 at 12 31 39 am

This setup, in Blender 2.8 is kind of a step in the right direction, still not sure where to plug Occlusion...

enzyme69 commented 5 years ago

I am curious also wether gltf2usdz has "opacity" option somewhere linked to GLTF output and translated into USDZ?

kcoley commented 5 years ago

@enzyme69 gltf2usd can read the opacity properties of a glTF file and map them to usdz, though things like alpha mask are not yet supported in the usdz specification.

enzyme69 commented 5 years ago

Aha... no wonder. I can make whole material transparent looking, but opacity is indeed strange. I can't remember but at some point I made double sided working.

kcoley commented 5 years ago

@enzyme69 closing for now