mikelyndon / usd2gltf

MIT License
28 stars 5 forks source link

Getting error in handle_texture #9

Open mechaadi opened 1 year ago

mechaadi commented 1 year ago

Hi, thanks for this great library 👍🏻 I am trying to convert a USDZ file to gltf format but getting the following error:

TypeError: can only concatenate str (not "NoneType") to str

Debug logs below:

Converting: /Users/mechaadi/Documents/projects/python/xyz/uploads/c2eb8896-bb3a-4255-b999-a814740fcf52/model.usdz
To: model.gltf
DEBUG:usd2gltf.converter:Created converter
DEBUG:usd2gltf.converter:Unzipped source file: /var/folders/mp/dbr6dwr97td2pfsrvpvxxylr0000gn/T/tmp391fxq3_/model/Users/mechaadi/Documents/projects/python/xyz/uploads/c2eb8896-bb3a-4255-b999-a814740fcf52/baked_mesh.usdc
DEBUG:usd2gltf.converter:== USD -> glTF Settings ==
DEBUG:usd2gltf.converter: - Interpolation: LINEAR
DEBUG:usd2gltf.converter:== Stage Contents ==
DEBUG:usd2gltf.converter:Materials: 
DEBUG:usd2gltf.converters.usd_material: - material[0]: /baked_mesh/Materials/texture_0 : texture_0
Traceback (most recent call last):
  File "/Users/mechaadi/Documents/projects/python/xyz/venv/bin/usd2gltf", line 8, in <module>
    sys.exit(main())
  File "/Users/mechaadi/Documents/projects/python/xyz/venv/lib/python3.9/site-packages/usd2gltf/cli.py", line 73, in main
    args.func(args)
  File "/Users/mechaadi/Documents/projects/python/xyz/venv/lib/python3.9/site-packages/usd2gltf/cli.py", line 17, in run
    factory.process(stage, args.output)
  File "/Users/mechaadi/Documents/projects/python/xyz/venv/lib/python3.9/site-packages/usd2gltf/converter.py", line 251, in process
    material_id, gltfMaterial = usd_material.convert(
  File "/Users/mechaadi/Documents/projects/python/xyz/venv/lib/python3.9/site-packages/usd2gltf/converters/usd_material.py", line 329, in convert
    gltfMaterial.pbrMetallicRoughness.baseColorTexture = handle_texture(
  File "/Users/mechaadi/Documents/projects/python/xyz/venv/lib/python3.9/site-packages/usd2gltf/converters/usd_material.py", line 148, in handle_texture
    "   - UsdPrimvarSampler: " + uv_map_name + " : " + str(uv_idx)
TypeError: can only concatenate str (not "NoneType") to str

Any help is much appreciated! 😄

mikelyndon commented 1 year ago

Hmmm. What's the name of your uv map? Seems to be failing on that. Also, how was the usdz authored? I know the apple ones had a bit of a weird way of setting up the uv primvar.

mechaadi commented 1 year ago

Hello, the usdz is generated using apple reality composer. I am attaching the USDZ file so you can inspect it better if needed. I tried to extract the USDZ file and got these files (img below)

Screenshot 2023-03-21 at 11 20 15

USDZ file: https://gofile.io/d/3Ps8C3

virokannas commented 1 year ago

I ran into this problem, too, until I added the specific st varname attribute. You can see it being added in Pixar's example code for creating materials: https://openusd.org/release/tut_simple_shading.html

But since models seem to work without it being specified, some examples (like the one NVidia's Omniverse documentation) omit it.

okamototomoyuki commented 5 months ago

I also get this error with some USDZ, so I modified usd_material.py as follows:

                logger.debug(
                    "   - UsdPrimvarSampler: " + uv_map_name + " : " + str(uv_idx)
                )

                uv_idx = len(converter.material_uv_indices[mat_path])
                if uv_map_name is not None:
                    logger.debug(
                        "   - UsdPrimvarSampler: " + uv_map_name + " : " + str(uv_idx)
                    )
                else:
                    logger.debug(
                        "   - UsdPrimvarSampler: None"
                    )
Red-54 commented 1 month ago

Works for me in only when we convert it to glb But it works thanks for that