I’m writing an importer for an animation format that, for each bone, stores keyframe poses relative to the parent bone (I think). As I understand it, this is different from the way Blender does skeletal animation, where the pose bone transformation is relative to the rest position of that bone. Unfortunately, I can’t think of a nice way of going from one format to another. However, like Blender, the format only stores values that have changed each keyframe (like “x position at frame 5=1.2, y rotation at frame 7=92, …”), instead of the whole pose, so I don’t have a full picture for each keyframe.
My temporary solution is to completely clear the rest pose. That means all of the bones have head/tail at 0,0,0 rotation 0, and the mesh is all clustered around that point. The animation then correctly sets the bone positions and fully fleshes out the pose. Unfortunately that will look really bad if an artist wants to make an animation and expects the “reset pose” button to work, or if they want to edit the mesh only to switch into edit mode and see a pile of vertices all scrunched up into a ball on the floor.
I think the “correct” way of doing this would be:
- For each keyframe point (“x position at frame 5=1.2”), evaluate the rest of the pose at that point in time, to get the whole picture (x,y,z position, x,y,z rotation, x,y,z scale). That pose would be in old, “absolute” space, and hopefully Blender has facilities to help evaluate curves correctly.
- Compile the pos/rot/scale into a 4x4 transformation matrix.
- Multiply by the inverse of the rest pose (again, compose from head pos/tail pos/spin if needed). Now it’s in “rest-relative” native Blender space.
- Decompose that matrix into pos/rot/scale
- Hope and pray that Blender decomposed it sanely
- Use the right piece of that transform as the new keyframe value (“x position at frame 5=54.2”)
I think it might work, but it’s a lot of effort and will probably result a lot of frustration debugging. An alternate approach I think would be to skip steps 4, 5, and 6, and just key with a full transformation matrix. Unfortunately, that might interpolate wrong, and there would be way too much extra data that an animator would have to deal with, since all key data would be there for every frame, not to mention general chaos in the f-curve viewer.
Do any Blender Python or general 3D developers have any experience with things like this? I’d appreciate any advice. Thanks!