Skip to content

Instantly share code, notes, and snippets.

@simonbroggi
Created January 25, 2019 17:45
Show Gist options
  • Save simonbroggi/5c8ff4c609826f7e6f81f61737eb8578 to your computer and use it in GitHub Desktop.
Save simonbroggi/5c8ff4c609826f7e6f81f61737eb8578 to your computer and use it in GitHub Desktop.
Blender script to generate shapekey from armature (or other) deformation
# generate shapekey from armature (or other) deformation
# deformation should not change the vertex order
import bpy
obj = bpy.context.selected_objects[0]
# use to_mesh to get deformed mesh data
# https://blender.stackexchange.com/questions/34789/how-to-get-vertex-coordinates-after-modifier-in-python
temp_data = obj.to_mesh(bpy.context.scene, True, 'PREVIEW')
verts = temp_data.vertices
# generate shapekey with shape_key_add and set the coordinates
# https://blender.stackexchange.com/questions/111661/creating-shape-keys-using-python
sk = obj.shape_key_add('Deform')
sk.interpolation = 'KEY_LINEAR'
for i in range(len(verts)):
sk.data[i].co = verts[i].co
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment