I am currently exploring uncharted territories of Mecanim. My goal is to implement my own IK solver via Mecanim muscle / DoF values, but getting and setting poses via a HumanPoseHandler is rather slow if done many times a frame. Thus, I’d like to simulate the behaviour of Mecanim on a lightweight, virtual skeleton instead. But don’t let me bore you with my reasons here and cut to the chase…

I’d like to know precisely how Mecanim computes a bone’s rotation from the corresponding muscle / DoF values (which are usually in the [-1,1] range)?

With some insight into the C# reference (especially here), I have worked out this code snippet that works under some circumstances:

```
public Quaternion BoneRotation(Avatar avatar, int bone, float x, float y, float z) {
var mx = HumanTrait.MuscleFromBone(bone, 0);
var my = HumanTrait.MuscleFromBone(bone, 1);
var mz = HumanTrait.MuscleFromBone(bone, 2);
var preQ = avatar.GetPreRotation(bone); // exposed via reflection
var sign = avatar.GetLimitSign(bone); // exposed via reflection
var r = Quaternion.Euler(
(mx >= 0) ? (MuscleAngle(mx, x) * sign.x) : 0.0f,
(my >= 0) ? (MuscleAngle(my, y) * sign.y) : 0.0f,
(mz >= 0) ? (MuscleAngle(mz, z) * sign.z) : 0.0f);
return parentRotation * preQ * r;
}
```

Calculating the individual DoF angles (*MuscleAngle*) from the muscle values is easy once you got the limits from the avatar settings. However, the calculated result is correct *only* if at most one DoF receives a non-zero value (e.g., x=0,y=0,z=1). As soon as multiple DoF angles are set (e.g., x=0,y=1,z=1), my result is wrong and while it appears that some post transformation is missing, for the hell of it, I cannot figure out what that would be.

So how does Mecanim combine the single DoF rotations into the bone’s final rotation?