Bases: MayaInstancePlugin
Validate all nurbsSurfaces and meshes have exactly one shader assigned.
This will error if a shape has no shaders or more than one shader.
Source code in client/ayon_maya/plugins/publish/validate_look_single_shader.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 | class ValidateSingleShader(plugin.MayaInstancePlugin):
"""Validate all nurbsSurfaces and meshes have exactly one shader assigned.
This will error if a shape has no shaders or more than one shader.
"""
order = ValidateContentsOrder
families = ['look']
label = 'Look Single Shader Per Shape'
actions = [ayon_maya.api.action.SelectInvalidAction]
# The default connections to check
def process(self, instance):
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError(
("Found shapes which don't have a single shader "
"assigned:\n{}").format(invalid))
@classmethod
def get_invalid(cls, instance):
# Get all shapes from the instance
shapes = cmds.ls(instance, type=["nurbsSurface", "mesh"], long=True)
# Check the number of connected shadingEngines per shape
no_shaders = []
more_than_one_shaders = []
for shape in shapes:
shading_engines = cmds.listConnections(shape,
destination=True,
type="shadingEngine") or []
# Only interested in unique shading engines.
shading_engines = list(set(shading_engines))
if not shading_engines:
no_shaders.append(shape)
elif len(shading_engines) > 1:
more_than_one_shaders.append(shape)
if no_shaders:
cls.log.error("No shaders found on: {}".format(no_shaders))
if more_than_one_shaders:
cls.log.error("More than one shader found on: "
"{}".format(more_than_one_shaders))
return no_shaders + more_than_one_shaders
|