Tested with USD 24.11
Hello World - Creating Your First USD Stage
This tutorial walks through creating a simple USD stage containing a transform and a sphere.
Python for USD
Open USD/extras/usd/tutorials/helloWorld/helloWorld.py to see the Python script that creates and exports the stage. It should look like the following.
from pxr import Usd, UsdGeom stage = Usd.Stage.CreateNew('HelloWorld.usda') xformPrim = UsdGeom.Xform.Define(stage, '/hello') spherePrim = UsdGeom.Sphere.Define(stage, '/hello/world') stage.GetRootLayer().Save()
Execute the Python script to create HelloWorld.usda.
$ python extras/usd/tutorials/helloWorld/helloWorld.py
Visualizing the stage
Use usdview to visualize and inspect the stage.
Open the stage in usdview:
$ usdview HelloWorld.usda
You can refine the geometry with the
menu item or use the hotkeys Ctrl-+ and Ctrl-- to increase or decrease the refinement.You can also bring up an embedded Python interpreter by pressing i or using the usdviewApi, that contains some useful variables. One is usdviewApi.prim, which refers to the first prim, hierarchically, in the set of currently selected prims.
menu item. This interpreter has a built-in API object,Select the sphere either by clicking it in the viewport or by clicking its name, world, in the tree view on the left. Then try the following commands:
>>> usdviewApi.prim Usd.Prim(</hello/world>) >>> usdviewApi.prim.GetTypeName() 'Sphere' >>> usdviewApi.prim.GetAttribute('radius').Get() 1.0
Viewing and editing USD file contents
The exported file is human-readable via usdcat and text-editable
via usdedit (both available in USD_INSTALL_ROOT/bin
in the default installation). The usdedit program will bring up
any .usd file as plain text in your EDITOR
regardless of its
underlying format, and save it back out in its original format when editing is
complete. See usdedit for more details.
This particular example can be edited in a text editor directly since we created a text-based USD file with the .usda extension. If we had created a binary usd file with the .usdc extension instead, both usdcat and usdedit would work just the same on it.
#usda 1.0
def Xform "hello"
{
def Sphere "world"
{
}
}