- Home /
Modify humanoid skeleton at runtime and retarget animation
I'm trying to implement dynamic resizing on my humanoid character models at runtime. In order to do so I make use of the AvatarBuilder.BuildHumanAvatar API.
Modifying the skeleton's T-Pose bone positions in the HumanDescription
I do manage to update the skeleton to its new size. Unfortunately on occasion I do seem to run into what seems to be a long-standing bug where upon animation some AABBs are invalid, as reported here.
However, for the models where this is not a problem, the sizing seems to work, except for some retargeting. To give you an idea, if I modify the legs to be longer, and then apply animation via an Animation Controller, the hip doesn't seem to retarget appropriately, leaving me with a bendy-kneed avatar. I would expect Mecanim's retargeting to kick in, appropriately adjusting the animation to the newly sized model.
For reference, if I try to make similar adjustments to the avatar in the editor by directly editing the skeleton's T-Pose positions in edit mode, this works fine. (Note, this is in the Avatar Configuration mode when choosing the Configure your asset's Rig). The animation does seem to get appropriately retargeted to the changed model when playing it afterwards.
My current thought is that I must be missing some API call or whatever trigger to appropriately have the retargeting happen. If any of you is aware of what must be done to have this taken into account I would love to know, because so far trawling through the documentation has not helped much, and the Google gods are not doing me any favours either.
Answer by bart_artanim · Feb 13, 2021 at 11:28 PM
In the end I managed to make this work.
Regarding the first issue where the model disappears when animated, showing errors with invalid AABBs, I have found that re-using an existing HumanDescription
retrieved from the Avatar does not function properly. If I regenerate the description from scratch, it works fine. I have created a sample project of how to do this here on Github.
Regarding the second issue, the answer is simple: make sure that the T-Pose definition you supply has the hip position adjusted to where the feet are planted on the ground (i.e. Y being 0). Just making the legs longer or short and not adjusting the hip will cause animation issues.