-
Notifications
You must be signed in to change notification settings - Fork 4
/
findConcaveUV.py
50 lines (36 loc) · 1.21 KB
/
findConcaveUV.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
40
41
42
43
44
45
46
47
48
49
50
from maya.api import OpenMaya
from maya import cmds
def getTriangleArea(Ax, Ay, Bx, By, Cx, Cy):
return (Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By)) / 2
def main():
sel = OpenMaya.MGlobal.getActiveSelectionList()
dagPath = sel.getDagPath(0)
itPoly = OpenMaya.MItMeshPolygon(dagPath)
badUVs = []
while not itPoly.isDone():
_, ids = itPoly.getTriangles()
numVerts = itPoly.polygonVertexCount()
for i in range(numVerts):
p1 = i
p2 = i + 1
if p2 > numVerts-1:
p2 -= numVerts
p3 = i + 2
if p3 > numVerts-1:
p3 -= numVerts
uv = [p1, p2, p3]
b = [itPoly.getUV(i) for i in uv]
area = getTriangleArea(
b[0][0],
b[0][1],
b[1][0],
b[1][1],
b[2][0],
b[2][1])
if area <= 0.00000000001:
badUVs.append(itPoly.index())
itPoly.next()
badFaces = [dagPath.fullPathName() + ".f[{}]".format(i) for i in badUVs]
cmds.select(badFaces, r=True)
if __name__ == "__main__":
main()