PDA

View Full Version : Proper way to do IK/FK matching?


DanHaffner
03-18-2009, 03:36 AM
I am working on my first IK/FK matching system. What I mean is the animator can switch to IK or to FK without the joints moving to a new location, allowing the animator to switch on the fly and not have to deal with the arm constantly going back and forth. I also have a stretchy IK system with a multiply divide node and a condition node, to allow or not allow scaling.

I have been told several ways to accomplish this, but I am having a hard time getting any of them to work. One way I was told was with point constraints, to point the either the IK or FK joints to the other, where ever it may be, then deleting the constraints. The problem I am having is the Bind joints don't want to follow the arm, here is a video of what I get:

http://www.vimeo.com/3732103

I tried to make it clear of what I was clicking and what joints were being selected.

--------------------------------------------------------------------------------------------

Another way of going about it was take all the values of all the joints, store them into variables, then pass those variables into the joints being switched too. The problem is I can't get this to work out all and my python code is getting rather large and it's just one arm switch from IK to FK, which doesn't even work.

Here is my code:

http://pastebin.com/m674e9c59

I commented out all the lines for the right arm since it isn't done yet.

--------------------------------------------------------------------------------------------

Lastly, I was told to use this MEL code:

float $ikLfLegRotA[] = `getAttr LF_Arm_01_IK.rotate`;

setAttr LF_Arm_01_FK.rotateX $ikLfLegRotA[0];
setAttr LF_Arm_01_FK.rotateY $ikLfLegRotA[1];
setAttr LF_Arm_01_FK.rotateZ $ikLfLegRotA[2];

But also take in the scale value of the IK joints and pass them to the FK scale X.

Any help would be great, I am going in circles here.

eek
03-18-2009, 06:57 AM
Ok the basics are this:

the fk chain at the elbow has a fake pole vector, to acheive this you do a linear interpolation between the wrist and shoulder based on the bone lengths (upper arm, lower arm) i.e if upper = 200 and lower = 100, you would do 1- (200/(200 + 100)) * upper + (200/(200+100)) * lower , then you project from this through the elbow at a maginitude of your choice.

Now the ik snaps to the fk, and the pole vector to the imaginary then the switch happens - a key at the time -1 is created of a value of fk = 100.0, ik = 0.0 then at the current frame ik = 100.0 , fk = 0.0.

Now to switch back the fk joints just match the ik ones and the switch happens again vice verse.

DanHaffner
03-18-2009, 01:54 PM
Can you explain that a little more, I am really confused on what you were trying to explain. I do have the pole vector parented to the FK shoulder joint, that what you were saying about a fake pole vector, or are you literally saying I need a fake pole vector out there?

Polimeno
03-18-2009, 03:21 PM
Ok the basics are this:

the fk chain at the elbow has a fake pole vector, to acheive this you do a linear interpolation between the wrist and shoulder based on the bone lengths (upper arm, lower arm) i.e if upper = 200 and lower = 100, you would do 1- (200/(200 + 100)) * upper + (200/(200+100)) * lower , then you project from this through the elbow at a maginitude of your choice.

Now the ik snaps to the fk, and the pole vector to the imaginary then the switch happens - a key at the time -1 is created of a value of fk = 100.0, ik = 0.0 then at the current frame ik = 100.0 , fk = 0.0.

Now to switch back the fk joints just match the ik ones and the switch happens again vice verse.

seems a nice solution eek, can you please post some pratical MXS code or a .max file ?

in a past solution/study, i did a match IKFK by tracking the transform of extra nodes (ie point_upper_ik/point_elbow_ik/point_upper_fk/point_elbow_fk) with weak reference,
where each one was place into the properly chain/bone with transform script.

DanHaffner,
take a look below :

http://seithcg.com/wordpress/?page_id=30
http://snolan.net/blog/ikfkArmSetup/ikfkArmSetup.html
http://www.macaronikazoo.com/download/zooToolBox.rar ...broken...
http://forums.cgsociety.org/showthread.php?t=469432

DanHaffner
03-18-2009, 05:39 PM
Thanks for the links, checking them out now.

3rd link is broke.

eek
03-18-2009, 05:43 PM
Can you explain that a little more, I am really confused on what you were trying to explain. I do have the pole vector parented to the FK shoulder joint, that what you were saying about a fake pole vector, or are you literally saying I need a fake pole vector out there?

ok so heres the basic math:

upperBoneLength = 100.0
lowerBoneLength = 100.0

shoulder = $shoulder.position
elbow = $elbow.position
wrist = $wrist.position

t = upperBoneLength / (upperBoneLength + lowerBoneLength) -- this is the ratio

fakePoleVector = normalize(elbow - ((1-t) * shoulder + wrist * t)) * magnitude + elbow

*magnitude is the offset from the elbow you want the fake pole vector to be. So basically i make a direction then i multiply it. This way its always a constraint direction from the elbow.

BUT and theres a big but. If both the upper and lower bones are perfectly straight then it'll break because theres no vectors to build a direction i.e they overlay each other.


One way to fix this is to instead of using the bone positions shoulder and wrist, you use two nulls, which are offseted from the bone, like so:

shoulder---Null
|
|
elbow
|
|
wrist------Null

blackseraphim
03-19-2009, 03:55 AM
i suggest you use a blendColors node instead of constrains for the ik-fk blending.
1. create an ik joint chain
2. create an fk joint chain
3. create a bind joint chain
connect the IK and FK joint chains to the blendColors node and connect the output of the blendColors node to the bind joint.

create 2 locators
one locator (which will be the guide of the pole vector for the switching of the IK) parent/ point-orient constrain it to the elbowFK_Joint. name it elbow_guide
and the other locator would be the guide for the arm controller. name it arm_control_Guide
(parent/point-orient constrain it to the wristFK_Jnt)

writing for the script of the IK-FK switching:

from IK to FK
-get the rotations of the IK joints
-set the rotations to the FK controllers

from FK to IK
-get the position of the guide Locator(elbow_guide)
-set the translation values of the locator to the poleVector controller
-get the translation values of the of the arm_control_Guide
-set the translation values of the locator to the arm IK controller

*take to consideration the joint orientation of the joints because if not fix earlier in the setup, it will create a problem for the later setup.

hope that helps.

Peter

CGTalk Moderation
03-19-2009, 03:55 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.