HdContainerDataSourceEditor example

Hi
I’m looking for a way to edit the material binding on a datasource. Can someone help with some pointers on how to do this?
Thanks

I was hoping if you could give me some pointers on how material datasources can be edited using HdContainerDataSourceEditor? I haven’t to able to find any examples/tests so far.
Basically I’m trying two things:

  1. Editing a mesh data source to assign a new material (HdMaterialBindingSchema)
  2. Editing a terminal value of a material in a datasource.

Hi Ashwin,

You can find some examples of the container data source editor here: OpenUSD/pxr/imaging/hd/testenv/testHdContainerDataSourceUtils.cpp at release · PixarAnimationStudios/OpenUSD · GitHub

If you want to override the material binding of a prim to “/Foo”, you could do:

HdSceneIndexPrim prim = sceneIndex.GetPrim("/Bar");
HdContainerDataSourceEditor edit(prim.dataSource);
edit.Set(HdMaterialBindingsSchema::GetDefaultLocator(),
  HdMaterialBindingsSchema::BuildRetained(1, {HdMaterialBindingsSchemaTokens->allPurpose},
    HdMaterialBindingSchema::BuildRetained(HdCreateTypedRetainedDataSource(SdfPath("/Foo")), nullptr)));
prim.dataSource = edit.Finish();

If you’re trying to modify a material network in particular, we have a specialization of the container data source editor for editing material networks:

Hope that helps!
Tom