WIP: Rigify - modifier keys on Rig Layers buttons #104998

Draft
Paolo Acampora wants to merge 6 commits from PaoloAcampora/rigify-ui-improvements:panel_modifier_keys into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit 87935385e5 - Show all commits

View File

@ -189,6 +189,19 @@ def is_pose_bone_all_locked(pose_bone: PoseBone) -> bool:
return True
def should_skip_bone(bone, pose_bones):
"""Return True if the bone should not be used (hidden, locked, etc..)"""
if bone.hide:
return True
if bone.name.startswith('VIS_'):
# "VIS_*" bones are used for drawing lines, e.g. line connecting knee to IK pole
return True
if is_pose_bone_all_locked(pose_bones[bone.name]):
return True
return False
# =============================================
# Operators
@ -265,13 +278,9 @@ class RIGIFY_OT_display_select_group(bpy.types.Operator):
coll = context.object.data.collections[self.collection_name]
if self.action == 'TOGGLE_SELECT':
pose_bones = context.object.pose.bones
for bone in coll.bones:
if bone.hide:
continue
if bone.name.startswith('VIS_'):
# "VIS_*" bones are used for drawing lines, e.g. line connecting knee to IK pole
continue
if is_pose_bone_all_locked(context.object.pose.bones[bone.name]):
if should_skip_bone(bone, pose_bones):
continue
bone.select = not bone.select
elif self.action == 'UNSELECT':
@ -310,34 +319,38 @@ class RIGIFY_OT_select_bone(bpy.types.Operator):
class RIGIFY_MT_select_from_group(bpy.types.Menu):
"""Display bones from the active collection in columns"""
bl_idname = "object.rigify_select_bone_from_group"
bl_label = "Select bone from group"
bl_label = "Select Bone"
def draw(self, context):
layout = self.layout
collection = context.object.data.collections.active
layout.label(text=collection.name)
# we need to know the side of each bone in advance
@staticmethod
def collect_bone_sides(collection, pose_bones):
left_bones = []
right_bones = []
mid_bones = []
right_bones = []
digits = ".0123456789" # used for stripping dot and number from bone names
for bone in collection.bones:
if bone.hide:
continue
if bone.name.startswith('VIS_'):
continue
if is_pose_bone_all_locked(context.object.pose.bones[bone.name]):
if should_skip_bone(bone, pose_bones):
continue
if bone.name.rstrip(f'.{i for i in range(10)}').endswith('.L'): # e.g. "*.L", "*.L.015", "*.L.023"
if bone.name.rstrip(digits).endswith('.L'): # e.g. "*.L", "*.L.015", "*.L.023"
left_bones.append(bone)
elif bone.name.rstrip(f'.{i for i in range(10)}').endswith('.R'): # e.g. "*.R", "*.R.015", "*.R.023"
continue
if bone.name.rstrip(digits).endswith('.R'): # e.g. "*.R", "*.R.015", "*.R.023"
right_bones.append(bone)
else:
mid_bones.append(bone)
return left_bones, mid_bones, right_bones
def draw(self, context):
collection = context.object.data.collections.active
# we need to know the side of each bone in advance
left_bones, mid_bones, right_bones = self.collect_bone_sides(collection, context.object.pose.bones)
layout = self.layout
# layout.label(text=collection.name)
# in case all the bones belong to one side, take all three columns and then bail out.
# XOR (^) is True if only one or all three lists contain values
@ -352,7 +365,7 @@ class RIGIFY_MT_select_from_group(bpy.types.Menu):
if left_bones:
column = row.column()
for bone in left_bones:
column.operator(RIGIFY_OT_select_bone.bl_idname, text=bone.name).bone_name = bone.name
column.operator(RIGIFY_OT_select_bone.bl_idname, text=bone.name).bone_name = bone.name
if mid_bones:
column = row.column()