diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-14 09:22:52 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-14 09:30:01 +0300 |
commit | 6aabd3a966a34faf40e27a557c217218d8fed01f (patch) | |
tree | 288f22cde130b1560750b8e37011f6d116acbfe5 /rigify | |
parent | d43b2ca4a9f31a9a3f988473a65de2095c9cfcc8 (diff) |
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
Diffstat (limited to 'rigify')
-rw-r--r-- | rigify/__init__.py | 28 | ||||
-rw-r--r-- | rigify/base_rig.py | 6 |
2 files changed, 34 insertions, 0 deletions
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 |