Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
Created October 3, 2015 12:11
Show Gist options
  • Save SEVEZ/ba115696df6c130beefc to your computer and use it in GitHub Desktop.
Save SEVEZ/ba115696df6c130beefc to your computer and use it in GitHub Desktop.
Normals from selected polygons
import maya.cmds as cmds
faces = cmds.filterExpand(sm=34, ex=True)
verts = cmds.ls((cmds.polyListComponentConversion(faces, ff=True, tv=True)), flatten=True)
normals = [[], [], []]
for v in verts:
conFaces = cmds.ls(cmds.polyListComponentConversion(v, fv=True, tf=True), flatten=True)
shaFaces = list(set(conFaces).intersection(set(faces)))
faceNorm = cmds.polyInfo(shaFaces, fn=True)
for normal in faceNorm:
label, vertex, x, y, z = normal.split()
normals[0].append(float(x))
normals[1].append(float(y))
normals[2].append(float(z))
x_avg = (sum(normals[0]) / len(shaFaces))
y_avg = (sum(normals[1]) / len(shaFaces))
z_avg = (sum(normals[2]) / len(shaFaces))
cmds.select(v)
cmds.polyNormalPerVertex(xyz = (x_avg, y_avg, z_avg))
normals[:] = [[], [], []]
cmds.select(cl=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment