Skip to content
Snippets Groups Projects
Commit 25c81824 authored by Alexander Gavrilov's avatar Alexander Gavrilov
Browse files

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.
parent b36e7edf
No related branches found
No related tags found
No related merge requests found
...@@ -172,6 +172,14 @@ class Generator(base_generate.BaseGenerator): ...@@ -172,6 +172,14 @@ class Generator(base_generate.BaseGenerator):
bpy.ops.object.duplicate() 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 the target rig and join
select_object(context, obj) select_object(context, obj)
...@@ -192,6 +200,9 @@ class Generator(base_generate.BaseGenerator): ...@@ -192,6 +200,9 @@ class Generator(base_generate.BaseGenerator):
for track in obj.animation_data.nla_tracks: for track in obj.animation_data.nla_tracks:
obj.animation_data.nla_tracks.remove(track) obj.animation_data.nla_tracks.remove(track)
def __freeze_driver_vars(self, obj):
if obj.animation_data:
# Freeze drivers referring to custom properties # Freeze drivers referring to custom properties
for d in obj.animation_data.drivers: for d in obj.animation_data.drivers:
for var in d.driver.variables: for var in d.driver.variables:
...@@ -202,9 +213,7 @@ class Generator(base_generate.BaseGenerator): ...@@ -202,9 +213,7 @@ class Generator(base_generate.BaseGenerator):
tar.data_path = "RIGIFY-" + tar.data_path tar.data_path = "RIGIFY-" + tar.data_path
def __rename_org_bones(self): def __rename_org_bones(self, obj):
obj = self.obj
#---------------------------------- #----------------------------------
# Make a list of the original bones so we can keep track of them. # Make a list of the original bones so we can keep track of them.
original_bones = [bone.name for bone in obj.data.bones] original_bones = [bone.name for bone in obj.data.bones]
...@@ -382,21 +391,13 @@ class Generator(base_generate.BaseGenerator): ...@@ -382,21 +391,13 @@ class Generator(base_generate.BaseGenerator):
childs[child] = child.parent_bone childs[child] = child.parent_bone
#------------------------------------------ #------------------------------------------
# Copy bones from metarig to obj # Copy bones from metarig to obj (adds ORG_PREFIX)
self.__duplicate_rig() self.__duplicate_rig()
obj.data.use_mirror_x = False obj.data.use_mirror_x = False
t.tick("Duplicate rig: ") 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 # Put the rig_name in the armature custom properties
rna_idprop_ui_prop_get(obj.data, "rig_id", create=True) rna_idprop_ui_prop_get(obj.data, "rig_id", create=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment