Documentation

Unity Engine

Download Unity

Unity Engine

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

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
BindingSet
to:
  1. Find the index of a binding from its identifier. Pass an array of identifiers, such as BindingSet.TranslationBindings, to BindingUtility.FindBindingIndex.
  2. Find the bit of a binding in the channel masks of an AnimationStream.
  3. Find where the data of a binding is stored in the AnimatedData buffer of an
    AnimationStream
    .
  4. Allocate the buffer of an
    AnimationStream
    with BindingSet.StreamSize elements, or the buffer of an AnimationStreamMask with BindingSet.StreamMaskSize elements.
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
AnimationStream
use one bit for each binding, with this index.
A 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
AnimatedData
buffer of an
AnimationStream
has the following sections, in this order:
  1. Translation values, stored as one
    float3
    for each translation binding, starting at BindingSet.TranslationSamplesOffset.
  2. Scale values, stored as one
    float3
    for each scale binding, starting at BindingSet.ScaleSamplesOffset.
  3. Float values, stored as one
    float
    for each float binding, starting at BindingSet.FloatSamplesOffset. The translation, scale, and float sections together fill BindingSet.InterpolatedDataChunkCount
    float4
    chunks, so padding follows the float values.
  4. Integer values, stored as one
    int
    for each integer binding, starting at BindingSet.IntSamplesOffset.
  5. Entity ID values, stored as one
    EntityId
    for each entity ID binding, starting at BindingSet.EntityIdSamplesOffset. The integer and entity ID sections together fill BindingSet.DiscreteDataChunkCount
    int4
    chunks, so padding follows the entity ID values.
  6. Rotation values, stored in quaternion4 chunks that each hold four rotations, starting at BindingSet.RotationSamplesOffset. BindingSet.RotationDataChunkCount gives the number of chunks.
  7. 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
AnimatedData
elements, which are 4 bytes each.
The following example uses the
Unity.Animations
and
Unity.Entities
namespaces. It finds a float channel by its identifier, then reads and writes its value in an animation stream.

Examples

// 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

EntityIdBindingsIdentifiers of the entity ID bindings of the rig. The position of an identifier is the index of its binding among the entity ID bindings.
FloatBindingsIdentifiers of the float bindings of the rig. The position of an identifier is the index of its binding among the float bindings.
IntBindingsIdentifiers of the integer bindings of the rig. The position of an identifier is the index of its binding among the integer bindings.
RotationBindingsIdentifiers of the rotation bindings of the rig. The position of an identifier is the index of its binding among the rotation bindings.
ScaleBindingsIdentifiers of the scale bindings of the rig. The position of an identifier is the index of its binding among the scale bindings.
TranslationBindingsIdentifiers 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

EntityIdKeyFloatCountNumber of curves of one entity ID binding. The curve of a clip stores an object index.
FloatKeyFloatCountNumber of curves of one float binding.
IntKeyFloatCountNumber of curves of one integer binding.
RotationKeyFloatCountNumber of curves of one rotation binding: the quaternion x, y, z, and w.
ScaleKeyFloatCountNumber of curves of one scale binding: x, y, and z.
TranslationKeyFloatCountNumber of curves of one translation binding: x, y, and z.

Properties

Property

Description

BindingCountTotal number of bindings of the rig.
ChannelMaskOffsetOffset 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.
ChannelSizeSize 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.
CurveCountTotal number of curves of the rig.
DiscreteDataChunkCountNumber of int4 chunks that hold the integer and entity ID data.
EntityIdBindingIndexIndex of the first entity ID binding among all the bindings of the rig.
EntityIdCurveCountNumber of curves of all the entity ID bindings, one for each binding.
EntityIdSamplesOffsetOffset of the entity ID data in an animation stream buffer, in AnimatedData elements.
FloatBindingIndexIndex of the first float binding among all the bindings of the rig.
FloatCurveCountNumber of curves of all the float bindings, one for each binding.
FloatSamplesOffsetOffset of the float data in an animation stream buffer, in AnimatedData elements.
IntBindingIndexIndex of the first integer binding among all the bindings of the rig.
IntCurveCountNumber of curves of all the integer bindings, one for each binding.
InterpolatedDataChunkCountNumber of float4 chunks that hold the translation, scale and float data.
IntSamplesOffsetOffset of the integer data in an animation stream buffer, in AnimatedData elements.
RotationBindingIndexIndex of the first rotation binding among all the bindings of the rig.
RotationCurveCountNumber of curves of all the rotation bindings, four for each binding.
RotationDataChunkCountNumber of chunks that hold the rotation data. Each chunk holds four rotations.
RotationSamplesOffsetOffset of the rotation data in an animation stream buffer, in AnimatedData elements.
ScaleBindingIndexIndex of the first scale binding among all the bindings of the rig.
ScaleCurveCountNumber of curves of all the scale bindings, three for each binding.
ScaleSamplesOffsetOffset of the scale data in an animation stream buffer, in AnimatedData elements.
StreamMaskSizeSize of the buffer of an animation stream mask, in WeightData elements.
StreamSizeSize of the buffer of an animation stream, in AnimatedData elements. The buffer holds the channel data and the channel masks.
TranslationBindingIndexIndex of the first translation binding among all the bindings of the rig. The value is always 0.
TranslationCurveCountNumber of curves of all the translation bindings, three for each binding.
TranslationSamplesOffsetOffset of the translation data in an animation stream buffer, in AnimatedData elements.