Node wrangler: Node socket interface class changed. #104849

Merged
Lukas Tönne merged 2 commits from LukasTonne/blender-addons:node-panels-final into main 2023-08-30 12:38:13 +02:00
46 changed files with 2472 additions and 5641 deletions
Showing only changes of commit 3dec88ba1a - Show all commits

View File

@ -23,7 +23,7 @@ from bl_ui_utils.layout import operator_context
class PoseLibraryPanel:
@classmethod
def pose_library_panel_poll(cls, context: Context) -> bool:
return bool(context.object and context.object.mode == 'POSE')
return context.mode == 'POSE'
@classmethod
def poll(cls, context: Context) -> bool:

View File

@ -5,8 +5,8 @@
bl_info = {
"name": "Copy Render Settings",
"author": "Bastien Montagne",
"version": (1, 2, 0),
"blender": (3, 6, 0),
"version": (2, 0, 0),
"blender": (4, 0, 0),
"location": "Render buttons (Properties window)",
"description": "Allows to copy a selection of render settings "
"from current scene to others.",

View File

@ -36,12 +36,20 @@ def scene_render_copy_settings_update():
# Get all available render settings, and update accordingly affected_settings…
props = {}
for prop in current_scene.render.bl_rna.properties:
for prop_container_id in (('render',), ('cycles',), ('eevee',), ('display', 'shading')):
prop_container = current_scene
for pc_id_item in prop_container_id:
prop_container = getattr(prop_container, pc_id_item, None)
if prop_container is None:
break
if prop_container is None:
continue;
for prop in prop_container.bl_rna.properties:
if prop.identifier in {'rna_type'}:
continue
if prop.is_readonly:
continue
props[prop.identifier] = prop.name
props[".".join(prop_container_id) + "." + prop.identifier] = prop.name
corr = 0
for i, sett in enumerate(cp_sett.affected_settings):
if sett.strid not in props:
@ -130,17 +138,28 @@ class RenderCopySettingsOPPreset(bpy.types.Operator):
# Real interesting stuff…
def do_copy(context, affected_settings, allowed_scenes):
# Stores render settings from current scene.
p = {sett: getattr(context.scene.render, sett)
for sett in affected_settings}
def resolve_rnapath_get(bdata, rna_path_items):
for item in rna_path_items:
bdata = getattr(bdata, item, None)
if bdata is None:
break
return bdata
def resolve_rnapath_set(bdata, rna_path_items, value):
bdata = resolve_rnapath_get(bdata, rna_path_items[:-1])
setattr(bdata, rna_path_items[-1], value)
# Stores various render settings from current scene.
p = {rna_path_items: resolve_rnapath_get(context.scene, rna_path_items)
for rna_path_items in affected_settings}
# put it in all other (valid) scenes render settings!
for scene in bpy.data.scenes:
# If scene not in allowed scenes, skip.
if scene.name not in allowed_scenes:
continue
# Propagate all affected settings.
for sett, val in p.items():
setattr(scene.render, sett, val)
for rna_path_items, val in p.items():
resolve_rnapath_set(scene, rna_path_items, val)
class RenderCopySettingsOPCopy(bpy.types.Operator):
@ -157,7 +176,7 @@ class RenderCopySettingsOPCopy(bpy.types.Operator):
def execute(self, context):
regex = None
cp_sett = context.scene.render_copy_settings
affected_settings = {sett.strid for sett in cp_sett.affected_settings if sett.copy}
affected_settings = {tuple(sett.strid.split(".")) for sett in cp_sett.affected_settings if sett.copy}
allowed_scenes = {sce.name for sce in cp_sett.allowed_scenes if sce.allowed}
do_copy(context, affected_settings=affected_settings, allowed_scenes=allowed_scenes)
return {'FINISHED'}

View File

@ -4,9 +4,9 @@
bl_info = {
"name": "Rigify",
"version": (0, 6, 7),
"version": (0, 6, 8),
"author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello, Alexander Gavrilov", # noqa
"blender": (3, 0, 0),
"blender": (4, 0, 0),
"description": "Automatic rigging from building-block components",
"location": "Armature properties, Bone properties, View3d tools panel, Armature Add menu",
"doc_url": "{BLENDER_MANUAL_URL}/addons/rigging/rigify/index.html",
@ -339,6 +339,12 @@ class RigifyColorSet(bpy.types.PropertyGroup):
)
standard_colors_lock: BoolProperty(default=True)
def apply(self, color: bpy.types.BoneColor):
color.palette = 'CUSTOM'
color.custom.normal = utils.misc.gamma_correct(self.normal)
color.custom.select = utils.misc.gamma_correct(self.select)
color.custom.active = utils.misc.gamma_correct(self.active)
class RigifySelectionColors(bpy.types.PropertyGroup):
select: FloatVectorProperty(
@ -362,6 +368,79 @@ class RigifyParameters(bpy.types.PropertyGroup):
name: StringProperty()
class RigifyBoneCollectionReference(bpy.types.PropertyGroup):
"""Reference from a RigifyParameters field to a bone collection."""
uid: IntProperty(name="Unique ID", default=-1)
def find_collection(self, *, update=False, raise_error=False) -> bpy.types.BoneCollection | None:
uid = self.uid
if uid < 0:
return None
arm = self.id_data.data
if name := self.get("name", ""):
name_coll = arm.collections.get(name)
if name_coll and name_coll.rigify_uid == uid:
return name_coll
for coll in arm.collections:
if coll.rigify_uid == uid:
if update:
self["name"] = coll.name
return coll
if raise_error:
raise utils.errors.MetarigError(f"Broken bone collection reference: {name} #{uid}")
return None
def set_collection(self, coll: bpy.types.BoneCollection | None):
if not coll:
self.uid = -1
self["name"] = ""
return
if coll.rigify_uid < 0:
coll.rigify_uid = utils.misc.choose_next_uid(coll.id_data.collections, "rigify_uid")
self.uid = coll.rigify_uid
self["name"] = coll.name
def _name_get(self):
if coll := self.find_collection(update=False):
return coll.name
if self.uid >= 0:
if name := self.get("name", ""):
return f"? {name} #{self.uid}"
return ""
def _name_set(self, new_val):
if not new_val:
self.set_collection(None)
return
arm = self.id_data.data
if new_coll := arm.collections.get(new_val):
self.set_collection(new_coll)
else:
self.find_collection(update=True)
def _name_search(self, _context, _edit):
arm = self.id_data.data
return [coll.name for coll in arm.collections]
name: StringProperty(
name="Collection Name", description="Name of the referenced bone collection",
get=_name_get, set=_name_set, search=_name_search
)
# Parameter update callback
in_update = False
@ -465,41 +544,15 @@ class RigifyParameterValidator(object):
self.__prop_table[name] = (self.__rig_name, new_def)
class RigifyArmatureLayer(bpy.types.PropertyGroup):
def get_group(self):
if 'group_prop' in self.keys():
return self['group_prop']
else:
return 0
def set_group(self, value):
arm = utils.misc.verify_armature_obj(bpy.context.object).data
colors = utils.rig.get_rigify_colors(arm)
if value > len(colors):
self['group_prop'] = len(colors)
else:
self['group_prop'] = value
name: StringProperty(name="Layer Name", default=" ")
row: IntProperty(name="Layer Row", default=1, min=1, max=32,
description='UI row for this layer')
# noinspection SpellCheckingInspection
selset: BoolProperty(name="Selection Set", default=False,
description='Add Selection Set for this layer')
group: IntProperty(name="Bone Group", default=0, min=0, max=32,
get=get_group, set=set_group,
description='Assign Bone Group to this layer')
####################
# REGISTER
classes = (
RigifyName,
RigifyParameters,
RigifyBoneCollectionReference,
RigifyColorSet,
RigifySelectionColors,
RigifyArmatureLayer,
RIGIFY_UL_FeatureSets,
RigifyFeatureSets,
RigifyPreferences,
@ -520,8 +573,6 @@ def register():
register_class(cls)
# Properties.
bpy.types.Armature.rigify_layers = CollectionProperty(type=RigifyArmatureLayer)
bpy.types.Armature.active_feature_set = EnumProperty(
items=feature_set_list.feature_set_items,
name="Feature Set",
@ -621,6 +672,56 @@ def register():
name="Transfer Only Selected",
description="Transfer selected bones only", default=True)
# BoneCollection properties
coll_store = bpy.types.BoneCollection
coll_store.rigify_uid = IntProperty(name="Unique ID", default=-1)
coll_store.rigify_ui_row = IntProperty(
name="UI Row", default=0, min=0,
description="If not zero, row of the UI panel where the button for this collection is shown")
coll_store.rigify_ui_title = StringProperty(
name="UI Title", description="Text to use on the UI panel button instead of the collection name")
coll_store.rigify_sel_set = BoolProperty(
name="Add Selection Set", default=False, description='Add Selection Set for this collection')
coll_store.rigify_color_set_id = IntProperty(name="Color Set ID", default=0, min=0)
def ui_title_get(coll):
return coll.rigify_ui_title or coll.name
def ui_title_set(coll, new_val):
coll.rigify_ui_title = "" if new_val == coll.name else new_val
coll_store.rigify_ui_title_name = StringProperty(
name="UI Title", description="Text to use on the UI panel button (does not edit the collection name)",
get=ui_title_get, set=ui_title_set
)
def color_set_get(coll):
idx = coll.rigify_color_set_id
if idx <= 0:
return ""
sets = utils.rig.get_rigify_colors(coll.id_data)
return sets[idx - 1].name if idx <= len(sets) else f"? {idx}"
def color_set_set(coll, new_val):
if new_val == "":
coll.rigify_color_set_id = 0
else:
sets = utils.rig.get_rigify_colors(coll.id_data)
for i, cset in enumerate(sets):
if cset.name == new_val:
coll.rigify_color_set_id = i + 1
break
def color_set_search(coll, _ctx, _edit):
return [cset.name for cset in utils.rig.get_rigify_colors(coll.id_data)]
coll_store.rigify_color_set_name = StringProperty(
name="Color Set", description="Color set specifying bone colors for this group",
get=color_set_get, set=color_set_set, search=color_set_search
)
prefs = RigifyPreferences.get_instance()
prefs.register_feature_sets(True)
prefs.update_external_rigs()
@ -658,7 +759,6 @@ def unregister():
arm_store: typing.Any = bpy.types.Armature
del arm_store.rigify_layers
del arm_store.active_feature_set
del arm_store.rigify_colors
del arm_store.rigify_selection_colors
@ -676,6 +776,16 @@ def unregister():
del id_store.rigify_active_type
del id_store.rigify_transfer_only_selected
coll_store: typing.Any = bpy.types.BoneCollection
del coll_store.rigify_uid
del coll_store.rigify_ui_row
del coll_store.rigify_ui_title
del coll_store.rigify_ui_title_name
del coll_store.rigify_sel_set
del coll_store.rigify_color_set_id
del coll_store.rigify_color_set_name
# Classes.
for cls in classes:
unregister_class(cls)

View File

@ -8,7 +8,7 @@ import traceback
import collections
from typing import Optional, TYPE_CHECKING, Collection, List
from bpy.types import PoseBone, Bone
from bpy.types import PoseBone, Bone, BoneCollection
from .utils.errors import MetarigError, RaiseErrorMixin
from .utils.naming import random_id
@ -274,10 +274,9 @@ class BaseGenerator:
return set(table.get(bone_name, []))
def set_layer_group_priority(self, bone_name: str,
layers: Collection[bool], priority: float):
for i, val in enumerate(layers):
if val:
self.layer_group_priorities[bone_name][i] = priority
layers: Collection[BoneCollection], priority: float):
for coll in layers:
self.layer_group_priorities[bone_name][coll.name] = priority
def rename_org_bone(self, old_name: str, new_name: str) -> str:
assert self.stage == 'instantiate'

View File

@ -6,28 +6,31 @@ import bpy
import re
import time
from typing import Optional
from typing import Optional, TYPE_CHECKING
from .utils.errors import MetarigError
from .utils.bones import new_bone
from .utils.layers import ORG_LAYER, MCH_LAYER, DEF_LAYER, ROOT_LAYER
from .utils.layers import ORG_COLLECTION, MCH_COLLECTION, DEF_COLLECTION, ROOT_COLLECTION, set_bone_layers
from .utils.naming import (ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, ROOT_NAME, make_original_name,
change_name_side, get_name_side, Side)
from .utils.widgets import WGT_PREFIX, WGT_GROUP_PREFIX
from .utils.widgets_special import create_root_widget
from .utils.mechanism import refresh_all_drivers
from .utils.misc import gamma_correct, select_object, ArmatureObject, verify_armature_obj
from .utils.misc import select_object, ArmatureObject, verify_armature_obj, choose_next_uid
from .utils.collections import (ensure_collection, list_layer_collections,
filter_layer_collections_by_object)
from .utils.rig import get_rigify_type, get_rigify_layers, get_rigify_target_rig,\
from .utils.rig import get_rigify_type, get_rigify_target_rig,\
get_rigify_rig_basename, get_rigify_force_widget_update, get_rigify_finalize_script,\
get_rigify_mirror_widgets
get_rigify_mirror_widgets, get_rigify_colors
from .utils.action_layers import ActionLayerBuilder
from . import base_generate
from . import rig_ui_template
from . import rig_lists
if TYPE_CHECKING:
from . import RigifyColorSet
RIG_MODULE = "rigs"
@ -50,6 +53,7 @@ class Generator(base_generate.BaseGenerator):
super().__init__(context, metarig)
self.id_store = context.window_manager
self.saved_visible_layers = {}
def find_rig_class(self, rig_type):
rig_module = rig_lists.rigs[rig_type]["module"]
@ -66,7 +70,7 @@ class Generator(base_generate.BaseGenerator):
self.collection = self.layer_collection.collection
def ensure_rig_object(self) -> ArmatureObject:
def ensure_rig_object(self) -> tuple[bool, ArmatureObject]:
"""Check if the generated rig already exists, so we can
regenerate in the same object. If not, create a new
object to generate the rig in.
@ -75,8 +79,9 @@ class Generator(base_generate.BaseGenerator):
meta_data = self.metarig.data
target_rig = get_rigify_target_rig(meta_data)
found = bool(target_rig)
if not target_rig:
if not found:
rig_basename = get_rigify_rig_basename(meta_data)
if rig_basename:
@ -107,7 +112,7 @@ class Generator(base_generate.BaseGenerator):
meta_data.rigify_target_rig = target_rig
target_rig.data.pose_position = 'POSE'
return target_rig
return found, target_rig
def __unhide_rig_object(self, obj: bpy.types.Object):
# Ensure the object is visible and selectable
@ -125,6 +130,10 @@ class Generator(base_generate.BaseGenerator):
if self.layer_collection not in self.usable_collections:
raise Exception('Could not generate: Could not find a usable collection.')
def __save_rig_data(self, obj: ArmatureObject, obj_found: bool):
if obj_found:
self.saved_visible_layers = {coll.name: coll.is_visible for coll in obj.data.collections}
def __find_legacy_collection(self) -> bpy.types.Collection:
"""For backwards comp, matching by name to find a legacy collection.
(For before there was a Widget Collection PointerProperty)
@ -202,6 +211,13 @@ class Generator(base_generate.BaseGenerator):
assert isinstance(widget.data, bpy.types.Mesh)
self.widget_mirror_mesh[mid_name] = widget.data
def ensure_root_bone_collection(self):
collections = self.metarig.data.collections
if ROOT_COLLECTION not in collections:
coll = collections.new(ROOT_COLLECTION)
coll.rigify_ui_row = choose_next_uid(collections, 'rigify_ui_row', min_value=1)
def __duplicate_rig(self):
obj = self.obj
metarig = self.metarig
@ -213,6 +229,10 @@ class Generator(base_generate.BaseGenerator):
obj.data.edit_bones.remove(bone)
bpy.ops.object.mode_set(mode='OBJECT')
# Remove all bone collections from the target armature.
for coll in list(obj.data.collections):
obj.data.collections.remove(coll)
# Select and duplicate metarig
select_object(context, metarig, deselect_all=True)
@ -324,10 +344,23 @@ class Generator(base_generate.BaseGenerator):
pb.lock_rotation_w = True
pb.lock_scale = (True, True, True)
def ensure_bone_collection(self, name):
coll = self.obj.data.collections.get(name)
if not coll:
coll = self.obj.data.collections.new(name)
return coll
def __assign_layers(self):
pose_bones = self.obj.pose.bones
pose_bones[self.root_bone].bone.layers = ROOT_LAYER
root_coll = self.ensure_bone_collection(ROOT_COLLECTION)
org_coll = self.ensure_bone_collection(ORG_COLLECTION)
mch_coll = self.ensure_bone_collection(MCH_COLLECTION)
def_coll = self.ensure_bone_collection(DEF_COLLECTION)
set_bone_layers(pose_bones[self.root_bone].bone, [root_coll])
# Every bone that has a name starting with "DEF-" make deforming. All the
# others make non-deforming.
@ -340,16 +373,16 @@ class Generator(base_generate.BaseGenerator):
# Move all the original bones to their layer.
if name.startswith(ORG_PREFIX):
layers = ORG_LAYER
layers = [org_coll]
# Move all the bones with names starting with "MCH-" to their layer.
elif name.startswith(MCH_PREFIX):
layers = MCH_LAYER
layers = [mch_coll]
# Move all the bones with names starting with "DEF-" to their layer.
elif name.startswith(DEF_PREFIX):
layers = DEF_LAYER
layers = [def_coll]
if layers is not None:
bone.layers = layers
set_bone_layers(bone, layers)
# Remove custom shapes from non-control bones
pbone.custom_shape = None
@ -392,17 +425,10 @@ class Generator(base_generate.BaseGenerator):
bone.custom_shape = obj_table[wgt_name]
def __compute_visible_layers(self):
# Reveal all the layers with control bones on them
vis_layers = [False for _ in range(0, 32)]
for bone in self.obj.data.bones:
for i in range(0, 32):
vis_layers[i] = vis_layers[i] or bone.layers[i]
for i in range(0, 32):
vis_layers[i] = vis_layers[i] and not (ORG_LAYER[i] or MCH_LAYER[i] or DEF_LAYER[i])
self.obj.data.layers = vis_layers
# Hide all layers without UI buttons
for coll in self.obj.data.collections:
user_visible = self.saved_visible_layers.get(coll.name, coll.is_visible)
coll.is_visible = user_visible and coll.rigify_ui_row > 0
def generate(self):
context = self.context
@ -417,13 +443,19 @@ class Generator(base_generate.BaseGenerator):
###########################################
# Create/find the rig object and set it up
self.obj = obj = self.ensure_rig_object()
obj_found, obj = self.ensure_rig_object()
self.obj = obj
self.__unhide_rig_object(obj)
# Collect data from the existing rig
self.__save_rig_data(obj, obj_found)
# Select the chosen working collection in case it changed
self.view_layer.active_layer_collection = self.layer_collection
self.ensure_root_bone_collection()
# Get rid of anim data in case the rig already existed
print("Clear rig animation data.")
@ -566,7 +598,7 @@ class Generator(base_generate.BaseGenerator):
create_selection_sets(obj, metarig)
# Create Bone Groups
create_bone_groups(obj, metarig, self.layer_group_priorities)
apply_bone_colors(obj, metarig, self.layer_group_priorities)
t.tick("The rest: ")
@ -596,6 +628,8 @@ class Generator(base_generate.BaseGenerator):
exec(finalize_script.as_string(), {})
bpy.ops.object.mode_set(mode='OBJECT')
obj.data.collections.active_index = 0
###########################################
# Restore active collection
view_layer.active_layer_collection = self.layer_collection
@ -632,7 +666,7 @@ def generate_rig(context, metarig):
base_generate.BaseGenerator.instance = None
def create_selection_set_for_rig_layer(rig: ArmatureObject, set_name: str, layer_idx: int) -> None:
def create_selection_set_for_rig_layer(rig: ArmatureObject, set_name: str, coll: bpy.types.BoneCollection) -> None:
"""Create a single selection set on a rig.
The set will contain all bones on the rig layer with the given index.
@ -641,14 +675,14 @@ def create_selection_set_for_rig_layer(rig: ArmatureObject, set_name: str, layer
sel_set.name = set_name
for b in rig.pose.bones:
if not b.bone.layers[layer_idx] or b.name in sel_set.bone_ids:
if coll not in b.bone.collections or b.name in sel_set.bone_ids:
continue
bone_id = sel_set.bone_ids.add()
bone_id.name = b.name
def create_selection_sets(obj: ArmatureObject, metarig: ArmatureObject):
def create_selection_sets(obj: ArmatureObject, _metarig: ArmatureObject):
"""Create selection sets if the Selection Sets addon is enabled.
Whether a selection set for a rig layer is created is controlled in the
@ -661,49 +695,40 @@ def create_selection_sets(obj: ArmatureObject, metarig: ArmatureObject):
obj.selection_sets.clear() # noqa
rigify_layers = get_rigify_layers(metarig.data)
for i, layer in enumerate(rigify_layers):
if layer.name == '' or not layer.selset:
for coll in obj.data.collections:
if not coll.rigify_sel_set:
continue
create_selection_set_for_rig_layer(obj, layer.name, i)
create_selection_set_for_rig_layer(obj, coll.name, coll)
def create_bone_groups(obj, metarig, priorities: Optional[dict[str, dict[int, float]]] = None):
def apply_bone_colors(obj, metarig, priorities: Optional[dict[str, dict[str, float]]] = None):
bpy.ops.object.mode_set(mode='OBJECT')
pb = obj.pose.bones
layers = metarig.data.rigify_layers
groups = metarig.data.rigify_colors
color_sets = get_rigify_colors(metarig.data)
color_map = {i+1: cset for i, cset in enumerate(color_sets)}
collection_table: dict[str, tuple[int, 'RigifyColorSet']] = {
coll.name: (i, color_map[coll.rigify_color_set_id])
for i, coll in enumerate(obj.data.collections)
if coll.rigify_color_set_id in color_map
}
priorities = priorities or {}
dummy = {}
# Create BGs
for layer in layers:
if layer.group == 0:
continue
g_id = layer.group - 1
name = groups[g_id].name
if name not in obj.pose.bone_groups.keys():
bg = obj.pose.bone_groups.new(name=name)
bg.color_set = 'CUSTOM'
bg.colors.normal = gamma_correct(groups[g_id].normal)
bg.colors.select = gamma_correct(groups[g_id].select)
bg.colors.active = gamma_correct(groups[g_id].active)
for b in pb:
try:
bone_priorities = priorities.get(b.name, dummy)
enabled = [i for i, v in enumerate(b.bone.layers) if v]
layer_index = max(enabled, key=lambda i: bone_priorities.get(i, 0))
except ValueError:
continue
if layer_index > len(layers) - 1: # bone is on reserved layers
continue
g_id = layers[layer_index].group - 1
if g_id >= 0:
name = groups[g_id].name
b.bone_group = obj.pose.bone_groups[name]
cset_collections = [coll.name for coll in b.bone.collections if coll.name in collection_table]
if cset_collections:
best_name = max(
cset_collections,
key=lambda n: (bone_priorities.get(n, 0), -collection_table[n][0])
)
_, cset = collection_table[best_name]
cset.apply(b.bone.color)
cset.apply(b.color)
def get_xy_spread(bones):

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -46,125 +46,44 @@ def create(obj): # noqa
arm.rigify_colors[5].select = Color((0.3137, 0.7843, 1.0000))
arm.rigify_colors[5].standard_colors_lock = True
for i in range(29):
arm.rigify_layers.add()
bone_collections = {}
arm.rigify_layers[0].name = "Face"
arm.rigify_layers[0].row = 1
arm.rigify_layers[0].selset = False
arm.rigify_layers[0].group = 5
arm.rigify_layers[1].name = "Face (Tweak)"
arm.rigify_layers[1].row = 2
arm.rigify_layers[1].selset = False
arm.rigify_layers[1].group = 4
arm.rigify_layers[2].name = " "
arm.rigify_layers[2].row = 1
arm.rigify_layers[2].selset = False
arm.rigify_layers[2].group = 0
arm.rigify_layers[3].name = "Spine"
arm.rigify_layers[3].row = 3
arm.rigify_layers[3].selset = False
arm.rigify_layers[3].group = 3
arm.rigify_layers[4].name = "Spine (Tweak)"
arm.rigify_layers[4].row = 4
arm.rigify_layers[4].selset = False
arm.rigify_layers[4].group = 4
arm.rigify_layers[5].name = "Tail"
arm.rigify_layers[5].row = 5
arm.rigify_layers[5].selset = False
arm.rigify_layers[5].group = 6
arm.rigify_layers[6].name = "Fins.L"
arm.rigify_layers[6].row = 6
arm.rigify_layers[6].selset = False
arm.rigify_layers[6].group = 5
arm.rigify_layers[7].name = "Fins.L (Tweak)"
arm.rigify_layers[7].row = 7
arm.rigify_layers[7].selset = False
arm.rigify_layers[7].group = 4
arm.rigify_layers[8].name = "Fins.R"
arm.rigify_layers[8].row = 6
arm.rigify_layers[8].selset = False
arm.rigify_layers[8].group = 5
arm.rigify_layers[9].name = "Fins.R (Tweak)"
arm.rigify_layers[9].row = 7
arm.rigify_layers[9].selset = False
arm.rigify_layers[9].group = 4
arm.rigify_layers[10].name = "Fins"
arm.rigify_layers[10].row = 8
arm.rigify_layers[10].selset = False
arm.rigify_layers[10].group = 3
arm.rigify_layers[11].name = "Fins (Tweak)"
arm.rigify_layers[11].row = 9
arm.rigify_layers[11].selset = False
arm.rigify_layers[11].group = 4
arm.rigify_layers[12].name = " "
arm.rigify_layers[12].row = 1
arm.rigify_layers[12].selset = False
arm.rigify_layers[12].group = 0
arm.rigify_layers[13].name = " "
arm.rigify_layers[13].row = 1
arm.rigify_layers[13].selset = False
arm.rigify_layers[13].group = 6
arm.rigify_layers[14].name = " "
arm.rigify_layers[14].row = 1
arm.rigify_layers[14].selset = False
arm.rigify_layers[14].group = 0
arm.rigify_layers[15].name = " "
arm.rigify_layers[15].row = 1
arm.rigify_layers[15].selset = False
arm.rigify_layers[15].group = 0
arm.rigify_layers[16].name = " "
arm.rigify_layers[16].row = 1
arm.rigify_layers[16].selset = False
arm.rigify_layers[16].group = 0
arm.rigify_layers[17].name = " "
arm.rigify_layers[17].row = 1
arm.rigify_layers[17].selset = False
arm.rigify_layers[17].group = 0
arm.rigify_layers[18].name = " "
arm.rigify_layers[18].row = 1
arm.rigify_layers[18].selset = False
arm.rigify_layers[18].group = 0
arm.rigify_layers[19].name = " "
arm.rigify_layers[19].row = 1
arm.rigify_layers[19].selset = False
arm.rigify_layers[19].group = 0
arm.rigify_layers[20].name = " "
arm.rigify_layers[20].row = 1
arm.rigify_layers[20].selset = False
arm.rigify_layers[20].group = 0
arm.rigify_layers[21].name = " "
arm.rigify_layers[21].row = 1
arm.rigify_layers[21].selset = False
arm.rigify_layers[21].group = 0
arm.rigify_layers[22].name = " "
arm.rigify_layers[22].row = 1
arm.rigify_layers[22].selset = False
arm.rigify_layers[22].group = 0
arm.rigify_layers[23].name = " "
arm.rigify_layers[23].row = 1
arm.rigify_layers[23].selset = False
arm.rigify_layers[23].group = 0
arm.rigify_layers[24].name = " "
arm.rigify_layers[24].row = 1
arm.rigify_layers[24].selset = False
arm.rigify_layers[24].group = 0
arm.rigify_layers[25].name = " "
arm.rigify_layers[25].row = 1
arm.rigify_layers[25].selset = False
arm.rigify_layers[25].group = 0
arm.rigify_layers[26].name = " "
arm.rigify_layers[26].row = 1
arm.rigify_layers[26].selset = False
arm.rigify_layers[26].group = 0
arm.rigify_layers[27].name = " "
arm.rigify_layers[27].row = 1
arm.rigify_layers[27].selset = False
arm.rigify_layers[27].group = 0
arm.rigify_layers[28].name = "Root"
arm.rigify_layers[28].row = 14
arm.rigify_layers[28].selset = False
arm.rigify_layers[28].group = 1
for bcoll in list(arm.collections):
arm.collections.remove(bcoll)
def add_bone_collection(name, *, ui_row=0, ui_title='', sel_set=False, color_set_id=0):
uid = len(arm.collections)
new_bcoll = arm.collections.new(name)
new_bcoll.rigify_uid = uid
new_bcoll.rigify_ui_row = ui_row
new_bcoll.rigify_ui_title = ui_title
new_bcoll.rigify_sel_set = sel_set
new_bcoll.rigify_color_set_id = color_set_id
bone_collections[name] = new_bcoll
def assign_bone_collections(pose_bone, *coll_names):
assert not len(pose_bone.bone.collections)
for name in coll_names:
bone_collections[name].assign(pose_bone)
def assign_bone_collection_refs(params, attr_name, *coll_names):
ref_list = getattr(params, attr_name + '_coll_refs', None)
if ref_list is not None:
for name in coll_names:
ref_list.add().set_collection(bone_collections[name])
add_bone_collection('Face', ui_row=1, color_set_id=5)
add_bone_collection('Face (Tweak)', ui_row=2, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Spine', ui_row=4, color_set_id=3)
add_bone_collection('Spine (Tweak)', ui_row=5, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Tail', ui_row=6, color_set_id=6)
add_bone_collection('Fins.L', ui_row=8, color_set_id=5)
add_bone_collection('Fins.L (Tweak)', ui_row=9, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Fins.R', ui_row=8, color_set_id=5)
add_bone_collection('Fins.R (Tweak)', ui_row=9, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Fins', ui_row=11, color_set_id=3)
add_bone_collection('Fins (Tweak)', ui_row=12, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Root', ui_row=15, color_set_id=1)
bones = {}
@ -421,24 +340,9 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Spine')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Spine (Tweak)')
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Spine (Tweak)')
pbone = obj.pose.bones[bones['spine.002']]
pbone.rigify_type = 'spines.basic_tail'
pbone.lock_location = (False, False, False)
@ -446,17 +350,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Tail')
try:
pbone.rigify_parameters.connect_chain = True
except AttributeError:
@ -465,6 +359,7 @@ def create(obj): # noqa
pbone.rigify_parameters.copy_rotation_axes = (True, False, True)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Spine (Tweak)')
pbone = obj.pose.bones[bones['spine.008']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -472,10 +367,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['spine.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -483,10 +375,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Tail')
pbone = obj.pose.bones[bones['spine.004']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -494,10 +383,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['chest_fin.Bot.L']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -505,17 +391,8 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Fins')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Spine (Tweak)')
pbone = obj.pose.bones[bones['chest_fin.Bot.R']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -523,17 +400,8 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, True, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Fins')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Tail')
pbone = obj.pose.bones[bones['spine']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -541,10 +409,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Tail')
pbone = obj.pose.bones[bones['mid_fin.Top']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -552,10 +417,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Fins')
pbone = obj.pose.bones[bones['mid_fin.Bot']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -563,10 +425,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, True, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Fins')
pbone = obj.pose.bones[bones['spine.005']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -574,10 +433,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['top_fin']]
pbone.rigify_type = 'limbs.simple_tentacle'
pbone.lock_location = (False, False, False)
@ -585,17 +441,8 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, False, False,
True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Fins')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Fins (Tweak)')
pbone = obj.pose.bones[bones['back_fin.T.Bk']]
pbone.rigify_type = 'limbs.super_finger'
pbone.lock_location = (False, False, False)
@ -603,21 +450,12 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Fins')
try:
pbone.rigify_parameters.primary_rotation_axis = 'Z'
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Fins (Tweak)')
pbone = obj.pose.bones[bones['back_fin.B.Bk']]
pbone.rigify_type = 'limbs.super_finger'
pbone.lock_location = (False, False, False)
@ -625,21 +463,12 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Fins')
try:
pbone.rigify_parameters.primary_rotation_axis = 'Z'
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Fins (Tweak)')
pbone = obj.pose.bones[bones['spine.006']]
pbone.rigify_type = 'spines.super_head'
pbone.lock_location = (False, False, False)
@ -647,21 +476,12 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Spine')
try:
pbone.rigify_parameters.connect_chain = True
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Spine (Tweak)')
pbone = obj.pose.bones[bones['shoulder.L']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -669,10 +489,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
try:
pbone.rigify_parameters.make_widget = False
except AttributeError:
@ -684,10 +501,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
try:
pbone.rigify_parameters.make_widget = False
except AttributeError:
@ -699,10 +513,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Fins')
pbone = obj.pose.bones[bones['back_fin.T.001.Bk']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -710,10 +521,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Fins')
pbone = obj.pose.bones[bones['back_fin.B.001.Bk']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -721,10 +529,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Fins')
pbone = obj.pose.bones[bones['spine.007']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -732,10 +537,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['side_fin.L']]
pbone.rigify_type = 'limbs.simple_tentacle'
pbone.lock_location = (False, False, False)
@ -743,21 +545,12 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, True, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Fins.L')
try:
pbone.rigify_parameters.copy_rotation_axes = (True, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Fins.L (Tweak)')
pbone = obj.pose.bones[bones['side_fin.R']]
pbone.rigify_type = 'limbs.simple_tentacle'
pbone.lock_location = (False, False, False)
@ -765,21 +558,12 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Fins.R')
try:
pbone.rigify_parameters.copy_rotation_axes = (True, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Fins.R (Tweak)')
pbone = obj.pose.bones[bones['back_fin.T.002.Bk']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -787,10 +571,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Fins')
pbone = obj.pose.bones[bones['eye.L']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -798,10 +579,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
pbone = obj.pose.bones[bones['eye.R']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -809,10 +587,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
pbone = obj.pose.bones[bones['jaw.master']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -820,10 +595,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
try:
pbone.rigify_parameters.make_widget = False
except AttributeError:
@ -839,10 +611,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, True, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Fins.L')
pbone = obj.pose.bones[bones['side_fin.R.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -850,10 +619,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Fins.R')
pbone = obj.pose.bones[bones['jaw']]
pbone.rigify_type = 'limbs.simple_tentacle'
pbone.lock_location = (False, False, False)
@ -861,10 +627,8 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Face (Tweak)')
pbone = obj.pose.bones[bones['jaw.002.L']]
pbone.rigify_type = 'limbs.simple_tentacle'
pbone.lock_location = (False, False, False)
@ -872,10 +636,8 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Face (Tweak)')
pbone = obj.pose.bones[bones['jaw.002.R']]
pbone.rigify_type = 'limbs.simple_tentacle'
pbone.lock_location = (False, False, False)
@ -883,10 +645,8 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Face (Tweak)')
pbone = obj.pose.bones[bones['jaw.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -894,10 +654,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
pbone = obj.pose.bones[bones['jaw.003.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -905,10 +662,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
pbone = obj.pose.bones[bones['jaw.003.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -916,10 +670,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Face')
bpy.ops.object.mode_set(mode='EDIT')
for bone in arm.edit_bones:
@ -934,7 +685,7 @@ def create(obj): # noqa
bone.bbone_x = bone.bbone_z = bone.length * 0.05
arm.edit_bones.active = bone
arm.layers = [(x in [0, 3, 5, 6, 8, 10]) for x in range(32)]
arm.collections.active_index = 0
return bones

File diff suppressed because it is too large Load Diff

View File

@ -46,125 +46,47 @@ def create(obj): # noqa
arm.rigify_colors[5].select = Color((0.3140, 0.7840, 1.0000))
arm.rigify_colors[5].standard_colors_lock = True
for i in range(29):
arm.rigify_layers.add()
bone_collections = {}
arm.rigify_layers[0].name = " "
arm.rigify_layers[0].row = 1
arm.rigify_layers[0].selset = False
arm.rigify_layers[0].group = 0
arm.rigify_layers[1].name = " "
arm.rigify_layers[1].row = 1
arm.rigify_layers[1].selset = False
arm.rigify_layers[1].group = 0
arm.rigify_layers[2].name = " "
arm.rigify_layers[2].row = 1
arm.rigify_layers[2].selset = False
arm.rigify_layers[2].group = 0
arm.rigify_layers[3].name = "Torso"
arm.rigify_layers[3].row = 3
arm.rigify_layers[3].selset = False
arm.rigify_layers[3].group = 3
arm.rigify_layers[4].name = "Torso (Tweak)"
arm.rigify_layers[4].row = 4
arm.rigify_layers[4].selset = False
arm.rigify_layers[4].group = 4
arm.rigify_layers[5].name = " "
arm.rigify_layers[5].row = 1
arm.rigify_layers[5].selset = False
arm.rigify_layers[5].group = 0
arm.rigify_layers[6].name = " "
arm.rigify_layers[6].row = 1
arm.rigify_layers[6].selset = False
arm.rigify_layers[6].group = 0
arm.rigify_layers[7].name = "Arm.L (IK)"
arm.rigify_layers[7].row = 7
arm.rigify_layers[7].selset = False
arm.rigify_layers[7].group = 2
arm.rigify_layers[8].name = "Arm.L (FK)"
arm.rigify_layers[8].row = 8
arm.rigify_layers[8].selset = False
arm.rigify_layers[8].group = 5
arm.rigify_layers[9].name = "Arm.L (Tweak)"
arm.rigify_layers[9].row = 9
arm.rigify_layers[9].selset = False
arm.rigify_layers[9].group = 4
arm.rigify_layers[10].name = "Arm.R (IK)"
arm.rigify_layers[10].row = 7
arm.rigify_layers[10].selset = False
arm.rigify_layers[10].group = 2
arm.rigify_layers[11].name = "Arm.R (FK)"
arm.rigify_layers[11].row = 8
arm.rigify_layers[11].selset = False
arm.rigify_layers[11].group = 5
arm.rigify_layers[12].name = "Arm.R (Tweak)"
arm.rigify_layers[12].row = 9
arm.rigify_layers[12].selset = False
arm.rigify_layers[12].group = 4
arm.rigify_layers[13].name = "Leg.L (IK)"
arm.rigify_layers[13].row = 10
arm.rigify_layers[13].selset = False
arm.rigify_layers[13].group = 2
arm.rigify_layers[14].name = "Leg.L (FK)"
arm.rigify_layers[14].row = 11
arm.rigify_layers[14].selset = False
arm.rigify_layers[14].group = 5
arm.rigify_layers[15].name = "Leg.L (Tweak)"
arm.rigify_layers[15].row = 12
arm.rigify_layers[15].selset = False
arm.rigify_layers[15].group = 4
arm.rigify_layers[16].name = "Leg.R (IK)"
arm.rigify_layers[16].row = 10
arm.rigify_layers[16].selset = False
arm.rigify_layers[16].group = 2
arm.rigify_layers[17].name = "Leg.R (FK)"
arm.rigify_layers[17].row = 11
arm.rigify_layers[17].selset = False
arm.rigify_layers[17].group = 5
arm.rigify_layers[18].name = "Leg.R (Tweak)"
arm.rigify_layers[18].row = 12
arm.rigify_layers[18].selset = False
arm.rigify_layers[18].group = 4
arm.rigify_layers[19].name = ""
arm.rigify_layers[19].row = 1
arm.rigify_layers[19].selset = False
arm.rigify_layers[19].group = 0
arm.rigify_layers[20].name = ""
arm.rigify_layers[20].row = 1
arm.rigify_layers[20].selset = False
arm.rigify_layers[20].group = 0
arm.rigify_layers[21].name = ""
arm.rigify_layers[21].row = 1
arm.rigify_layers[21].selset = False
arm.rigify_layers[21].group = 0
arm.rigify_layers[22].name = ""
arm.rigify_layers[22].row = 1
arm.rigify_layers[22].selset = False
arm.rigify_layers[22].group = 0
arm.rigify_layers[23].name = ""
arm.rigify_layers[23].row = 1
arm.rigify_layers[23].selset = False
arm.rigify_layers[23].group = 0
arm.rigify_layers[24].name = ""
arm.rigify_layers[24].row = 1
arm.rigify_layers[24].selset = False
arm.rigify_layers[24].group = 0
arm.rigify_layers[25].name = ""
arm.rigify_layers[25].row = 1
arm.rigify_layers[25].selset = False
arm.rigify_layers[25].group = 0
arm.rigify_layers[26].name = ""
arm.rigify_layers[26].row = 1
arm.rigify_layers[26].selset = False
arm.rigify_layers[26].group = 0
arm.rigify_layers[27].name = ""
arm.rigify_layers[27].row = 1
arm.rigify_layers[27].selset = False
arm.rigify_layers[27].group = 0
arm.rigify_layers[28].name = "Root"
arm.rigify_layers[28].row = 14
arm.rigify_layers[28].selset = False
arm.rigify_layers[28].group = 1
for bcoll in list(arm.collections):
arm.collections.remove(bcoll)
def add_bone_collection(name, *, ui_row=0, ui_title='', sel_set=False, color_set_id=0):
uid = len(arm.collections)
new_bcoll = arm.collections.new(name)
new_bcoll.rigify_uid = uid
new_bcoll.rigify_ui_row = ui_row
new_bcoll.rigify_ui_title = ui_title
new_bcoll.rigify_sel_set = sel_set
new_bcoll.rigify_color_set_id = color_set_id
bone_collections[name] = new_bcoll
def assign_bone_collections(pose_bone, *coll_names):
assert not len(pose_bone.bone.collections)
for name in coll_names:
bone_collections[name].assign(pose_bone)
def assign_bone_collection_refs(params, attr_name, *coll_names):
ref_list = getattr(params, attr_name + '_coll_refs', None)
if ref_list is not None:
for name in coll_names:
ref_list.add().set_collection(bone_collections[name])
add_bone_collection('Torso', ui_row=1, color_set_id=3)
add_bone_collection('Torso (Tweak)', ui_row=2, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Arm.L (IK)', ui_row=4, color_set_id=2)
add_bone_collection('Arm.L (FK)', ui_row=5, ui_title='(FK)', color_set_id=5)
add_bone_collection('Arm.L (Tweak)', ui_row=6, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Arm.R (IK)', ui_row=4, color_set_id=2)
add_bone_collection('Arm.R (FK)', ui_row=5, ui_title='(FK)', color_set_id=5)
add_bone_collection('Arm.R (Tweak)', ui_row=6, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Leg.L (IK)', ui_row=8, color_set_id=2)
add_bone_collection('Leg.L (FK)', ui_row=9, ui_title='(FK)', color_set_id=5)
add_bone_collection('Leg.L (Tweak)', ui_row=10, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Leg.R (IK)', ui_row=8, color_set_id=2)
add_bone_collection('Leg.R (FK)', ui_row=9, ui_title='(FK)', color_set_id=5)
add_bone_collection('Leg.R (Tweak)', ui_row=10, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Root', ui_row=13, color_set_id=1)
bones = {}
@ -379,24 +301,9 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Torso')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Torso (Tweak)')
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Torso (Tweak)')
pbone = obj.pose.bones[bones['spine.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -404,10 +311,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
pbone = obj.pose.bones[bones['pelvis.L']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -415,10 +319,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
try:
pbone.rigify_parameters.make_control = False
except AttributeError:
@ -430,10 +331,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
try:
pbone.rigify_parameters.make_control = False
except AttributeError:
@ -445,10 +343,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
try:
pbone.rigify_parameters.limb_type = 'leg'
except AttributeError:
@ -461,20 +356,8 @@ def create(obj): # noqa
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Leg.L (FK)')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Leg.L (Tweak)')
pbone = obj.pose.bones[bones['thigh.R']]
pbone.rigify_type = 'limbs.leg'
pbone.lock_location = (False, False, False)
@ -482,24 +365,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Leg.R (IK)')
try:
pbone.rigify_parameters.limb_type = 'leg'
except AttributeError:
@ -512,6 +378,8 @@ def create(obj): # noqa
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Leg.R (FK)')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Leg.R (Tweak)')
pbone = obj.pose.bones[bones['spine.002']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -519,10 +387,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
pbone = obj.pose.bones[bones['shin.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -530,10 +395,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
pbone = obj.pose.bones[bones['shin.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -541,10 +403,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.R (IK)')
pbone = obj.pose.bones[bones['spine.003']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -552,10 +411,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
pbone = obj.pose.bones[bones['foot.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -563,10 +419,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
pbone = obj.pose.bones[bones['foot.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -574,10 +427,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.R (IK)')
pbone = obj.pose.bones[bones['spine.004']]
pbone.rigify_type = 'spines.super_head'
pbone.lock_location = (False, False, False)
@ -585,21 +435,12 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
try:
pbone.rigify_parameters.connect_chain = True
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Torso (Tweak)')
pbone = obj.pose.bones[bones['shoulder.L']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -607,10 +448,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
try:
pbone.rigify_parameters.make_widget = True
except AttributeError:
@ -626,10 +464,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
try:
pbone.rigify_parameters.make_widget = True
except AttributeError:
@ -645,10 +480,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
pbone = obj.pose.bones[bones['breast.R']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -656,10 +488,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
pbone = obj.pose.bones[bones['toe.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -667,10 +496,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
pbone = obj.pose.bones[bones['heel.02.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -678,10 +504,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
pbone = obj.pose.bones[bones['toe.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -689,10 +512,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.R (IK)')
pbone = obj.pose.bones[bones['heel.02.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -700,10 +520,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.R (IK)')
pbone = obj.pose.bones[bones['spine.005']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -711,10 +528,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
pbone = obj.pose.bones[bones['upper_arm.L']]
pbone.rigify_type = 'limbs.arm'
pbone.lock_location = (False, False, False)
@ -722,28 +536,13 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.L (IK)')
try:
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, False, False, False, False, True, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Arm.L (Tweak)')
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Arm.L (FK)')
pbone = obj.pose.bones[bones['upper_arm.R']]
pbone.rigify_type = 'limbs.arm'
pbone.lock_location = (False, False, False)
@ -751,28 +550,13 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.R (IK)')
try:
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, False, False, False, False, False, False, False,
True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Arm.R (Tweak)')
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Arm.R (FK)')
pbone = obj.pose.bones[bones['spine.006']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -780,10 +564,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Torso')
pbone = obj.pose.bones[bones['forearm.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -791,10 +572,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.L (IK)')
pbone = obj.pose.bones[bones['forearm.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -802,10 +580,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.R (IK)')
pbone = obj.pose.bones[bones['hand.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -813,10 +588,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.L (IK)')
pbone = obj.pose.bones[bones['hand.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -824,10 +596,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.R (IK)')
bpy.ops.object.mode_set(mode='EDIT')
for bone in arm.edit_bones:
@ -842,7 +611,7 @@ def create(obj): # noqa
bone.bbone_x = bone.bbone_z = bone.length * 0.05
arm.edit_bones.active = bone
arm.layers = [(x in [3, 7, 10, 13, 16]) for x in range(32)]
arm.collections.active_index = 0
return bones

View File

@ -46,125 +46,48 @@ def create(obj): # noqa
arm.rigify_colors[5].select = Color((0.3137, 0.7843, 1.0000))
arm.rigify_colors[5].standard_colors_lock = True
for i in range(29):
arm.rigify_layers.add()
bone_collections = {}
arm.rigify_layers[0].name = " "
arm.rigify_layers[0].row = 1
arm.rigify_layers[0].selset = False
arm.rigify_layers[0].group = 0
arm.rigify_layers[1].name = " "
arm.rigify_layers[1].row = 2
arm.rigify_layers[1].selset = False
arm.rigify_layers[1].group = 0
arm.rigify_layers[2].name = " "
arm.rigify_layers[2].row = 2
arm.rigify_layers[2].selset = False
arm.rigify_layers[2].group = 0
arm.rigify_layers[3].name = "Spine"
arm.rigify_layers[3].row = 3
arm.rigify_layers[3].selset = False
arm.rigify_layers[3].group = 3
arm.rigify_layers[4].name = "Spine (Tweak)"
arm.rigify_layers[4].row = 4
arm.rigify_layers[4].selset = False
arm.rigify_layers[4].group = 4
arm.rigify_layers[5].name = " "
arm.rigify_layers[5].row = 5
arm.rigify_layers[5].selset = False
arm.rigify_layers[5].group = 0
arm.rigify_layers[6].name = " "
arm.rigify_layers[6].row = 6
arm.rigify_layers[6].selset = False
arm.rigify_layers[6].group = 0
arm.rigify_layers[7].name = "Arm.L (IK)"
arm.rigify_layers[7].row = 7
arm.rigify_layers[7].selset = False
arm.rigify_layers[7].group = 2
arm.rigify_layers[8].name = "Arm.L (FK)"
arm.rigify_layers[8].row = 8
arm.rigify_layers[8].selset = False
arm.rigify_layers[8].group = 5
arm.rigify_layers[9].name = "Arm.L (Tweak)"
arm.rigify_layers[9].row = 9
arm.rigify_layers[9].selset = False
arm.rigify_layers[9].group = 4
arm.rigify_layers[10].name = "Arm.R (IK)"
arm.rigify_layers[10].row = 7
arm.rigify_layers[10].selset = False
arm.rigify_layers[10].group = 2
arm.rigify_layers[11].name = "Arm.R (FK)"
arm.rigify_layers[11].row = 8
arm.rigify_layers[11].selset = False
arm.rigify_layers[11].group = 5
arm.rigify_layers[12].name = "Arm.R (Tweak)"
arm.rigify_layers[12].row = 9
arm.rigify_layers[12].selset = False
arm.rigify_layers[12].group = 4
arm.rigify_layers[13].name = "Leg.L (IK)"
arm.rigify_layers[13].row = 10
arm.rigify_layers[13].selset = False
arm.rigify_layers[13].group = 2
arm.rigify_layers[14].name = "Leg.L (FK)"
arm.rigify_layers[14].row = 11
arm.rigify_layers[14].selset = False
arm.rigify_layers[14].group = 5
arm.rigify_layers[15].name = "Leg.L (Tweak)"
arm.rigify_layers[15].row = 12
arm.rigify_layers[15].selset = False
arm.rigify_layers[15].group = 4
arm.rigify_layers[16].name = "Leg.R (IK)"
arm.rigify_layers[16].row = 10
arm.rigify_layers[16].selset = False
arm.rigify_layers[16].group = 2
arm.rigify_layers[17].name = "Leg.R (FK)"
arm.rigify_layers[17].row = 11
arm.rigify_layers[17].selset = False
arm.rigify_layers[17].group = 5
arm.rigify_layers[18].name = "Leg.R (Tweak)"
arm.rigify_layers[18].row = 12
arm.rigify_layers[18].selset = False
arm.rigify_layers[18].group = 4
arm.rigify_layers[19].name = "Tail"
arm.rigify_layers[19].row = 13
arm.rigify_layers[19].selset = False
arm.rigify_layers[19].group = 6
arm.rigify_layers[20].name = ""
arm.rigify_layers[20].row = 1
arm.rigify_layers[20].selset = False
arm.rigify_layers[20].group = 0
arm.rigify_layers[21].name = ""
arm.rigify_layers[21].row = 13
arm.rigify_layers[21].selset = False
arm.rigify_layers[21].group = 0
arm.rigify_layers[22].name = ""
arm.rigify_layers[22].row = 13
arm.rigify_layers[22].selset = False
arm.rigify_layers[22].group = 0
arm.rigify_layers[23].name = ""
arm.rigify_layers[23].row = 1
arm.rigify_layers[23].selset = False
arm.rigify_layers[23].group = 0
arm.rigify_layers[24].name = ""
arm.rigify_layers[24].row = 1
arm.rigify_layers[24].selset = False
arm.rigify_layers[24].group = 0
arm.rigify_layers[25].name = ""
arm.rigify_layers[25].row = 1
arm.rigify_layers[25].selset = False
arm.rigify_layers[25].group = 0
arm.rigify_layers[26].name = ""
arm.rigify_layers[26].row = 1
arm.rigify_layers[26].selset = False
arm.rigify_layers[26].group = 0
arm.rigify_layers[27].name = ""
arm.rigify_layers[27].row = 1
arm.rigify_layers[27].selset = False
arm.rigify_layers[27].group = 0
arm.rigify_layers[28].name = "Root"
arm.rigify_layers[28].row = 14
arm.rigify_layers[28].selset = False
arm.rigify_layers[28].group = 1
for bcoll in list(arm.collections):
arm.collections.remove(bcoll)
def add_bone_collection(name, *, ui_row=0, ui_title='', sel_set=False, color_set_id=0):
uid = len(arm.collections)
new_bcoll = arm.collections.new(name)
new_bcoll.rigify_uid = uid
new_bcoll.rigify_ui_row = ui_row
new_bcoll.rigify_ui_title = ui_title
new_bcoll.rigify_sel_set = sel_set
new_bcoll.rigify_color_set_id = color_set_id
bone_collections[name] = new_bcoll
def assign_bone_collections(pose_bone, *coll_names):
assert not len(pose_bone.bone.collections)
for name in coll_names:
bone_collections[name].assign(pose_bone)
def assign_bone_collection_refs(params, attr_name, *coll_names):
ref_list = getattr(params, attr_name + '_coll_refs', None)
if ref_list is not None:
for name in coll_names:
ref_list.add().set_collection(bone_collections[name])
add_bone_collection('Spine', ui_row=1, color_set_id=3)
add_bone_collection('Spine (Tweak)', ui_row=2, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Arm.L (IK)', ui_row=4, color_set_id=2)
add_bone_collection('Arm.L (FK)', ui_row=5, ui_title='(FK)', color_set_id=5)
add_bone_collection('Arm.L (Tweak)', ui_row=6, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Arm.R (IK)', ui_row=4, color_set_id=2)
add_bone_collection('Arm.R (FK)', ui_row=5, ui_title='(FK)', color_set_id=5)
add_bone_collection('Arm.R (Tweak)', ui_row=6, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Leg.L (IK)', ui_row=8, color_set_id=2)
add_bone_collection('Leg.L (FK)', ui_row=9, ui_title='(FK)', color_set_id=5)
add_bone_collection('Leg.L (Tweak)', ui_row=10, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Leg.R (IK)', ui_row=8, color_set_id=2)
add_bone_collection('Leg.R (FK)', ui_row=9, ui_title='(FK)', color_set_id=5)
add_bone_collection('Leg.R (Tweak)', ui_row=10, ui_title='(Tweak)', color_set_id=4)
add_bone_collection('Tail', ui_row=12, color_set_id=6)
add_bone_collection('Root', ui_row=15, color_set_id=1)
bones = {}
@ -414,28 +337,13 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
try:
pbone.rigify_parameters.pivot_pos = 4
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Spine (Tweak)')
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Spine (Tweak)')
pbone = obj.pose.bones[bones['spine.003']]
pbone.rigify_type = 'spines.basic_tail'
pbone.lock_location = (False, False, False)
@ -443,21 +351,12 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Tail')
try:
pbone.rigify_parameters.connect_chain = True
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Spine (Tweak)')
pbone = obj.pose.bones[bones['spine.005']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -465,10 +364,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['spine.002']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -476,10 +372,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Tail')
pbone = obj.pose.bones[bones['spine.006']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -487,10 +380,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['pelvis.L']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -498,10 +388,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
try:
pbone.rigify_parameters.make_control = False
except AttributeError:
@ -513,10 +400,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
try:
pbone.rigify_parameters.make_control = False
except AttributeError:
@ -528,10 +412,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
try:
pbone.rigify_parameters.limb_type = 'paw'
except AttributeError:
@ -540,20 +421,8 @@ def create(obj): # noqa
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Leg.L (FK)')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Leg.L (Tweak)')
pbone = obj.pose.bones[bones['thigh.R']]
pbone.rigify_type = 'limbs.rear_paw'
pbone.lock_location = (False, False, False)
@ -561,24 +430,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collections(pbone, 'Leg.R (IK)')
try:
pbone.rigify_parameters.limb_type = 'paw'
except AttributeError:
@ -587,6 +439,8 @@ def create(obj): # noqa
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Leg.R (FK)')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Leg.R (Tweak)')
pbone = obj.pose.bones[bones['spine.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -594,10 +448,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Tail')
pbone = obj.pose.bones[bones['spine.007']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -605,10 +456,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['shin.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -616,10 +464,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
pbone = obj.pose.bones[bones['shin.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -627,10 +472,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.R (IK)')
pbone = obj.pose.bones[bones['spine']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -638,10 +480,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Tail')
pbone = obj.pose.bones[bones['spine.008']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -649,10 +488,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['foot.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -660,10 +496,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
pbone = obj.pose.bones[bones['foot.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -671,10 +504,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.R (IK)')
pbone = obj.pose.bones[bones['spine.009']]
pbone.rigify_type = 'spines.super_head'
pbone.lock_location = (False, False, False)
@ -682,21 +512,12 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
try:
pbone.rigify_parameters.connect_chain = True
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Spine (Tweak)')
pbone = obj.pose.bones[bones['shoulder.L']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -704,10 +525,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.L (IK)')
try:
pbone.rigify_parameters.make_widget = False
except AttributeError:
@ -719,10 +537,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.R (IK)')
try:
pbone.rigify_parameters.make_widget = False
except AttributeError:
@ -734,10 +549,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine (Tweak)')
pbone = obj.pose.bones[bones['breast.R']]
pbone.rigify_type = 'basic.super_copy'
pbone.lock_location = (False, False, False)
@ -745,10 +557,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'YXZ'
pbone.bone.layers = [
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine (Tweak)')
pbone = obj.pose.bones[bones['toe.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -756,10 +565,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.L (IK)')
try:
pbone.rigify_parameters.limb_type = 'paw'
except AttributeError:
@ -771,10 +577,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Leg.R (IK)')
try:
pbone.rigify_parameters.limb_type = 'paw'
except AttributeError:
@ -786,10 +589,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['front_thigh.L']]
pbone.rigify_type = 'limbs.front_paw'
pbone.lock_location = (False, False, False)
@ -797,10 +597,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.L (IK)')
try:
pbone.rigify_parameters.limb_type = 'paw'
except AttributeError:
@ -809,20 +606,8 @@ def create(obj): # noqa
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, False, False, False, False, True, False, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Arm.L (FK)')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Arm.L (Tweak)')
pbone = obj.pose.bones[bones['front_thigh.R']]
pbone.rigify_type = 'limbs.front_paw'
pbone.lock_location = (False, False, False)
@ -830,10 +615,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.R (IK)')
try:
pbone.rigify_parameters.limb_type = 'paw'
except AttributeError:
@ -842,20 +624,8 @@ def create(obj): # noqa
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = (
False, False, False, False, False, False, False, False, False, False, False,
True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = (
False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
except AttributeError:
pass
assign_bone_collection_refs(pbone.rigify_parameters, 'fk', 'Arm.R (FK)')
assign_bone_collection_refs(pbone.rigify_parameters, 'tweak', 'Arm.R (Tweak)')
pbone = obj.pose.bones[bones['spine.011']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -863,10 +633,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Spine')
pbone = obj.pose.bones[bones['front_shin.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -874,10 +641,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.L (IK)')
pbone = obj.pose.bones[bones['front_shin.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -885,10 +649,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.R (IK)')
pbone = obj.pose.bones[bones['front_foot.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -896,10 +657,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.L (IK)')
pbone = obj.pose.bones[bones['front_foot.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -907,10 +665,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.R (IK)')
pbone = obj.pose.bones[bones['front_toe.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -918,10 +673,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.L (IK)')
try:
pbone.rigify_parameters.limb_type = 'paw'
except AttributeError:
@ -933,10 +685,7 @@ def create(obj): # noqa
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
False, False, False, False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
assign_bone_collections(pbone, 'Arm.R (IK)')
try:
pbone.rigify_parameters.rotation_axis = 'x'
except AttributeError:
@ -959,7 +708,7 @@ def create(obj): # noqa
bone.bbone_x = bone.bbone_z = bone.length * 0.05
arm.edit_bones.active = bone
arm.layers = [(x in [3, 4, 7, 10, 13, 16, 19]) for x in range(32)]
arm.collections.active_index = 0
return bones

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@ from .generic_ui_list import draw_ui_list
from ..utils.naming import mirror_name
from ..utils.action_layers import ActionSlotBase
from ..utils.rig import get_rigify_target_rig
from ..utils.rig import get_rigify_target_rig, is_valid_metarig
def get_action_slots(arm: Armature) -> Sequence['ActionSlot']:
@ -323,7 +323,7 @@ class DATA_PT_rigify_actions(Panel):
@classmethod
def poll(cls, context):
return context.object.mode in ('POSE', 'OBJECT')
return context.object.mode in ('POSE', 'OBJECT') and is_valid_metarig(context)
def draw(self, context: Context):
armature_id_store = context.object.data

View File

@ -5,6 +5,7 @@
import bpy
import importlib
from ..utils.layers import is_collection_ref_list_prop, mirror_ref_list
from ..utils.naming import Side, get_name_base_and_sides, mirror_name
from ..utils.misc import property_to_python
@ -35,6 +36,7 @@ class POSE_OT_rigify_copy_single_parameter(bpy.types.Operator):
and context.active_pose_bone
and context.active_object.data.get('rig_id') is None
and get_rigify_type(context.active_pose_bone)
and len(context.selected_pose_bones) > 1
)
def invoke(self, context, event):
@ -56,6 +58,13 @@ class POSE_OT_rigify_copy_single_parameter(bpy.types.Operator):
value = getattr(params, self.property_name)
num_copied = 0
# If copying collection references, include the toggle
is_coll_refs = self.property_name.endswith("_coll_refs")
if is_coll_refs:
assert is_collection_ref_list_prop(value)
coll_refs_toggle_prop = self.property_name[:-10] + "_layers_extra"
coll_refs_toggle_val = getattr(params, coll_refs_toggle_prop)
# Copy to different bones of appropriate rig types
for sel_pbone in context.selected_pose_bones:
rig_type = get_rigify_type(sel_pbone)
@ -67,15 +76,27 @@ class POSE_OT_rigify_copy_single_parameter(bpy.types.Operator):
new_value = value
# If mirror requested and copying to a different side bone, mirror the value
do_mirror = False
if self.mirror_bone and active_split.side != Side.MIDDLE and value:
sel_split = get_name_base_and_sides(sel_pbone.name)
if sel_split.side == -active_split.side:
new_value = mirror_name(value)
do_mirror = True
# Assign the final value
sel_params = get_rigify_params(sel_pbone)
if is_coll_refs and do_mirror:
mirror_ref_list(getattr(sel_params, self.property_name), value)
elif do_mirror:
setattr(sel_params, self.property_name, mirror_name(value))
else:
setattr(sel_params, self.property_name, new_value)
if is_coll_refs:
setattr(sel_params, coll_refs_toggle_prop, coll_refs_toggle_val) # noqa
num_copied += 1
if num_copied:
@ -125,8 +146,20 @@ def copy_rigify_params(from_bone: bpy.types.PoseBone, to_bone: bpy.types.PoseBon
from_params = from_bone.get('rigify_parameters')
if from_params and rig_type:
param_dict = property_to_python(from_params)
if x_mirror:
param_dict = recursive_mirror(param_dict)
to_bone['rigify_parameters'] = recursive_mirror(param_dict)
# Bone collection references must be mirrored specially
from_params_typed = get_rigify_params(from_bone)
to_params_typed = get_rigify_params(to_bone)
for prop_name in param_dict.keys():
if prop_name.endswith("_coll_refs"):
ref_list = getattr(from_params_typed, prop_name)
if is_collection_ref_list_prop(ref_list):
mirror_ref_list(getattr(to_params_typed, prop_name), ref_list)
else:
to_bone['rigify_parameters'] = param_dict
else:
try:

View File

@ -11,6 +11,7 @@ from mathutils import Vector
from ..utils.errors import MetarigError
from ..utils.rig import get_rigify_type
from ..utils.node_merger import NodeMerger
from ..utils.layers import ControlLayersOption, set_bone_layers, union_layer_lists
def find_face_bone(obj):
@ -289,15 +290,22 @@ def parent_bone(obj, name_map, bone, parent=None, connect=False, **_kwargs):
def set_layers(obj, name_map, layer_table, bone, layer=2, pri_layer=None, sec_layer=None, **_kwargs):
bone = name_map.get(bone, bone)
pbone = obj.pose.bones[bone]
pbone.bone.layers = layer_table[layer]
main_layers = layer_table[layer]
set_bone_layers(pbone.bone, main_layers)
if pri_layer:
pbone.rigify_parameters.skin_primary_layers_extra = True
pbone.rigify_parameters.skin_primary_layers = layer_table[pri_layer]
if pri_layer is not None:
pri_layers = layer_table[pri_layer]
ControlLayersOption.SKIN_PRIMARY.set(
pbone.rigify_parameters,
pri_layers if pri_layers != main_layers else None
)
if sec_layer:
pbone.rigify_parameters.skin_secondary_layers_extra = True
pbone.rigify_parameters.skin_secondary_layers = layer_table[sec_layer]
if sec_layer is not None:
sec_layers = layer_table[sec_layer]
ControlLayersOption.SKIN_SECONDARY.set(
pbone.rigify_parameters,
sec_layers if sec_layers != main_layers else None
)
connect_ends_map = {
@ -370,17 +378,10 @@ def update_face_rig(obj):
# Find the layer settings
face_pbone = obj.pose.bones[face_bone]
main_layers = list(face_pbone.bone.layers)
main_layers = list(face_pbone.bone.collections)
if face_pbone.rigify_parameters.primary_layers_extra:
primary_layers = face_pbone.rigify_parameters.primary_layers
else:
primary_layers = main_layers
if face_pbone.rigify_parameters.secondary_layers_extra:
secondary_layers = face_pbone.rigify_parameters.secondary_layers
else:
secondary_layers = main_layers
primary_layers = ControlLayersOption.FACE_PRIMARY.get(face_pbone.rigify_parameters) or main_layers
secondary_layers = ControlLayersOption.FACE_SECONDARY.get(face_pbone.rigify_parameters) or main_layers
# Edit mode changes
bpy.ops.object.mode_set(mode='EDIT')
@ -397,15 +398,14 @@ def update_face_rig(obj):
# Set bone layers
layer_table = {
0: main_layers, 1: primary_layers, 2: secondary_layers,
'*': [a or b or c for a, b, c in zip(main_layers, primary_layers, secondary_layers)],
'*': union_layer_lists([main_layers, primary_layers, secondary_layers]),
}
process_all(partial(set_rig, obj, name_map), name_map)
process_all(partial(set_layers, obj, name_map, layer_table), name_map)
for i, v in enumerate(layer_table['*']):
if v:
obj.data.layers[i] = True
for bcoll in layer_table['*']:
bcoll.is_visible = True
# noinspection PyPep8Naming

View File

@ -13,8 +13,6 @@ from . import base_generate
from rna_prop_ui import rna_idprop_quote_path
from .utils.rig import get_rigify_layers
UI_IMPORTS = [
'import bpy',
@ -885,11 +883,7 @@ class RigBakeSettings(bpy.types.Panel):
'''
def layers_ui(layers, layout):
""" Turn a list of booleans + a list of names into a layer UI.
"""
code = '''
UI_LAYERS_PANEL = '''
class RigLayers(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
@ -906,39 +900,22 @@ class RigLayers(bpy.types.Panel):
def draw(self, context):
layout = self.layout
row_table = collections.defaultdict(list)
for coll in context.active_object.data.collections:
row_id = coll.get('rigify_ui_row', 0)
if row_id > 0:
row_table[row_id].append(coll)
col = layout.column()
for row_id in range(min(row_table.keys()), 1 + max(row_table.keys())):
row = col.row()
row_buttons = row_table[row_id]
if row_buttons:
for coll in row_buttons:
title = coll.get('rigify_ui_title') or coll.name
row.prop(coll, 'is_visible', toggle=True, text=title)
else:
row.separator()
'''
rows = {}
for i in range(28):
if layers[i]:
if layout[i][1] not in rows:
rows[layout[i][1]] = []
rows[layout[i][1]] += [(layout[i][0], i)]
keys = list(rows.keys())
keys.sort()
for key in keys:
code += "\n row = col.row()\n"
i = 0
for layer in rows[key]:
if i > 3:
code += "\n row = col.row()\n"
i = 0
code += f" row.prop(context.active_object.data, 'layers', "\
f"index={layer[1]}, toggle=True, text='{layer[0]}')\n"
i += 1
# Root layer
code += "\n row = col.row()"
code += "\n row.separator()"
code += "\n row = col.row()"
code += "\n row.separator()\n"
code += "\n row = col.row()\n"
code += " row.prop(context.active_object.data, 'layers', "\
"index=28, toggle=True, text='Root')\n"
return code
def quote_parameters(positional: list[Any], named: dict[str, Any]):
@ -1179,19 +1156,6 @@ class ScriptGenerator(base_generate.GeneratorPlugin):
metarig = self.generator.metarig
rig_id = self.generator.rig_id
vis_layers = self.obj.data.layers
# Ensure the collection of layer names exists
rigify_layers = get_rigify_layers(metarig.data)
for i in range(1 + len(rigify_layers), 29):
rigify_layers.add()
# Create list of layer name/row pairs
layer_layout = []
for layer in rigify_layers:
layer_layout += [(layer.name, layer.row)]
# Generate the UI script
script = metarig.data.rigify_rig_ui
@ -1227,7 +1191,7 @@ class ScriptGenerator(base_generate.GeneratorPlugin):
self.ui_register = UI_REGISTER_BAKE_SETTINGS + self.ui_register
script.write(UI_BAKE_SETTINGS)
script.write(layers_ui(vis_layers, layer_layout))
script.write(UI_LAYERS_PANEL)
script.write("\ndef register():\n")

View File

@ -161,5 +161,7 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -236,5 +236,7 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -222,5 +222,7 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -185,5 +185,7 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -816,10 +816,6 @@ def create_sample(obj):
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False]
pbone = obj.pose.bones[bones['spine.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -827,10 +823,6 @@ def create_sample(obj):
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False]
pbone = obj.pose.bones[bones['spine.002']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -838,10 +830,6 @@ def create_sample(obj):
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False]
pbone = obj.pose.bones[bones['spine.003']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -849,10 +837,6 @@ def create_sample(obj):
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [
True, False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False]
bpy.ops.object.mode_set(mode='EDIT')
for bone in arm.edit_bones:
@ -865,5 +849,6 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
arm.layers = [(x in [0]) for x in range(32)]

View File

@ -189,5 +189,7 @@ def create_sample(obj):
bone.select_tail = True
bone.bbone_x = bone.bbone_z = bone.length * 0.05
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -12,6 +12,7 @@ from bpy.types import PoseBone
from mathutils import Vector, Matrix
from ...rig_ui_template import PanelLayout
from ...utils.layers import set_bone_layers, union_layer_lists
from ...utils.naming import make_derived_name, mirror_name, change_name_side, Side, SideZ
from ...utils.bones import align_bone_z_axis, put_bone, TypedBoneDict
from ...utils.widgets import (widget_generator, generate_circle_geometry,
@ -567,8 +568,7 @@ class EyeClusterControl(RigComponent):
def get_master_control_layers(self):
"""Combine layers of all eyes for the cluster control."""
all_layers = [list(self.get_bone(rig.base_bone).layers) for rig in self.rig_list]
return [any(items) for items in zip(*all_layers)]
return union_layer_lists(list(self.get_bone(rig.base_bone).collections) for rig in self.rig_list)
def get_all_rig_control_bones(self):
"""Make a list of all control bones of all clustered eyes."""
@ -601,7 +601,7 @@ class EyeClusterControl(RigComponent):
bone = self.get_bone(name)
bone.matrix = self.matrix
bone.length = self.size
bone.layers = self.get_master_control_layers()
set_bone_layers(bone, self.get_master_control_layers())
return name
def make_child_control(self, rig: Rig):
@ -836,5 +836,7 @@ def create_sample(obj):
bone.select_tail = True
bone.bbone_x = bone.bbone_z = bone.length * 0.05
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -874,5 +874,7 @@ def create_sample(obj):
bone.select_tail = True
bone.bbone_x = bone.bbone_z = bone.length * 0.05
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -54,16 +54,6 @@ class Rig:
self.face_length = obj.data.bones[self.org_bones[0]].length
self.params = params
if params.primary_layers_extra:
self.primary_layers = list(params.primary_layers)
else:
self.primary_layers = None
if params.secondary_layers_extra:
self.secondary_layers = list(params.secondary_layers)
else:
self.secondary_layers = None
def orient_org_bones(self):
bpy.ops.object.mode_set(mode='EDIT')
@ -316,12 +306,10 @@ class Rig:
for bone in tweaks:
if bone in primary_tweaks:
if self.primary_layers:
pb[bone].bone.layers = self.primary_layers
ControlLayersOption.FACE_PRIMARY.assign(self.params, pb, [bone])
create_face_widget(self.obj, bone, size=1.5)
else:
if self.secondary_layers:
pb[bone].bone.layers = self.secondary_layers
ControlLayersOption.FACE_SECONDARY.assign(self.params, pb, [bone])
create_face_widget(self.obj, bone)
return {'all': tweaks}
@ -2364,6 +2352,8 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
def create_square_widget(rig, bone_name, size=1.0, bone_transform_name=None):

View File

@ -173,20 +173,6 @@ def create_sample(obj, limb=False):
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
try:
pbone.rigify_parameters.tweak_layers = [
False, False, False, False, False, False, False, False, False, True, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = [
False, False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
@ -217,5 +203,7 @@ def create_sample(obj, limb=False):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -226,20 +226,6 @@ def create_sample(obj):
pbone.rigify_parameters.limb_type = "paw"
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = [
False, False, False, False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = [
False, False, False, False, False, False, False, False, False, True, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
pbone = obj.pose.bones[bones['front_shin.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -278,5 +264,7 @@ def create_sample(obj):
bone.select_tail = True
bone.bbone_x = bone.bbone_z = bone.length * 0.05
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -405,6 +405,10 @@ def create_sample(obj):
bpy.ops.object.mode_set(mode='EDIT')
arm = obj.data
def assign_bone_collections(pose_bone):
if active := arm.collections.active:
active.assign(pose_bone)
bones = {}
bone = arm.edit_bones.new('thigh.L')
@ -454,42 +458,10 @@ def create_sample(obj):
pbone.rigify_parameters.separate_ik_layers = True
except AttributeError:
pass
try:
pbone.rigify_parameters.ik_layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, True, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.separate_hose_layers = True
except AttributeError:
pass
try:
pbone.rigify_parameters.hose_layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.limb_type = "leg"
except AttributeError:
pass
try:
pbone.rigify_parameters.fk_layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, True, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.extra_ik_toe = True
except AttributeError:
@ -538,14 +510,7 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
for eb in arm.edit_bones:
eb.layers = (False, False, False, False, False, False, False, False, False, False, False,
False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
arm.layers = (False, False, False, False, False, False, False, False, False, False, False,
False, False, True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False)
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -309,20 +309,6 @@ def create_sample(obj):
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
try:
pbone.rigify_parameters.fk_layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = [
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, True, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.limb_type = "paw"
except AttributeError:
@ -368,5 +354,7 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -163,5 +163,7 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -665,17 +665,6 @@ def create_sample(obj):
pbone.lock_rotation_w = False
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
try:
pbone.rigify_parameters.extra_layers = [
False, False, False, False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_extra_layers = False
except AttributeError:
pass
try:
pbone.rigify_parameters.ik_local_location = False
except AttributeError:
@ -706,3 +695,5 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)

View File

@ -422,3 +422,5 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)

View File

@ -525,7 +525,7 @@ class ControlBoneNode(MainMergeNode, BaseSkinNode):
layers = self.rig.get_control_node_layers(self)
if layers:
bone = self.get_bone(self.control_bone).bone
set_bone_layers(bone, layers, not self.is_master_node)
set_bone_layers(bone, layers, combine=not self.is_master_node)
def rig_bones(self):
if self.is_master_node:

View File

@ -170,9 +170,9 @@ class BaseSkinChainRig(BaseSkinRig):
"""
return get_bone_quaternion(self.obj, self.base_bone)
def get_control_node_layers(self, node: 'ControlBoneNode') -> list[bool]:
def get_control_node_layers(self, node: 'ControlBoneNode') -> list[bpy.types.BoneCollection]:
"""Returns the armature layers to use for the given control node owned by this rig."""
return list(self.get_bone(self.base_bone).bone.layers)
return list(self.get_bone(self.base_bone).bone.collections)
def make_control_node_widget(self, node: 'ControlBoneNode'):
"""Called to generate the widget for nodes with ControlNodeIcon.CUSTOM."""

View File

@ -348,13 +348,6 @@ def create_sample(obj):
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
try:
pbone.rigify_parameters.tweak_layers = [
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
pbone = obj.pose.bones[bones['spine.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -388,5 +381,7 @@ def create_sample(obj):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)
return bones

View File

@ -212,13 +212,6 @@ def create_sample(obj, *, parent=None):
pbone.rigify_parameters.connect_chain = bool(parent)
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = [
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
pbone = obj.pose.bones[bones['tail.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -245,3 +238,5 @@ def create_sample(obj, *, parent=None):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)

View File

@ -394,13 +394,6 @@ def create_sample(obj, *, parent=None):
pbone.rigify_parameters.connect_chain = bool(parent)
except AttributeError:
pass
try:
pbone.rigify_parameters.tweak_layers = [
False, False, False, False, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
except AttributeError:
pass
pbone = obj.pose.bones[bones['neck.001']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@ -427,3 +420,5 @@ def create_sample(obj, *, parent=None):
bone.select_head = True
bone.select_tail = True
arm.edit_bones.active = bone
if bcoll := arm.collections.active:
bcoll.assign(bone)

View File

@ -3,6 +3,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
from bpy.types import UIList, UILayout, Armature
from bpy.props import (
BoolProperty,
IntProperty,
@ -10,15 +11,18 @@ from bpy.props import (
StringProperty
)
from typing import TYPE_CHECKING, Callable
from collections import defaultdict
from typing import TYPE_CHECKING, Callable, Any
from mathutils import Color
from .utils.errors import MetarigError
from .utils.rig import write_metarig, get_rigify_type, get_rigify_target_rig, get_rigify_layers, \
from .utils.layers import ROOT_COLLECTION
from .utils.rig import write_metarig, get_rigify_type, get_rigify_target_rig, \
get_rigify_colors, get_rigify_params
from .utils.widgets import write_widget
from .utils.naming import unique_name
from .utils.rig import upgrade_metarig_types, outdated_types
from .utils.rig import upgrade_metarig_types, outdated_types, upgrade_metarig_layers, \
is_valid_metarig, metarig_needs_upgrade
from .utils.misc import verify_armature_obj, ArmatureObject, IdPropSequence
from .rigs.utils import get_limb_generated_names
@ -82,17 +86,18 @@ class DATA_PT_rigify(bpy.types.Panel):
@classmethod
def poll(cls, context):
obj = context.object
if not context.object:
return False
return obj.type == 'ARMATURE' \
and obj.data.get("rig_id") is None
return is_valid_metarig(context, allow_needs_upgrade=True)
def draw(self, context):
C = context
layout = self.layout
obj = verify_armature_obj(C.object)
if metarig_needs_upgrade(obj):
layout.label(text="This metarig requires upgrading to Bone Collections", icon='ERROR')
layout.operator("armature.rigify_upgrade_layers", text="Upgrade Metarig")
return
WARNING = "Warning: Some features may change after generation"
show_warning = False
show_update_metarig = False
@ -107,7 +112,7 @@ class DATA_PT_rigify(bpy.types.Panel):
# If we are in edit mode and the bone was just created,
# a pose bone won't exist yet.
continue
if bone.layers[30] and (list(set(pose_bone.keys()) & set(check_props))):
if list(set(pose_bone.keys()) & set(check_props)): # bone.layers[30] and
show_warning = True
break
@ -166,6 +171,10 @@ class DATA_PT_rigify_advanced(bpy.types.Panel):
bl_parent_id = 'DATA_PT_rigify'
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return is_valid_metarig(context)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
@ -205,12 +214,7 @@ class DATA_PT_rigify_samples(bpy.types.Panel):
@classmethod
def poll(cls, context):
obj = context.object
if not obj:
return False
return obj.type == 'ARMATURE' \
and obj.data.get("rig_id") is None \
and obj.mode == 'EDIT'
return is_valid_metarig(context) and context.object.mode == 'EDIT'
def draw(self, context):
layout = self.layout
@ -236,9 +240,34 @@ class DATA_PT_rigify_samples(bpy.types.Panel):
props.metarig_type = rigify_types[id_store.rigify_active_type].name
# noinspection SpellCheckingInspection
# noinspection PyPep8Naming
class DATA_PT_rigify_layer_names(bpy.types.Panel):
bl_label = "Layer Names"
class DATA_UL_rigify_bone_collections(UIList):
def draw_item(self, _context, layout, armature, bcoll, _icon, _active_data,
_active_prop_name, _index=0, _flt_flag=0):
active_bone = armature.edit_bones.active or armature.bones.active
has_active_bone = active_bone and bcoll.name in active_bone.collections
split = layout.split(factor=0.7)
split.prop(bcoll, "name", text="", emboss=False,
icon='DOT' if has_active_bone else 'BLANK1')
if cset := bcoll.rigify_color_set_name:
split.label(text=cset, icon="COLOR", translate=False)
icons = layout.row(align=True)
icons.prop(bcoll, "rigify_sel_set", text="", toggle=True, emboss=False,
icon='RADIOBUT_ON' if bcoll.rigify_sel_set else 'RADIOBUT_OFF')
icons.label(text="", icon='RESTRICT_SELECT_OFF' if bcoll.rigify_ui_row > 0 else 'RESTRICT_SELECT_ON')
icons.prop(bcoll, "is_visible", text="", emboss=False,
icon='HIDE_OFF' if bcoll.is_visible else 'HIDE_ON')
# noinspection PyPep8Naming
class DATA_PT_rigify_collection_list(bpy.types.Panel):
bl_label = "Bone Collection UI"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@ -247,89 +276,227 @@ class DATA_PT_rigify_layer_names(bpy.types.Panel):
@classmethod
def poll(cls, context):
if not context.object:
return False
return context.object.type == 'ARMATURE' and context.active_object.data.get("rig_id") is None
return is_valid_metarig(context)
def draw(self, context):
layout = self.layout
obj = verify_armature_obj(context.object)
arm = obj.data
rigify_layers = get_rigify_layers(arm)
rigify_colors = get_rigify_colors(arm)
# Copy the bone collection list
active_coll = arm.collections.active
# Ensure that the layers exist
if len(rigify_layers) < 29:
layout.operator("pose.rigify_layer_init")
return
row = layout.row()
# UI
main_row = layout.row(align=True).split(factor=0.05)
col1 = main_row.column()
col2 = main_row.column()
col1.label()
for i in range(32):
if i == 16 or i == 29:
col1.label()
col1.label(text=str(i))
row.template_list(
"DATA_UL_rigify_bone_collections",
"collections",
arm,
"collections",
arm.collections,
"active_index",
rows=(4 if active_coll else 1),
)
col: bpy.types.UILayout = col2
col = row.column(align=True)
col.operator("armature.collection_add", icon='ADD', text="")
col.operator("armature.collection_remove", icon='REMOVE', text="")
if active_coll:
col.separator()
col.operator("armature.collection_move", icon='TRIA_UP', text="").direction = 'UP'
col.operator("armature.collection_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
for i, rigify_layer in enumerate(rigify_layers):
# note: rigify_layer == arm.rigify_layers[i]
if (i % 16) == 0:
col = col2.column()
if i == 0:
col.label(text="Top Row:")
else:
col.label(text="Bottom Row:")
if (i % 8) == 0:
col = col2.column()
if i != 28:
row = col.row(align=True)
icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON'
row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon)
# row.prop(arm, "layers", index=i, text="Layer %d" % (i + 1), toggle=True, icon=icon)
row.prop(rigify_layer, "name", text="")
row.prop(rigify_layer, "row", text="UI Row")
icon = 'RADIOBUT_ON' if rigify_layer.selset else 'RADIOBUT_OFF'
row.prop(rigify_layer, "selset", text="", toggle=True, icon=icon)
row.prop(rigify_layer, "group", text="Bone Group")
else:
row = col.row(align=True)
if active_coll:
col = layout.column()
col.use_property_split = True
col.use_property_decorate = False
icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON'
row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon)
# row.prop(arm, "layers", index=i, text="Layer %d" % (i + 1), toggle=True, icon=icon)
row1 = row.split(align=True).row(align=True)
row1.prop(rigify_layer, "name", text="")
row1.prop(rigify_layer, "row", text="UI Row")
row1.enabled = False
icon = 'RADIOBUT_ON' if rigify_layer.selset else 'RADIOBUT_OFF'
row.prop(rigify_layer, "selset", text="", toggle=True, icon=icon)
row.prop(rigify_layer, "group", text="Bone Group")
if rigify_layer.group == 0:
row.label(text='None')
else:
row.label(text=rigify_colors[rigify_layer.group-1].name)
col.prop(active_coll, "rigify_color_set_name", icon="COLOR")
col.prop(active_coll, "rigify_sel_set")
col.separator()
col = col2.column()
col.label(text="Reserved:")
# reserved_names = {28: 'Root', 29: 'DEF', 30: 'MCH', 31: 'ORG'}
reserved_names = {29: 'DEF', 30: 'MCH', 31: 'ORG'}
# for i in range(28, 32):
for i in range(29, 32):
row = col.row(align=True)
icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON'
row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon)
row.label(text=reserved_names[i])
col.prop(active_coll, "rigify_ui_row", )
row = col.row()
row.active = active_coll.rigify_ui_row > 0 # noqa
row.prop(active_coll, "rigify_ui_title")
if ROOT_COLLECTION not in arm.collections:
layout.label(text=f"The '{ROOT_COLLECTION}' collection will be added upon generation", icon='ERROR')
# noinspection PyPep8Naming
class DATA_OT_rigify_add_bone_groups(bpy.types.Operator):
bl_idname = "armature.rigify_add_bone_groups"
bl_label = "Rigify Add Standard Bone Groups"
class DATA_PT_rigify_collection_ui(bpy.types.Panel):
bl_label = "UI Layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_options = set()
bl_parent_id = "DATA_PT_rigify_collection_list"
@classmethod
def poll(cls, context):
return is_valid_metarig(context)
@staticmethod
def draw_btn_block(arm: Armature, parent: UILayout, bcoll_id: int, loose=False):
bcoll = arm.collections[bcoll_id]
block = parent.row(align=True)
if bcoll == arm.collections.active:
block.prop(bcoll, "rigify_ui_title_name", text="", emboss=True)
if not loose:
props = block.operator(text="", icon="X", operator="armature.rigify_collection_set_ui_row")
props.index = bcoll_id
props.row = 0
else:
props = block.operator(text=bcoll.rigify_ui_title_name, operator="armature.rigify_collection_select")
props.index = bcoll_id
def draw(self, context):
layout = self.layout
obj = verify_armature_obj(context.object)
arm = obj.data
# Sort into button rows
row_table = defaultdict(list)
for i, bcoll in enumerate(arm.collections):
row_table[bcoll.rigify_ui_row].append(i)
active_bcoll_idx = arm.collections.active_index
if active_bcoll_idx < 0:
layout.label(text="Click a button to select a collection:", icon="INFO")
box = layout.box()
last_row = max(row_table.keys())
for row_id in range(1, last_row + 2):
row = box.row()
row_items = row_table[row_id]
grid = row.grid_flow(row_major=True, columns=len(row_items), even_columns=True)
for bcoll_id in row_items:
self.draw_btn_block(arm, grid, bcoll_id)
btn_row = row.row(align=True)
if active_bcoll_idx >= 0:
props = btn_row.operator(text="", icon="TRIA_LEFT", operator="armature.rigify_collection_set_ui_row")
props.index = active_bcoll_idx
props.row = row_id
if row_id < last_row + 1:
props = btn_row.operator(text="", icon="ADD", operator="armature.rigify_collection_add_ui_row")
props.row = row_id
props.add = True
else:
btn_row.label(text="", icon="BLANK1")
if row_id < last_row:
props = btn_row.operator(text="", icon="REMOVE", operator="armature.rigify_collection_add_ui_row")
props.row = row_id + 1
props.add = False
else:
btn_row.label(text="", icon="BLANK1")
if 0 in row_table:
box = layout.box()
box.label(text="No button:")
grid = box.grid_flow(row_major=True, columns=2, even_columns=True)
for i, bcoll_id in enumerate(row_table[0]):
self.draw_btn_block(arm, grid, bcoll_id, loose=True)
# noinspection PyPep8Naming
class DATA_OT_rigify_collection_select(bpy.types.Operator):
bl_idname = "armature.rigify_collection_select"
bl_label = "Make Collection Active"
bl_description = "Make this collection active"
bl_options = {'UNDO_GROUPED'}
index: IntProperty(name="Index")
@staticmethod
def button(layout, *, index, **kwargs):
props = layout.operator(**kwargs)
props.index = index
@classmethod
def poll(cls, context):
return context.object and context.object.type == 'ARMATURE'
def execute(self, context):
obj = verify_armature_obj(context.object)
obj.data.collections.active_index = self.index
return {'FINISHED'}
# noinspection PyPep8Naming
class DATA_OT_rigify_collection_set_ui_row(bpy.types.Operator):
bl_idname = "armature.rigify_collection_set_ui_row"
bl_label = "Move Between UI Rows"
bl_options = {'UNDO'}
index: IntProperty(name="Index")
row: IntProperty(name="Row")
select: BoolProperty(name="Select")
@classmethod
def poll(cls, context):
return context.object and context.object.type == 'ARMATURE'
@classmethod
def description(cls, context, properties: Any):
if properties.row == 0:
return "Remove this button from the UI panel"
else:
return "Move the active button to this UI panel row"
def execute(self, context):
obj = verify_armature_obj(context.object)
if self.select:
obj.data.collections.active_index = self.index
obj.data.collections[self.index].rigify_ui_row = self.row
return {'FINISHED'}
# noinspection PyPep8Naming
class DATA_OT_rigify_collection_add_ui_row(bpy.types.Operator):
bl_idname = "armature.rigify_collection_add_ui_row"
bl_label = "Add/Remove UI Rows"
bl_options = {'UNDO'}
row: IntProperty(name="Row")
add: BoolProperty(name="Add")
@classmethod
def poll(cls, context):
return context.object and context.object.type == 'ARMATURE'
@classmethod
def description(cls, context, properties: Any):
if properties.add:
return "Insert a new row before this one, shifting buttons down"
else:
return "Remove this row, shifting buttons up"
def execute(self, context):
obj = verify_armature_obj(context.object)
for coll in obj.data.collections:
if coll.rigify_ui_row >= self.row:
coll.rigify_ui_row += (1 if self.add else -1)
return {'FINISHED'}
# noinspection PyPep8Naming
class DATA_OT_rigify_add_color_sets(bpy.types.Operator):
bl_idname = "armature.rigify_add_color_sets"
bl_label = "Rigify Add Standard Color Sets"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
@ -376,6 +543,7 @@ class DATA_OT_rigify_add_bone_groups(bpy.types.Operator):
class DATA_OT_rigify_use_standard_colors(bpy.types.Operator):
bl_idname = "armature.rigify_use_standard_colors"
bl_label = "Rigify Get active/select colors from current theme"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
@ -405,6 +573,7 @@ class DATA_OT_rigify_use_standard_colors(bpy.types.Operator):
class DATA_OT_rigify_apply_selection_colors(bpy.types.Operator):
bl_idname = "armature.rigify_apply_selection_colors"
bl_label = "Rigify Apply user defined active/select colors"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
@ -431,9 +600,10 @@ class DATA_OT_rigify_apply_selection_colors(bpy.types.Operator):
# noinspection PyPep8Naming
class DATA_OT_rigify_bone_group_add(bpy.types.Operator):
bl_idname = "armature.rigify_bone_group_add"
bl_label = "Rigify Add Bone Group color set"
class DATA_OT_rigify_color_set_add(bpy.types.Operator):
bl_idname = "armature.rigify_color_set_add"
bl_label = "Rigify Add Color Set"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
@ -461,9 +631,9 @@ class DATA_OT_rigify_bone_group_add(bpy.types.Operator):
# noinspection PyPep8Naming
class DATA_OT_rigify_bone_group_add_theme(bpy.types.Operator):
bl_idname = "armature.rigify_bone_group_add_theme"
bl_label = "Rigify Add Bone Group color set from Theme"
class DATA_OT_rigify_color_set_add_theme(bpy.types.Operator):
bl_idname = "armature.rigify_color_set_add_theme"
bl_label = "Rigify Add Color Set from Theme"
bl_options = {"REGISTER", "UNDO"}
theme: EnumProperty(items=(
@ -519,9 +689,10 @@ class DATA_OT_rigify_bone_group_add_theme(bpy.types.Operator):
# noinspection PyPep8Naming
class DATA_OT_rigify_bone_group_remove(bpy.types.Operator):
bl_idname = "armature.rigify_bone_group_remove"
bl_label = "Rigify Remove Bone Group color set"
class DATA_OT_rigify_color_set_remove(bpy.types.Operator):
bl_idname = "armature.rigify_color_set_remove"
bl_label = "Rigify Remove Color Set"
bl_options = {'UNDO'}
idx: IntProperty()
@ -536,21 +707,22 @@ class DATA_OT_rigify_bone_group_remove(bpy.types.Operator):
rigify_colors.remove(self.idx)
# set layers references to 0
rigify_layers = get_rigify_layers(obj.data)
for coll in obj.data.collections:
idx = coll.rigify_color_set_id
for layer in rigify_layers:
if layer.group == self.idx + 1:
layer.group = 0
elif layer.group > self.idx + 1:
layer.group -= 1
if idx == self.idx + 1:
coll.rigify_color_set_id = 0
elif idx > self.idx + 1:
coll.rigify_color_set_id = idx - 1
return {'FINISHED'}
# noinspection PyPep8Naming
class DATA_OT_rigify_bone_group_remove_all(bpy.types.Operator):
bl_idname = "armature.rigify_bone_group_remove_all"
bl_label = "Rigify Remove All Bone Groups"
class DATA_OT_rigify_color_set_remove_all(bpy.types.Operator):
bl_idname = "armature.rigify_color_set_remove_all"
bl_label = "Rigify Remove All Color Sets"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
@ -564,15 +736,15 @@ class DATA_OT_rigify_bone_group_remove_all(bpy.types.Operator):
rigify_colors.remove(0)
# set layers references to 0
for layer in get_rigify_layers(obj.data):
layer.group = 0
for coll in obj.data.collections:
coll.rigify_color_set_id = 0
return {'FINISHED'}
# noinspection PyPep8Naming
class DATA_UL_rigify_bone_groups(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index=0, flt_flag=0):
class DATA_UL_rigify_color_sets(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_prop_name, index=0, flt_flag=0):
row = layout.row(align=True)
row = row.split(factor=0.1)
row.label(text=str(index+1))
@ -591,18 +763,19 @@ class DATA_UL_rigify_bone_groups(bpy.types.UIList):
# noinspection PyPep8Naming
class DATA_MT_rigify_bone_groups_context_menu(bpy.types.Menu):
bl_label = 'Rigify Bone Groups Specials'
class DATA_MT_rigify_color_sets_context_menu(bpy.types.Menu):
bl_label = 'Rigify Color Sets Specials'
def draw(self, context):
layout = self.layout
layout.operator('armature.rigify_bone_group_remove_all')
layout.operator('armature.rigify_color_set_remove_all')
# noinspection SpellCheckingInspection
# noinspection PyPep8Naming
class DATA_PT_rigify_bone_groups(bpy.types.Panel):
bl_label = "Bone Groups"
class DATA_PT_rigify_color_sets(bpy.types.Panel):
bl_label = "Color Sets"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@ -611,9 +784,7 @@ class DATA_PT_rigify_bone_groups(bpy.types.Panel):
@classmethod
def poll(cls, context):
if not context.object:
return False
return context.object.type == 'ARMATURE' and context.active_object.data.get("rig_id") is None
return is_valid_metarig(context)
def draw(self, context):
obj = verify_armature_obj(context.object)
@ -634,18 +805,18 @@ class DATA_PT_rigify_bone_groups(bpy.types.Panel):
row.prop(armature, 'rigify_colors_lock', text='Unified select/active colors', icon=icon)
row.operator("armature.rigify_apply_selection_colors", icon='FILE_REFRESH', text='Apply')
row = layout.row()
row.template_list("DATA_UL_rigify_bone_groups", "", obj.data, "rigify_colors", obj.data, "rigify_colors_index")
row.template_list("DATA_UL_rigify_color_sets", "", obj.data, "rigify_colors", obj.data, "rigify_colors_index")
col = row.column(align=True)
col.operator("armature.rigify_bone_group_add", icon='ADD', text="")
col.operator("armature.rigify_bone_group_remove", icon='REMOVE', text="").idx = idx
col.menu("DATA_MT_rigify_bone_groups_context_menu", icon='DOWNARROW_HLT', text="")
col.operator("armature.rigify_color_set_add", icon='ADD', text="")
col.operator("armature.rigify_color_set_remove", icon='REMOVE', text="").idx = idx
col.menu("DATA_MT_rigify_color_sets_context_menu", icon='DOWNARROW_HLT', text="")
row = layout.row()
row.prop(armature, 'rigify_theme_to_add', text='Theme')
op = row.operator("armature.rigify_bone_group_add_theme", text="Add From Theme")
op = row.operator("armature.rigify_color_set_add_theme", text="Add From Theme")
op.theme = theme
row = layout.row()
row.operator("armature.rigify_add_bone_groups", text="Add Standard")
row.operator("armature.rigify_add_color_sets", text="Add Standard")
# noinspection PyPep8Naming
@ -658,10 +829,7 @@ class BONE_PT_rigify_buttons(bpy.types.Panel):
@classmethod
def poll(cls, context):
if not context.object:
return False
return (context.object.type == 'ARMATURE' and context.active_pose_bone and
context.active_object.data.get("rig_id") is None)
return is_valid_metarig(context) and context.active_pose_bone
def draw(self, context):
C = context
@ -822,24 +990,6 @@ def rigify_report_exception(operator, exception):
operator.report({'ERROR'}, '\n'.join(message))
class LayerInit(bpy.types.Operator):
"""Initialize armature rigify layers"""
bl_idname = "pose.rigify_layer_init"
bl_label = "Add Rigify Layers"
bl_options = {'UNDO', 'INTERNAL'}
def execute(self, context):
obj = verify_armature_obj(context.object)
arm = obj.data
rigify_layers = get_rigify_layers(arm)
for i in range(1 + len(rigify_layers), 30):
rigify_layers.add()
rigify_layers[28].name = 'Root'
rigify_layers[28].row = 14
return {'FINISHED'}
def is_metarig(obj):
if not (obj and obj.data and obj.type == 'ARMATURE'):
return False
@ -895,9 +1045,20 @@ class UpgradeMetarigTypes(bpy.types.Operator):
bl_options = {'UNDO'}
def execute(self, context):
for obj in bpy.data.objects:
if type(obj.data) == bpy.types.Armature:
upgrade_metarig_types(obj)
upgrade_metarig_types(verify_armature_obj(context.active_object))
return {'FINISHED'}
class UpgradeMetarigLayers(bpy.types.Operator):
"""Upgrades the metarig from bone layers to bone collections"""
bl_idname = "armature.rigify_upgrade_layers"
bl_label = "Rigify Upgrade Metarig Layers"
bl_description = 'Upgrades the metarig from bone layers to bone collections'
bl_options = {'UNDO'}
def execute(self, context):
upgrade_metarig_layers(verify_armature_obj(context.active_object))
return {'FINISHED'}
@ -1466,30 +1627,74 @@ class OBJECT_OT_Rot2Pole(bpy.types.Operator):
return {'FINISHED'}
# noinspection PyPep8Naming
class POSE_OT_rigify_collection_ref_add(bpy.types.Operator):
bl_idname = "pose.rigify_collection_ref_add"
bl_label = "Add Bone Collection Reference"
bl_description = "Add a new row to the bone collection reference list"
bl_options = {'UNDO'}
prop_name: StringProperty(name="Property Name")
@classmethod
def poll(cls, context):
return is_valid_metarig(context) and context.active_pose_bone
def execute(self, context):
params = get_rigify_params(context.active_pose_bone)
getattr(params, self.prop_name).add()
return {'FINISHED'}
# noinspection PyPep8Naming
class POSE_OT_rigify_collection_ref_remove(bpy.types.Operator):
bl_idname = "pose.rigify_collection_ref_remove"
bl_label = "Remove Bone Collection Reference"
bl_description = "Remove this row from the bone collection reference list"
bl_options = {'UNDO'}
prop_name: StringProperty(name="Property Name")
index: IntProperty(name="Entry Index")
@classmethod
def poll(cls, context):
return is_valid_metarig(context) and context.active_pose_bone
def execute(self, context):
params = get_rigify_params(context.active_pose_bone)
getattr(params, self.prop_name).remove(self.index)
return {'FINISHED'}
###############
# Registering
classes = (
DATA_OT_rigify_add_bone_groups,
DATA_OT_rigify_add_color_sets,
DATA_OT_rigify_use_standard_colors,
DATA_OT_rigify_apply_selection_colors,
DATA_OT_rigify_bone_group_add,
DATA_OT_rigify_bone_group_add_theme,
DATA_OT_rigify_bone_group_remove,
DATA_OT_rigify_bone_group_remove_all,
DATA_UL_rigify_bone_groups,
DATA_MT_rigify_bone_groups_context_menu,
DATA_OT_rigify_color_set_add,
DATA_OT_rigify_color_set_add_theme,
DATA_OT_rigify_color_set_remove,
DATA_OT_rigify_color_set_remove_all,
DATA_UL_rigify_color_sets,
DATA_MT_rigify_color_sets_context_menu,
DATA_PT_rigify,
DATA_PT_rigify_advanced,
DATA_PT_rigify_bone_groups,
DATA_PT_rigify_layer_names,
DATA_PT_rigify_color_sets,
DATA_UL_rigify_bone_collections,
DATA_PT_rigify_collection_list,
DATA_PT_rigify_collection_ui,
DATA_OT_rigify_collection_select,
DATA_OT_rigify_collection_set_ui_row,
DATA_OT_rigify_collection_add_ui_row,
DATA_PT_rigify_samples,
BONE_PT_rigify_buttons,
VIEW3D_PT_rigify_animation_tools,
VIEW3D_PT_tools_rigify_dev,
LayerInit,
Generate,
UpgradeMetarigTypes,
UpgradeMetarigLayers,
Sample,
VIEW3D_MT_rigify,
EncodeMetarig,
@ -1501,6 +1706,8 @@ classes = (
OBJECT_OT_TransferIKtoFK,
OBJECT_OT_ClearAnimation,
OBJECT_OT_Rot2Pole,
POSE_OT_rigify_collection_ref_add,
POSE_OT_rigify_collection_ref_remove,
)

View File

@ -32,7 +32,7 @@ from .rig import RIG_DIR, METARIG_DIR, TEMPLATE_DIR, outdated_types, upgrade_met
from .rig import write_metarig, get_resource
from .rig import connected_children_names, has_connected_children
from .layers import get_layers, ControlLayersOption
from .layers import ControlLayersOption
# Definitions so bad as to make them strictly compatibility only
from .bones import copy_bone as copy_bone_simple

View File

@ -134,13 +134,15 @@ def copy_bone(obj: ArmatureObject, bone_name: str, assign_name='', *,
if obj == bpy.context.active_object and bpy.context.mode == 'EDIT_ARMATURE':
if assign_name == '':
assign_name = bone_name
# Copy the edit bone
edit_bone_1 = obj.data.edit_bones[bone_name]
edit_bone_2 = obj.data.edit_bones.new(assign_name)
bone_name_2 = edit_bone_2.name
# Copy edit bone attributes
edit_bone_2.layers = list(edit_bone_1.layers)
for coll in edit_bone_1.collections:
coll.assign(edit_bone_2)
edit_bone_2.head = Vector(edit_bone_1.head)
edit_bone_2.tail = Vector(edit_bone_1.tail)

View File

@ -4,49 +4,70 @@
import bpy
from typing import TYPE_CHECKING, Sequence, Optional, Mapping
from bpy.types import Bone, UILayout, Object, PoseBone, Armature
from typing import TYPE_CHECKING, Sequence, Optional, Mapping, Iterable, Any
from bpy.types import bpy_prop_collection # noqa
from bpy.types import Bone, UILayout, Object, PoseBone, Armature, BoneCollection, EditBone
from .misc import ArmatureObject
from .naming import mirror_name_fuzzy
if TYPE_CHECKING:
from ..base_rig import BaseRig
from .. import RigifyBoneCollectionReference
ORG_LAYER = [n == 31 for n in range(0, 32)] # Armature layer that original bones should be moved to.
MCH_LAYER = [n == 30 for n in range(0, 32)] # Armature layer that mechanism bones should be moved to.
DEF_LAYER = [n == 29 for n in range(0, 32)] # Armature layer that deformation bones should be moved to.
ROOT_LAYER = [n == 28 for n in range(0, 32)] # Armature layer that root bone should be moved to.
ROOT_COLLECTION = "Root"
DEF_COLLECTION = "DEF"
ORG_COLLECTION = "ORG"
MCH_COLLECTION = "MCH"
def get_layers(layers) -> list[bool]:
""" Does its best to extract a set of layers from any data thrown at it.
"""
if type(layers) == int:
return [x == layers for x in range(0, 32)]
elif type(layers) == str:
items = layers.split(",")
layers = []
for i in items:
try:
layers += [int(float(i))]
except ValueError:
pass
return [x in layers for x in range(0, 32)]
elif type(layers) == tuple or type(layers) == list:
return [x in layers for x in range(0, 32)]
else:
try:
list(layers)
except TypeError:
pass
else:
return [x in layers for x in range(0, 32)]
def set_bone_layers(bone: Bone | EditBone, layers: Sequence[BoneCollection], *, combine=False):
if not layers:
return
if not combine:
for coll in list(bone.collections):
coll.unassign(bone)
for coll in layers:
coll.assign(bone)
def set_bone_layers(bone: Bone, layers: Sequence[bool], combine=False):
if combine:
bone.layers = [a or b for a, b in zip(bone.layers, layers)]
else:
bone.layers = layers
def union_layer_lists(lists: Iterable[Iterable[BoneCollection | None] | None]) -> list[BoneCollection]:
all_collections = dict()
for lst in lists:
if lst is not None:
all_collections.update({coll.name: coll for coll in lst if coll is not None})
return list(all_collections.values())
def find_used_collections(obj: ArmatureObject) -> dict[str, BoneCollection]:
bcoll_map = {}
for bone in obj.data.bones:
bcoll_map.update({coll.name: coll for coll in bone.collections})
return bcoll_map
def is_collection_ref_list_prop(param: Any) -> bool:
from .. import RigifyBoneCollectionReference
return (isinstance(param, bpy_prop_collection) and
all(isinstance(item, RigifyBoneCollectionReference) for item in param))
def mirror_ref_list(to_ref_list, from_ref_list):
to_ref_list.clear()
for ref in from_ref_list:
to_ref = to_ref_list.add()
to_ref['uid'] = ref['uid']
to_ref['name'] = ref['name']
to_ref.name = mirror_name_fuzzy(ref.name)
##############################################
@ -54,48 +75,56 @@ def set_bone_layers(bone: Bone, layers: Sequence[bool], combine=False):
##############################################
def layout_layer_buttons(layout: UILayout, params, option: str, active_layers: Sequence[bool]):
"""Draw a layer selection button UI with certain layers marked with dots."""
outer = layout.row()
for x in [0, 8]:
col = outer.column(align=True)
for y in [0, 16]:
row = col.row(align=True)
for i in range(x+y, x+y+8):
row.prop(
params, option, index=i, toggle=True, text="",
icon="LAYER_ACTIVE" if active_layers[i] else "NONE"
)
class ControlLayersOption:
def __init__(self, name: str,
toggle_name: Optional[str] = None,
toggle_default=True, description="Set of control layers"):
toggle_default=True, description="Set of bone collections"):
self.name = name
self.toggle_default = toggle_default
self.description = description
self.toggle_option = self.name+'_layers_extra'
self.layers_option = self.name+'_layers'
self.refs_option = self.name + '_coll_refs'
if toggle_name:
self.toggle_name = toggle_name
else:
self.toggle_name = "Assign " + self.name.title() + " Layers"
self.toggle_name = "Assign " + self.name.title() + " Collections"
def get(self, params) -> Optional[list[bool]]:
def get(self, params) -> Optional[list[BoneCollection]]:
if getattr(params, self.toggle_option):
return list(getattr(params, self.layers_option))
result = []
for ref in getattr(params, self.refs_option):
coll = ref.find_collection(update=True, raise_error=True)
if coll:
result.append(coll)
if not result:
bones = [pbone for pbone in params.id_data.pose.bones if pbone.rigify_parameters == params]
print(f"RIGIFY: empty {self.name} layer list on bone {bones[0].name if bones else '?'}")
return result
else:
return None
def set(self, params, layers):
if self.refs_option in params:
del params[self.refs_option]
setattr(params, self.toggle_option, layers is not None)
if layers:
items = getattr(params, self.refs_option)
for coll in layers:
item: RigifyBoneCollectionReference = items.add()
item.set_collection(coll)
def assign(self, params,
bone_set: Object | Mapping[str, Bone | PoseBone],
bone_list: Sequence[str],
bone_list: Sequence[str], *,
combine=False):
layers = self.get(params)
@ -109,20 +138,22 @@ class ControlLayersOption:
if isinstance(bone, PoseBone):
bone = bone.bone
set_bone_layers(bone, layers, combine)
set_bone_layers(bone, layers, combine=combine)
def assign_rig(self, rig: 'BaseRig', bone_list: Sequence[str], combine=False, priority=None):
def assign_rig(self, rig: 'BaseRig', bone_list: Sequence[str], *, combine=False, priority=None):
layers = self.get(rig.params)
bone_set = rig.obj.data.bones
if layers:
for name in bone_list:
set_bone_layers(bone_set[name], layers, combine)
set_bone_layers(bone_set[name], layers, combine=combine)
if priority is not None:
rig.generator.set_layer_group_priority(name, layers, priority)
def add_parameters(self, params):
from .. import RigifyBoneCollectionReference
prop_toggle = bpy.props.BoolProperty(
name=self.toggle_name,
default=self.toggle_default,
@ -131,27 +162,47 @@ class ControlLayersOption:
setattr(params, self.toggle_option, prop_toggle)
prop_layers = bpy.props.BoolVectorProperty(
size=32,
prop_coll_refs = bpy.props.CollectionProperty(
type=RigifyBoneCollectionReference,
description=self.description,
subtype='LAYER',
default=tuple([i == 1 for i in range(0, 32)])
)
setattr(params, self.layers_option, prop_layers)
setattr(params, self.refs_option, prop_coll_refs)
def parameters_ui(self, layout: UILayout, params):
box = layout.box()
box.prop(params, self.toggle_option)
row = box.row()
row.prop(params, self.toggle_option)
active = getattr(params, self.toggle_option)
from ..operators.copy_mirror_parameters import make_copy_parameter_button
from ..base_rig import BaseRig
make_copy_parameter_button(row, self.refs_option, base_class=BaseRig, mirror_bone=True)
if not active:
return
active_layers = bpy.context.active_pose_bone.bone.layers[:]
props = row.operator(operator="pose.rigify_collection_ref_add", text="", icon="ADD")
props.prop_name = self.refs_option
layout_layer_buttons(box, params, self.layers_option, active_layers)
refs = getattr(params, self.refs_option)
if len(refs):
col = box.column(align=True)
for i, ref in enumerate(refs):
row = col.row(align=True)
row.prop(ref, "name", text="")
row.alert = ref.uid >= 0 and not ref.find_collection()
props = row.operator(operator="pose.rigify_collection_ref_remove", text="", icon="REMOVE")
props.prop_name = self.refs_option
props.index = i
else:
box.label(text="Use the plus button to add list entries", icon="INFO")
# Declarations for auto-completion
FK: 'ControlLayersOption'

View File

@ -164,6 +164,14 @@ def map_apply(func, *inputs):
collections.deque(map(func, *inputs), maxlen=0)
def find_index(sequence, item, default=None):
for i, elem in enumerate(sequence):
if elem == item:
return i
return default
##############################################
# Lazy references
##############################################
@ -277,6 +285,13 @@ def select_object(context: bpy.types.Context, obj: bpy.types.Object, deselect_al
view_layer.objects.active = obj
def choose_next_uid(collection: typing.Iterable, prop_name: str, *, min_value=0):
return 1 + max(
(getattr(obj, prop_name, min_value - 1) for obj in collection),
default=min_value-1,
)
##############################################
# Text
##############################################
@ -349,6 +364,9 @@ class IdPropSequence(typing.Mapping[str, T], ABC):
def __setitem__(self, key: str | int, value: T):
pass
def __iter__(self) -> typing.Iterator[T]:
pass
def add(self) -> T:
pass

View File

@ -10,6 +10,8 @@ import enum
from typing import Optional, TYPE_CHECKING
from .misc import map_list
if TYPE_CHECKING:
from ..base_generate import BaseGenerator
@ -336,3 +338,30 @@ def choose_derived_bone(generator: 'BaseGenerator', original: str, subtype: str,
return direct
return None
_MIRROR_MAP_RAW = [
("Left", "Right"),
("L", "R"),
]
_MIRROR_MAP = {
**{a: b for a, b in _MIRROR_MAP_RAW},
**{b: a for a, b in _MIRROR_MAP_RAW},
**{a.lower(): b.lower() for a, b in _MIRROR_MAP_RAW},
**{b.lower(): a.lower() for a, b in _MIRROR_MAP_RAW},
}
_MIRROR_RE = [
r"(?<![a-z])(left|light)(?![a-z])",
r"(?<=[\._])(l|r)(?![a-z])",
]
def mirror_name_fuzzy(name: str) -> str:
"""Try to mirror a name by trying various patterns without expecting any rigid structure."""
for reg in _MIRROR_RE:
new_name = re.sub(reg, lambda m: _MIRROR_MAP.get(m[0], m[0]), name, flags=re.IGNORECASE)
if new_name != name:
return new_name
return name

View File

@ -8,17 +8,18 @@ import importlib.util
import re
from itertools import count
from collections import defaultdict
from typing import TYPE_CHECKING, Any, Optional
from bpy.types import bpy_struct, Constraint, Object, PoseBone, Bone, Armature
from bpy.types import bpy_prop_array # noqa
from bpy.types import bpy_prop_array, bpy_prop_collection # noqa
from idprop.types import IDPropertyArray
from .misc import ArmatureObject, wrap_list_to_lines, IdPropSequence
from .misc import ArmatureObject, wrap_list_to_lines, IdPropSequence, find_index
if TYPE_CHECKING:
from ..base_rig import BaseRig
from .. import RigifyColorSet, RigifyArmatureLayer
from .. import RigifyColorSet
RIG_DIR = "rigs" # Name of the directory where rig types are kept
METARIG_DIR = "metarigs" # Name of the directory where metarigs are kept
@ -61,10 +62,6 @@ def get_rigify_colors(arm: Armature) -> IdPropSequence['RigifyColorSet']:
return arm.rigify_colors # noqa
def get_rigify_layers(arm: Armature) -> IdPropSequence['RigifyArmatureLayer']:
return arm.rigify_layers # noqa
def get_rigify_target_rig(arm: Armature) -> Optional[ArmatureObject]:
return arm.rigify_target_rig # noqa
@ -89,6 +86,19 @@ def is_rig_base_bone(obj: Object, name):
return bool(get_rigify_type(obj.pose.bones[name]))
def metarig_needs_upgrade(obj):
return bool(obj.data.get("rigify_layers"))
def is_valid_metarig(context, *, allow_needs_upgrade=False):
obj = context.object
if not context.object:
return False
if obj.type != 'ARMATURE' or obj.data.get("rig_id") is not None:
return False
return allow_needs_upgrade or not metarig_needs_upgrade(context.object)
def upgrade_metarig_types(metarig: Object, revert=False):
"""
Replaces rigify_type properties from old versions with their current names.
@ -120,6 +130,175 @@ def upgrade_metarig_types(metarig: Object, revert=False):
parameters.make_widget = False
def resolve_layer_names(layers):
"""Combine full layer names if some buttons use fragments with parentheses only."""
ui_rows = defaultdict(list)
name_counts = defaultdict(int)
for i, layer in enumerate(layers):
if name := layer.get("name").strip():
name_counts[name] += 1
ui_rows[layer.get("row", 1)].append(name)
def needs_rename(n):
return name_counts[n] > 1 or n.startswith("(")
def clean_stem(raw_name):
return re.sub(r"\s*\(.*\)$", "", raw_name)
def search_left(my_row, col_idx):
while col_idx > 0:
col_idx -= 1
if not needs_rename(my_row[col_idx]):
return clean_stem(my_row[col_idx])
def search_up(my_row, row_idx, col_idx):
while row_idx > 1:
row_idx -= 1
prev_row = ui_rows[row_idx]
if len(prev_row) != len(my_row):
return None
if not needs_rename(prev_row[col_idx]):
return clean_stem(prev_row[col_idx])
names = []
for i, layer in enumerate(layers):
name: str = layer.get("name", "").strip()
if name and needs_rename(name):
row = layer.get("row", 1)
cur_row = ui_rows[row]
cur_col = cur_row.index(name)
if stem := search_left(cur_row, cur_col):
name = stem + " " + name
elif stem := search_up(cur_row, row, cur_col):
name = stem + " " + name
names.append(name)
return names
def upgrade_metarig_layers(metarig: ArmatureObject):
from .layers import DEF_COLLECTION, MCH_COLLECTION, ORG_COLLECTION, ROOT_COLLECTION
arm = metarig.data
# Find layer collections
coll_table = {}
for coll in arm.collections:
if m := re.match(r'^Layer (\d+)', coll.name):
coll_table[int(m[1]) - 1] = coll
# Assign UIDs from layer index
for idx, coll in coll_table.items():
coll.rigify_uid = idx
# Assign names to special layers if they exist
special_layers = {28: ROOT_COLLECTION, 29: DEF_COLLECTION, 30: MCH_COLLECTION, 31: ORG_COLLECTION}
for idx, name in special_layers.items():
if coll := coll_table.get(idx):
coll.name = name
# Apply existing layer metadata
if layers := arm.get("rigify_layers"):
names = resolve_layer_names(layers)
# Enforce the special names
for idx, name in special_layers.items():
if idx < len(names) and names[idx]:
names[idx] = name
cur_idx = 0
for i, layer in enumerate(layers):
coll = coll_table.get(i)
old_name = layer.get("name", "").strip()
new_name = names[i]
if new_name:
if not coll:
coll = arm.collections.new(new_name)
coll.rigify_uid = i
coll_table[i] = coll
else:
coll.name = new_name
if coll:
coll_idx = find_index(arm.collections, coll)
if hasattr(arm.collections, 'move'):
arm.collections.move(coll_idx, cur_idx)
cur_idx += 1
coll.rigify_ui_row = layer.get("row", 1)
if old_name and old_name != coll.name:
coll.rigify_ui_title = old_name
coll.rigify_sel_set = layer.get("selset", False)
coll.rigify_color_set_id = layer.get("group_prop", 0)
del arm["rigify_layers"]
arm.collections.active_index = 0
# Remove empty rows, and ensure the root button position is at the bottom
root_bcoll = coll_table.get(28)
used_rows = set()
for bcoll in arm.collections:
if bcoll != root_bcoll and bcoll.rigify_ui_row > 0:
used_rows.add(bcoll.rigify_ui_row)
row_map = {}
for i in range(1, max(used_rows) + 1):
if i in used_rows:
row_map[i] = len(row_map) + 1
for bcoll in arm.collections:
if bcoll == root_bcoll:
bcoll.rigify_ui_row = len(row_map) + 3
elif bcoll.rigify_ui_row > 0:
bcoll.rigify_ui_row = row_map[bcoll.rigify_ui_row]
# Convert the layer references in rig component parameters
default_layers = [i == 1 for i in range(32)]
default_map = {
'faces.super_face': ['primary', 'secondary'],
'limbs.simple_tentacle': ['tweak'],
'limbs.super_finger': ['tweak'],
}
for pose_bone in metarig.pose.bones:
params = get_rigify_params(pose_bone)
# Work around the stupid legacy default where one layer is implicitly selected
for name_stem in default_map.get(get_rigify_type(pose_bone), []):
prop_name = name_stem + "_layers"
if prop_name not in params and name_stem + "_coll_refs" not in params:
params[prop_name] = default_layers
for prop_name, prop_value in list(params.items()):
if prop_name.endswith("_layers") and isinstance(prop_value, IDPropertyArray) and len(prop_value) == 32:
entries = []
for i, show in enumerate(prop_value.to_list()):
if show:
coll = coll_table.get(i)
entries.append({"uid": i, "name": coll.name if coll else "<?>"})
params[prop_name[:-7] + "_coll_refs"] = entries
del params[prop_name]
##############################################
# Misc
##############################################
@ -293,6 +472,8 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create",
Write a metarig as a python script, this rig is to have all info needed for
generating the real rig with rigify.
"""
from .. import RigifyBoneCollectionReference
code = [
"import bpy\n",
"from mathutils import Color\n\n",
@ -340,22 +521,47 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create",
code.append(' arm.rigify_colors[' + str(i)
+ '].standard_colors_lock = ' + str(standard_colors_lock))
# Rigify layer layout info
rigify_layers = get_rigify_layers(arm)
# Rigify collection layout info
if layers:
collection_attrs = {
'ui_row': 0, 'ui_title': '', 'sel_set': False, 'color_set_id': 0
}
if layers and len(rigify_layers) > 0:
code.append("\n for i in range(" + str(len(rigify_layers)) + "):")
code.append(" arm.rigify_layers.add()\n")
code.append('\n bone_collections = {}')
for i in range(len(rigify_layers)):
name = rigify_layers[i].name
row = rigify_layers[i].row
selset = rigify_layers[i].selset
group = rigify_layers[i].group
code.append(' arm.rigify_layers[' + str(i) + '].name = "' + name + '"')
code.append(' arm.rigify_layers[' + str(i) + '].row = ' + str(row))
code.append(' arm.rigify_layers[' + str(i) + '].selset = ' + str(selset))
code.append(' arm.rigify_layers[' + str(i) + '].group = ' + str(group))
code.append('\n for bcoll in list(arm.collections):'
'\n arm.collections.remove(bcoll)\n')
args = ', '.join(f'{k}={repr(v)}' for k, v in collection_attrs.items())
code.append(f" def add_bone_collection(name, *, {args}):")
code.append(f" uid = len(arm.collections)")
code.append(f" new_bcoll = arm.collections.new(name)")
code.append(f" new_bcoll.rigify_uid = uid")
for k, _v in collection_attrs.items():
code.append(f" new_bcoll.rigify_{k} = {k}")
code.append(" bone_collections[name] = new_bcoll")
code.append("""
def assign_bone_collections(pose_bone, *coll_names):
assert not len(pose_bone.bone.collections)
for name in coll_names:
bone_collections[name].assign(pose_bone)
def assign_bone_collection_refs(params, attr_name, *coll_names):
ref_list = getattr(params, attr_name + '_coll_refs', None)
if ref_list is not None:
for name in coll_names:
ref_list.add().set_collection(bone_collections[name])
""")
for i, bcoll in enumerate(arm.collections):
args = [repr(bcoll.name)]
for k, v in collection_attrs.items():
value = getattr(bcoll, "rigify_" + k)
if value != v:
args.append(f"{k}={repr(value)}")
code.append(f" add_bone_collection({', '.join(args)})")
# write parents first
bones = [(len(bone.parent_recursive), bone.name) for bone in arm.edit_bones]
@ -398,13 +604,25 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create",
code.append(" pbone.lock_rotation_w = %s" % str(pbone.lock_rotation_w))
code.append(" pbone.lock_scale = %s" % str(tuple(pbone.lock_scale)))
code.append(" pbone.rotation_mode = %r" % pbone.rotation_mode)
if layers:
bone_layers = pbone.bone.layers
code += _format_property_value(" pbone.bone.layers = ", list(bone_layers))
if layers and len(pbone.bone.collections):
args = ', '.join(f"'{bcoll.name}'" for bcoll in pbone.bone.collections)
code.append(f" assign_bone_collections(pbone, {args})")
# Rig type parameters
for param_name in rigify_parameters.keys():
param = _get_property_value(rigify_parameters, param_name)
if isinstance(param, bpy_prop_collection):
if (layers and param_name.endswith("_coll_refs") and
all(isinstance(item, RigifyBoneCollectionReference) for item in param)):
bcoll_set = [item.find_collection() for item in param]
bcoll_set = [bcoll for bcoll in bcoll_set if bcoll is not None]
if len(bcoll_set) > 0:
args = ', '.join(f"'{bcoll.name}'" for bcoll in bcoll_set)
code.append(f" assign_bone_collection_refs("
f"pbone.rigify_parameters, '{param_name[:-10]}', {args})")
continue
if param is not None:
code.append(" try:")
code += _format_property_value(
@ -458,20 +676,11 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create",
code.append(" bone.bbone_x = bone.bbone_z = bone.length * 0.05")
code.append(" arm.edit_bones.active = bone")
# Set appropriate layers visible
if layers:
# Find what layers have bones on them
active_layers = []
for bone_name in bones:
bone = obj.data.bones[bone_name]
for i in range(len(bone.layers)):
if bone.layers[i]:
if i not in active_layers:
active_layers.append(i)
active_layers.sort()
code.append("\n arm.layers = [(x in " + str(active_layers) +
") for x in range(" + str(len(arm.layers)) + ")]")
if not layers:
code.append(" if bcoll := arm.collections.active:")
code.append(" bcoll.assign(bone)")
else:
code.append("\n arm.collections.active_index = 0")
code.append("\n return bones")