Skip to content

Instantly share code, notes, and snippets.

@simonbroggi
Created September 30, 2022 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonbroggi/baa6dcd1fc4eb2aff59b238cba9fb835 to your computer and use it in GitHub Desktop.
Save simonbroggi/baa6dcd1fc4eb2aff59b238cba9fb835 to your computer and use it in GitHub Desktop.
Blender script to convert active attribute to a shape key
import bpy
# convert the activ attribute to a shape key
# the active attribute is expected to be a Vector in the Vertex domain
def active_attribute_to_shape_key(context):
obj = context.active_object
mesh = obj.data
attribute_index = mesh.attributes.active_index
attribute = mesh.attributes[attribute_index]
# if there are no shape keys, add the Basis Shape Key
if not mesh.shape_keys:
sk_basis = obj.shape_key_add(name="Basis")
sk_basis.interpolation = 'KEY_LINEAR'
# add shape key with the name of the selected attribute
sk_attribute = obj.shape_key_add(name=attribute.name)
sk_attribute.interpolation = 'KEY_LINEAR'
# assign the values from the attribute to the shape key
for i in range(len(mesh.vertices)):
sk_attribute.data[i].co = attribute.data[i].vector
active_attribute_to_shape_key(bpy.context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment