How can you make a generated animation work with a humanoid avatar?

Hello everybody!

We have a live stream of motion data, that gets applied to a model in Unity. Now we are trying to record the animation within Unity, which works with a generic animation (by getting the transforms of the bones every FixedUpdate and generating AnimationCurves from that data at the end. We are saving the animation with CreateAsset and SaveAssets as an anim-file).

But since the generic animation only works on the character it was recorded with, we would like to make the animation humanoid via code. We found AnimationClip.humanMotion, but the information in the documentation is not really helpful and all questions regarding it, have no answers. So our question is:
How can you make an animation, that was generated at runtime, work with humanoid avatars?

I finally got it:

Humanoid animations use muscles instead of bones and axes (you can get the corresponding muscles with HumanTrait.MuscleFromBone) and the type of the animation curves has to be “Animator”.
This post showed me that HumanPoseHandler is the class I was looking for and with GetHumanPose it is pretty easy to do the rest (It is important to have the right root of the skeleton). There is a short example by Jan Kolkmeier. I also noticed a bug, where Unity crashes when trying to use GetHumanPose with an avatar that has “TranslationDoF” enabled and has an unsupported hierarchy. Disabling TranslationDoF fixed that for me, the bug report can be found here.