From 25c81824e45b28910cf93a9997e6629dc162f4e7 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov <angavrilov@gmail.com> Date: Sun, 17 Jan 2021 00:12:58 +0300 Subject: [PATCH] Rigify: fix the ORG bone rename affecting objects dependent on the rig. The issue is that if a different object has a constraint or driver targeting a control of the rig, renaming the bone after join when re-generating the rig would change that target to the ORG bone. To fix this, apply the renames to the temporary copy of the metarig before joining it to the rig armature object. This also requires moving the driver freeze to this stage. --- rigify/generate.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/rigify/generate.py b/rigify/generate.py index 613ef59fd..62f846826 100644 --- a/rigify/generate.py +++ b/rigify/generate.py @@ -172,6 +172,14 @@ class Generator(base_generate.BaseGenerator): bpy.ops.object.duplicate() + # Rename org bones in the temporary object + temp_obj = context.view_layer.objects.active + + assert temp_obj and temp_obj != metarig + + self.__freeze_driver_vars(temp_obj) + self.__rename_org_bones(temp_obj) + # Select the target rig and join select_object(context, obj) @@ -192,6 +200,9 @@ class Generator(base_generate.BaseGenerator): for track in obj.animation_data.nla_tracks: obj.animation_data.nla_tracks.remove(track) + + def __freeze_driver_vars(self, obj): + if obj.animation_data: # Freeze drivers referring to custom properties for d in obj.animation_data.drivers: for var in d.driver.variables: @@ -202,9 +213,7 @@ class Generator(base_generate.BaseGenerator): tar.data_path = "RIGIFY-" + tar.data_path - def __rename_org_bones(self): - obj = self.obj - + def __rename_org_bones(self, obj): #---------------------------------- # Make a list of the original bones so we can keep track of them. original_bones = [bone.name for bone in obj.data.bones] @@ -382,21 +391,13 @@ class Generator(base_generate.BaseGenerator): childs[child] = child.parent_bone #------------------------------------------ - # Copy bones from metarig to obj + # Copy bones from metarig to obj (adds ORG_PREFIX) self.__duplicate_rig() obj.data.use_mirror_x = False t.tick("Duplicate rig: ") - #------------------------------------------ - # Add the ORG_PREFIX to the original bones. - bpy.ops.object.mode_set(mode='OBJECT') - - self.__rename_org_bones() - - t.tick("Make list of org bones: ") - #------------------------------------------ # Put the rig_name in the armature custom properties rna_idprop_ui_prop_get(obj.data, "rig_id", create=True) -- GitLab