Inverse Kinematics
With the ability to alter animation before it is applied to the resulting rig, there is a possibility of Inverse Kinematics (IK) algorithms in Rukhanka becoming available.
There are several IK algorithms available in the base Rukhanka distribution:
Override Transform
This is a very simple algorithm, which for a given rig bone overrides position and/or rotation taken from other entity. It can be used by attaching OverrideTransformIKAuthoring
authoring MonoBehaviour
to the bone entity that needs to be affected:
The following parameters can be configured:
- Target - an entity whose position and rotation will be used for affected bone.
- Position Weight - degree of influence of target position on result bone placement.
- Rotation Weight - degree of influence of target rotation on result bone placement.
Weight values for all algorithms are ranged between 0 and 1. If zero, the algorithm will have no influence on the final pose. If one, the bone pose will be completely overridden by the algorithm output pose. Values in between will interpolate linearly between the original bone pose and algorithm output.
Corresponding OverrideTransformIKComponent
has the following declaration:
public struct OverrideTransformIKComponent: IComponentData, IEnableableComponent
{
public Entity target;
public float positionWeight;
public float rotationWeight;
}
Aim
The aim algorithm rotates a bone chain to face a target entity. It can be enabled and configured by using AimIKAuthoring
authoring MonoBehaviour
to any bone of the affected rig:
Configuration parameters:
- Target - affected bones will be rotated to face this entity.
- Weight - degree of influence of aimed rotation on result bones orientation.
- Min and Max Angles - aimed rotation can be constrained by minimum and maximum angles (given in degrees).
- Bone Forward Vector - a vector that will be used by the aim algorithm as a forward vector.
- Affected Bones - list bones with associated weights. Bones will be processed in the order they are declared. To prevent multiple rotations make sure that parent bones come before children.
AimIKAuthoring
converted to AimIKComponent
with base algorithm parameters and AimIKAffectedBoneComponent
buffer with affected bones list. They have the following declarations:
public struct AimIKComponent: IComponentData, IEnableableComponent
{
public Entity target;
public float2 angleLimits;
public float3 forwardVector;
public float weight;
}
public struct AimIKAffectedBoneComponent : IBufferElementData
{
public Entity boneEntity;
public float weight;
}
Forward And Backward Reaching Inverse Kinematics (FABRIK)
FABRIK algorithm can be used when a chain of connected bones needs to reach some target position. FABRIKAuthouring
authoring MonoBehaviour
can be used to enable and configure the algorithm. FABRIKAuthouring
should be attached to the root bone of the affected chain.
It has the following configurable properties:
- Weight - degree of influence of the FABRIK algorithm on positions and rotations of the affected bone chain.
- Tip - end of the affected bone chain. All bones from the root chain bone (the bone with
FABRIKAuthouring
attached) and this bone will be affected by the FABRIK algorithm. - Target - an entity whose pose will be used as a goal position.
- Num Iterations - maximum number of algorithm iterations in an attempt to reach the target.
- Threshold - chain tip and target position difference value that will be treated by an algorithm as "acceptable" during solving. If the tip-to-target distance is less than the threshold FABRIK will stop its computation.
FABRIKAuthouring
is converted into FABRIKComponent
with the following declaration:
public struct FABRIKComponent: IComponentData, IEnableableComponent
{
public Entity tip, target;
public int numIterations;
public float weight, threshold;
}
Two Bone IK
Two Bone IK
is a simple algorithm that operates on two connected bones. It is used for reaching the target position by two-bone systems like lower-upper legs/arms. TwoBoneIKAuthoring
should be attached to the root bone of the affected chain.
It has the following configurable properties:
- Weight - degree of influence of the IK algorithm on rotations of the affected bones.
- Mid - middle bone of the affected chain.
- Tip - end of the affected bone chain.
- Target - an entity whose pose will be used as a goal position.
- Mid Bend Hint - an entity whose pose will be used to correctly orient middle bone bend orientation. Generally, it should be located in front of the desired mid-bone position.
TwoBoneIKAuthouring
is converted into TwoBoneIKComponent
with the following declaration:
public struct TwoBoneIKComponent: IComponentData, IEnableableComponent
{
public Entity mid, tip, target, midBentHint;
public float weight;
}
All described algorithms have a usage example in Rukhanka samples