Hello all,
I am splitting a scene into several parts and while doing so have an intermediate stage with the geometry, but not the materials. I would like to create new materials in this stage with the same name as the originals.
However, on this new stage,
for prim in new_model_stage.Traverse():
print(prim)
binding = prim.GetRelationship("material:binding")
if binding:
material_paths = binding.GetTargets()
will print an error about the invalid binding and then the paths are empty. Is there a way to get the value of the targets even though these dont exist at the moment ?
Thanks,
Koen
Hmmm… might need to see an example.. but I can say that currently, if the stages are connected via sublayering, you should be able to query the targets even if the prims don’t exist, but if the bindings are expressed in a referenced layer and point to a prim outside the referenced root prim, then there is no way to get the targets, because they don’t map/translae into the referencing stage’s namespace.
The code I am writing is to split a large usd into several smaller ones. In this case, a level exported as a single usd from blender is split into a bunch of models and some other files.
I could look up the information I need in the original stage, but thought it was pretty elegant to just use the new stage ( there several orders of magnitude less prims on the split of stage). I just need the name of the material for now, this ended up working:
def fix_material_bindings(new_model_stage) -> None:
"""Move the materials to under the prim representing the model, or they will be lost."""
for prim in new_model_stage.Traverse():
binding = prim.GetRelationship("material:binding")
# the target is no longer valid on this stage, so we need to get the name from
# the raw spec data
if binding:
material_name = "shaderball"
for spec in binding.GetPropertyStack():
for target in spec.targetPathList.explicitItems:
material_name = target.name
break
binding.SetTargets([stub_material(new_model_stage, material_name)])
return