Skip to content
Snippets Groups Projects
Commit 008bcf44 authored by Alexander Gavrilov's avatar Alexander Gavrilov
Browse files

Rigify: internal API enhancements.

Add a LazyRigComponent class that has to be explicitly enabled
to start receiving callbacks.

Support calling GeneratorPlugin instance callbacks in the same
stage they were created.
parent 287f8443
Branches
Tags
No related merge requests found
......@@ -31,6 +31,7 @@ from .utils.misc import clone_parameters, assign_parameters
from . import base_rig
from itertools import count
#=============================================
# Generator Plugin
......@@ -284,13 +285,24 @@ class BaseGenerator:
self.stage = method_name
for rig in [*self.rig_list, *self.plugin_list]:
for rig in self.rig_list:
rig.rigify_invoke_stage(method_name)
assert(self.context.active_object == self.obj)
assert(self.obj.mode == 'OBJECT')
assert(num_bones == len(self.obj.data.bones))
# Allow plugins to be added to the end of the list on the fly
for i in count(0):
if i >= len(self.plugin_list):
break
self.plugin_list[i].rigify_invoke_stage(method_name)
assert(self.context.active_object == self.obj)
assert(self.obj.mode == 'OBJECT')
assert(num_bones == len(self.obj.data.bones))
def __run_edit_stage(self, method_name):
assert(self.context.active_object == self.obj)
......@@ -299,13 +311,24 @@ class BaseGenerator:
self.stage = method_name
for rig in [*self.rig_list, *self.plugin_list]:
for rig in self.rig_list:
rig.rigify_invoke_stage(method_name)
assert(self.context.active_object == self.obj)
assert(self.obj.mode == 'EDIT')
assert(num_bones == len(self.obj.data.edit_bones))
# Allow plugins to be added to the end of the list on the fly
for i in count(0):
if i >= len(self.plugin_list):
break
self.plugin_list[i].rigify_invoke_stage(method_name)
assert(self.context.active_object == self.obj)
assert(self.obj.mode == 'EDIT')
assert(num_bones == len(self.obj.data.edit_bones))
def invoke_initialize(self):
self.__run_object_stage('initialize')
......
......@@ -267,14 +267,25 @@ class RigUtility(BoneUtilityMixin, MechanismUtilityMixin):
self.owner.register_new_bone(new_name, old_name)
class RigComponent(GenerateCallbackHost, RigUtility):
"""Base class for utility classes that generate part of a rig using callbacks."""
class LazyRigComponent(GenerateCallbackHost, RigUtility):
"""Base class for utility classes that generate part of a rig using callbacks. Starts as disabled."""
def __init__(self, owner):
super().__init__(owner)
self.owner.rigify_sub_objects = objects = self.owner.rigify_sub_objects or []
self.is_component_enabled = False
def enable_component(self):
if not self.is_component_enabled:
self.is_component_enabled = True
self.owner.rigify_sub_objects = objects = self.owner.rigify_sub_objects or []
objects.append(self)
objects.append(self)
class RigComponent(LazyRigComponent):
"""Base class for utility classes that generate part of a rig using callbacks."""
def __init__(self, owner):
super().__init__(owner)
self.enable_component()
#=============================================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment