Seeking a faster method to apply materials to specific prims in a large scene, as current approaches are too slow

Hello everyone!

My team and I want to implement a new extension for our omniverse kit app. We have a very very large scene with millions of prims. At a certain point we receive information from an external source. Based on this information, we want to quickly apply some materials or highlights to the prims that match the information and grey out all other prims. So basically, we need to traverse the stage for every prim and apply to all prims or meshes the desired material. I’ve managed to get something working with commands.execute, but the performance is pretty poor for the big stage (takes several minutes to apply).

def bind_material_batch(self, prims: List[Usd.Prim], mat: Material):
    omni.kit.commands.execute('BindMaterialCommand',
                                prim_path=[prim.GetPath() for prim in prims],
                                material_path=mat.GetPath() if mat.GetPath() != Sdf.Path.emptyPath else "",
                                strength=UsdShade.Tokens.weakerThanDescendants)

For a single prim, I found another solution using the MaterialBindingAPI, but I can’t find a way to use this API for a collection of prims:

prim.ApplyAPI(UsdShade.MaterialBindingAPI)
UsdShade.MaterialBindingAPI(prim).Bind(mat, UsdShade.Tokens.weakerThanDescendants, UsdShade.Tokens.allPurpose)

Do you know of any other ways to archive something like a super performant highlighting / material switching of prims in a very large scene?

Here is an example file and an example script of changing the materials two different ways.
cubes_with_materials.usd (228.8 KB)
change_materials.py (1.3 KB)

The second one is using the usdrt API to change the material and it seems to be measurably faster, even with 10000 prims only. Also attached a script to generate the file
generate_test.py (4.3 KB)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.