Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2020-12-05 18:59:13 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2020-12-07 14:11:53 +0300
commitc93dc355888ec2f9a4376ad6cf0422277c69d565 (patch)
treecb30669758c2c036c3819b9fecca0a8ef4c5219d /rigify/utils/bones.py
parent53bfa6c93a17b6fa6bcc19f86c3c8df17cb57c5c (diff)
Rigify: keep custom widgets already assigned in metarig.
Also make error handling more robust and extend constraint relink mixin.
Diffstat (limited to 'rigify/utils/bones.py')
-rw-r--r--rigify/utils/bones.py51
1 files changed, 28 insertions, 23 deletions
diff --git a/rigify/utils/bones.py b/rigify/utils/bones.py
index 92b91ade..659afeae 100644
--- a/rigify/utils/bones.py
+++ b/rigify/utils/bones.py
@@ -174,7 +174,7 @@ def copy_bone(obj, bone_name, assign_name='', *, parent=False, inherit_scale=Fal
raise MetarigError("Cannot copy bones outside of edit mode")
-def copy_bone_properties(obj, bone_name_1, bone_name_2):
+def copy_bone_properties(obj, bone_name_1, bone_name_2, transforms=True, props=True, widget=True):
""" Copy transform and custom properties from bone 1 to bone 2. """
if obj.mode in {'OBJECT','POSE'}:
# Get the pose bones
@@ -182,28 +182,33 @@ def copy_bone_properties(obj, bone_name_1, bone_name_2):
pose_bone_2 = obj.pose.bones[bone_name_2]
# Copy pose bone attributes
- pose_bone_2.rotation_mode = pose_bone_1.rotation_mode
- pose_bone_2.rotation_axis_angle = tuple(pose_bone_1.rotation_axis_angle)
- pose_bone_2.rotation_euler = tuple(pose_bone_1.rotation_euler)
- pose_bone_2.rotation_quaternion = tuple(pose_bone_1.rotation_quaternion)
-
- pose_bone_2.lock_location = tuple(pose_bone_1.lock_location)
- pose_bone_2.lock_scale = tuple(pose_bone_1.lock_scale)
- pose_bone_2.lock_rotation = tuple(pose_bone_1.lock_rotation)
- pose_bone_2.lock_rotation_w = pose_bone_1.lock_rotation_w
- pose_bone_2.lock_rotations_4d = pose_bone_1.lock_rotations_4d
+ if transforms:
+ pose_bone_2.rotation_mode = pose_bone_1.rotation_mode
+ pose_bone_2.rotation_axis_angle = tuple(pose_bone_1.rotation_axis_angle)
+ pose_bone_2.rotation_euler = tuple(pose_bone_1.rotation_euler)
+ pose_bone_2.rotation_quaternion = tuple(pose_bone_1.rotation_quaternion)
+
+ pose_bone_2.lock_location = tuple(pose_bone_1.lock_location)
+ pose_bone_2.lock_scale = tuple(pose_bone_1.lock_scale)
+ pose_bone_2.lock_rotation = tuple(pose_bone_1.lock_rotation)
+ pose_bone_2.lock_rotation_w = pose_bone_1.lock_rotation_w
+ pose_bone_2.lock_rotations_4d = pose_bone_1.lock_rotations_4d
# Copy custom properties
- for key in pose_bone_1.keys():
- if key != "_RNA_UI" \
- and key != "rigify_parameters" \
- and key != "rigify_type":
- prop1 = rna_idprop_ui_prop_get(pose_bone_1, key, create=False)
- pose_bone_2[key] = pose_bone_1[key]
- if prop1 is not None:
- prop2 = rna_idprop_ui_prop_get(pose_bone_2, key, create=True)
- for key in prop1.keys():
- prop2[key] = prop1[key]
+ if props:
+ for key in pose_bone_1.keys():
+ if key != "_RNA_UI" \
+ and key != "rigify_parameters" \
+ and key != "rigify_type":
+ prop1 = rna_idprop_ui_prop_get(pose_bone_1, key, create=False)
+ pose_bone_2[key] = pose_bone_1[key]
+ if prop1 is not None:
+ prop2 = rna_idprop_ui_prop_get(pose_bone_2, key, create=True)
+ for key in prop1.keys():
+ prop2[key] = prop1[key]
+
+ if widget:
+ pose_bone_2.custom_shape = pose_bone_1.custom_shape
else:
raise MetarigError("Cannot copy bone properties in edit mode")
@@ -393,9 +398,9 @@ class BoneUtilityMixin(object):
self.register_new_bone(name, bone_name)
return name
- def copy_bone_properties(self, src_name, tgt_name):
+ def copy_bone_properties(self, src_name, tgt_name, **kwargs):
"""Copy pose-mode properties of the bone."""
- copy_bone_properties(self.obj, src_name, tgt_name)
+ copy_bone_properties(self.obj, src_name, tgt_name, **kwargs)
def rename_bone(self, old_name, new_name):
"""Rename the bone, returning the actual new name."""