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?