Skip to content

Commit 61644b3

Browse files
authored
BLEN-214: Material doesn't update on import from MatX library if render enabled. (#265)
PURPOSE Material doesn't update on import from MatX library if render enabled. EFFECT OF CHANGE Material updates properly when import from MaterialX Library during viewport render.
1 parent b84a839 commit 61644b3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/hdusd/export/material.py

+13
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,20 @@ def sync_update_all(root_prim, mat: bpy.types.Material):
9292
mx_file = utils.get_temp_file(".mtlx", f'{mat.name}{mat.hdusd.mx_node_tree.name if mat.hdusd.mx_node_tree else ""}',
9393
is_rand=True)
9494
mx.writeToXmlFile(doc, str(mx_file))
95+
surfacematerial = next(node for node in doc.getNodes() if node.getCategory() == 'surfacematerial')
9596

9697
for mat_prim in mat_prims:
9798
mat_prim.GetReferences().ClearReferences()
9899
mat_prim.GetReferences().AddReference(f"./{mx_file.name}", "/MaterialX")
100+
101+
# apply new bind if shader switched to MaterialX or vice versa
102+
mesh_prim = next((prim for prim in mat_prim.GetParent().GetChildren() if prim.GetTypeName() == 'Mesh'), None)
103+
if not mesh_prim:
104+
return None
105+
106+
usd_mat = UsdShade.Material.Define(root_prim.GetStage(), mat_prim.GetPath().AppendChild('Materials').
107+
AppendChild(surfacematerial.getName()))
108+
109+
bindings = UsdShade.MaterialBindingAPI(mesh_prim)
110+
bindings.UnbindAllBindings()
111+
bindings.Bind(usd_mat)

0 commit comments

Comments
 (0)