Query Skeleton Animation

Hi, I try to read an skeleton animation from an usda file exported with Houdini. I have not yet much experience with USD, so if my understanding of concepts is wrong, please correct me. So if I understand it correctly following the docs, I first try to find the skeletonRoots and then create a SkelCache, populate it with my current skelRoot. Then I retrieve all needed data, e.g. the bind poses of the joints. Next I should be able to find the animations and get all the joint transformations at a time defined by a UsdTimeCode value. That’s what I tried to do in this simple code: readSkeleton source. In line 83 I try to get a UsdSkelAnimQuery from skelQuery.GetAnimQuery() but the result is always invalid so it seems I have a wrong understandig what i need to do to find the animation of the current skelRoot. If needed, here is the usd file: Two frame skel anim.. I’d appreciate some hints how to proceed, thanks.

I think you're on the right track, my recommendation is to try this in python first and then see what's wrong with the cpp usage.  I tried downloading your example and I can print out the joint transformations just fine as follows:

import os

from pxr import Usd, Sdf, Vt, Gf, UsdSkel, UsdGeom

srcLayerName = "/home/pkanyuk/Download/agentNoInst.usda"

stage = Usd.Stage.Open(srcLayerName)

skelPrims = [prim for prim in Usd.PrimRange(stage.GetPseudoRoot()) if prim.IsA(UsdSkel.Skeleton)]
skelPrim = skelPrims[0]
skelCache = UsdSkel.Cache()

skel = UsdSkel.Skeleton(skelPrim)
skelQuery = skelCache.GetSkelQuery(skel)

startFrame = int(stage.GetStartTimeCode())
endFrame = int(stage.GetEndTimeCode())

restXforms = skel.GetRestTransformsAttr().Get()


for frame in range(startFrame,endFrame+1):
    jointLocalXforms = skelQuery.ComputeJointLocalTransforms(frame)
    restRelativeXforms = skelQuery.ComputeJointRestRelativeTransforms(frame)
   
    print(jointLocalXforms)


When I run that script I get the following output:

[( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) ), ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) ), ( (5.960464477539063e-8, 0.9999999403953552, 1.2246467202362698e-16, 0), (-0.9999999403953552, 5.960464477539063e-8, 1.2246467202362698e-16, 0), (1.2246467202362698e-16, -1.2246467202362698e-16, 1, 0), (0, 0, 0, 1) ), ( (5.960464477539063e-8, -0.9999999403953552, 1.2246467202362698e-16, 0), (0.9999999403953552, 5.960464477539063e-8, 1.2246467202362698e-16, 0), (-1.2246467202362698e-16, 1.2246467202362698e-16, 1, 0), (1, 0, 0, 1) )]
[( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) ), ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) ), ( (5.960464477539063e-8, 0.9999999403953552, 1.2246467202362698e-16, 0), (-0.9999999403953552, 5.960464477539063e-8, 1.2246467202362698e-16, 0), (1.2246467202362698e-16, -1.2246467202362698e-16, 1, 0), (0, 0, 0, 1) ), ( (5.960464477539063e-8, -0.9999999403953552, 1.2246467202362698e-16, 0), (0.9999999403953552, 5.960464477539063e-8, 1.2246467202362698e-16, 0), (-1.2246467202362698e-16, 1.2246467202362698e-16, 1, 0), (1, 0, 0, 1) )]

Thank you very much. I’ll try it first with python as you suggested. So it seems that I do not need the skelAnimQuery at all to get the skeleton animation data. Is that correct?