Created
January 25, 2019 17:45
-
-
Save simonbroggi/5c8ff4c609826f7e6f81f61737eb8578 to your computer and use it in GitHub Desktop.
Blender script to generate shapekey from armature (or other) deformation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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