Loading and exporting .anim files at runtime

Alright, mecanim keeps giving me really hard time.

But ranting aside. .anim format itself presents another challenge altogether, due to complete lack of documentation on internal workings of mecanim.
Here’s the current problem i have - Animator permits SetBoneLocalRotation. Which is fine, however - .anim (yaml serialization) format itself (humanoid one, not generic/legacy) contains a set of curves which are muscle set tensors such as

Spine Front-Back
Spine Left-Right
Spine Twist Left-Right
Chest Front-Back
Chest Left-Right
Chest Twist Left-Right
UpperChest Front-Back
UpperChest Left-Right
UpperChest Twist Left-Right
Neck Nod Down-Up
Neck Tilt Left-Right
Neck Turn Left-Right
Head Nod Down-Up
...

…And no way of setting those to animator. Could you, perhaps, provide a table of translating these into direct bone rotations? And also explaining why mecanim is STILL so rigid and under-exposed to scripting, after all this time?

p.s. I mean, I do suspect that you compile animations and state machines into bytecode for sake of speed optimization, but don’t tell me you could’ve not added JIT recompiler for them. This goes completely against every other piece of flexibility unity3d has to offer.

p.p.s. Or is SetBoneLocalRotation for legacy/generics only, and humanoid is completely sealed beyond a rigid wall?

1 Like

Desperate bump

have you try to use the HumanPoseHandler

if you want to know which transform is mapped to which human bone you can use Animator.GetBoneTransform()

also take a look at HumanTrait class which expose all the muscle and to which human transform they map to

Oh, hey. this is actually useful. however - there is another problem with this - you see - Left Upper Leg In-Out, Left Upper Leg Twist In-Out, Left Lower Leg Stretch - these are not directly compatible with Quaternion rotations. Can you explain how to convert from one to another? like to example. twist in-out for the left side of body is reverse of one in right side of body?

The algorithm to convert from FK pose to muscle pose is complex and needs a lot of data that is not accessible from c#, the easiest way to convert it is to use the HumanPoseHandler

Basically you create a HumanPose
https://docs.unity3d.com/ScriptReference/HumanPose.html
you set all the muscle values and then you call
https://docs.unity3d.com/ScriptReference/HumanPoseHandler.SetHumanPose.html

Yes, but what if i’m building a tool to mix animations? I mean sure - i already handle loading, thanks to your post i now fully handle everything. However - i cannot take that prototype outside of unity because you walled off your algorithm.

I mean - does it really matter that you spill out that part of properitary information? it’s still only compliant with unity mecanim. On the other hand it will help me (and potentially anyone else) to build a service system compliant with unity.
Or even - build a better, more open mecanim for unity to begin with and sell it as 3rd party asset (because as I’ve mentioned - rigidness is awfull)

p.s. and no you don’t go out of work either, since you can suck-in all the improvements into your own system, just like unity3d does with most of the best assets (textmeshpro, ngui), you’re still gonna have support and development role.

Ok, i have few questions regarding yaml serialiation itself actually.

  1. m_ClipBindingConstant: what is this?
  2. Why does it mirror it’s own curves with m_EditorCurves ?

We have no plan to publish it and it not because it proprietary information but because it complex and would need a lot of love before it could be published and we simply don’t have the bandwidth for this.

this is all the baked bindings for a clip which tell us which animation curve map to which unity component attribute.

Editor curve like the name imply are not serialized for standalone build, they are all stripped when we do build for the player

Well. this all was successful. Biggest boon of unity3d serialized yaml format is that it can be stripped to bare minimum you require, and rest will be filled with default variables. i’ve been able to build a working .anim exporter. And it works quite alright. So thanks again.

3 Likes

What about importing .anim files at runtime? Is this possible?

(I’ve been googling for a while now and so far the answer appears to be “no”… or at least, not without getting down and dirty with the yaml format, as you have done… but I hope I’m missing something.)

1 Like

Hello forerunner,I meet the same problem now,I need to export .anim files at runtime too. Could you explain how you did it. Thanks for your help!

I second this @smoketh ! Would you be able to share any progress you made on exporting anim at runtime?
Thanks!

Any progress on this would reallly help me, I am quite desperate

I need to export anim curves eith muscles too. How to do that?

So you just create the anim text file yourself not? I am trying that too.
In this way I can createvthe muscle data, so the anim file parser can parse it

Wow I created the exporter too. LOL. It was’nt so Hard…