ozz-animation

Samples - Two bone IK

View two_bone_ik sample source code.

Description

Performs two bone IK on robot arm skeleton.

Initializing WebGL

Concept

This sample uses ozz::animation::IKTwoBoneJob to compute two bone IK on a skeleton. Inverse kinematic allows a chain of joints to reach a target position. The job computes the transformations (rotations only) that needs to be applied to the first two joints of the chain such that the third joint reaches the provided target position (if possible). The three joints don’t need to be consecutive though, they just require to be from the same chain.

Sample usage

The sample exposes IKTwoBoneJob parameters:

Target position is animated by the sample, but can also be tweaked manually, as well as skeleton root transformation. Fix initial transform option select whether ik job is run from the skeleton bind pose or the last frame transforms. This allows to use IK job’s weighting parameter, as well as stressing it with a wide range of input.

Implementation

  1. At initialization time:
  2. Loads skeleton. See “playback” sample for more details.
  3. Locates the three joint indices from the skeleton, searching them by name.
  4. At run time:
  5. Updates skeleton joints model-space matrices from local-space transforms, just like it would be done at the end of animation sampling and blending stages.
  6. Target and pole vectors are converted to skeleton model space.
  7. Setup IKTwoBoneJob with sample parameters, providing the three joints model-space matrices.
  8. Once run, the job outputs two quaternions for the two first joints of the chain. The samples multiplies them to their respective local-space rotations.
  9. Model-space matrices must be updated again. Only the children of the first joint of the chain need to be updated again.