Created
January 30, 2017 22:48
-
-
Save hotcakesdeluxe/d424c4c06514f55dc67dff4f96a6ac42 to your computer and use it in GitHub Desktop.
Maya python for point to poly constraining locators to a mesh. Not super useful on its own, but good first step to automatic face rig.
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
# maya Python Script | |
# based on https://gist.github.com/protofALk/4564420 | |
import maya.cmds as cmds | |
import pymel.core as pm | |
class NumericString: | |
def __init__(self, rawValue): | |
self.rawValue = rawValue | |
def __cmp__(self, other): | |
if self.rawValue == other.rawValue: return 0 | |
if self.rawValue == None: return -1 | |
if other.rawValue == None: return 1 | |
if self.rawValue == "": return -1 | |
if other.rawValue == "": return 1 | |
xList = self.getValueList(self.rawValue) | |
yList = self.getValueList(other.rawValue) | |
for i in range(min(len(xList), len(yList))): | |
compareResult = self.compareTwoVals(xList[i], yList[i]) | |
if compareResult != 0: | |
return compareResult | |
return cmp(len(xList), len(yList)) | |
def compareTwoVals(self, xVal, yVal): | |
if xVal.isdigit() and yVal.isdigit(): | |
return cmp(int(xVal), int(yVal)) | |
if not xVal.isdigit() and not yVal.isdigit(): | |
return cmp(xVal, yVal) | |
if xVal.isdigit(): | |
return -1 | |
return 1 | |
def getValueList(self, rawValue): | |
values = [] | |
tempVal = "" | |
for i in range(len(rawValue)): | |
val = rawValue[i] | |
if val.isdigit(): | |
tempVal += str(val) | |
else: | |
if tempVal != "": | |
values.append(tempVal) | |
tempVal = "" | |
values.append(val) | |
if tempVal != "": | |
values.append(tempVal) | |
return values | |
def SortNumericStringList(original): | |
newList = [NumericString(x) for x in original] | |
newList.sort() | |
return [x.rawValue for x in newList] | |
# make an array with alle the 'birnen*' | |
def getSpecificObjectsIntoArray(objectName): | |
return cmds.ls(objectName) | |
# make an array with all the selected verticies | |
def selectedVerticies(): | |
vertexSelection = cmds.ls(sl=True) | |
cmds.ConvertSelectionToVertices() | |
vertexSelection = cmds.ls(sl=True, fl= True) | |
vertexSelection = SortNumericStringList(vertexSelection) | |
return vertexSelection | |
# iterate over vertex array | |
def placer(objectName): | |
specificObjectList = getSpecificObjectsIntoArray(objectName) | |
specificObjectList = SortNumericStringList(specificObjectList) | |
for i,selectedVertex in enumerate(selectedVerticies()[:len(specificObjectList)]): | |
#place a birne on each verticy with rows columns intact | |
cmds.move(cmds.pointPosition(selectedVertex)[0], cmds.pointPosition(selectedVertex)[1], cmds.pointPosition(selectedVertex)[2], specificObjectList[i], a=True, ws=True) | |
cmds.select(selectedVertex) | |
cmds.select(specificObjectList[i], add = True) | |
#currently has to use PYMEL implentation as python cmds does not work 'because maya' | |
pm.runtime.PointOnPolyConstraint() | |
cmds.select(cl=True) | |
def makeLocs(): | |
sel = cmds.ls(sl = True) | |
currSel = sel[0] | |
vertNum= cmds.polyEvaluate(v = True) | |
i = 0 | |
while (i < vertNum): | |
cmds.spaceLocator() | |
i+=1 | |
cmds.select(currSel) | |
makeLocs() | |
placer('locator*') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment