Animation Graph

Note

Common import:

from pxr import Sdf, Usd
from pxr import AnimGraphSchema, AnimGraphSchemaTools
import omni.anim.graph.core as ag
import carb

Add animation graph

anim_graph = AnimGraphSchemaTools.createAnimationGraph(stage, Sdf.Path("/World/AnimationGraph"))

# or
omni.kit.commands.execute("CreateAnimationGraphCommand", path=Sdf.Path("/World/AnimationGraph"), skeleton_path=Sdf.Path.emptyPath)

Note

we may set/clear original skeletal animation at root joint by

skeleton_prim = stage.GetPrimAtPath("/World/character/f_avg_root")
skeleton_bindingAPI = UsdSkel.BindingAPI(skeleton_prim)

# set
skeleton_bindingAPI.GetAnimationSourceRel().SetTargets(["/World/character/f_avg_root/Animation"])

# clear
skeleton_bindingAPI.GetAnimationSourceRel().SetTargets([])

Set Skeleton

rel = anim_graph.GetSkelSkeletonRel()
rel.SetTargets([_skeleton_path])

# or
omni.kit.commands.execute("CreateAnimationGraphCommand", path=Sdf.Path("/World/AnimationGraph"), skeleton_path=_skeleton_path)

Apply animation graph api

AnimGraphSchemaTools.applyAnimationGraphAPI(stage, path, self._animation_graph_path)

# or
omni.kit.commands.execute("ApplyAnimationGraphAPICommand", paths=self._apply_prim_paths, animation_graph_path=selected_prim.GetPath())

Remove animation graph api

if stage.GetPrimAtPath(path).HasAPI(AnimGraphSchema.AnimationGraphAPI):
    AnimGraphSchemaTools.removeAnimationGraphAPI(stage, path)

# or
omni.kit.commands.execute("RemoveAnimationGraphAPICommand", paths=selected_paths)

Create Animation Clip

omni.kit.commands.execute(
            'CreatePrimCommand',
            prim_type="AnimationClip",
            prim_path="/World/AnimationGraph/Animation",
            select_new_prim=True,
        )

Get character

character = ag.get_character("/World/character")

Get character position (run time)

t = carb.Float3(0, 0, 0)
q = carb.Float4(0, 0, 0, 1)
character.get_world_transform(t, q)

Get joint position (run time)

t = carb.Float3(0, 0, 0)
q = carb.Float4(0, 0, 0, 1)
character.get_joint_transform("f_avg_L_Foot", t, q)