Last active
October 22, 2021 08:52
-
-
Save TSCG/99b1175d64811010e78b to your computer and use it in GitHub Desktop.
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 | |
import maya.cmds as cmds | |
def TsRelaxVtxs(): | |
vtxs = cmds.ls(fl=True, sl=True) | |
if len(vtxs) == 0: | |
cmds.error("Please select some vertices.") | |
else: | |
if type( pm.selected(fl=1)[0] ) != pm.MeshVertex: | |
cmds.error("selection is not vertices.") | |
else: | |
#get Obj Name | |
obj = vtxs[0].split(".")[0] | |
#Create Tgt Obj | |
tgtObj = cmds.duplicate( obj, n=obj+"Tgt" ) | |
cmds.makeIdentity( tgtObj, apply=True, t=1, r=1, s=1 ) | |
#RelaxVtx cel | |
cmds.polyAverageVertex( vtxs, i=1, ch=False ) | |
snapToClosestPointOnMesh( vtxs, tgtObj[0] ) | |
#clean | |
cmds.delete( tgtObj ) | |
def snapToClosestPointOnMesh( vtxList, tgtObj ): | |
tgtObjShape = pm.PyNode(tgtObj).getShapes() | |
tmpCpNode = cmds.createNode( 'closestPointOnMesh', ss=True ) | |
cmds.connectAttr( tgtObjShape[0]+'.outMesh', tmpCpNode+'.inMesh' ) | |
cmds.connectAttr( tgtObjShape[0]+'.worldMatrix[0]', tmpCpNode+'.inputMatrix' ) | |
for tmp in vtxList: | |
tmpPos = cmds.pointPosition( tmp, w=True) | |
cmds.setAttr(tmpCpNode+".inPosition", tmpPos[0],tmpPos[1],tmpPos[2]) | |
fixPos = cmds.getAttr(tmpCpNode+".result.position") | |
cmds.xform( tmp, worldSpace=True, translation=fixPos[0]) | |
cmds.delete(tmpCpNode) | |
TsRelaxVtxs() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment