Hello World Redux - Using Generic Prims

Hello World Redux - Using Generic Prims


Setup Python

Ensure that you have configured your python environment, this is described in the USD Tutorials document.

In this tutorial, we revisit our Hello World! example, but this example passes in hard-coded typenames 'Xform' and 'Sphere', which correspond to the typenames appearing after the 'defs' in the ASCII representation of the scene description. 

The UsdGeom schemata used in the previous example are the prim types that will always be supported in USD, and provide first-class API (with all the syntactic benefits to developer workflows, such as tab-completion) to introspect and author properties upon them.

Note that Define() will return a schema object on which the full schema-specific API is available, as opposed to DefinePrim() which returns a generic UsdPrim (which is accessible via GetPrim() on the schema object). Think of a UsdPrim as the object's generic, persistent presence in the scenegraph, and the schema as the first-class way of getting at its type-specific data.

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

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.

Graphics Home