Skip to content

Commit

Permalink
Adds support for drivers on shapekeys (#2) and prepares addon for sub…
Browse files Browse the repository at this point in the history
…mission to blender extensions
  • Loading branch information
smokejohn committed Jan 1, 2025
1 parent 4b9bb90 commit ec831f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
30 changes: 23 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@

bl_info = {
"name": "SKkeeper",
"description": "Applies modifiers and keeps shapekeys",
"author": "Johannes Rauch",
"version": (1, 7),
"version": (1, 8, 0),
"blender": (2, 80, 3),
"location": "Search > Apply modifiers (Keep Shapekeys)",
"description": "Applies modifiers and keeps shapekeys",
"category": "Utility",
"wiki_url": "https://github.com/smokejohn/SKkeeper",
"location": "View3D > Object",
"doc_url": "https://github.com/smokejohn/SKkeeper",
"tracker_url": "https://github.com/smokejohn/SKkeeper/issues",
"category": "Object",
}

import time
Expand Down Expand Up @@ -285,10 +286,25 @@ def keep_shapekeys(self, mode=Mode.ALL):
bpy.data.objects.remove(shapekey_obj)
bpy.data.meshes.remove(mesh_data)


# delete the original and its mesh data
orig_name = self.obj.name
orig_data = self.obj.data

# transfer over drivers on shapekeys if they exist
if orig_data.shape_keys.animation_data is not None:
receiver.data.shape_keys.animation_data_create()
for orig_driver in orig_data.shape_keys.animation_data.drivers:
receiver.data.shape_keys.animation_data.drivers.from_existing(src_driver=orig_driver)

# if the driver has variable targets that refer to the original object we need to
# retarget them to the new receiver because we delete the original object later
for fcurve in receiver.data.shape_keys.animation_data.drivers:
for variable in fcurve.driver.variables:
for target in variable.targets:
if target.id == self.obj:
target.id = receiver


# delete the original and its mesh data
bpy.data.objects.remove(self.obj)
bpy.data.meshes.remove(orig_data)

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

name=SKkeeper
version=v1.7
version=v1.8.0
folder=./SKkeeper

mkdir "$folder"
Expand Down
Binary file added tests/testtfile_driver_on_shapekey.blend
Binary file not shown.

0 comments on commit ec831f1

Please sign in to comment.