Home Coding, Scripting, Shaders

4 joint IK FK snapping

hanaharu
polycounter lvl 8
Offline / Send Message
hanaharu polycounter lvl 8
Hello all!

Im making a robot who has an upper and lower elbow. I have successfully created an ikfk blend and have been able to get the fk to snap correctly to my ik. However when snapping the ik to the fk, I can only get the wrist to match positions.

I used the upper elbow as my pole vector but i think i might need to use a point in between both elbow joints? Anways, When I run my script it appears to not account for the rotation of the lower elbow i suppose which does make sense…

But Im really unsure how to approach this so any assistance would be greatly appreciated

I’ve attached the code I used following a tutorial below if it helps

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]
fkElbow = 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(fkelbow, 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 = (fkwPos + fksPos) / 2

#find pv direction
pvOrigin = fkePos - midpoint

#extend that length
pvRaw = pvOrigin * 2


#position pvRaw at midpoint
pvPos = pvRaw + midpoint

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

Sign In or Register to comment.