Hello World - Creating Your First USD Stage

Hello World - Creating Your First USD Stage


Setup Python

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

This tutorial will walk you through creating a simple USD stage, containing a transform and a sphere.

Python for USD

  1. Open USD/extras/usd/tutorials/helloWorld/helloWorld.py to see the Python snippet to create and export the stage. It should look like the snippet below.

    from pxr import Usd, UsdGeom
    stage = Usd.Stage.CreateNew('HelloWorld.usda')
    xformPrim = UsdGeom.Xform.Define(stage, '/hello')
    spherePrim = UsdGeom.Sphere.Define(stage, '/hello/world')
  2. Execute the Python script to create a .usda file.

    $ python extras/usd/tutorials/helloWorld/helloWorld.py

Visualizing the stage

usdview can be used to visualize/introspect the stage

  1.  Try opening the stage in usdview: 

    $ usdview HelloWorld.usda

  2. You can refine the geometry via the View --> Complexity menu or with the hotkeys CTRL+ and CTRL- to bring the complexity respectively up and down.

  3. In usdview, you can also bring up an embedded interpreter by hitting i or using the Window --> Interpreter menu item. This interpeter has a few useful preset variables. One such variable is prim, which represents the first prim, hierarchically, in the set of currently selected prims.
    Select the sphere by either clicking on it in the viewport or selecting the "world" prim in the view on the left, then try out the following commands:

    >>> usdviewApi.prim
    >>> usdviewApi.prim.GetTypeName()
    >>> usdviewApi.prim.GetAttribute('radius').Get()


Viewing and editing the contents of the *.usda file

The exported file is human-readable via usdcat and ASCII-editable via usdedit (both available in USD_INSTALL_ROOT/bin in the default installation), which will bring up any .usd layer, regardless of its encoding, as plain text in your $EDITOR (follow the usdedit link for more details), and save it back out in its original format. (This particular example can be edited by invoking a text editor directly, since we created an ASCII-based USD file by calling CreateInMemory().)

#usda 1.0

def Xform "hello"
    def Sphere "world"

Further Reading

  • UsdStage is the outermost container for scene description, which owns and presents composed prims as a scenegraph
  • UsdPrim is the sole persistent scenegraph object on a UsdStage

Graphics Home