Bases: MayaInstancePlugin
, OptionalPyblishPluginMixin
Validate all meshes in the instance have unlocked normals
These can be unlocked manually through
Modeling > Mesh Display > Unlock Normals
Source code in client/ayon_maya/plugins/publish/validate_mesh_normals_unlocked.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 | class ValidateMeshNormalsUnlocked(plugin.MayaInstancePlugin,
OptionalPyblishPluginMixin):
"""Validate all meshes in the instance have unlocked normals
These can be unlocked manually through:
Modeling > Mesh Display > Unlock Normals
"""
order = ValidateMeshOrder
families = ['model']
label = 'Mesh Normals Unlocked'
actions = [ayon_maya.api.action.SelectInvalidAction,
RepairAction]
optional = True
@staticmethod
def has_locked_normals(mesh):
"""Return whether mesh has at least one locked normal"""
sel = om2.MGlobal.getSelectionListByName(mesh)
node = sel.getDependNode(0)
fn_mesh = om2.MFnMesh(node)
_, normal_ids = fn_mesh.getNormalIds()
for normal_id in normal_ids:
if fn_mesh.isNormalLocked(normal_id):
return True
return False
@classmethod
def get_invalid(cls, instance):
"""Return the meshes with locked normals in instance"""
meshes = cmds.ls(instance, type='mesh', long=True)
return [mesh for mesh in meshes if cls.has_locked_normals(mesh)]
def process(self, instance):
"""Raise invalid when any of the meshes have locked normals"""
if not self.is_active(instance.data):
return
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError(
"Meshes found with locked normals:\n\n{0}".format(
_as_report_list(sorted(invalid))
),
title="Locked normals"
)
@classmethod
def repair(cls, instance):
"""Unlocks all normals on the meshes in this instance."""
invalid = cls.get_invalid(instance)
for mesh in invalid:
cmds.polyNormalPerVertex(mesh, unFreezeNormal=True)
|
get_invalid(instance)
classmethod
Return the meshes with locked normals in instance
Source code in client/ayon_maya/plugins/publish/validate_mesh_normals_unlocked.py
| @classmethod
def get_invalid(cls, instance):
"""Return the meshes with locked normals in instance"""
meshes = cmds.ls(instance, type='mesh', long=True)
return [mesh for mesh in meshes if cls.has_locked_normals(mesh)]
|
has_locked_normals(mesh)
staticmethod
Return whether mesh has at least one locked normal
Source code in client/ayon_maya/plugins/publish/validate_mesh_normals_unlocked.py
36
37
38
39
40
41
42
43
44
45
46
47 | @staticmethod
def has_locked_normals(mesh):
"""Return whether mesh has at least one locked normal"""
sel = om2.MGlobal.getSelectionListByName(mesh)
node = sel.getDependNode(0)
fn_mesh = om2.MFnMesh(node)
_, normal_ids = fn_mesh.getNormalIds()
for normal_id in normal_ids:
if fn_mesh.isNormalLocked(normal_id):
return True
return False
|
process(instance)
Raise invalid when any of the meshes have locked normals
Source code in client/ayon_maya/plugins/publish/validate_mesh_normals_unlocked.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69 | def process(self, instance):
"""Raise invalid when any of the meshes have locked normals"""
if not self.is_active(instance.data):
return
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError(
"Meshes found with locked normals:\n\n{0}".format(
_as_report_list(sorted(invalid))
),
title="Locked normals"
)
|
repair(instance)
classmethod
Unlocks all normals on the meshes in this instance.
Source code in client/ayon_maya/plugins/publish/validate_mesh_normals_unlocked.py
| @classmethod
def repair(cls, instance):
"""Unlocks all normals on the meshes in this instance."""
invalid = cls.get_invalid(instance)
for mesh in invalid:
cmds.polyNormalPerVertex(mesh, unFreezeNormal=True)
|