-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate_mesh_normals_unlocked.py
39 lines (31 loc) · 1.31 KB
/
validate_mesh_normals_unlocked.py
1
2
3
4
5
6
7
8
9
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
import pyblish.api
from maya import cmds
class ValidateMeshNormalsUnlocked(pyblish.api.Validator):
""" Validate meshes in the instance have unlocked normals """
families = ['model']
hosts = ['maya']
category = 'geometry'
version = (0, 1, 0)
label = 'Mesh Normals Unlocked'
def has_locked_normals(self, mesh):
mesh_vertexface = cmds.polyListComponentConversion(mesh, toVertexFace=True)
locked_normals = cmds.polyNormalPerVertex(mesh_vertexface, q=1, freezeNormal=True)
if any(locked_normals):
return True
else:
return False
def process(self, instance):
""" Checks all nodes for locked normals, if any found it's considered invalid. """
meshes = cmds.ls(instance, type='mesh', long=True)
invalid = []
for mesh in meshes:
if self.has_locked_normals(mesh):
invalid.append(mesh)
if invalid:
raise ValueError("Meshes found with locked normals: {0}".format(invalid))
def repair(self, instance):
""" Unlocks all normals on the meshes in this instance. """
meshes = cmds.ls(instance, type='mesh', long=True)
for mesh in meshes:
if self.has_locked_normals(mesh):
cmds.polyNormalPerVertex(mesh, unFreezeNormal=True)