RigBuilder
An intermediate data representing the rig.
Read time 3 minutesLast updated 3 hours ago
Definition
- Type: Struct
- Namespace: Unity.Animations
- Assembly: UnityEngine.AnimationCoreModule
- Implements: IDisposable
[BurstCompile]public struct RigBuilder : IDisposable
Remarks
If you don't use the Skeleton but your own custom rig representation, as long as you have a method to convert this representation to a RigBuilder, we can build a RigDefinition from it.
The following example uses the , , , , and namespaces. It builds a rig definition with three bones and one float channel.
Unity.AnimationsUnity.CollectionsUnity.EntitiesUnity.MathematicsUnityEngineAdditional Resources: RigDefinition, BindingSet
Examples
// This example builds a rig definition for a three-bone character with one float channel.// The caller owns the returned rig definition and must dispose it.public static BlobObjectReference<RigDefinition> BuildCharacterRig(){ using RigBuilder rigBuilder = new RigBuilder(Allocator.Temp); // Add the bones. Add the parent of a bone before the bone itself. // The root bone has a ParentIndex of -1. rigBuilder.Add(new SkeletonNode { Id = "Root", ParentIndex = -1, LocalTranslationDefaultValue = float3.zero, LocalRotationDefaultValue = quaternion.identity, LocalScaleDefaultValue = new float3(1f) }); rigBuilder.Add(new SkeletonNode { Id = "Spine", ParentIndex = 0, LocalTranslationDefaultValue = new float3(0f, 1f, 0f), LocalRotationDefaultValue = quaternion.identity, LocalScaleDefaultValue = new float3(1f) }); rigBuilder.Add(new SkeletonNode { Id = "Head", ParentIndex = 1, LocalTranslationDefaultValue = new float3(0f, 0.5f, 0f), LocalRotationDefaultValue = quaternion.identity, LocalScaleDefaultValue = new float3(1f) }); // Add a float channel that animation can write to. The channel is the intensity of a light on the Head bone. // Clips find the channel through the identifier that FloatChannel.Create computes from the transform path // and the property name. The property name is the serialized name m_Intensity, not intensity. The last // argument is the default value of the channel. rigBuilder.Add(FloatChannel.Create("Root/Spine/Head", typeof(Light), "m_Intensity", 1f)); // Create the immutable rig definition. The result has three bones and one float channel. return rigBuilder.ToRigDefinition();}
Constructors
Constructor | Description |
|---|---|
| RigBuilder(Unity.Collections.Allocator) | RigBuilder constructor. |
Properties
Property | Description |
|---|---|
| IsCreated | Returns true if the RigBuilder has been properly created. |
| RootMotionBoneId | The identifier of the bone whose motion gives the root motion of a clip. |
Methods
Method | Description |
|---|---|
| Add | Adds an EntityIdChannel to the RigBuilder. |
| Clear | Clears all RigBuilder channels. |
| Dispose | Disposes the RigBuilder. |
| GetBoneIndex | Finds the index of the skeleton node that has an identifier. |
| Remove | Removes the entity ID channels that have the same identifier as a channel. |
| Replace | Replaces the entity ID channel that has the same identifier as a channel. |
| ToRigDefinition | Creates a RigDefinition from the current RigBuilder data. |
| TryGet | Gets the skeleton node at a bone index. |
| TrySetBoneDefaultRotation | Sets the default rotation of the bone at a bone index. |
| TrySetBoneDefaultScale | Sets the default scale of the bone at a bone index. |
| TrySetBoneDefaultTranslation | Sets the default translation of the bone at a bone index. |
| TrySetDefaultEntityId | Sets the default value of the entity ID channel that has an identifier. |
| TrySetDefaultFloat | Sets the default value of the float channel that has an identifier. |
| TrySetDefaultInt | Sets the default value of the integer channel that has an identifier. |
| TrySetDefaultRotation | Sets the default value of the rotation channel that has an identifier. |
| TrySetDefaultScale | Sets the default value of the scale channel that has an identifier. |
| TrySetDefaultTranslation | Sets the default value of the translation channel that has an identifier. |
Static Methods
Method | Description |
|---|---|
| Create | Create RigBuilder from an Avatar asset. |