kcoley / gltf2usd

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

A bunch of joints, animated, cannot be converted #13

Closed enzyme69 closed 6 years ago

enzyme69 commented 6 years ago

I basically have bunch of joints, animated, under Armature, exported from Blender.

loopingnoise.zip

Error Message:

192-168-1-4:source jimmygunawan$ python gltf2usd.py -g loopingnoise.gltf -o loopingnoise.usda
Traceback (most recent call last):
  File "gltf2usd.py", line 1105, in <module>
    convert_to_usd(args.gltf_file, args.usd_file, args.fps, args.verbose)
  File "gltf2usd.py", line 1094, in convert_to_usd
    GLTF2USD(gltf_file=gltf_file, usd_file=usd_file, fps=fps, verbose=verbose)
  File "gltf2usd.py", line 63, in __init__
    self.convert()
  File "gltf2usd.py", line 1080, in convert
    self.convert_nodes_to_xform()
  File "gltf2usd.py", line 101, in convert_nodes_to_xform
    self._convert_animations_to_usd()
  File "gltf2usd.py", line 511, in _convert_animations_to_usd
    self._convert_skin_animations_to_usd()
  File "gltf2usd.py", line 623, in _convert_skin_animations_to_usd
    self._store_joint_animations(usd_animation, joint_values, joint_map)
  File "gltf2usd.py", line 667, in _store_joint_animations
    rotation = joint.skeleton_joint.GetRestTransformsAttr().Get()[joint.joint_index].ExtractRotation()
AttributeError: 'dict' object has no attribute 'GetRestTransformsAttr'

I don't have root of this bones, wondering if this is an issue?

wave-electron commented 6 years ago

@enzyme69 @kcoley My guess is gltf2usd.py may not handle this exception. I've tried numerous bone based animations, building the source glTF with either the COLLADA2glTF or FBX2glTF tool. The animations may load and work as expected in sandbox.babylonjs.com, but the glTF is converting to USD with distorted or broken animations that won't even load in xcode as usda or safari as a usdz. I've only successfully converted 2 bone animations so far.... and may have tried a dozen or so models to date. Even my newton_cradle model isn't converting correctly, but works fine in the glTF sandbox. The static pose meshes seem fine in most cases you can check these using the older beta 5 xcode, but the animation conversion fails in all beta versions I've tried including 6. I think the bone naming issues can be easily fixed for all cases, but different animation exceptions will require more testing and debugging. For example if you have a morph target with weight, the program will hang with an exception currently. Another issue is you take the same animation and save it as either a dae or fbx, and use the respective tools to build each glTF file, these glTF files can be widely different in node structure even though they run similar animations in the sandbox.babylonjs.com. I also performed diff operations comparing the resulting usda files and they are very different in many respects. IMHO it will take considerable time to work through some of these issues. Personally I'm unfamiliar with glTF orUSD schema to tackle some of these problems in a timely fashion. I think it would be helpful to know definitely what cases the tool will work for in its current state, and the glTF converter or exporter used to create the glTF input file. I can put together a list of what in currently hasn't worked for, but @kcoley be in a much better position to know the cases it was designed to work for.

wave-electron commented 6 years ago

Its only a guess based on the error. “dict object has no attribute “GetRestTransformAttr”. It seems that maybe USD schema is looking for a Rest pose that may be missing?

the USD schema for GetRestTransformAttr

A blender user had flagged this issue with glTF exporter... missing rest pose on glTF export in respect to the Armature. (July 2018)

glTF-Blender-Exporter issue

@enzyme69 As a workaround you could try exporting as a dae file and using the COLLADA2glTF command tool to see if fixes the missing rest pose error.

kcoley commented 6 years ago

@wave-electron @enzyme69 I have some time tonight to look into this. I suspect it is related to glTF node animations that are attached to joints and transferring to USD, or essentially attaching meshes to joint nodes. I believe this case was not handled for certain meshes exported from the Blender exporter, so I will see if I can get that working. Any sample models you can provide would be great

kcoley commented 6 years ago

@wave-electron @enzyme69 I just merged a change to master that may help with this issue. The bug was on my side with an API change I had made earlier. I was able to get the loopingnoise gltf converted to usda and working on iOS.

loopingNoise.usdz.zip

Feel free to try pulling from master and let me know if you run into other issues.

enzyme69 commented 6 years ago

@kcoley Thanks for the update, looks like only 1 Torus is animating, but at least no error this time 👍 I will investigate this from the USDA...

I will try again using simpler bone and animation. All I have here is just a bunch of mesh torus, joined into a single surface, and each of this torus got skinned into bones and animated randomly using nose.

Previously I thought that maybe bone naming or my hierarchy is the issue... 1) bunch of free bones animating does not work 2) parent those bones under a single root bone still does not work 3) rename bone hierarchy does not work 4) maybe giving each bone a different name works, instead of bone_00, bone_01, bone_02 ? not sure, will check.

PS: I am slowly reading your code to do this conversion. Ideally it should just work from Blender export to USDA, but then Blender is Python 3 hit head into Mac but anyhow, I really quite like this GLTF2USD workflow.

kcoley commented 6 years ago

@enzyme69 interesting, I was able to get all the toruses to animate on iOS, though it doe look different in XCode Beta 6. This could be another difference in behavior between Mac OS and iOS. I made a screen recording on my phone for reference. IMG_1338.TRIM.MOV.zip

enzyme69 commented 6 years ago

@kcoley You are right!! It's also working and animating on my side on iPhone and iPad.

I guess we can send bug report to Apple. MacOS and iOS USDZ has different behaviour. Sometimes it works on MacOS and not on iOS... at least this works on iOS!!

Thanks!