Created
February 6, 2019 07:38
-
-
Save jocelynkim/5e31ca1543628269790ddf9bc3786653 to your computer and use it in GitHub Desktop.
Maya script that merges overlapping vertices within each selected mesh, using a user-specified merge threshold.
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
import pymel.core as pm | |
# mergeVerts() | |
# Author: Jocelyn Kim | |
# Function: Mass merge overlapping vertices on selected mesh(es) under a user-specified threshold | |
# 'meshes' is a list of all of the meshes in the user's selection | |
meshes = [x for x in [ thing for thing in pm.selected() if thing.getShape()] if x.getShape().nodeType() == 'mesh'] | |
# UI Layout | |
win = pm.window (title="Merge Overlapping Vertices", rtf=True) | |
layout = pm.columnLayout() | |
threshold_text = pm.text (label='Merge Threshold', parent=layout) | |
threshold_field = pm.textField (tx='0.001', parent=layout) | |
btn = pm.button (label='MERGE', parent=layout) | |
def onButtonPressed (*args): | |
# for every mesh in the 'meshes' list: | |
for mesh in meshes: | |
numVerts = mesh.verts | |
oldVerts = float(len(numVerts)) | |
# clear selection list before starting | |
pm.select (clear=True) | |
# selected vertices in this mesh | |
for v in numVerts: | |
pm.select(v, add=True) | |
# designate new threshold value based on what user specified (defaults to 0.001) | |
thr = pm.textField (threshold_field, query=True, text=True) | |
newThreshold = float(thr) | |
# merge 'em! | |
pm.polyMergeVertex (d=newThreshold) | |
newVerts = float(len(mesh.verts)) | |
print ("MERGED for mesh: " + mesh + "~ old vert count: " + str(oldVerts) + ", new vert count: " + str(newVerts)) | |
pm.deleteUI(win) | |
btn.setCommand (onButtonPressed) | |
win.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment