Hello World Redux - Using Generic Prims

In this tutorial, we revisit the Hello World! example, but this example passes in hard-coded typenames Xform and Sphere, which correspond to the typenames appearing after the def specifiers in the usda scene description representation.

The UsdGeom API used in the previous tutorial, is part of USD’s built-in geometry schema. These prim types and associated C++ and Python API have first-class support in USD and provide domain-specific interfaces to create, manipulate, introspect and author properties upon them.

Note that UsdGeomXform::Define returns a schema object on which the full schema-specific API is available, as opposed to UsdStage::DefinePrim which returns a generic UsdPrim. In USD, all schema classes have a GetPrim() member function that returns its underlying UsdPrim. Think of a UsdPrim as the object’s generic, persistent presence in the scenegraph, and the schema object as the first-class way to access its domain-specific data and functionality.

from pxr import Usd
stage = Usd.Stage.CreateNew('HelloWorldRedux.usda')
xform = stage.DefinePrim('/hello', 'Xform')
sphere = stage.DefinePrim('/hello/world', 'Sphere')
stage.GetRootLayer().Save()

The code above produces identical scene description to the previous tutorial, which you can see using usdcat:

#usda 1.0

def Xform "hello"
{
    def Sphere "world"
    {
    }
}

In the next tutorial, we’ll look at UsdGeom API in action on prim properties.