WIP: Rigify - modifier keys on Rig Layers buttons #104998
@ -189,6 +189,19 @@ def is_pose_bone_all_locked(pose_bone: PoseBone) -> bool:
|
|||||||
|
|
||||||
return True
|
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
|
# Operators
|
||||||
|
|
||||||
@ -265,13 +278,9 @@ class RIGIFY_OT_display_select_group(bpy.types.Operator):
|
|||||||
coll = context.object.data.collections[self.collection_name]
|
coll = context.object.data.collections[self.collection_name]
|
||||||
|
|
||||||
if self.action == 'TOGGLE_SELECT':
|
if self.action == 'TOGGLE_SELECT':
|
||||||
|
pose_bones = context.object.pose.bones
|
||||||
for bone in coll.bones:
|
for bone in coll.bones:
|
||||||
if bone.hide:
|
if should_skip_bone(bone, pose_bones):
|
||||||
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]):
|
|
||||||
continue
|
continue
|
||||||
bone.select = not bone.select
|
bone.select = not bone.select
|
||||||
elif self.action == 'UNSELECT':
|
elif self.action == 'UNSELECT':
|
||||||
@ -310,35 +319,39 @@ class RIGIFY_OT_select_bone(bpy.types.Operator):
|
|||||||
class RIGIFY_MT_select_from_group(bpy.types.Menu):
|
class RIGIFY_MT_select_from_group(bpy.types.Menu):
|
||||||
"""Display bones from the active collection in columns"""
|
"""Display bones from the active collection in columns"""
|
||||||
bl_idname = "object.rigify_select_bone_from_group"
|
bl_idname = "object.rigify_select_bone_from_group"
|
||||||
bl_label = "Select bone from group"
|
bl_label = "Select Bone"
|
||||||
|
|
||||||
def draw(self, context):
|
@staticmethod
|
||||||
|
def collect_bone_sides(collection, pose_bones):
|
||||||
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
|
|
||||||
left_bones = []
|
left_bones = []
|
||||||
right_bones = []
|
|
||||||
mid_bones = []
|
mid_bones = []
|
||||||
|
right_bones = []
|
||||||
|
|
||||||
|
digits = ".0123456789" # used for stripping dot and number from bone names
|
||||||
for bone in collection.bones:
|
for bone in collection.bones:
|
||||||
if bone.hide:
|
if should_skip_bone(bone, pose_bones):
|
||||||
continue
|
|
||||||
if bone.name.startswith('VIS_'):
|
|
||||||
continue
|
|
||||||
if is_pose_bone_all_locked(context.object.pose.bones[bone.name]):
|
|
||||||
continue
|
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)
|
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)
|
right_bones.append(bone)
|
||||||
else:
|
else:
|
||||||
mid_bones.append(bone)
|
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.
|
# 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
|
# XOR (^) is True if only one or all three lists contain values
|
||||||
if not all((left_bones, mid_bones, right_bones)) and bool(left_bones) ^ bool(mid_bones) ^ bool(right_bones):
|
if not all((left_bones, mid_bones, right_bones)) and bool(left_bones) ^ bool(mid_bones) ^ bool(right_bones):
|
||||||
|
Loading…
Reference in New Issue
Block a user