TExcelTAD
Home › Game Physics & Animation › Skeletons and Poses

Skeletons and Poses

A character mesh has thousands of vertices, but an animator moves maybe 30 to 150 bones (joints). The skeleton is a transform hierarchy like any scene graph, with a few conventions that every runtime shares.

The data

  • Each bone has a name, a parent index (-1 for the root) and a local transform: its translation, rotation and scale relative to the parent.
  • A pose is one local transform per bone. Animation clips produce poses; blending and IK modify them.
  • The model-space (or "global", "component-space") transform of a bone is its parent's model transform times its local transform, all the way up to the root.
  • The bind pose (rest pose, reference pose) is the pose the mesh was modelled and skinned in, usually a T-pose or A-pose.

Runtimes store bones in an array sorted so that every parent comes before its children. Then converting a whole pose from local to model space is one loop with no recursion and no pointer chasing:

cpp
for (int i = 0; i < boneCount; i++)
    model[i] = parent[i] < 0 ? local[i] : model[parent[i]] * local[i];

Here it is in 2D, where a transform is an angle plus a translation, for a hips–spine–head–arm skeleton:

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>

double z0(double v) { return std::fabs(v) < 5e-4 ? 0.0 : v; }
const double DEG = 3.141592653589793 / 180;

// A 2D rigid transform: rotate by `angle`, then translate by (x, y).
struct Xform { double angle, x, y; };
Xform combine(const Xform& parent, const Xform& local) {      // parent * local
    double c = std::cos(parent.angle), s = std::sin(parent.angle);
    return {parent.angle + local.angle, parent.x + c * local.x - s * local.y, parent.y + s * local.x + c * local.y};
}

struct Bone { std::string name; int parent; Xform local; };   // local = relative to the parent

int main() {
    std::cout << std::fixed << std::setprecision(3);
    // Bones are stored so that every parent comes before its children.
    std::vector<Bone> skeleton = {
        {"hips",      -1, {0,          0, 1.0}},
        {"spine",      0, {90 * DEG,   0, 0.0}},   // points up
        {"head",       1, {0,        0.6, 0.0}},
        {"upper_arm",  1, {-90 * DEG, 0.5, 0.0}},  // shoulder; -90 from the spine points the arm right (T-pose)
        {"forearm",    3, {0,        0.3, 0.0}},
        {"hand",       4, {0,        0.3, 0.0}},
    };
    for (int pose = 0; pose < 2; pose++) {
        if (pose == 1) {                            // animate: raise the arm and bend the elbow
            skeleton[3].local.angle = 0 * DEG;
            skeleton[4].local.angle = 90 * DEG;
        }
        std::vector<Xform> model(skeleton.size());
        for (size_t i = 0; i < skeleton.size(); i++) {
            const Bone& b = skeleton[i];
            model[i] = b.parent < 0 ? b.local : combine(model[b.parent], b.local);
        }
        std::cout << (pose == 0 ? "bind pose:\n" : "arm raised, elbow bent:\n");
        for (size_t i = 0; i < skeleton.size(); i++)
            std::cout << "  " << std::setw(9) << skeleton[i].name << " at (" << z0(model[i].x) << ", " << z0(model[i].y)
                      << "), facing " << std::setw(7) << z0(model[i].angle / DEG) << " deg\n";
    }
}
bind pose:
       hips at (0.000, 1.000), facing   0.000 deg
      spine at (0.000, 1.000), facing  90.000 deg
       head at (0.000, 1.600), facing  90.000 deg
  upper_arm at (0.000, 1.500), facing   0.000 deg
    forearm at (0.300, 1.500), facing   0.000 deg
       hand at (0.600, 1.500), facing   0.000 deg
arm raised, elbow bent:
       hips at (0.000, 1.000), facing   0.000 deg
      spine at (0.000, 1.000), facing  90.000 deg
       head at (0.000, 1.600), facing  90.000 deg
  upper_arm at (0.000, 1.500), facing  90.000 deg
    forearm at (0.000, 1.800), facing 180.000 deg
       hand at (-0.300, 1.800), facing 180.000 deg

In the second pose only two numbers changed (the upper arm's and the forearm's local angles), yet the forearm and hand moved to new positions in model space: children inherit their parents' motion for free. That is why animation data is stored in local space. A clip that only rotates the shoulder still moves the hand, and the same clip works whether the character is standing at the origin or on the far side of the map.

Note: Local rotations are usually all a clip contains for most bones, because bone lengths don't change. Translation tracks are kept for the root (to move the character, see Blend Trees, Root Motion and Events) and for a few special bones (a pelvis that bobs, a weapon bone).

Inverse bind matrices

The mesh's vertices are stored in model space in the bind pose. To make a vertex follow its bone, the renderer needs a matrix that takes the vertex:

  1. from bind-pose model space into the bone's own space (where the vertex has fixed coordinates, whatever the bone does), and then
  2. from bone space into the current pose's model space.

Step 1 is the inverse of the bone's model transform in the bind pose: the inverse bind matrix, computed once at import and stored with the mesh (glTF stores them as inverseBindMatrices on the skin). Step 2 is the bone's current model transform. Their product is the skin matrix uploaded to the GPU each frame:

text
skin[i] = model[i] * inverseBind[i]

In the bind pose the two cancel and every skin matrix is the identity, which is the first sanity check any skinning code should pass:

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>

double z0(double v) { return std::fabs(v) < 5e-4 ? 0.0 : v; }
const double DEG = 3.141592653589793 / 180;

