Skip to content

Instantly share code, notes, and snippets.

@rondreas
Last active November 19, 2018 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondreas/27910a45d8fc3a9d530ca7fcfc85f080 to your computer and use it in GitHub Desktop.
Save rondreas/27910a45d8fc3a9d530ca7fcfc85f080 to your computer and use it in GitHub Desktop.
hardsurface modelling script to set normals for all vertices on a face.
import pymel.core as pm
def faceNormal():
""" """
# Store old selection,
selection = pm.selected()
# Convert selection to faces,
pm.mel.ConvertSelectionToFaces()
# Iterate over each face in a flattened list of active selection,
for face in pm.selected(flatten = True):
# Get the face normal and list of vertices.
normal = face.getNormal()
pm.select(face)
pm.mel.ConvertSelectionToVertices()
# set their normal to normal of face.
for vertex in pm.selected(flatten = True):
# FIX: previously set normals will be overwritten by the latest operation,
pm.polyNormalPerVertex( vertex, xyz = normal )
# Restore previous selection,
pm.select(selection)
if __name__ == "__main__":
faceNormal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment