[Bf-extensions-cvs] [8e02b436] master: Rigify: Remove pass_index driver hack in favor of Custom Property to attach rig script

Demeter Dzadik noreply at git.blender.org
Wed Nov 4 13:02:25 CET 2020


Commit: 8e02b43628efe466a5cbffc724ecab7a0750a44b
Author: Demeter Dzadik
Date:   Wed Nov 4 12:48:27 2020 +0100
Branches: master
https://developer.blender.org/rBA8e02b43628efe466a5cbffc724ecab7a0750a44b

Rigify: Remove pass_index driver hack in favor of Custom Property to attach rig script

In days of old, Custom Properties couldn't store datablock pointers, so a driver variable was used to reference the script datablock, thereby keeping it attached to the rig when the rig is linked or appended. This can now be achieved much more elegantly with one short line of code.

Reviewed By: angavrilov

Differential Revision: https://developer.blender.org/D9082

===================================================================

M	rigify/rig_ui_template.py
M	rigify/utils/rig.py

===================================================================

diff --git a/rigify/rig_ui_template.py b/rigify/rig_ui_template.py
index 4f0ba936..642b5110 100644
--- a/rigify/rig_ui_template.py
+++ b/rigify/rig_ui_template.py
@@ -23,7 +23,6 @@ import bpy
 from collections import OrderedDict
 
 from .utils.animation import SCRIPT_REGISTER_BAKE, SCRIPT_UTILITIES_BAKE
-from .utils.rig import attach_persistent_script
 
 from . import base_generate
 
@@ -1242,4 +1241,4 @@ class ScriptGenerator(base_generate.GeneratorPlugin):
         exec(script.as_string(), {})
 
         # Attach the script to the rig
-        attach_persistent_script(self.obj, script)
+        self.obj['rig_ui'] = script
diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py
index 0c07cfe6..e1957a21 100644
--- a/rigify/utils/rig.py
+++ b/rigify/utils/rig.py
@@ -95,34 +95,6 @@ def get_resource(resource_name):
     return module
 
 
-def attach_persistent_script(obj, script):
-    """Make sure the ui script always follows the rig around"""
-    skip = False
-    driver = None
-
-    if not obj.animation_data:
-        obj.animation_data_create()
-
-    for fcurve in obj.animation_data.drivers:
-        if fcurve.data_path == 'pass_index':
-            driver = fcurve.driver
-            for variable in driver.variables:
-                if variable.name == script.name:
-                    skip = True
-                    break
-            break
-
-    if not skip:
-        if not driver:
-            fcurve = obj.driver_add("pass_index")
-            driver = fcurve.driver
-
-        variable = driver.variables.new()
-        variable.name = script.name
-        variable.targets[0].id_type = 'TEXT'
-        variable.targets[0].id = script
-
-
 def connected_children_names(obj, bone_name):
     """ Returns a list of bone names (in order) of the bones that form a single
         connected chain starting with the given bone as a parent.



More information about the Bf-extensions-cvs mailing list