How to create material/look variants for a model? #3197
-
How to create material/look USD variants for a model or simply export material(binds) without model data in USD? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @frankchen211, As of the most recent version of the plugin (0.23.0) you can only export materials when they are attached to a mesh. In Maya 2024 using LookDevX you can author materials and bind them in a new layer so there is no export needed. If you dont have Maya 2024 and want to run a process to to remove mesh properties other than their material binding and maybe the display color you would have to do something like this. # Pixar
from pxr import Usd, UsdGeom, Sdf
# Choose the layer you want to remove the model data from and open it in a stage.
layer_to_edit = "/PATH/TO/LAYER"
stage = Usd.Stage.Open(layer_to_edit)
stage_layer = stage.GetRootLayer()
# Traverse the stage and remove and properties that are not related to the Materials and Shaders
for prim in stage.TraverseAll():
# Ignore Arnold options Prim, I'm assuming you are using Arnold
if prim.GetTypeName() == 'ArnoldOptions':
continue
if prim.GetTypeName() not in ['Material', 'Shader']:
for prim_property in prim.GetAuthoredProperties():
if prim_property.GetName() not in ['material:binding', 'primvars:displayColor']:
if prim.GetTypeName() == 'GeomSubset':
pass
else:
prim.RemoveProperty(prim_property.GetName())
stage_layer.Save() This should create a layer with only the Material and their mesh bindings (you might need to tinker with this to get the results you specifically want) As for making a variant you can create a variant set and add variants to it on any prim, once you do if you want any opinions to be authored under that variant you need to do it under its context Here is an example: # Choose the layer you want to add the variant to
layer_to_edit = "/PATH/TO/LAYER"
stage = Usd.Stage.Open(layer_to_edit)
# Im assuming default prim but could be any
default_prim = stage.GetDefaultPrim()
stage_layer = stage.GetRootLayer()
# Get the Variant sets and add/set a variant
variant_sets = default_prim.GetVariantSets().AddVariantSet('MTL')
variant_sets.AddVariant("default_mtl")
variant_sets.SetVariantSelection("default_mtl")
# Add a reference to the variant
with variant_sets.GetVariantEditContext():
default_prim.GetReferences().AddReference("/PATH/TO/LAYER")
# Save the stage with the new variant
stage_layer.Save() Hope this can help. Cheers, Jason Coelho |
Beta Was this translation helpful? Give feedback.
Hi @frankchen211,
As of the most recent version of the plugin (0.23.0) you can only export materials when they are attached to a mesh. In Maya 2024 using LookDevX you can author materials and bind them in a new layer so there is no export needed.
If you dont have Maya 2024 and want to run a process to to remove mesh properties other than their material binding and maybe the display color you would have to do something like this.