I've been trying doing this for probably 3 years, and still not had any success, and sadly there is almost no information about this online.
Basically, I want to reuse animations from one skeleton on another.
Both skeletons have exactly the same hierarchy of joints, except that each roint has a different offset matrix (position + rotation).
The best result I can get is by just copying the offset matrices from the original skeleton to the target skeleton (animation below).
Of course, this ignores completely the original skeleton, so this solution can't work.
If I get the idea right, ideally I just have to calculate a matrix per each joint, that converts the animation data from the original bone to the target bone orientation.
I though this would be done like this.
transformed_keyframe_mat = inverted_original_offset_mat * original_keyframe_mat * target_offset_mat
This however does not work, and in frustration I've tried all possible permutations of this multiplications, the animation always appears all wrong (head twisted inside body, paws twisted and stretched, etc).
My current animation algorithm works like this (with many parts I not understand!)
1 - Each joint has two precalculated matrices (a relative and a absolute offset matrix). The absolute offset matrix can be used to bring vertices from the joint space to the world space. And the relative matrix I have no clue what transformation it actually does if I apply it to vertices.
2 - After selecting the keyframes for current time and interpolating them, I get a keyframe/animation matrix for each joint. I call this 'relative frame matrix'. I then concatenate them to obtain a 'absolute frame matrix' per joint.
3 - I calculate the final matrices for each joint by multiplying the inverse of the 'absolute offset matrix' by the 'absolute frame matrix'. This supposedly brings the vertices to 'joint space', then applies the current animation and then somehow puts them back in world space (why?? I'm not sure how this even is working now... I've written this code like 4 or 5 years ago)
I'm not sure if there is even another way to do this. For example, is is possible to avoid concatenating all 'relative frame matrices' into 'absolute frame matrices' every frame? I've tried that, but I did not have any sucess, the animation always appears wrong.
Finally, where would the retargeting step happen?