adobe/USD-Fileformat-plugins

Converting usdz to glb to usd fails

fire opened this issue · 13 comments

fire commented

Expected Behaviour

Converting usdz to glb to usd does not cause error.

pancakes_2x

Actual Behaviour

Converting usdz to glb to usd causes weird geometry.

image

Reproduce Scenario (including but not limited to)

Steps to Reproduce

  1. .\bin\usdcat.exe ..\pancakes.usdz -o pancakes.glb
  2. .\bin\usdcat.exe pancakes.glb -o pancakes.usd

Platform and Version

Windows 11 V-Sekai@2fe88a1

Sample Code that illustrates the problem

See steps to reproduce.

Logs taken while reproducing problem

PS C:\Users\ernest.lee\Downloads\usd-install> .\bin\usdcat.exe ..\pancakes.usdz -o pancakes.glb
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface2sg/place2dTexture11 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface2sg/place2dTexture12 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface2sg/place2dTexture13 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface3sg/place2dTexture16 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface3sg/place2dTexture17 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface3sg/place2dTexture18 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface5sg/place2dTexture19 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface5sg/place2dTexture21 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface5sg/place2dTexture20 is reading primvar . Only 'st' is supported
Warning: in readInput at line 889 of D:\a\USD-Fileformat-plugins\USD-Fileformat-plugins\utils\layerRead.cpp -- Texture reader /pancakes/Looks/usdpreviewsurface7sg/place2dTexture22 is reading primvar . Only 'st' is supported
PS C:\Users\ernest.lee\Downloads\usd-install> .\bin\usdcat.exe pancakes.glb -o pancakes.usd

https://developer.apple.com/augmented-reality/quick-look/ "Pancake"

I ran your file through Reality Converter and it found a variety of issues with the file.

Screenshot 2024-03-14 at 08 42 13 Screenshot 2024-03-14 at 08 42 27 Screenshot 2024-03-14 at 08 42 34

It also seems that textures have not gotten embedded.

copy_asset: Can't resolve path c:\Users\ernest.lee\Downloads\usd-install\pancakes.glb[pancakes_n.png]

fire commented

That's really helpful, is there a text based log I can generate? How did you generate this?

@fire Reality Converter is a free tool provided by Apple https://developer.apple.com/augmented-reality/tools/

I am not sure though at this stage how up to date the tool is with the later versions of USD this repo is using. I think Apple is still using 19.05 in their iOS implementation. Someone correct me if I am wrong.

Their python usdz tools for example break in the most recent USD release as the CreatePrimvar method has changed as part of a new primvarsAPI.

Did you test using the latest USD release (24.03) or use the one mentioned in this repo (23.08)?

@fire I just did a test with a usdz I provided and it worked to glTF binary, however it is missing the materials when converting back to USD.

image

I also found that converting from glTF binary to usdz is not supported:

Cannot save layer @test.usdz@: writing package usdz layer is not allowed through this API.
Coding Error: in _WriteToFile at line 4744 of C:\repos\OpenUSD\pxr\usd\sdf\layer.cpp -- Cannot save layer @test.usdz@: writing package usdz layer is not allowed through this API.

edit: found it also modifies the face normals:

this is the input:
image

fire commented

I suspect somewhere in this repository there would be two bugs:

  1. the convention for normals would be another way
  2. writing package usdz layer is not allowed through this API.

yeah. it is still looking good when just doing the usdz to glb conversion. I suppose there there might be an issue in the glb to usd conversion somewhere?

image

out.zip

Unfortunately usdz is not a standard export format. The process to create a usdz is using usdzip which comes with usds command line tools.
For untextured gltf models, the way to make a usdz would be:

usdcat mygltf.gltf -o mygltf.usd
usdzip mygltf.usdz ./mygltf.usd

Note how we first convert to usd, if we don't, we will embed the gltf which is probably not what you want to happen since a usdz reader without the plugin won't know what to do.

Also, this workflow doesn't support textured assets at the moment since we refer the textures as embedded textures in the gltf file. The reason for this is we want to create in memory files where we do tweaks to map the gltf material model more acurately to the usd models. This is annoying and a future with materialx we can get out of this and implement all this with shaders but this is the best we can do now unless we want to sacrifice material translation.
The correct way would be an export process where we not only convert the usd but write out all images to disk and reference the files and then make that into the usdz we create.

We are looking to provide utilities/api's to help facilitate that down the road.

Thanks for the report, as @dlarsson-adobe mentioned we are working on this. Unfortunately, the updated release today will not help the issue but I'm hopeful we will have some fixes to help address this next month in v1.0.3

thank you @dlarsson-adobe @kwblackstone I am really glad Adobe started this and is taking the initiative for USD interchange between common formats. Looking forward to your fixes next month. Have you considered making https://github.com/pablode/guc part of this as it does indeed solve the last piece of the puzzle (glTF back to usdz conversion).

Hey @lanxinger the latest release addressed an export issue we had here when needing to triangulate meshes with varying and faceVarying primvars. Please try out the latest release.

Closing, please reoopen or create a new issue if you are still seeing an issue.