Created
February 2, 2021 11:55
-
-
Save fabiangeisler/16ad8f932a2a3bdaf7b019743298343f to your computer and use it in GitHub Desktop.
Maya polygon smooth algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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