Understanding Usd and Sdf structures: Worked Example — Data Modeling (NVIDIA-Certified Professional: OpenUSD Development)
{ "title": "NVIDIA-Certified Professional: OpenUSD Development - Understanding Usd and Sdf Structures: Worked Example", "category": "NVIDIA-Certified...
Understanding Usd and Sdf Structures: A Worked Example
In the NVIDIA-Certified Professional: OpenUSD Development exam, a solid grasp of Usd and Sdf structures is essential. These form the foundation for representing and manipulating 3D scene data efficiently. This worked example will guide you through the process of creating and understanding a simple Usd stage, focusing on prims, properties, and the underlying Sdf layer structure.
Scenario
Suppose you are tasked with creating a Usd stage representing a simple 3D scene containing a cube prim with a color property. You need to understand how Usd and Sdf structures represent this data and how to access and modify it.
Step 1: Creating the Usd Stage
First, create an in-memory Usd stage where the scene will be built.
- Use Usd.Stage.CreateNew(\"example.usda\") to create a new stage.
- This stage internally manages an SdfLayer which stores the scene description in the USDA ASCII format.
Step 2: Defining a Prim
Next, define a prim named /Cube of type Mesh.
- Call stage.DefinePrim(\"/Cube\", \"Mesh\").
- This creates a UsdPrim object representing a 3D mesh.
- Underneath, this adds a prim specification to the SdfLayer at path /Cube with type Mesh.
Step 3: Adding Properties and Primvars
Usd properties include attributes and relationships. Here, add a color attribute as a primvar.
- Create a primvar named displayColor using UsdGeom.PrimvarsAPI(prim).CreatePrimvar(\"displayColor\", Sdf.ValueTypeNames.Color3f, UsdGeom.Tokens.uniform).
- Set its value to a color, e.g., red: primvar.Set(Gf.Vec3f(1.0, 0.0, 0.0)).
- This adds a property specification in the SdfLayer under /Cube.displayColor with the value.
Step 4: Understanding Value Types and TimeSamples
The value type of the attribute is Color3f, indicating a 3-component float vector. Usd supports timeSamples to store animated values.
- For static values, the attribute has a single value at default time.
- For animation, multiple timeSamples can be set, e.g., primvar.Set(value, time=1.0), primvar.Set(value, time=2.0).
Step 5: Using Built-in Schemas
The Mesh prim type is a built-in Usd schema that defines standard properties like points, normals, and faceVertexIndices. Using these schemas ensures interoperability and consistency.
Step 6: Inspecting the Sdf Layer
Finally, inspect the underlying SdfLayer to see the serialized scene description.
- Call stage.GetRootLayer().Export(\"example.usda\") to save the ASCII representation.
- The file will show the prim definition and its properties in a human-readable format:
Summary
This example demonstrates how Usd and Sdf structures work together:
- Usd provides the API abstraction for scene graph manipulation.
- Sdf manages the low-level scene description data.
- Prims represent scene objects; properties and primvars store data.
- Value types and timeSamples enable static and animated data.
- Built-in schemas standardize prim definitions.
Mastering these concepts is crucial for effective 3D content pipeline development and optimization using OpenUSD, as tested in the NVIDIA-Certified Professional: OpenUSD Development exam.
" }More in this topic
Ready to test your knowledge?
Put what you've learned into practice with a quick quiz and track your progress.
Test your knowledge →