Main Generator Engine
This describes the main classes that manage the generation of a rig.
The rig generation process is managed by an instance of the Generator class. It duplicates the metarig, instantiates the rig objects, creates the root control bone, executes the generation stages, and manages some other global operations.
The generator instance has the following fields:
- Blender context in which the generation was invoked.
- Current scene.
- Current view layer.
- Current layer collection.
- Current collection.
- The original metarig object.
- The rig object being generated.
- The name of the current stage being executed.
- The ScriptGenerator object that manages generation of the UI script.
- The random identifier string for the rig being generated.
- A list of all rig instances.
- A list of all rig instances without a parent rig.
- A map from bone names to the rig instance that owns them.
These are the public methods of the Generator class:
- By default, all bones left without a parent are parented to the root control. This method excludes a bone from this function.
- Looks up a rig class by its ID string.
Rigs that don't inherit from the
BaseRig class are considered to use the legacy interface, and are wrapped in a
rigify.base_generate.LegacyRig wrapper class. The wrapper itself inherits from
BaseRig, and translates between the two API interfaces.
The old style
generate method is invoked during the
generate_bones stage, because that is the only stage that can create bones.
- The instance of the legacy rig wrapped by the class.
In some special cases (mainly backward compatibility) it is necessary to present one or more different rig components as one, with the actual set of rigs depending on the structure and parameters of the rig.
This can be achieved by implementing a
Rig class that inherits from
rigify.base_generate.SubstitutionRig. Such classes are handled specially during the rig instantiation phase: instead of saving the newly created rig instance, the Generator immediately invokes its
substitute() method, and uses the list of rig instances returned from it instead.
- The instance of Generator.
- The rig being generated.
- The name of the main bone that instantiated the rig.
- The parameters attached to the main bone.
- Invoked immediately after instantiation and expected to return a list of rig instances.
- If it is necessary, this method may temporarily switch to edit mode to modify bone parenting and/or orientations.
- Returns the parameters container for the given bone.
rig.assign_params(bone_name, param_dict=None, ...)
- Assigns values into the parameter container of the given bone. Parameter values may be supplied as a dictionary, or directly as named parameters. If both are supplied, the named parameters have precedence.
- Creates a rig instance of the given type (specified as a class, or an ID string) for the specified bone.
Some functionality within the generation process isn't naturally tied to any specific rig component, and is instead equally shared between all of them. The generation of the UI script is one such example.
Such features can be conveniently implemented via classes that inherit from
rigify.base_generate.GeneratorPlugin. Due to the metaclass and base classes used by GeneratorPlugin, such classes become parameterized singletons, which can have the same stage callbacks as regular rig classes.
- Stage callbacks of the generator plugin instances are invoked after all of the rig callbacks are completed, in the order of decreasing priority.
- The Generator instance.
- The rig being generated.
- Initializes the plugin instance. As a parameterized singleton, every unique set of constructor parameter values creates a separate class instance, while passing the same values result in the same object.