[Bf-extensions-cvs] [01e8af33] master: Rigify: annotate and fix warnings in basic rig components.
Alexander Gavrilov
noreply at git.blender.org
Sun Nov 13 14:23:33 CET 2022
Commit: 01e8af3348fac2babe3b5218dbe4ecdaa0e1eace
Author: Alexander Gavrilov
Date: Sat Nov 12 23:54:17 2022 +0200
Branches: master
https://developer.blender.org/rBA01e8af3348fac2babe3b5218dbe4ecdaa0e1eace
Rigify: annotate and fix warnings in basic rig components.
Introduce a method to annotate types and names of entries in the
`bones` container of rig components and apply it, and other type
annotations, to a number of not very complex rig classes.
- Introduce BaseRigMixin as a typed base class for mixins intended
for use in rig classes (using BaseRig as a parent causes issues).
- Introduce TypedBoneDict that does not suppress the unknown attribute
analysis in PyCharm, and use it in a system of subclasses to
annotate the bones in various rigs. BaseBoneDict is necessary
because the annotation affects all subclasses, so TypedBoneDict
cannot inherit from BoneDict with the annotation.
- Add or adjust other type annotations of rig methods and utilities.
- Fix other warnings, e.g. undeclared attributes, excessively long
lines, whitespace style issues and typos.
===================================================================
M rigify/base_rig.py
M rigify/operators/action_layers.py
M rigify/rigs/basic/copy_chain.py
M rigify/rigs/basic/pivot.py
M rigify/rigs/basic/raw_copy.py
M rigify/rigs/basic/super_copy.py
M rigify/rigs/chain_rigs.py
M rigify/rigs/limbs/simple_tentacle.py
M rigify/rigs/limbs/super_finger.py
M rigify/rigs/spines/basic_spine.py
M rigify/rigs/spines/basic_tail.py
M rigify/rigs/spines/spine_rigs.py
M rigify/rigs/spines/super_head.py
M rigify/rigs/spines/super_spine.py
M rigify/rigs/utils.py
M rigify/rigs/widgets.py
M rigify/utils/animation.py
M rigify/utils/bones.py
M rigify/utils/layers.py
M rigify/utils/rig.py
===================================================================
diff --git a/rigify/base_rig.py b/rigify/base_rig.py
index b0bcc027..c284cc20 100644
--- a/rigify/base_rig.py
+++ b/rigify/base_rig.py
@@ -2,11 +2,11 @@
import collections
-from bpy.types import PoseBone
-from typing import TYPE_CHECKING, Any, Callable, Optional
+from bpy.types import PoseBone, UILayout, Context
+from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar, Generic
from .utils.errors import RaiseErrorMixin
-from .utils.bones import BoneDict, BoneUtilityMixin
+from .utils.bones import BoneDict, BoneUtilityMixin, TypedBoneDict, BaseBoneDict
from .utils.mechanism import MechanismUtilityMixin
from .utils.metaclass import BaseStagedClass
from .utils.misc import ArmatureObject
@@ -144,14 +144,19 @@ class GenerateCallbackHost(BaseStagedClass, define_stages=True):
pass
-class BaseRig(GenerateCallbackHost, RaiseErrorMixin, BoneUtilityMixin, MechanismUtilityMixin):
+_Org = TypeVar('_Org', bound=str | list[str] | BaseBoneDict)
+_Ctrl = TypeVar('_Ctrl', bound=str | list[str] | BaseBoneDict)
+_Mch = TypeVar('_Mch', bound=str | list[str] | BaseBoneDict)
+_Deform = TypeVar('_Deform', bound=str | list[str] | BaseBoneDict)
+
+
+class BaseRigMixin(RaiseErrorMixin, BoneUtilityMixin, MechanismUtilityMixin):
generator: 'BaseGenerator'
obj: ArmatureObject
script: 'ScriptGenerator'
base_bone: str
params: Any
- bones: BoneDict
rigify_parent: Optional['BaseRig']
rigify_children: list['BaseRig']
@@ -160,6 +165,28 @@ class BaseRig(GenerateCallbackHost, RaiseErrorMixin, BoneUtilityMixin, Mechanism
rigify_new_bones: dict[str, Optional[str]]
rigify_derived_bones: dict[str, set[str]]
+ ##############################################
+ # Annotated bone containers
+
+ class ToplevelBones(TypedBoneDict, Generic[_Org, _Ctrl, _Mch, _Deform]):
+ org: _Org
+ ctrl: _Ctrl
+ mch: _Mch
+ deform: _Deform
+
+ class CtrlBones(TypedBoneDict):
+ pass
+
+ class MchBones(TypedBoneDict):
+ pass
+
+ bones: ToplevelBones[str | list[str] | BoneDict,
+ str | list[str] | BoneDict, # Use CtrlBones in overrides
+ str | list[str] | BoneDict, # Use MchBones in overrides
+ str | list[str] | BoneDict]
+
+
+class BaseRig(GenerateCallbackHost, BaseRigMixin):
"""
Base class for all rigs.
@@ -182,7 +209,7 @@ class BaseRig(GenerateCallbackHost, RaiseErrorMixin, BoneUtilityMixin, Mechanism
self.params = get_rigify_params(pose_bone)
# Collection of bone names for use in implementing the rig
- self.bones = BoneDict(
+ self.bones = self.ToplevelBones(
# ORG bone names
org=self.find_org_bones(pose_bone),
# Control bone names
@@ -205,7 +232,7 @@ class BaseRig(GenerateCallbackHost, RaiseErrorMixin, BoneUtilityMixin, Mechanism
self.rigify_new_bones = dict()
self.rigify_derived_bones = collections.defaultdict(set)
- def register_new_bone(self, new_name, old_name=None):
+ def register_new_bone(self, new_name: str, old_name: Optional[str] = None):
"""Registers this rig as the owner of this new bone."""
self.rigify_new_bones[new_name] = old_name
self.generator.bone_owners[new_name] = self
@@ -216,7 +243,7 @@ class BaseRig(GenerateCallbackHost, RaiseErrorMixin, BoneUtilityMixin, Mechanism
###########################################################
# Bone ownership
- def find_org_bones(self, pose_bone: PoseBone) -> str | list[str] | BoneDict:
+ def find_org_bones(self, pose_bone: PoseBone) -> str | list[str] | BaseBoneDict:
"""
Select bones directly owned by the rig. Returning the
same bone from multiple rigs is an error.
@@ -240,7 +267,7 @@ class BaseRig(GenerateCallbackHost, RaiseErrorMixin, BoneUtilityMixin, Mechanism
pass
@classmethod
- def parameters_ui(cls, layout, params):
+ def parameters_ui(cls, layout: UILayout, params):
"""
This method draws the UI of the rigify_parameters defined on the pose_bone
:param layout:
@@ -250,7 +277,7 @@ class BaseRig(GenerateCallbackHost, RaiseErrorMixin, BoneUtilityMixin, Mechanism
pass
@classmethod
- def on_parameter_update(cls, context, pose_bone, params, param_name):
+ def on_parameter_update(cls, context: Context, pose_bone: PoseBone, params, param_name: str):
"""
A callback invoked whenever a parameter value is changed by the user.
"""
@@ -267,7 +294,7 @@ class RigUtility(BoneUtilityMixin, MechanismUtilityMixin):
self.owner = owner
self.obj = owner.obj
- def register_new_bone(self, new_name, old_name=None):
+ def register_new_bone(self, new_name: str, old_name: Optional[str] = None):
self.owner.register_new_bone(new_name, old_name)
diff --git a/rigify/operators/action_layers.py b/rigify/operators/action_layers.py
index c089722a..b81ac0ef 100644
--- a/rigify/operators/action_layers.py
+++ b/rigify/operators/action_layers.py
@@ -119,21 +119,21 @@ class ActionSlot(PropertyGroup, ActionSlotBase):
trans_min: FloatProperty(
name="Min",
default=-0.05,
- description="Value that the transformation value must reach to put the action's timeline"
+ description="Value that the transformation value must reach to put the action's timeline "
"to the first frame. Rotations are in degrees"
)
trans_max: FloatProperty(
name="Max",
default=0.05,
- description="Value that the transformation value must reach to put the action's timeline"
+ description="Value that the transformation value must reach to put the action's timeline "
"to the last frame. Rotations are in degrees"
)
is_corrective: BoolProperty(
name="Corrective",
- description="Indicate that this is a corrective action. Corrective actions will activate"
- "based on the activation of two other actions (using End Frame if both inputs"
+ description="Indicate that this is a corrective action. Corrective actions will activate "
+ "based on the activation of two other actions (using End Frame if both inputs "
"are at their End Frame, and Start Frame if either is at Start Frame)"
)
diff --git a/rigify/rigs/basic/copy_chain.py b/rigify/rigs/basic/copy_chain.py
index cf77a834..3dbf79d4 100644
--- a/rigify/rigs/basic/copy_chain.py
+++ b/rigify/rigs/basic/copy_chain.py
@@ -11,6 +11,10 @@ class Rig(SimpleChainRig):
and constrain it.
This is a control and deformation rig.
"""
+
+ make_controls: bool
+ make_deforms: bool
+
def initialize(self):
super().initialize()
@@ -72,15 +76,17 @@ class Rig(SimpleChainRig):
# Parameter UI
@classmethod
- def add_parameters(self, params):
+ def add_parameters(cls, params):
""" Add the parameters of this rig type to the
RigifyParameters PropertyGroup
"""
- params.make_controls = bpy.props.BoolProperty(name="Controls", default=True, description="Create control bones for the copy")
- params.make_deforms = bpy.props.BoolProperty(name="Deform", default=True, description="Create deform bones for the copy")
+ params.make_controls = bpy.props.BoolProperty(
+ name="Controls", default=True, description="Create control bones for the copy")
+ params.make_deforms = bpy.props.BoolProperty(
+ name="Deform", default=True, description="Create deform bones for the copy")
@classmethod
- def parameters_ui(self, layout, params):
+ def parameters_ui(cls, layout, params):
""" Create the ui for the rig parameters.
"""
r = layout.row()
diff --git a/rigify/rigs/basic/pivot.py b/rigify/rigs/basic/pivot.py
index a129e1e8..6812cde5 100644
--- a/rigify/rigs/basic/pivot.py
+++ b/rigify/rigs/basic/pivot.py
@@ -13,15 +13,27 @@ from ...utils.switch_parent import SwitchParentBuilder
class Rig(BaseRig):
""" A rig providing a rotation pivot control that can be moved. """
- def find_org_bones(self, pose_bone):
- return pose_bone.name
+ class CtrlBones(BaseRig.CtrlBones):
+ master: str
+ pivot: str
+
+ class MchBones(BaseRig.MchBones):
+ pass
+
+ bones: BaseRig.ToplevelBones[str, CtrlBones, MchBones, str]
+
+ make_control: bool
+ make_pivot: bool
+ make_deform: bool
+
+ def find_org_bones(self, pose_bone) -> str:
+ return pose_bone.name
def initialize(self):
self.make_control = self.params.make_extra_control
self.make_pivot = self.params.make_control or not self.make_control
- self.make_deform = self.params.make_extra_deform
-
+ self.make_deform = self.params.make_extra_deform
def generate_bones(self):
org = self.bones.org
@@ -44,8 +56,7 @@ class Rig(BaseRig):
if self.make_deform:
self.bones.deform = self.copy_bone(org, make_derived_name(org, 'def'), bbone=True)
-
- def build_parent_switch(self, master_name):
+ def build_parent_switch(self, master_name: str):
pbuilder = SwitchParentBuilder(self.generator)
org_parent = self.get_bone_parent(self.bones.org)
@@ -68,7 +79,7 @@ class Rig(BaseRig):
tags.discard('')
return tags
- def register_parent(self, master_name, tags):
+ def register_parent(self, master_name: str, tags: set[str]):
pbuilder = SwitchParentBuilder(self.generator)
inject = self.rigify_parent if 'injected' in tags else None
@@ -78,7 +89,6 @@ class Rig(BaseRig):
inject_into=inject, tags=tags
)
-
def parent_bones(self):
ctrl = self.bones.ctrl
@@ -94,7 +104,6 @@ class Rig(BaseRig):
if self.make_deform:
self.set_bone_parent(self.bones.deform, self.bones.org, use_connect=False)
-
def configure_bones(self):
org = self.bones.org
ctrl = self.bones.ctrl
@@ -102,7 +111,6 @@ class Rig(BaseRig):
self.c
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list