BindingSet
Binding layout of a rig, used to find a binding by its identifier and to size the buffers of an animation stream.
Read time 6 minutesLast updated 3 hours ago
Definition
- Type: Struct
- Namespace: Unity.Animations
- Assembly: UnityEngine.AnimationCoreModule
public struct BindingSet
Remarks
A rig definition stores its binding set in RigDefinition.Bindings, and RigBuilder fills it in when it creates the RigDefinition. Read a to:
BindingSet- Find the index of a binding from its identifier. Pass an array of identifiers, such as BindingSet.TranslationBindings, to BindingUtility.FindBindingIndex.
- Find the bit of a binding in the channel masks of an AnimationStream.
- Find where the data of a binding is stored in the AnimatedData buffer of an .
AnimationStream - Allocate the buffer of an with BindingSet.StreamSize elements, or the buffer of an AnimationStreamMask with BindingSet.StreamMaskSize elements.
AnimationStream
A binding connects one animated channel of the rig to a unique identifier. A rig has translation, rotation, scale, float, integer, and entity ID bindings.
The bindings of a rig are indexed in one sequence, in this order: translation, scale, float, integer, entity ID, and rotation. The first-binding index properties, such as BindingSet.RotationBindingIndex and BindingSet.IntBindingIndex, give the index of the first binding of each kind. The channel masks of an use one bit for each binding, with this index.
AnimationStreamA curve is one float value of a binding. A translation or scale binding has three curves, a rotation binding has four, and a float, integer, or entity ID binding has one. The curve count properties, such as BindingSet.ScaleCurveCount and BindingSet.FloatCurveCount, give the number of curves of each kind.
The buffer of an has the following sections, in this order:
AnimatedDataAnimationStream- Translation values, stored as one for each translation binding, starting at BindingSet.TranslationSamplesOffset.
float3 - Scale values, stored as one for each scale binding, starting at BindingSet.ScaleSamplesOffset.
float3 - Float values, stored as one for each float binding, starting at BindingSet.FloatSamplesOffset. The translation, scale, and float sections together fill BindingSet.InterpolatedDataChunkCount
floatchunks, so padding follows the float values.float4 - Integer values, stored as one for each integer binding, starting at BindingSet.IntSamplesOffset.
int - Entity ID values, stored as one for each entity ID binding, starting at BindingSet.EntityIdSamplesOffset. The integer and entity ID sections together fill BindingSet.DiscreteDataChunkCount
EntityIdchunks, so padding follows the entity ID values.int4 - Rotation values, stored in quaternion4 chunks that each hold four rotations, starting at BindingSet.RotationSamplesOffset. BindingSet.RotationDataChunkCount gives the number of chunks.
- Channel masks, stored as two bit arrays with the pass mask first and the frame mask second, starting at BindingSet.ChannelMaskOffset. Each mask has one bit for each binding, rounded up to a multiple of 64 bits.
Offsets and sizes count elements, which are 4 bytes each.
AnimatedDataThe following example uses the and namespaces. It finds a float channel by its identifier, then reads and writes its value in an animation stream.
Unity.AnimationsUnity.EntitiesExamples
// This example finds a float channel by its identifier, then increases its value in the animation stream.// Returns false if the rig has no float channel with that identifier.public static bool TryIncreaseFloatChannel( ref AnimationStream stream, StringHash channelId, float amount, out float newValue){ // Search the float bindings of the rig of the stream. FindBindingIndex returns -1 when there is no match. ref BindingSet bindings = ref stream.RigDefinition.Bindings; int channelIndex = BindingUtility.FindBindingIndex(ref bindings.FloatBindings, channelId); if (channelIndex < 0) { newValue = 0f; return false; } // The binding index is also the index of the float in the stream. newValue = stream.GetFloat(channelIndex) + amount; stream.SetFloat(channelIndex, newValue); return true;}
Fields
Value | Description |
|---|---|
| EntityIdBindings | Identifiers of the entity ID bindings of the rig. The position of an identifier is the index of its binding among the entity ID bindings. |
| FloatBindings | Identifiers of the float bindings of the rig. The position of an identifier is the index of its binding among the float bindings. |
| IntBindings | Identifiers of the integer bindings of the rig. The position of an identifier is the index of its binding among the integer bindings. |
| RotationBindings | Identifiers of the rotation bindings of the rig. The position of an identifier is the index of its binding among the rotation bindings. |
| ScaleBindings | Identifiers of the scale bindings of the rig. The position of an identifier is the index of its binding among the scale bindings. |
| TranslationBindings | Identifiers of the translation bindings of the rig. The position of an identifier is the index of its binding among the translation bindings. |
Static Fields
Value | Description |
|---|---|
| EntityIdKeyFloatCount | Number of curves of one entity ID binding. The curve of a clip stores an object index. |
| FloatKeyFloatCount | Number of curves of one float binding. |
| IntKeyFloatCount | Number of curves of one integer binding. |
| RotationKeyFloatCount | Number of curves of one rotation binding: the quaternion x, y, z, and w. |
| ScaleKeyFloatCount | Number of curves of one scale binding: x, y, and z. |
| TranslationKeyFloatCount | Number of curves of one translation binding: x, y, and z. |
Properties
Property | Description |
|---|---|
| BindingCount | Total number of bindings of the rig. |
| ChannelMaskOffset | Offset of the channel masks in an animation stream buffer, in AnimatedData elements. The pass mask comes first, then the frame mask. Each mask has one bit for each binding. |
| ChannelSize | Size of the channel data of an animation stream, in AnimatedData elements. The size includes the padding that fills the chunks and excludes the channel masks. |
| CurveCount | Total number of curves of the rig. |
| DiscreteDataChunkCount | Number of int4 chunks that hold the integer and entity ID data. |
| EntityIdBindingIndex | Index of the first entity ID binding among all the bindings of the rig. |
| EntityIdCurveCount | Number of curves of all the entity ID bindings, one for each binding. |
| EntityIdSamplesOffset | Offset of the entity ID data in an animation stream buffer, in AnimatedData elements. |
| FloatBindingIndex | Index of the first float binding among all the bindings of the rig. |
| FloatCurveCount | Number of curves of all the float bindings, one for each binding. |
| FloatSamplesOffset | Offset of the float data in an animation stream buffer, in AnimatedData elements. |
| IntBindingIndex | Index of the first integer binding among all the bindings of the rig. |
| IntCurveCount | Number of curves of all the integer bindings, one for each binding. |
| InterpolatedDataChunkCount | Number of float4 chunks that hold the translation, scale and float data. |
| IntSamplesOffset | Offset of the integer data in an animation stream buffer, in AnimatedData elements. |
| RotationBindingIndex | Index of the first rotation binding among all the bindings of the rig. |
| RotationCurveCount | Number of curves of all the rotation bindings, four for each binding. |
| RotationDataChunkCount | Number of chunks that hold the rotation data. Each chunk holds four rotations. |
| RotationSamplesOffset | Offset of the rotation data in an animation stream buffer, in AnimatedData elements. |
| ScaleBindingIndex | Index of the first scale binding among all the bindings of the rig. |
| ScaleCurveCount | Number of curves of all the scale bindings, three for each binding. |
| ScaleSamplesOffset | Offset of the scale data in an animation stream buffer, in AnimatedData elements. |
| StreamMaskSize | Size of the buffer of an animation stream mask, in WeightData elements. |
| StreamSize | Size of the buffer of an animation stream, in AnimatedData elements. The buffer holds the channel data and the channel masks. |
| TranslationBindingIndex | Index of the first translation binding among all the bindings of the rig. The value is always 0. |
| TranslationCurveCount | Number of curves of all the translation bindings, three for each binding. |
| TranslationSamplesOffset | Offset of the translation data in an animation stream buffer, in AnimatedData elements. |