AnimTestbed/3rdparty/ozz-animation/samples/two_bone_ik
Martin Felis c7d2d195a3 Updated ozz-animation to version 0.14.3 (commit 92c392b667844) 2024-03-17 12:47:11 +01:00
..
CMakeLists.txt Updated ozz-animation to version 0.14.1 @35b2efd4 2023-03-26 13:28:12 +02:00
README.md Updated ozz-animation to version 0.14.1 @35b2efd4 2023-03-26 13:28:12 +02:00
sample_two_bone_ik.cc Updated ozz-animation to version 0.14.3 (commit 92c392b667844) 2024-03-17 12:47:11 +01:00

README.md

Ozz-animation sample: Two bone IK

Description

Performs two bone IK on robot arm skeleton.

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:

  • The pole vector which defines where the direction the middle joint should point to, allowing to control IK chain orientation.
  • Twist_angle which rotates IK chain around the vector define by start-to-target vector.
  • Soften ratio, allowing the chain to gradually fall behind the target position. This prevents the joint chain from snapping into the final position, softening the final degrees before the joint chain becomes flat.
  • Weight given to the IK correction. This allows to blend / interpolate from zero to full IK. float weight;

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 rest 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.