Skip to content

Instantly share code, notes, and snippets.

@fabiangeisler
Created February 2, 2021 11:55
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 fabiangeisler/16ad8f932a2a3bdaf7b019743298343f to your computer and use it in GitHub Desktop.
Save fabiangeisler/16ad8f932a2a3bdaf7b019743298343f to your computer and use it in GitHub Desktop.
Maya polygon smooth algorithm
'''
Simple PyMel smooth (NOT subdivide) algorithm
A simple example of a smooth algorithm in PyMel. This is NOT fast or optimized!
The math behind it is as follows:
- The new position of a vertex is the average of its position and all positions of its connected vertices.
- The weight of original position of the vertex is the same as the number of connected vertices.
'''
import pymel.core as pm
# Select some verticies on an poly object for this to run
vertices = pm.ls(selection=True, flatten=True)
finalPositions = []
for vertex in vertices:
numConVerts = len(vertex.connectedVertices().indices())
position = vertex.getPosition(space="world") * numConVerts
for conVert in vertex.connectedVertices():
position += conVert.getPosition(space="world")
numConVerts += 1
finalPositions.append(position / numConVerts)
for vertex, position in zip(vertices, finalPositions):
vertex.setPosition(position, space="world")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment