Materials and Shaders#

What Is a Material?#

How Does It Work?#

Working With Python#

Examples#

Tip

You can run these examples locally as Jupyter notebooks. See How to Run Notebooks Locally for setup instructions.

Example 1: UsdShade and Material#

UsdShade is a schema for creating and binding materials.

Material provides a container to store data for defining a “shading material” to a renderer.

UsdShade and Materials will be covered in later topics and are only covered here to show another use case for schema-specific APIs.

NOTE: The material is not applied to the cube so it will not show up in the scene visually, but it is displayed in the hierarchy.

 1from pxr import Usd, UsdGeom, UsdShade
 2
 3stage: Usd.Stage = create_new_stage("_assets/materials.usda")
 4
 5world: UsdGeom.Xform = UsdGeom.Xform.Define(stage, "/World")
 6stage.SetDefaultPrim(world.GetPrim())
 7
 8box: UsdGeom.Xform = UsdGeom.Xform.Define(stage, world.GetPath().AppendPath("Box"))
 9geo_scope: UsdGeom.Scope = UsdGeom.Scope.Define(stage, box.GetPath().AppendPath("Geometry"))
10box_geo: UsdGeom.Cube = UsdGeom.Cube.Define(stage, geo_scope.GetPath().AppendPath("Cube"))
11
12# ADD CODE BELOW HERE
13# vvvvvvvvvvvvvvvvvvv
14
15# Define a new Scope primitive at the path "/World/Box/Materials" on the current stage:
16mat_scope: UsdGeom.Scope = UsdGeom.Scope.Define(stage, box.GetPath().AppendPath("Materials"))
17
18# Define a new Material primitive at the path "/World/Box/Materials/BoxMat" on the current stage:
19box_mat: UsdShade.Material = UsdShade.Material.Define(stage, mat_scope.GetPath().AppendPath("BoxMat"))
20
21# ^^^^^^^^^^^^^^^^^^^^
22# ADD CODE ABOVE HERE
23
24
25stage.Save()
26DisplayUSD("_assets/materials.usda", show_usd_code=True)
Loading your model...
_assets/materials.usda
        
    

Key Takeaways#