Store each animation frame as new object Is it possible to store each animation frame as a new object? I searched quite a long time now on google and was wondering that I cannot find any information about this.

I just have a simple model with a simple pose animation and I'm looking for a way to get each frame stored as a new object, that I end up with maybe 100 objects "frame001", "frame002", "frame003", ...

I need this for a game engine that does not support bone animations, but I can fake such an animation by exporting this object (as a collada) and then setting only one of the "frame-objects" visible in this engine.



I tried to write a quick and dirty python script myself after some basic reading, but unfortunately the most important action (the conversion to a mesh) does not work:

import bpy

count=0

for x in range(bpy.data.scenes["Scene"].frame_start,bpy.data.scenes["Scene"].frame_end):
    bpy.ops.object.duplicate_move()

bpy.ops.object.select_all(action='DESELECT')

obs = bpy.data.objects
bpy.data.scenes["Scene"].frame_current=0        
for ob in obs:
    bpy.ops.object.select_all(action='DESELECT')
    if ob.type == 'MESH' and ob.name.startswith("model"):
        if count&gt;0:
            ob.select=True
            bpy.ops.object.convert(target='MESH')
            bpy.data.scenes["Scene"].frame_current+=1
        count=count+1
You should avoid operators whenever possible:

import bpy

scene = bpy.context.scene
frame_current = scene.frame_current

for f in range(scene.frame_start, scene.frame_end + 1):
    scene.frame_set(f)

    meshes = []
    for ob in scene.objects:
        if ob.type == 'MESH' and ob.name.startswith("model"):
            me = ob.to_mesh(scene, True, 'PREVIEW')
            meshes.append(me)

    # do something with the meshes (note: they aren't linked to anything)

    # Clean up mesh copies
    for me in meshes:
        bpy.data.meshes.remove(me)

scene.frame_set(frame_current)


This will apply modifiers to all mesh objects in the current scene that start with the name model. The resulting (new!) mesh datablocks can be used for export.

Note however, that you will have to create objects and link the meshes to them if you plan to call an export operator - they usually export all (selected) objects, not invisible mesh datablocks. You may wanna check out the exporter code and see if you can import the actual export routine to avoid that operator call and maybe even the object creation.



If you want to apply animation in a way, that there's one static object per frame of an animated model, you may use the following script:

import bpy

scene = bpy.context.scene
frame_current = scene.frame_current

r = range(scene.frame_start, scene.frame_end + 1)
l = len(str(len(r)))
obs = []

for f in r:
    scene.frame_set(f)

    for ob in scene.objects:
        if ob.type == 'MESH' and ob.name.startswith("model"):
            me = ob.to_mesh(scene, True, 'PREVIEW')
            me.transform(ob.matrix_world)
            new_ob = bpy.data.objects.new("%s_frame%0*i" % (ob.name, l, f), me)
            obs.append(new_ob)

scene.frame_set(frame_current)
for ob in obs:
    scene.objects.link(ob)
scene.update()


It applies modifiers as well as transformations (.matrix_world, so loc/rot/scale).