How do you go about enabling bi-directional motion transfer for a custom constraint?
Hi, Adding bi-directional motion transfer for your custom constraints will requires a bit of manual labor. As specified in the documentation, not all constraints implement both “transfer to skeleton” and “transfer to constraint”, and enabling the latter requires implementing an inverse constraint to “undo” the constraint effect.
I recommend having a look at an existing constraint to grasp the workflow. The TwoBoneIKConstraint would be a very good example. Have a look at TwoBoneIKConstraintEditor.cs
to see how we hook the constraint with the baking api and TwoBoneIKInverseConstraint.cs
+ TwoBoneIKInverseConstraintJob.cs
to see how the inverse constraint is implemented.
To hook up your constraint, you need to create a BakeParameters class for your constraint (link) a bit like so:
[BakeParameters(typeof(MyCustomConstraint))]
class MyCustomConstraintBakeParameters : BakeParameters<MyCustomConstraint>
{
public override bool canBakeToSkeleton => true;
public override bool canBakeToConstraint => true; // Only enable this if your constraint is inversable.
public override IEnumerable<EditorCurveBinding> GetSourceCurveBindings(RigBuilder rigBuilder, MyCustomConstraint constraint)
{
// Return the list of bindings driving your constraint evaluation
}
public override IEnumerable<EditorCurveBinding> GetConstrainedCurveBindings(RigBuilder rigBuilder, MyCustomConstraint constraint)
{
// Return the list of bindings driven by your constraint.
}
}