Hi! I've been working on an animation system to gain some experience, and I want to implement 2d blend spaces. Here's the struct of a 2d blend space:
Blend_Space_2d :: struct
{
Node :: struct
{
clip : *Asset (Animation_Clip);
position : Vec2;
}
skeleton : *Asset (Skeleton);
nodes : [..]Node;
}
I am currently stuck trying to calculate the influences of each node in the blend space. I took a look at Unity's blend trees, and it seems that only at most the 3 closest nodes to the input position can influence the final pose. So right now I sort an array of nodes based on their distance to the input position, how do I calculate the influences of each of the three closest nodes. I have already identified some special cases:
- When the closest node's distance to the input position is 0, its influence is 1 and the two other nodes have an influence of 0 (don't forget the influences must add up to 1),
- When the 3 nodes are equidistant to ‘position’, all nodes have the same influence of ⅓,
- When ‘position’ lies on the edge formed by nodes A and B, node C has an influence of 0 and it is trivial to then calculate the influences of node A and B (influence = 1 - distance to position / distance between A and B)
It seems obvious that the influence of a node is function of its distance to the input position, but I'm having a hard time figuring out what this function is. Any ideas ?