forked from SindreOpsahl/edgeLord.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edgeLord.py
52 lines (40 loc) · 1.62 KB
/
edgeLord.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
import maya.cmds as cmds
#import edgeLord
#edgeLord.run()
def run():
#get selected edgeloop
edgeLoop = cmds.ls(selection=True)
#get verticles in the edge loop
vertLoop = cmds.polyListComponentConversion(edgeLoop, fromEdge=True, toVertex=True)
#sort individual verticles into a list
vertLoop = cmds.ls(vertLoop, flatten=True)
#open undo chunk so entire operation is a single action
cmds.undoInfo(openChunk = True)
#soften the mesh normals
mesh = cmds.listRelatives(parent=1)
cmds.polySoftEdge(mesh, angle=180)
#run on each vertex on the edgeloop
for vert in vertLoop:
#unlock the normal of the vertex
cmds.polyNormalPerVertex(vert, unFreezeNormal=True)
#get the normals of the vertex on the loop
vertNormals = list(cmds.polyNormalPerVertex(vert, query=True, xyz=True))
#get only the first three vectors
vertNormals = vertNormals[:3]
# select the neighboring verticles using the declared function below
vertNeighbors(vert, vertLoop)
#set their normal angle to match the vertex on the loop
cmds.polyNormalPerVertex(xyz=vertNormals)
#reselect the edge loops
cmds.select(edgeLoop)
#close undo chunk, operation is done
cmds.undoInfo(closeChunk = True)
# function to select a vertex's perpendicular neighbors
def vertNeighbors(vert, vertLoop):
#find the verticles connected to this vertex by edges
connectedEdges = cmds.polyListComponentConversion(vert, toEdge=True)
connectedVerts = cmds.polyListComponentConversion(connectedEdges, toVertex = True)
#select the connected verticles, then deselect the verticles on the loop
cmds.select(connectedVerts, replace = True)
cmds.select(vertLoop, deselect = True)
run()