-
Notifications
You must be signed in to change notification settings - Fork 4
/
separatePolygonsByUVShells.py
59 lines (47 loc) · 1.57 KB
/
separatePolygonsByUVShells.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
51
52
53
54
55
56
57
58
59
from maya.api import OpenMaya
from maya import cmds
import time
class UVShell():
def __init__(self, shellIndex, dagPath):
self.uvIndices = []
self.shellIndex = shellIndex
self.dagPath = dagPath
self.fullPathList = []
def setPath(self):
for i in self.uvIndices:
path = self.dagPath + ".map[%s]" % i
self.fullPathList.append(path)
def selectTextureBorderEdges(obj):
sel = OpenMaya.MSelectionList()
sel.add(obj)
dagPath = sel.getDagPath(0)
fnMesh = OpenMaya.MFnMesh(dagPath)
nbUvShells, uvShellIds = fnMesh.getUvShellsIds()
uvShells = [UVShell(i, dagPath.fullPathName()) for i in range(nbUvShells)]
for n, i in enumerate(uvShellIds):
uvShells[i].uvIndices.append(n)
for i in uvShells:
i.setPath()
edges = []
for s in uvShells:
cmds.select(s.fullPathList[0], r=True)
cmds.ConvertSelectionToUVShellBorder()
cmds.ConvertSelectionToVertices()
cmds.ConvertSelectionToContainedEdges()
shellBorderEdges = cmds.ls(sl=True, fl=True, long=True)
edges.extend(shellBorderEdges)
cmds.select(d=True)
return list(set(edges))
def main():
sel = cmds.ls(sl=True, fl=True, long=True)
for i in sel:
edges = selectTextureBorderEdges(i)
cmds.select(edges, r=True)
cmds.DetachEdgeComponent(edges)
cmds.select(i, r=True)
cmds.SeparatePolygon()
cmds.select(sel, r=True)
if __name__ == "__main__":
t = time.time()
main()
print time.time() - t