animating datablocks

I NEED HELP! :slight_smile:
Does anyone out there know how I might be able to swap out one piece of mesh for another during animation? I’d really like to be able to call different mouth shapes out by animating the mesh datablock but that doesn’t seem to be able to be animated.

Any thoughts would be appreciated.

It’s for my thread here::

http://www.blenderartists.org/forum/showthread.php?330479-Ron-amp-Obi-Exploring-2D-animation-in-Blender

Glenn

Assuming that you are not using shape keys for some reason (this is what they are for) you could write a frame_change handler that swapped datablocks on specific frames.

Here is a simple setup if you are code inclined.


import bpy
def pre_frame_change(scene):
    lst_datablocks = ['shape-1', 'shape-2','shape-3']   # Name of datablocks in memory.
    lst_frames_to_change_on = [15,45,75]                # Frame number associated datablock should be active.
    ob_to_swap_into = 'Cube'                                  # Name of your object here (swap container).
    ob = bpy.data.objects.get(ob_to_swap_into)
    for i,frame_num in enumerate(lst_frames_to_change_on):
        if scene.frame_current == frame_num:
            # Time to swap datablocks.
            db = bpy.data.meshes.get(lst_datablocks[i])
            if db != None:
                ob.data = db        # Assign new datablock to container object.
                break
            else:
                # Name fetched from list does not exist in memory.
                pass


bpy.app.handlers.frame_change_pre.append(pre_frame_change)

Shape keys don’t always have the flexibility of good ol’ replacement.

Gonna have to try that code out soon :slight_smile: