IK snap/match Issues

python
maya
rigging
#1

Hello,

I have been following a tutorial for a IK match script and have come up with this

import maya.cmds as cmds
import maya.OpenMaya as om

#select the joints we need
sel = cmds.ls(sl=True)

#assign selection
fkWrist = sel[0]
fkShldr = sel[1]
fkuElbow = sel[2]
ikwrist = sel[3]
ikpv = sel[4]

#get positions from fk
fkwRaw = cmds.xform(fkWrist, ws=True, q=True, t=True)
fkwPos = om.MVector(fkwRaw[0], fkwRaw[1], fkwRaw[2])

fkeRaw = cmds.xform(fkuElbow, ws=True, q=True, t=True)
fkePos = om.MVector(fkeRaw[0], fkeRaw[1], fkeRaw[2])

fksRaw = cmds.xform(fkShldr, ws=True, q=True, t=True)
fksPos = om.MVector(fksRaw[0], fksRaw[1], fksRaw[2])

#set position of IK wrist ctrl
cmds.move(fkwPos.x, fkwPos.y, fkwPos.z, ikwrist)

#start figuring out pole vector pos

#find avg (midpoint) of shoulder and wrist
midpoint = (fksPos + fkwPos) / 2

#find pv direction
pvOrigin = fkePos + midpoint

#extend that length
pvRaw = pvOrigin

#position pvRaw at midpoint
pvPos = pvRaw + midpoint

#stick pole vector at pvPos
cmds.move(pvPos.x, pvPos.y, pvPos.z, ikpv)

First, the script doesnt work correctly if I select my IK wrist control, I have to select the IKhandle. I’m really not sure why this happens and I was hoping someone could explain since I would prefer selecting the control

When selecting IK handle:

For some reason upon running this my Ik wrist joint matches the position of the fk wrist but the elbow appears to be reflected. My pole vector acts strange as well, as it flys up super high over the rig. I’m failry certain that the reflection has something to do with the pole vector moving incorrectly but, upon search here for some answers, I found that if I added this line

cmds.xform(ikwrist, rotation=fkWrist, worldSpace=True)

all the joints seem to try and up correctly but my pole vector stays in its original place.

Would someone be able to assist me with getting this working properly? as this behavior is really messing with my head

#2

Can only post one image at a time since i’m new but I hope these extra ones help
When selecting IK wrist control:

#3

After adding

cmds.xform(ikwrist, rotation=fkWrist, worldSpace=True)
:

#4

didn’t get the chance to earlier but here is what Ive been testing it on

https://mega.nz/#!WIYzGSaB!3s0M-kIgna6gpO1cD3qVmeXwtFHt8b9GBdDt-WG5oiU

#5

My suggestion for a complex problem that is going wrong, start again and try make it more simple to prove out where it is working and where it is not.

My suggestion for dealing with your pole vector:
Use transforms to store and apply the offset. All you need to do to align a pole vector is return it to its pose relative to the forearm, which using matrix maths is easy ( using sudo code as I don’t use Maya) :

-- get the reference pose:
poleVectorRefPose = poleVector.Transform * inverse(forearm.Transform)
-- apply the pose relative to the forearms current transform:
poleVector.Transform = poleVectorRefPose * forearm.Transform

Simple as that.

2 Likes