Last active
June 25, 2023 01:53
-
-
Save dtupper/de61c102702b08d3fcb5af328746e0c1 to your computer and use it in GitHub Desktop.
reset_selected_verts_to_basis.py
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 | |
def set_basis_shapekey(ignore_keys=[], ignore_active=False): | |
obj = bpy.context.active_object | |
if obj.type != 'MESH': | |
print("Active object is not a Mesh") | |
return | |
if len(obj.data.shape_keys.key_blocks) < 2: | |
print("Not enough shape keys") | |
return | |
basis_key = obj.data.shape_keys.key_blocks['Basis'] | |
selected_verts = [v for v in obj.data.vertices if v.select] | |
active_key = obj.active_shape_key | |
for key in obj.data.shape_keys.key_blocks[1:]: | |
if key.name in ignore_keys or (ignore_active and key == active_key): | |
print(f"Skipping shape key: {key.name}") | |
continue | |
print(f"Processing shape key: {key.name}") | |
for vert in selected_verts: | |
diff_vector = key.data[vert.index].co - basis_key.data[vert.index].co | |
key.data[vert.index].co -= diff_vector | |
# call the function with shape key names to ignore and a flag to ignore the active key | |
set_basis_shapekey(['shape_key_1', 'shape_key_2'], True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment