- Home /
Import Blender Animation without Unnecessary Keyframes?
This question pertains to importing animations into the legacy Animation system.
Whenever I import an animated mesh from Blender, be it using the built-in Unity FBX Importer (importing a .blend file), or the built-in Blender FBX Exporter (importing a .fbx file), the resultant AnimationClips have keyframes defined for all bones, even those that are not being animated. These bones have keyframes associated with their localPosition/localRotation/localScale and are flat linear curves -- they do nothing but hold the bone stationary.
Holding bones stationary breaks animation blending. All animation clips define animation states for every bone, so animations cannot fall through to lower layers. (Additive blending works fine, of course.)
Is there something I am missing in my export pipeline? In my import pipeline?
EDIT: I did some more research and tracked down a Blender Developer a lot more knowledgeable than me about this process. Ultimately, he told me that its not really possible if you're using IK. The IK propogate to other bones, which can themselves be under the effects of IK, and propogate further, etc, to the point where you have to distinguish between tiny floating point values and zero to know if the bone is being animated in an action or not.
He mentioned other constraints in the form of additional ways for a bone to be indirectly animated (drivers, unusual parenting with hinges, "etc"), which I did not understand but figured was worth mentioning.
So what are my options? I can duplicate an animation and remove the bones I don't think are animated in a given animation, and set up a Unity AssetPostProcessor which copies my imported animations to the target duplicate, inheriting the same bone rejection as before, or I can forfeit animation blending and depend on additive blending instead. For now, I think I will go with the latter, though I'm not happy about it.
A hack, if you can't get the import fixed (or if it just always animates all bones?), is to use Add$$anonymous$$ixingTransform. It tells an animation to only use certain bones.
Answer by Loius · May 19, 2014 at 02:58 PM
Back in blender 2.49 I had to rewrite their export script - it was export_fbx.py or something like that. Simple change once I figured out the language, just had to say "if no bone data continue" inside the bone's for-loop and everything worked out.
...
Looks like 2.6 still uses export_fbx.py. Might be able to find the issue by searching for 'animation' or 'bones'. I don't remember the specifics. :(
Edit: But I found them: http://answers.unity3d.com/questions/29802/playing-two-animations-from-one-armature.html
Thanks Loius, this looks very promising. I am using a more recent version of Blender (2.7, 2014) than this refers to (??, 2010) and the export_fbx.py file has changed dramatically since then so I don't really know how to implement the suggested changes.
Any additional assistance would be greatly appreciated. :)
Here's the current export_fbx.py: http://pastebin.com/e0J3Gtx6
looks like this is replacement for the part i changed before:
#for bonename, bone, obname, me, armob in ob_bones:
for ob_generic in (ob_bones, ob_meshes, ob_null, ob_cameras, ob_lights, ob_arms):
for my_ob in ob_generic:
if ob_generic == ob_meshes and my_ob.fbxArm:
# do nothing,
pass
else:
It looks like blenName and blenAction still exist, soooo maaaaybe that last else could change to:
elif ob_generic == ob_bones and my_ob.blenName in blenAction.getChannelNames():
crossed fingers
that'll probably disable all animation besides keyframed bones if it works
you need "if this bone's name is in the action's channel names"
Thanks Loius, I appreciate the effort. That was the same conversion that I gathered to try, but getChannelNames is depreciated (no longer exists, to be precise). I tried to look around the API but didn't get much of anywhere.
Here is the Action object that blenAction represents, I think: http://www.blender.org/documentation/blender_python_api_2_68a_release/bpy.types.Action.html
Which has a collection member "groups", which has a collection member "channels". I tried to impart some python-fu to get at the same logic, assu$$anonymous$$g these channels are the same referenced by your getChannelNames (could be completely different), but ultimately couldn't figure it out.
It's possible that blenAction.groups' names is the old getChannelNames. Create a new array that is all of them together?
Unfortunately I barely know python. Something like this?
channelNames = [g.name for g in blenAction.groups]
If that's not it, it might be the .channels, which sould be something like this:
channelNames = [c.name for c in [g.channels for g in blenAction.groups]]
I just copied the syntax from that file, I hope it makes sense. x_x
Did some more research and tracked down a Blender Developer a lot more knowledgeable than me about this process. Ultimately, he told me that its not really possible if you're using I$$anonymous$$. The I$$anonymous$$ propogate to other bones, which can themselves be under the effects of I$$anonymous$$, and propogate further, etc, to the point where you have to distinguish between tiny floating point values and zero to know if the bone is being animated in an action or not.
He mentioned other constraints in the form of additional ways for a bone to be indirectly animated (drivers, unusual parenting with hinges, "etc"), which I did not understand but figured was worth mentioning.
So what are my options? I can duplicate an animation and remove the bones I don't think are animated in a given animation, and set up a Unity AssetPostProcessor which copies my imported animations to the target duplicate, inheriting the same bone rejection as before, or I can forfeit animation blending and depend on additive blending ins$$anonymous$$d. For now, I think I will go with the latter, though I'm not happy about it.
Your answer
Follow this Question
Related Questions
importing destructible object from blender 0 Answers
Blender Scaling Import Problem. 1 Answer
Blender to Unity animations not importing correctly 1 Answer
Unity Partially Ignoring Blender Animation 1 Answer
Mecanim animation importing 2 Answers