Exporting shape keys as full meshes

Hi, all!

I need to export shape key data as full separate meshes (including normals, UV textures, etc.)
The idea was to apply shape keys sequentally to the mesh and export its data, but that doesn’t work
for some reason.
I do


                               node.active_shape_key_index = 0
                                for shape in node.data.shape_keys.key_blocks:
                                        shape.value = 1.0
                                        node.data.update()
#here we actually export mesh data from node.data
...
                                        #shape.value = 0
                                        node.data.update()
                                        print("Shape key", shape.name)
                                        node.active_shape_key_index += 1


But I see that all exported data are the same, while meshes are named properly.
This script leaves shape keys applied in Blender GUI, so it seems to work somehow, but exported data is not changed.
Any ideas?

I’ve created this script in attemt to make something working:


import bpy

def display_data(data):
    print(data)
    for l in data.tessfaces:
        print(l)
        print(l.vertices)
        for g in l.vertices:
            print(data.vertices[g].co)

scene = bpy.context.scene
for obj in scene.objects:
    bpy.context.scene.objects.active = obj
    if obj.type == "MESH":
        obj.data.update(calc_tessface=True)
        display_data(obj.data)
        for k in range(0, len(obj.data.shape_keys.key_blocks)):
            shape = obj.data.shape_keys.key_blocks[k]
            print("Shape key: " + shape.name)
            shape.value = 1.0
            obj.active_shape_key_index = k
            obj.data.update()
            scene.update()
            bpy.ops.object.mode_set(mode='EDIT')
            bpy.ops.object.mode_set(mode='OBJECT')
            d = obj.to_mesh(scene, True, "PREVIEW")
            d.update(calc_tessface=True)
            bpy.ops.object.mode_set(mode='EDIT')
            bpy.ops.object.mode_set(mode='OBJECT')
            display_data(d)
            shape.value = 0.0
            obj.data.update()
            d.update()
            scene.update()

I will export instead of display, but I think I miss something - I thing much of this is not needed,
any ideas?

The way I was able to achieve this was to(via script):

  1. duplicate object and make duplicate active/selected and original unselected.
  2. activate the desired shape key.
  3. loop through and delete all shape key while skipping the desired one.
  4. delete desired shape key(this locks in the desired shape key).
  5. export data from mesh
  6. delete object, return focus to original
    rinse, repeat

If this isn’t helpful enough, I can probably find the code I wrote.

Did you check on Object.to_mesh()?

http://www.blender.org/documentation/blender_python_api_2_71_release/bpy.types.Object.html?highlight=to_mesh#bpy.types.Object.to_mesh

Combine it with bpy.context.scene.frame_set(…)