# How to bake softbody animation into keyframes?

I am trying to bake a softbody animation into keyframes but I can't, does anyone knows how to do it? Thanks!

• Could you add some specifics like what version you are using, what you have tried already, etc? – VRM Jan 21 '15 at 19:33
• – gandalf3 Jan 21 '15 at 20:10
• Hi there, I am using version 2.72 and I am trying to export a mesh with soft-body in .FBX format but can't achieve this. – Hernan Jan 22 '15 at 12:42

You can't bake softbody into keyframes anymore, blender uses shape keys now. So you would need to generate a shape key for every frame of animation and also keyframe that shapekey to its frame. You do that with running this script:

import bpy

obj = bpy.context.active_object
start = bpy.context.scene.frame_start
end = bpy.context.scene.frame_end

def insert_keyframe(sk, f):
sk.keyframe_insert("value", frame=f-1)
sk.keyframe_insert("value", frame=f+1)
sk.value = 1.0
sk.keyframe_insert("value", frame=f)

meshes = []
for f in range(start, end+1):
bpy.context.scene.frame_set(f)
meshes.append(obj.to_mesh(scene=bpy.context.scene, apply_modifiers=True, settings='PREVIEW'))

for i in range(0, end-start+1):
insert_keyframe(key, i+start)
for vert_id in range(len(obj.data.vertices)):
key.data[vert_id].co = meshes[i].vertices[vert_id].co

for mesh in meshes:
bpy.data.meshes.remove(mesh)


Don't forget to turn your modifier off or to delete it (or it will override the shape key animation)

Also you can export your softbody animation as an New Tek's .mdd mesh cache format (export addon will do this) and load this file into Mesh Cache modifier. This allows you to for example offset the animation and further manipulate it.

• Thanks Jerryno for your response!, ok I achieved exporting in .mdd format and load it in the Mesh Cache modifier. Also y deleted the soft-body physics and it works perfectly. Now I would need to export it in .FBX, but apparently something is missing because in the fbx preview visor the effect doesn't appear, should I do something else to export it correctly? Thank you! – Hernan Jan 21 '15 at 20:34
• Also how can I generate a shape key for every frame of animation and also keyframe that shapekey to its frame? – Hernan Jan 22 '15 at 13:03
• OK, I could manage to have my mesh with shape keys!, the problem is that i need to export it in .FBX (ASCII), do you know how can I solve this?? – Hernan Jan 22 '15 at 14:32
• @Pete Yep for such situation it would be better to design the script a bit differently. Maybe also some workflow already exist for your application. This would be a good new question on this site, better searchable for other users also. If no one beats me to it I'll post the altered script as an answer or a better solution if there is. – Jaroslav Jerryno Novotny Aug 11 '15 at 7:14
• Thanks man! I've done so here: blender.stackexchange.com/questions/35547/… – Pete Aug 12 '15 at 3:02

I need to chime in, just because I had the same question - but wound up with a different take on kind of the same answer as above:

I agree with the sentiment that "you can't bake them into key frames" anymore - but you can run the script above to do so - however, (at least in my case) what I wanted to do was to tweak and better control how/when/where the animation was played back.

So in my case, merely animating the shape keys themselves was ideal. This means, after you have your softbody/cloth or whatever simulation - go into the "modifier" and "save to shape key". Then, just animate that shape key in the graph editor/dopesheet - just as you would have done to your mesh.

This is actually much cleaner than editing animations recorder through the blender game engine (which is what I thought it would be like to "export" the physics mesh animation to keyframes) - where you would have one keyframe for every frame. (This is what the script above gives you - and you wouldnt' need that either). You just have keyframe points at any time you create a keyframe for your shape key changing.

Sorry for the longwinded explanation - but now I understand why they mad you do it with the shape keys - and am happier for it!