Partial animation with blend masks

It may be necessary to have more refined control over animation blends, instead of just blending all bones at once. This can be achieved with a 'blend mask' wich allows you to set the blend weight for each bone individually. A typical use-case for using 'blend masks' is to exclude lower-body bones so that animation plays only on the upper-body, regardless of the full-body state.

Example

We have two animations: "running" and "shooting". If we want to shoot while running we have to disable (set weight to zero) the lower-body bones for the "shooting" animation and the upper-body bones for the "running" animtion. Assuming the skeleton has 40 bones and the bones 0-31 represent the upper-body and the bones 32-39 the lower-body the blend masks are setup as follows:

AnimationState* running = entity->GetAnimationState("running");
running->CreateBlendMask(40U);
for (int i = 0; i < 32; ++i)
{
    running->SetBlendMaskEntry(i, 0.0f);
}

AnimationState* shooting = entity->GetAnimationState("shooting");
shooting->CreateBlendMask(40U);
for (int i = 32; i < 40; ++i)
{
    shooting->SetBlendMaskEntry(i, 0.0f);
}

Note that the weights in the blend mask are absolute and they are not modulated with the averaged weight of the animation state. You have to prevent 'overshooting' (weights > 1.0f) yourself, when blending multiple animations. For the example above this would require that for every body-part (upper-body, lower-body etc.) you have to loop through all the animation states affecting that part, sum up their weights, calculate the weight factor '1.0f / summed_weights' and then apply this factor to all weights in the blendmask.