Search Unity

Mecanim Muscle Space Causes Unexpected Root Motion

Discussion in 'Animation' started by bteitler, Sep 10, 2016.

  1. bteitler

    bteitler

    Joined:
    May 11, 2014
    Posts:
    52
    I'm attempting to write a streaming animation loader that can re-target human motion by receiving animation data in real time (like from a motion capture system) or streaming animation data from large BVH files. After some research, it seems like the easiest / cleanest solution since 5.3 for this type of integration with Unity is to use Mecanim and the "HumanPoseHandler" interface's "GetHumanPose" and "SetHumanPose" to do the re-targeting in Muscle Space.. However, it seems that muscle space applies some unknown secret root translation that I can't account for. At first, I thought maybe I made some mistake in generating the source Avatar at runtime, but it seems like the problem is visible in the Avatar editor's muscle configurator:

    Here is a video of the problem in the Avatar Muscle editor:

    Note that the whole body's bones are moving up and down even though I'm just moving the individual muscle for one shoulder axis. This is undesired and does not occur if you rotate the shoulder joint's game object manually.

    Here is a video of the issue happening at runtime, where I'm retargeting motion from a BVH file onto the "dude" avatar. The green dots represent the rotate-able bones of the Avatar created at runtime with the skeleton as defined in the BVH file. Every frame, I re-target the the motion onto the Dude avatar using "GetHumanPose"/"SetHumanPose".

    Note that I'm simply rotating the right hip joint of the source avatar's hip bone, but this results in some root translation on the target avatar. I'm making sure to set the "bodyPosition" to zero when re-targeting.

    Code (csharp):
    1. sourceHumanPoseHandler.GetHumanPose(ref humanPose);
    2. humanPose.bodyPosition = Vector3.zero;
    3. destinationPoseHandler.SetHumanPose(ref humanPose);
    Can someone explain what is happening in these cases? Is this root motion expected, and if so, why? And how can I remove it?
     
    roumenf likes this.
  2. bteitler

    bteitler

    Joined:
    May 11, 2014
    Posts:
    52
    After poking around a bit more.. it looks like the hip bone gets set to a position that looks like the center of mass. The hip bone seems to be set to this even though I overwrote the "bodyPosition" on the HumanPose to zero. This is non-intuitive. Looks like setting the bodyPosition before applying it to an avatar actually has no effect, and it simply corresponds to the position the hip (muscle?) is set to during "GetHumanPose". I have no idea why this center of mass offset would get applied in the avatar muscle editor.. seems confusing.

    So basically as I understand it, I have to override the HumanPose's hip muscle (unclear to me how to do this with the API) before applying to the avatar, or I have to manually override the hip game object's position after applying the pose (ugly but easy to do). Moving on the with the latter for now..
     
    roumenf likes this.