Get the pole vector using three positions.
First we write the function using Maya's OpenMaya MVector class to help us with doing
the math. Below is a function which takes three non-default arguments which are the three points in space to use for the calculation.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| from maya import OpenMaya
def getPoleVectorPosition(startPnt, middlePnt, endPnt, scaler=1):
'''
This will return the position for where the pole vector location is.
:param startPnt: The first point to use for locating the pole vector.
:type startPnt: list | tuple | MPoint | MVector
:param middlePnt: The second point to use for locating the pole vector.
:type middlePnt: list | tuple | MPoint | MVector
:param endPnt: The final point to use for locating the pole vector.
:type endPnt: list | tuple | MPoint | MVector
:return: Position for the pole vector
:rtype: tuple
'''
# Here we will do some type checking.
for pnt in (startPnt,middlePnt,endPnt):
if not isinstance(pnt,(list,tuple,OpenMaya.MPoint)):
raise TypeError('{0} is must be one of the following type: list, tuple, MPoint, MVector'.format(pnt))
# MVectors
startVector = OpenMaya.MVector(startPnt[0],startPnt[1],startPnt[2])
middleVector = OpenMaya.MVector(middlePnt[0],middlePnt[1],middlePnt[2])
endVector = OpenMaya.MVector(endPnt[0],endPnt[1],endPnt[2])
# This is the vector from origin to the exact point between the
# start and end points passed in.
midVector = (startVector + endVector) / 2
# scale the vector by using the scaler passed in by the user.
diffVectorScaled = (middleVector - midVector) * scaler
# now we get the pole vector with the scale already included.
poleVector = midVector + diffVectorScaled
return (poleVector.x, poleVector.y, poleVector.z)
|
First we create the joints and position them.
1
2
3
4
| from maya import cmds
upperArmL=cmds.joint(name='upperArm_l_bind',position=(1,5,0))
lowerArmL=cmds.joint(name='lowerArm_l_bind',position=(6,5,-2))
wristL=cmds.joint(name='wrist_l_bind',position=(5,11,0))
|
Even though we know the positions of the joints. I will query them using the xform command.
1
2
3
| upperArmLPnt=cmds.xform(upperArmL,q=True,ws=True,t=True)
lowerArmLPnt=cmds.xform(lowerArmL,q=True,ws=True,t=True)
wristLPnt=cmds.xform(wristL,q=True,ws=True,t=True)
|
Now we will just pass those positions into the function we wrote above and use it to position a new joint.
1
2
3
| poleVectorPnt = getPoleVectorPosition(upperArmLPnt,lowerArmLPnt,wristLPnt)
cmds.joint(name='pv_l_ik',position=poleVectorPnt)
|
Comments
Post a Comment