struct Xform { double angle, x, y; };
Xform combine(const Xform& p, const Xform& l) {
    double c = std::cos(p.angle), s = std::sin(p.angle);
    return {p.angle + l.angle, p.x + c * l.x - s * l.y, p.y + s * l.x + c * l.y};
}
Xform inverse(const Xform& t) {                    // undo the translation, then the rotation
    double c = std::cos(t.angle), s = std::sin(t.angle);
    return {-t.angle, -(c * t.x + s * t.y), -(-s * t.x + c * t.y)};
}
struct P { double x, y; };
P apply(const Xform& t, P p) {
    double c = std::cos(t.angle), s = std::sin(t.angle);
    return {t.x + c * p.x - s * p.y, t.y + s * p.x + c * p.y};
}

struct Bone { std::string name; int parent; Xform local; };

std::vector<Xform> modelPose(const std::vector<Bone>& sk) {
    std::vector<Xform> m(sk.size());
    for (size_t i = 0; i < sk.size(); i++) m[i] = sk[i].parent < 0 ? sk[i].local : combine(m[sk[i].parent], sk[i].local);
    return m;
}

int main() {
    std::cout << std::fixed << std::setprecision(3);
    std::vector<Bone> sk = {
        {"shoulder", -1, {0, 0, 1.5}},
        {"forearm",   0, {0, 0.3, 0}},
        {"hand",      1, {0, 0.3, 0}},
    };
    // Computed once when the mesh is bound: the inverse of each bone's model transform in the bind pose.
    std::vector<Xform> bind = modelPose(sk), inverseBind;
    for (const Xform& b : bind) inverseBind.push_back(inverse(b));

    // Mesh vertices are stored in model space, in the bind pose.
    struct Vert { std::string name; P pos; int bone; };
    std::vector<Vert> verts = {{"sleeve", {0.15, 1.55}, 0}, {"wrist", {0.55, 1.45}, 1}, {"fingertip", {0.70, 1.50}, 2}};

    for (int frame = 0; frame < 2; frame++) {
        if (frame == 1) { sk[0].local.angle = 90 * DEG; sk[1].local.angle = 90 * DEG; }
        std::vector<Xform> model = modelPose(sk);
        std::cout << (frame == 0 ? "bind pose\n" : "posed (shoulder 90, elbow 90)\n");
        for (size_t i = 0; i < sk.size(); i++) {
            Xform skin = combine(model[i], inverseBind[i]);     // bind space -> bone space -> posed model space
            std::cout << "  skin[" << sk[i].name << "] = rotate " << std::setw(7) << z0(skin.angle / DEG)
                      << " deg, move (" << z0(skin.x) << ", " << z0(skin.y) << ")\n";
        }
        for (const Vert& v : verts) {
            P p = apply(combine(model[v.bone], inverseBind[v.bone]), v.pos);
            std::cout << "  " << std::setw(9) << v.name << " -> (" << z0(p.x) << ", " << z0(p.y) << ")\n";
        }
    }
}
bind pose
  skin[shoulder] = rotate   0.000 deg, move (0.000, 0.000)
  skin[forearm] = rotate   0.000 deg, move (0.000, 0.000)
  skin[hand] = rotate   0.000 deg, move (0.000, 0.000)
     sleeve -> (0.150, 1.550)
      wrist -> (0.550, 1.450)
  fingertip -> (0.700, 1.500)
posed (shoulder 90, elbow 90)
  skin[shoulder] = rotate  90.000 deg, move (1.500, 1.500)
  skin[forearm] = rotate 180.000 deg, move (0.300, 3.300)
  skin[hand] = rotate 180.000 deg, move (0.300, 3.300)
     sleeve -> (-0.050, 1.650)
      wrist -> (-0.250, 1.850)
  fingertip -> (-0.400, 1.800)

In the bind pose every skin transform is "rotate 0, move 0", so the vertices stay where the artist put them. After rotating the shoulder by 90° and the elbow by another 90°, each vertex rotates with its bone around the right pivot: the fingertip ends up at (-0.4, 1.8), left of the shoulder, exactly where a raised arm with a bent elbow puts it.

Notice that the forearm and the hand get the same skin transform here: the hand has no rotation of its own, so it is rigidly attached to the forearm.

Where the pose comes from

A full frame of character animation is a pipeline over these arrays:

Stage Works in Lesson
Sample clips into local poses local space Keyframes and Sampling
Blend poses (walk + run, upper body aim) local space Blending Poses and Quaternions
Local → model space the loop above this lesson
IK, look-at, foot placement model space, then written back to local Two-Bone IK, FABRIK
Skin matrices → GPU model * inverseBind Skinning

Engines call these the same things with different names: Unity's Avatar and the bones under a SkinnedMeshRenderer; Unreal's Skeleton asset, the reference pose and "component space"; Godot's Skeleton3D with get_bone_pose() (local) and get_bone_global_pose() (model space).

Tip: When importing a character into a different engine, a wrong bind pose or a different up axis shows up as a character lying on its back or bones pointing the wrong way. Check the skeleton in the bind pose first, with animation disabled.

Test yourself

Why are bones stored with every parent before its children?

  1. To save memory
  2. So local-to-model conversion is one forward loop: a parent's model transform is always ready when a child needs it
  3. Because GPUs require it
  4. So bones can be sorted by name

What is the inverse bind matrix of a bone?

  1. The bone's local transform inverted every frame
  2. The inverse of the bone's model transform in the bind pose, mapping bind-pose vertices into the bone's own space
  3. The transpose of the projection matrix
  4. The parent's transform

What should every skin matrix equal when the skeleton is in its bind pose?

  1. Zero
  2. The identity
  3. The inverse bind matrix
  4. The root bone's transform