Removing drivers without losing animation

Is it possible to remove a driver from a shape key and somehow bake the keyframes onto the mesh?

This seems fairly simple, I want a driven shape key with a bone that makes animation easier but when it comes to exporting my animation data I need the keyframes to not be on the bones that I’m using as a control panel but on the actual mesh.

Any Ideas?

If you just need the mesh data then you can export an animation as OBJ data and you get 1 .OBJ file per-frame with the deformed mesh in it.

I probably should have mentioned that we’re working in Unity and using Mega-fiers for the morphs for our character’s face. This means I’m exporting all my shape-keys animation data out as a .mor file but when the keys are controlled by drivers this data isn’t recognised as the keyframes are on the bone controlling the shape key and not the mesh itself.

Thats why I really need to know how to bake animation data from a driver down onto the actual object being driven.

Thanks for getting back to me though, wish that was an option.

Hi danny_anny,

Whilst playing around with drivers I noticed you could also keyframe over the top of them with code. This will give the impression in the UI they are being animated by keyframes, yet the driver takes precedence.

In the example file I have a cube with a shape key driven by the x pos of a bone in the armature. If you run the script you will see that it creates the keyframes for the shape keys, whilst still being driven by the bone. To run the script right click in script window and “run script” (Make sure you have the cube selected (active))


import bpy

context = bpy.context
scene = context.scene
object = context.object

frame = scene.frame_start
scene.frame_set(frame)

while frame <= scene.frame_end:
    object.data.shape_keys.keyframe_insert('key_blocks["Key 1"].value')
    frame = frame + 1
    scene.frame_set(frame)

This is a simple example for only one shapekey, modifying for more isn’t difficult, if you need a hand give me a hoy.

Attachments

driver_to_keyframes.blend (445 KB)

Thanks batFINGER that’s pretty much exactly what I meant! I know very little about scripting or code. What if i wanted to repeat exactly what you just did but for 18 shape keys all driven by separate bones within one armature (acting as a facial control panel)?

I sort of understand the way that script works and I can see that it is specifically set up to affect “Key 1”. Where Key 1 is written, if i wanted to replace it with the names for all of my shape keys how would I go about doing that? If you could just give me an example in terms of Key 1, Key 2, Key 3 etc so i can get an idea of how it works and then replace it with my own shape key names? It would be much easier to do it all in one go than to go through and run the script for each shape key.

Thanks a bunch, incredibly helpful!

This is prob an improvement. It looks at the shapekeys that have drivers and keyframes those.


import bpy

context = bpy.context
scene = context.scene
object = context.object

frame = scene.frame_start

while frame <= scene.frame_end:
    scene.frame_set(frame)
    for fcurve in object.data.shape_keys.animation_data.drivers.values():  
        object.data.shape_keys.keyframe_insert(fcurve.data_path)
    frame = frame + 1

This script will remove the keyframed fcurves for shapekeys with drivers (Clean up after export)


import bpy

context = bpy.context
scene = context.scene
object = context.object

# dictionary of shape_key fcurves keyed by data_path
fcurve_dict = {}
fcurves = object.data.shape_keys.animation_data.action.fcurves
for fcurve in fcurves:
    fcurve_dict[fcurve.data_path] = fcurve

for fcurve in object.data.shape_keys.animation_data.drivers.values():    
    fcurves.remove(fcurve_dict[fcurve.data_path])

This is exactly it. And you’ve given me a clean up script. You’re the Hero that Blender deserves!

Hey i want to say thank you very much, this save me ton of headaches
there’s some error in script

here the link to fix baking driver

the bake remover still works, just the bake script didn’t

anyway, thank you very much!