Usage Examples#
Apply Skel Binding API to Selected Prims#
from pxr import Sdf, UsdSkel, UsdGeom, Usd
from omni.kit.property.skel import ApplySkelBindingAPICommand
import omni.usd
# Make sure we have a valid stage or create one if needed
usd_context = omni.usd.get_context()
stage = usd_context.get_stage()
if not stage:
# Create a new stage if one doesn't exist
usd_context.new_stage()
stage = usd_context.get_stage()
# Now we can safely get the edit target layer
layer = stage.GetEditTarget().GetLayer()
# Create mesh prims for the example (needed for skeletal binding)
character_prim = UsdGeom.Mesh.Define(stage, "/World/Character")
arm_prim = UsdGeom.Mesh.Define(stage, "/World/Character/Arm")
# List of prim paths to apply the Skel Binding API
prim_paths = [Sdf.Path("/World/Character"), Sdf.Path("/World/Character/Arm")]
# Create and execute the command directly
cmd = ApplySkelBindingAPICommand(layer=layer, paths=prim_paths)
cmd.do() # Execute the command directly
# The command can be undone manually if needed
# cmd.undo()
Create Skeletal Animation Widgets#
import omni.ui as ui
from omni.kit.property.skel import (
MeshSkelBindingAttributesWidget,
SkelAnimationAttributesWidget,
SkelAnimationAnnotationPropertiesWidget
)
# Create a window with tabs to demonstrate different widget types
window = ui.Window("Skeletal Animation Widgets", width=500, height=600)
with window.frame:
with ui.VStack():
# Create a tab bar to switch between different widget types
with ui.HStack(height=30):
binding_button = ui.Button("Skeletal Binding", width=ui.Fraction(1/3))
animation_button = ui.Button("Animation Attributes", width=ui.Fraction(1/3))
annotation_button = ui.Button("Animation Annotation", width=ui.Fraction(1/3))
# Container for the widgets
container = ui.Frame()
# Create the widgets but keep them hidden initially
with container:
# Widget stack - only one will be visible at a time
with ui.VStack():
with ui.Frame(visible=True) as binding_frame:
# MeshSkelBindingAttributesWidget for skeletal binding properties
binding_widget = MeshSkelBindingAttributesWidget("Skeletal Binding")
ui.Label("This widget shows binding properties like:")
with ui.VStack(height=0, spacing=5):
ui.Label("• skel:skeleton", alignment=ui.Alignment.LEFT)
ui.Label("• skel:skinningMethod", alignment=ui.Alignment.LEFT)
ui.Label("• skel:blendShapeTargets", alignment=ui.Alignment.LEFT)
with ui.Frame(visible=False) as animation_frame:
# SkelAnimationAttributesWidget for animation properties
animation_widget = SkelAnimationAttributesWidget("Skeletal Animation")
ui.Label("This widget handles 'skel:animationSource' property")
ui.Label("on skeletal primitives (Skeleton and Root types)")
with ui.Frame(visible=False) as annotation_frame:
# SkelAnimationAnnotationPropertiesWidget for animation annotations
annotation_widget = SkelAnimationAnnotationPropertiesWidget(
"Animation Annotation",
full_tag_tracking=True
)
ui.Label("This widget maintains bidirectional mapping")
ui.Label("between tags and primitives")
# Set up the tab switching functionality
def show_binding(binding_button=binding_button):
binding_frame.visible = True
animation_frame.visible = False
annotation_frame.visible = False
def show_animation(animation_button=animation_button):
binding_frame.visible = False
animation_frame.visible = True
annotation_frame.visible = False
def show_annotation(annotation_button=annotation_button):
binding_frame.visible = False
animation_frame.visible = False
annotation_frame.visible = True
binding_button.set_clicked_fn(show_binding)
animation_button.set_clicked_fn(show_animation)
annotation_button.set_clicked_fn(show_annotation)
Screenshot:#
Register Widgets in the Property Window#
import omni.ui as ui
from omni.kit.property.skel import (
SkelAnimationAttributesWidget,
MeshSkelBindingAttributesWidget,
SkelAnimationAnnotationPropertiesWidget,
SkelAnimationAnnotationSchemeDelegate
)
import omni.kit.window.property as property_window
# Create the widgets
skel_animation_widget = SkelAnimationAttributesWidget("Skeletal Animation")
mesh_skel_binding_widget = MeshSkelBindingAttributesWidget("Skeletal Binding")
skel_animation_annotation_widget = SkelAnimationAnnotationPropertiesWidget("Animation Annotation")
# Create the scheme delegate that determines when to show animation annotation widgets
skel_animation_annotation_scheme = SkelAnimationAnnotationSchemeDelegate()
# Register the widgets with the property window
window = property_window.get_window()
if window:
# Register widgets for different property categories
window.register_widget("prim", "skel_animation", skel_animation_widget)
window.register_widget("prim", "mesh_skel_binding", mesh_skel_binding_widget)
window.register_widget("prim", "skel_animation_annotation", skel_animation_annotation_widget)
# Register the scheme delegate to control when animation annotation widgets appear
window.register_scheme_delegate("prim", "skel_animation_annotation_scheme", skel_animation_annotation_scheme)