Well, after I got some sleep with the problem I was able to split it to better redefine it.
The idea is the following - we have a character (lets assume we have very simple one), having 2 limbs and a set of bones which are parents to these limbs. All bones orientation is random (we want use skeletons made in different software). We have our controls which we want to use, which work always the same (I rotate control over X axis then my bone rotates over character-relative (local) X axis, not around bone X axis.
So idea is to find conversion quaternion, which would allow converting character space to bone local space. The conversion is required every frame as bone spaces change.
So LookAt approach will almost never work as it assumes that in local space Z is always front and Y is up. The magic will work for axis-oriented bones (fully vertical or horizontal for humanoid) with wrapping up vector so, that it points in bone direction, but it is not enough if bone’s front is reversed.
The magic resolution to this problem is “inserting” a parent “bone” which is oriented in character space. if we rotate “child”, the “child” will obey and rotate in space we like.
Of course we do not want to change actual skeleton to implement this, so this have to be done with quaternion math.
The good thing about this approach is that we calculate the conversion only once, during skeleton load, we don’t need to convert this every frame. I think this is actual power behind mecanim.
But now I need to find out which mith I need which is really complex for my poor brain now, but understanding that is a progress already.
btw, mecanim is not a part f that C# code drop, grepping through that one can find that mecanim is native code (written in whatever compiled language they use, C, C++ or something).