Friday, 22 November 2013

Blender Quick Tip: How to set up IK pole vectors without breaking the bind pose


 
Blender's IK system let's you assign targets (called Pole Vectors) which lets you control the orientation of the bend in the IK chain. But there's a common problem...


Say you're rigging an IK arm.
You need to be able to control the orientation of the elbows, and you do this using IK pole vectors.

But there's a catch, isn't there? When you add the pole vector, your binding pose breaks! That's bad. When you are rigging, Thou shalt honour the bind pose and keep it holy. Preserve it, pure, sanctified and unscathed.

How do we fix this?

Notice that Blender's IK constraint requires that you specify a Pole Angle. By varying this value, you can rotate the elbow around the arm's axis. What value should you put in there? Well, that's the problem. Yes, you can vary it by hand until the elbow is roughly in the binding pose, but if you do it this way, you won't get it exactly right.



To fix this problem, you need to understand exactly what the pole angle is. Check out my diagram.

Line A is the x-axis of the upper arm bone. Line B is drawn from the Pole Target and intersects the IK axis at 90°. The Pole Angle is the angle the IK system will put between lines A and B.

In other words, if the Pole Target is located exactly on the upper arm's positive x-axis, setting the Pole Angle to 0° will put the IK arm into the rest pose.






This is how you can set it up:
  • In pose mode, make sure your entire rig is in its rest pose (select everything, hit alt-S, then alt-R, then alt-G)
  • In edit mode, duplicate the upper arm bone. This will become your elbow target.
  • Keeping the duplicate bone selected, go into pose mode. Move the bone a distance of your choosing along its positive local x axis. Don't get this wrong - it has to be the the local x-axis in the positive direction.
  • Go to menu Pose -> Apply -> Apply Pose as Rest Pose
  • Add the IK constraint to the forearm bone as normal. Use the new bone as a pole vector. Set the Pole Angle to 0°.
Tada! You can flip between pose mode and edit mode, and the arm won't twitch.

Some other notes:
  • You don't have to use a pole angle of 0°. If the Pole Target is on the negative local x-axis, set the Pole Angle to 180°. Put the Pole Target on the positive local z-axis and set the Pole Angle to 90° - whatever it is you need to do.
  • What if you have 3 or more bones in the IK chain? Well, Blender uses the x-axis of the basal-most bone when using the Pole Angle. In a 2 bone arm setup, the upper arm is the basal-most bone.
That's it! Happy rigging!


12 comments:

  1. Hi, this is by far the most explicit and detailed description of pole target I've found so far!
    I really appreciate the last point about the most base bone to determine the x axis. But I have a follow-up question, does the x axis you're recommending have to be the local pose x axis, or local edit x axis, of that basal-most bone?

    ReplyDelete
    Replies
    1. Hi there,
      I'm talking about the local pose x-axis. The x-axis that corresponds to the bone itself. When you try and use the local x-axis in edit mode, Blender thinks you're talking about the local x-axis of the armature, and that's not what you want.

      It *is* however possible to set up custom transform orientations in edit mode. When you're in edit mode, select a bone, look at the bottom of the hotkey "n" panel. There's some "transform orientations" tools which let you use the local axes of the selected bone. Blender doesn't update the local axes if you move the bone though, so if you move it, you need to reload the local axes- that can be kinda annoying.

      Delete
  2. Hello,
    the pole angle picture is all wrong.
    The pole angle is actually angle between line_C and upper_arms x_axis, where line_C is projection of line_B onto XZ plane of upper_arm's bone by vector ik_axis.
    Also line_A is not an upper_arms x_axis and you don't need it.

    ReplyDelete
    Replies
    1. Ah cool- thanks for the info!
      I'm guessing you're familiar with the source code? Would you be able to direct me to where this is calculated? I'd love to take a look.

      My conclusions were based on what I observed while using Blender. When I was doing it, the y-axis of the upper arm was almost parallel to the IK axis ... in which case our two descriptions would be nearly identical.

      Delete
    2. Well I dont know the source code, but I was writing an addon that adds a pole_bone at 3D cursor and calculates its pole_angle so the ik chain does not move. Your blog is actually the only place giving some info on this matter and kicked me in the right direction. Unfortunatelly the angle was wrong so I had to investigate.

      If you try to rotate the pole bone around ik_axis and then compensate same amount in the pole_angle, the ik chain does not come back to the same position. The difference is bigger the bigger is angle between ik_axis and upper_arm_bone.

      What put me onto right track was that if you change upper_arms bone_roll and compensate same amount in pole_angle, the ik chain stays in place. And when you move pole_bone in ik_axis direction nothing rotates. When I projected the angle everything started to work correctly.

      The easiest way is adjusting the bone_roll so the pole is on x_axis as you mention in the article, but sometimes ik/fk switching or stretch or both is in place and rebinding the character and changing all the bones is too much work. Its kinda sad there is not much documentation on this..

      Delete
    3. Very cool! May I ask if your script is published anywhere?
      Your info might be welcomed on the Blender wiki.

      I learned a really cool trick in school about writing IK/FK scripts. Calculating the IK pole target's pose from an FK pose is tricky because there's little to no docs on how the IK chains work. But! You can do this:
      * Set up an IK chain
      * Give it a pole bone (do it so that it doesn't pop).
      * Duplicate the pole bone
      * Parent the new bone to the upper FK arm bone.

      This new bone serves as a target for the pole bone when you switch IK -> FK. I've yet to try it in Blender (I've tried it in other software packages) but it definitely works!

      Delete
    4. The script is part of company tools so I can't publish it, but I can post the math for the pole angle in pseudocode:
      u = crossproduct(ik_axis, pole_location - upper_arm_location)
      v = crossproduct(u, upper_arm)
      pole_angle = signed_angle(upper_arms_x_axis, v)

      The trick you posted is indeed nice and will save some calculations:)

      Delete
    5. Awesome!
      I will most definitely try that out. Blender needs a tool which sets the correct pole angle - I might try and make one some time.
      Thank you!

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. You, sir, here, receive all my due respect and honour. (Where did you get the information about the exact workings of the system?)

    ReplyDelete
  5. Priceless knowledge, thank you!

    ReplyDelete
  6. I've found that, if it isn't super necessary for you to have the exact original bone positions, this will work:

    1. Create the pole arbitrarily and place it arbitrarily. 2. Adjust the angle until the bones are close to the original pose. 3. In the menu go to Pose->Apply->Apply Pose as Rest Pose.

    ReplyDelete