Material Assignments, Methods, Collection-Based Binding
- Collection-Based Binding:
- Collection-based binding allows you to assign a material to a collection of prims, which is useful for managing material assignments across multiple prims efficiently.
- This method uses UsdCollectionAPI to define collections of prims and then binds materials to these collections.
- Example:
from pxr import Usd, UsdShade, UsdCollection
stage = Usd.Stage.Open("path/to/your.usda")
collection = UsdCollection.CollectionAPI.Apply(stage.GetPrimAtPath("/path/to/collection"))
collection.CreateIncludesRel().AddTarget("/path/to/prim1")
collection.CreateIncludesRel().AddTarget("/path/to/prim2")
material = UsdShade.Material.Define(stage, "/path/to/material")
UsdShade.MaterialBindingAPI(stage.GetPrimAtPath("/path/to/collection")).Bind(collection, material)
```