Mirroring skeletal animations
Mirroring animation is a process to mirror an animation over an axis. If your engine does not support this, animators must create mirrored animations manually, so this feature can save a lot of work. There is not much information how to do this, maybe the best source is Unreal Developer Network.
We shall assume that our bones positions are stored as points in space and rotations are stored as quaternions. Let's also assume that positions and rotations are in space of parent bone. To mirror an animation we must do three operations.
Firstly, we must mirror the positions of all bones. This one is easy. We just change the sign of one coordinate. The coordinate depends on an axis over which we want to mirror. If we want to mirror over an x axis, then we do something like:
translation.x = -translation.x
Secondly, mirroring rotation is little complicated. Let's imagine for a while that our rotations are represented by euler angles and we want to mirror it over an x-axis. It means we want to invert yaw and roll, but keep the original pitch value. To do this with a quaternion, we must change it in following way:
rotation.x = -rotation.x
rotation.w = -rotation.w
Even though this may seem to be enough to mirror an animation, one more step needs to be done. Bones from one side must be mapped to another side, e.g. bone of left arm is now on right side, however vertices influenced by this bone are parts of triangles, that are attached to left part of torso, but the torso itself is one bone at the center and it is not mirrored. Therefore some triangles goes from left part of torso through the whole torso to left hand, which is on right side of torso. Mapping of bones must be done manually by some map, that says bone LeftArm is mapped to bone RightArm.
Sources:
- Unreal developer network - Animation Mirroring - http://udn.epicgames.com/Three/AnimationMirroring.html
- Steve Rotenberg - Computer Animation - graphics.ucsd.edu/courses/cse169_w05/CSE169_11.ppt
Discussion: