Created
September 30, 2022 16:28
-
-
Save simonbroggi/baa6dcd1fc4eb2aff59b238cba9fb835 to your computer and use it in GitHub Desktop.
Blender script to convert active attribute to a shape key
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
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