Created
January 23, 2019 20:15
-
-
Save hotcakesdeluxe/f1976ee0760ebb310aeaad341a8ec26a to your computer and use it in GitHub Desktop.
for Maya, makes a control object for your pole vector on an IK limb
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 maya.cmds as cmds | |
import maya.api.OpenMaya as OpenMaya | |
pv = cmds.circle(n='poleVector_ctrl') | |
pvGrp = cmds.group(pv, n = 'poleVector_o') | |
start = cmds.xform(IKJoints[0], q = 1, ws =1, t =1) | |
mid = cmds.xform(IKJoints[1], q = 1, ws =1, t =1) | |
end = cmds.xform(IKJoints[2], q = 1, ws =1, t =1) | |
#create 3 vectors. this uses openmaya api's MVector, could also use a python math module? | |
startV = OpenMaya.MVector(start[0], start[1], start[2]) | |
midV = OpenMaya.MVector(mid[0], mid[1], mid[2]) | |
endV = OpenMaya.MVector(end[0], end[1], end[2]) | |
#get start to end vector, and start to mid vector. start to end will essentially be the visible IKHandle | |
startEnd = endV - startV | |
startMid = midV - startV | |
#dot product to get project | |
dotP = startMid * startEnd | |
#projection length | |
proj = float(dotP) / float(startEnd.length()) | |
#normalize values | |
startEndN = startEnd.normal() | |
#normalized vector | |
projV = startEndN * proj | |
aimV = startMid - projV | |
#change this value to change the distance the pv control from the joint | |
aimV*= 10 | |
#add arrow vector to the mid | |
finalV = aimV + midV | |
cmds.xform(pvGrp, ws =1, t= (finalV.x, finalV.y, finalV.z)) | |
cmds.poleVectorConstraint(pv, IKHandle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment