diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2021-01-17 00:12:58 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2021-01-18 12:31:05 +0300 |
commit | 25c81824e45b28910cf93a9997e6629dc162f4e7 (patch) | |
tree | 63369910cdfabb65511b199bab0c520e3a6a70f6 | |
parent | b36e7edf2cfa63c5d81f49958b8763f8355c85f4 (diff) |
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.
-rw-r--r-- | rigify/generate.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/rigify/generate.py b/rigify/generate.py index 613ef59f..62f84682 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,7 +391,7 @@ 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 @@ -390,14 +399,6 @@ class Generator(base_generate.BaseGenerator): 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) obj.data["rig_id"] = self.rig_id |