Sunday, November 4, 2007

IK/FK Blending Methods

This last week I worked a lot on IK/FK blending.

Most of the week was pure research, and I didn't find a method that I really liked for doing it. Those are the methods that I considered so far:

1. The Maya built-in IK blending:
When you create an IK handle in Maya, it has an attribute called "IK Blend". This attribute goes from 0 to 1. When it is 1, the joint that is affected by the IK will be in the exact position of the IK handle. When it is 0, the IK handle is ignored and the joints can be rotated normally as if there wasn't an IK.
When the IK blend attribute is 0.5, the joint position is affected by both the rotation of the joints and the IK handle, and it will be somewhere in the middle.

Pros:
* This method is very easy to setup - all you need is an IK handle attached to your skeleton.
* You can key the joint rotation when the IK is active (IK blend = 1) and then your FK will "snap" to your IK.

Cons:
* When the IK is active, it's hard to see where exactly the joints will be positioned if the IK wasn't active (there is a mark "FK" which is only visible when choosing the IK).
* When the IK is not active, you can see the position of the IK itself but you cannot see the position of the joints on the way (for example the knee joint). This means you have much less control of where your joints would be whenever you animate the transition between IK and FK.
* When switching from IK to FK the skeleton will "jump" from one position to another. The IK is not attached to the FK and the FK is not attached to the IK. A smooth transition between IK to FK or the other way around will require a lot of keyframes on a lot of attributes, including the rotation of the joints, the position of the IK, and the IK blend attribute itself.


2. The 3 arms setup:
As far as I know, this setup is the most common setup for IK/FK blending.
It requires 3 arms: One is the "real" arm, one is the "IK" arm, and one is the "FK" arm. After you create these 3 arms, the IK is always active on the IK arm and there is no IK at all on the FK arm.
Your wrist control can then control only the IK arm and your elbow and shoulder controls can control only the FK arm. The real arm is positioned based on an attribute similar to the built in IK blend, which is now a blend between the two other arms.

Pros:
* This setup gives you absolute control of both your FK skeleton and your IK skeleton, even while you are animating the other skeleton.
* Snapping the IK to the FK or the other way around in order to switch IK to FK in one frame (instead of blending it over a few frames) is easier.

Cons:
* This setup is quite complicated, and if you want your controls to follow the real arm (while controlling the IK/FK arms), it gets even more complicated.
* The real skeleton will still "jump" when moving from IK to FK or the other way around. The large amount of keyframes is still necessary to combine IK and FK animation smoothly.


3. Constraining the IK:
I tried combining the first method with point and orient constraints on the controls. When IK blend = 1, the orientation of the controls is constrained to the orientation of the joints that is calculated from the IK. When IK blend = 0, the position of the IK control is constrained to the position of the skeleton.

Pros:
* Blending from IK to FK can be done instantly (on a single keyframe) since there is no "jump" - the IK control and the skeleton are always located in the same position.
* Less keyframes are necessary when going from IK to FK or the other way around.

Cons:
* This setup is very complicated, and requires a lot of connections and expressions.
* It is still necessary to keyframe an IK blend attribute (even though it can go from 0 to 1 in a single frame).


My goal was to find a way to animate the IK when I need to and the joint rotation (FK) when I need to without having to constantly change and animate the values of IK blend. This is the method that I finally chose:

4. Parenting and rotating the IK:
I parented the IK control to the elbow control, and the elbow control to the shoulder control. This way when I rotate the controls the IK rotates around them and the overall result is almost as if I rotated the knee, while the IK is always active (IK blend = 1).
This method is not perfect - if I will need real FK control I would have to set the IK blend to 0 and rotate the skeleton joints manually. That means I will be using the first method for this. Most of the time this will not be necessary as rotating the IK handle will be good enough.

Pros:
* The setup is as simple as the first method.
* In some cases rotating the IK around the elbow will give the same result as using FK.
* In those cases it won't be necessary to change or keyframe the IK blend attribute - it will always be 1.
* In special cases I will be able to revert to using Maya built in IK/FK blending.

Cons:
* After moving the IK, the rotation will not be around the elbow since the elbow already moved. This might cause unnatural movement of the arm, in which case it will be necessary to use complex IK/FK blending like in the first method.
* The shoulder control cannot be parented to the main control of the character (otherwise the IK will have no meaning). When the character will move while the IK is active, the shoulder control will not be in its place and rotating the IK around it will have the same effect as rotating the elbow control after the IK was moved.
* When using the built in IK/FK blending, all the cons of the first method will apply. Hopefully this will only occur in special cases and not every time I need FK, because most of the time I'll control the character with the IK.


As I said earlier this is the setup I will use.
I'll go over the specific details of the setup I created in another post.

No comments: