[Bf-extensions-cvs] [6aabd3a9] master: Rigify: add a generic callback for all rig parameters.

Alexander Gavrilov noreply at git.blender.org
Sat Sep 14 08:34:19 CEST 2019


Commit: 6aabd3a966a34faf40e27a557c217218d8fed01f
Author: Alexander Gavrilov
Date:   Sat Sep 14 09:22:52 2019 +0300
Branches: master
https://developer.blender.org/rBA6aabd3a966a34faf40e27a557c217218d8fed01f

Rigify: add a generic callback for all rig parameters.

This may be useful for things like mirroring. Since the parameter
name space is shared by all rigs, it would be inappropriate for
individual rigs to add their specific callbacks to properties.

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

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

M	rigify/__init__.py
M	rigify/base_rig.py

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

diff --git a/rigify/__init__.py b/rigify/__init__.py
index 0ca663a8..35669a6a 100644
--- a/rigify/__init__.py
+++ b/rigify/__init__.py
@@ -267,6 +267,31 @@ class RigifySelectionColors(bpy.types.PropertyGroup):
 class RigifyParameters(bpy.types.PropertyGroup):
     name: StringProperty()
 
+# Parameter update callback
+
+in_update = False
+
+def update_callback(prop_name):
+    from .utils.rig import get_rigify_type
+
+    def callback(params, context):
+        global in_update
+        # Do not recursively call if the callback updates other parameters
+        if not in_update:
+            try:
+                in_update = True
+                bone = context.active_pose_bone
+
+                if bone and bone.rigify_parameters == params:
+                    rig_info = rig_lists.rigs.get(get_rigify_type(bone), None)
+                    if rig_info:
+                        rig_cb = getattr(rig_info["module"].Rig, 'on_parameter_update', None)
+                        if rig_cb:
+                            rig_cb(context, bone, params, prop_name)
+            finally:
+                in_update = False
+
+    return callback
 
 # Remember the initial property set
 RIGIFY_PARAMETERS_BASE_DIR = set(dir(RigifyParameters))
@@ -328,6 +353,9 @@ class RigifyParameterValidator(object):
         # actually defining the property modifies the dictionary with new parameters, so copy it now
         new_def = (val[0], val[1].copy())
 
+        # inject a generic update callback that calls the appropriate rig classmethod
+        val[1]['update'] = update_callback(name)
+
         setattr(self.__params, name, val)
         self.__prop_table[name] = (self.__rig_name, new_def)
 
diff --git a/rigify/base_rig.py b/rigify/base_rig.py
index cae0e569..6b01c43a 100644
--- a/rigify/base_rig.py
+++ b/rigify/base_rig.py
@@ -236,6 +236,12 @@ class BaseRig(GenerateCallbackHost, RaiseErrorMixin, BoneUtilityMixin, Mechanism
         """
         layout.label(text="No options")
 
+    @classmethod
+    def on_parameter_update(cls, context, pose_bone, params, param_name):
+        """
+        A callback invoked whenever a parameter value is changed by the user.
+        """
+
 
 #=============================================
 # Rig Utility



More information about the Bf-extensions-cvs mailing list