Modelers are handing me game meshes with multiple materials, which we need to break up for the engine.
so I wish script some solutions.
I want to list all materials used by meshes in the scene.
This is what I have, it seems to work, but Maya materials is a bit new for me
so I am posting for an stupidity check.
def list_scene_materials():
"""
list all materials used by geometry in the scene
"""
scene_materials=[]
all_sgs=pm.ls(type='shadingEngine')
for sg in all_sgs:
# if an sg has 'sets' members, it is used in the scene
if pm.sets(sg, q=True):
materials = pm.listConnections('{}.surfaceShader'.format(sg))
if materials:
scene_materials.extend(materials)
return list(set(scene_materials))
The mapping between shaderGroups, materials and meshes is a bit confusing.
I think it works like this:
when a mesh uses multiple materials
each material must plug into the surface shader input of a unique shader group
(I assume other inputs like Volume or Displacement won’t get used for animated game meshes)
each shader group then plugs into an ObjectGroups element of the shape node
(I assume ObjectGroups = faces in this case)
Does my code have any problems?
Are my assumptions flawed?