Hi everyone!
I just wanted to share a script I've done for Maya to quickly be able to set the vertex normals based on the face normals. I know there are a few ways to do this within native maya, as well as a few scripts, but I haven't been able to find one which averages the normals for verts shared by multiple selected faces. This can be quite annoying when setting up curved or round surfaces.
The GetVertNormalFromFace script for 3ds Max does a good job for this if I remember correctly. What mine does is essentially the same but in Maya. Just make a face selection of the faces you want to set the vert normals for and run the script.
To run the script, just paste into the script editor as python and drag it to a shelf, or set it up as a hotkey
Here's the script:
# ---------------------------------------------------------------------------------------
# - pompVertNormFaceAvg
#
# - Sets the vertex normals of a face selection,
# averaging normals shared by multiple selected faces.
#
#
# - by Pontus Karlsson 2013 (www.pomperi.com)
# ---------------------------------------------------------------------------------------
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)
I hope someone finds it useful
Replies
http://wiki.polycount.com/VertexNormal?action=show&redirect=Vertex+Normal#FaceNRMtoVert
I hope that clears things up a bit