def apply_shaders(relationships, namespace=None):
"""Given a dictionary of `relationships`, apply shaders to meshes
Arguments:
relationships (avalon-core:shaders-1.0): A dictionary of
shaders and how they relate to meshes.
"""
if namespace is not None:
# Append namespace to shader group identifier.
# E.g. `blinn1SG` -> `Bruce_:blinn1SG`
relationships = {
"%s:%s" % (namespace, shader): relationships[shader]
for shader in relationships
}
for shader, ids in relationships.items():
print("Looking for '%s'.." % shader)
shader = next(iter(cmds.ls(shader)), None)
assert shader, "Associated shader not part of asset, this is a bug"
for id_ in ids:
mesh, faces = (id_.rsplit(".", 1) + [""])[:2]
# Find all meshes matching this particular ID
# Convert IDs to mesh + id, e.g. "nameOfNode.f[1:100]"
meshes = list(".".join([mesh, faces])
for mesh in lsattr("mbID", value=mesh))
if not meshes:
continue
print("Assigning '%s' to '%s'" % (shader, ", ".join(meshes)))
cmds.sets(meshes, forceElement=shader)
评论列表
文章目录