Xform#
In Universal Scene Description, Xforms play a key role in defining the spatial transformations of objects in a scene.
What is an Xform?#
In OpenUSD, an Xform is a type of prim that stores transformation data, such as translation, rotation, and scaling, which apply to its child prims. This makes Xforms a powerful tool for grouping and manipulating the spatial arrangement of objects in a 3D scene. Xform stands for ‘transform’, reflecting its role in transforming the space in which its children reside.
How Does It Work?#
Xform prims allow for hierarchical transformations, meaning that transformations applied to a parent Xform affect all of its child prims. This is essential in complex scenes where multiple objects need to move or scale relative to the parent. Typical use cases include animating characters or robotic arms, where different parts are children of an Xform prim, or arranging furniture in architectural visualization, where all items in a room might be scaled or rotated together.
Working With Python#
Working with Xform in USD via Python involves several functions:
1# Used to define a new Xform prim at a specified path on a given stage
2UsdGeom.Xform.Define(stage, path)
3
4# Retrieves the order of transformation operations, which is crucial for understanding how multiple transformations are combined. Different orders can yield different results, so understanding XformOpOrder is important.
5xform.GetXformOpOrderAttr()
6
7# Adds a new transform operation to the Xform prim, such as translation or rotation, with specified value
8xform.AddXformOp(opType, value)
Examples#
Example 1: UsdGeom and Xform#
UsdGeom
defines the 3D graphics-related prim and property schemas that together form a basis for interchanging geometry between Digital Content Creation (DCC) tools in a graphics pipeline.
Some things to know about UsdGeom
:
All classes in
UsdGeom
inherit fromUsdGeomImageable
, whose intent is to capture any prim type that might want to be rendered or visualized.All geometry prims are directly transformable.
UsdGeomXformable
encapsulates the schema for a prim that is transformable.
UsdGeomXform
is a concrete prim schema for a transform, which is transformable and can transform other child prims as a group.
1# Import the necessary modules from the pxr package:
2from pxr import Usd, UsdGeom
3
4# Create a new USD stage with root layer named "xform_prim.usda":
5file_path = "_assets/xform_prim.usda"
6stage: Usd.Stage = Usd.Stage.CreateNew(file_path)
7
8# Define a new Xform primitive at the path "/World" on the current stage:
9world: UsdGeom.Xform = UsdGeom.Xform.Define(stage, "/World")
10
11# Save changes to the current stage to its root layer:
12stage.Save()
13print(stage.ExportToString(addSourceFileComment=False))
#usda 1.0
def Xform "World"
{
}
Key Takeaways#
Now, we’ve explored what Xform prims are and how they function within the USD framework. We’ve seen how Xform prims are essential for defining and managing spatial transformations in a scene, making them indispensable for any 3D content creation workflow.