Almost every animator I have worked with expects space switches in the rig. Functionally, a space switch is a toggle that changes what a control is parented to. The “old fashion” way to do this involves a constraint on a transform above the control. The constraint targets are whatever you want them to be. This method is has no respect for boundaries and is not compatible with the component based workflow.
Making the space switch on a control part of the component would work almost all the time. But, inevitably, you’ll run into a situation where your usual doesn’t work, like when you’re suddenly asked to rig an army of slugs. So, you need to make the space switch both optional and variable; able to be added or removed from a component as necessary.
Why not make it a component?
A space switch drives the parent transform of a control. Usually this drives the translate or rotate, or both. You could modify the graph and offset the attributes on the parent transform. However, it is not always guaranteed how a control’s parent transform will be driven.
It is much easier to add another transform between the control and its parent to apply the offset.
Under ordinary circumstances, components enforce rigid boundaries. The space switch component is special in that it is “inside” another component, and therefor can be aware of its internals. This lets it get the world matrix of the control parent (arm_L_hand_ctrl_srtOffset in the example above), so that it can calculate the offset against it.
The offset is calculated by simple matrix math.
In the space switch component, each parent space has two transforms. The srtOffset offset is orthogonal to the control. Its parent transform is driven by the transform the control will follow when it is in that space. The srtOffset’s position is guided, so any time the component is put into guide mode, it tracks the control.
The output srtOffset (on the right side of the graph), drives the spaceSwitch_srtOffset above the control. Up to three space switches can be connected to a single control. A space switch can only be connected to one control.
The space switch component has a handful of attributes for tracking the parents so they can be added/removed, and the control to which the component is connected.
As an aside – message attributes are awesome and you should use them.
The tracking attributes are necessary for the tooling. By default, the space switch control has no parents. Once the space switch is in the rig, the tooling allows parents to be added or removed, and a control connected or disconnected. The tooling is entirely in the Maya Python API 2.0 … except for the parts of the API that’s missing.
With the tooling, setting up a space switch can be scripted. The tooling also supports the –query flag, so the space switch state can be saved as plain old data – a control, a flag, and a list of parents.
If you’ve done any profiling, you know that one of the pitfalls of constraints, and therefor space switches, is the evaluation cluster. If the toggle attribute is on the control, and the toggle attribute affects the parent, Maya cannot schedule those nodes in parallel.
My solution for this is simple – don’t connect the toggle attribute on the control to the space switch.
I’ll get into that next post.