FreeformBlendSpace2DData
The precomputed data that the freeform 2D blend space function of BlendSpaceUtility needs.
Read time 2 minutesLast updated 3 hours ago
Definition
- Type: Struct
- Namespace: Unity.Animations
- Assembly: UnityEngine.AnimationCoreModule
- Implements: IDisposable
public struct FreeformBlendSpace2DData : IDisposable
Remarks
The constructor precomputes the geometry of the blend space once for a set of animation positions and for one FreeformBlendSpace2DMode.
Reuse the same instance for every call of BlendSpaceUtility.ComputeBlendSpace2DFreeformWeights, as long as the animation positions don't change. The data holds unmanaged memory. Call FreeformBlendSpace2DData.Dispose when you no longer need it.
The weight function also writes temporary data inside the instance. Don't use the same instance from several threads or jobs at the same time.
The following example uses the and namespaces. It computes the weights of several streams for a 2D input, then mixes the streams with a Core.PoseMixer.
Unity.CollectionsUnity.MathematicsAdditional Resources: BlendSpaceUtility, FreeformBlendSpace2DMode
Examples
// This example blends several poses placed in a 2D blend space, for example the strafe animations of a// character, according to a 2D input such as the movement direction and speed.// The poses buffer holds the animated data of one pose after the other, in the same order as the positions,// each with the stream size of the rig of the output stream.public static void BlendStrafe( NativeArray<AnimatedData> poses, NativeArray<float2> positions, float2 input, ref AnimationStream output){ // Precompute the data of the blend space once, and keep it as long as the positions do not change. // The mode selects the algorithm that computes the weights. using FreeformBlendSpace2DData blendSpace = new FreeformBlendSpace2DData(positions, FreeformBlendSpace2DMode.Cartesian, Allocator.Temp); // Compute one weight per pose. using NativeArray<float> weights = new NativeArray<float>(positions.Length, Allocator.Temp); BlendSpaceUtility.ComputeBlendSpace2DFreeformWeights(input, blendSpace, weights); // Mix all the poses with their weights. The weights sum to 1, so the default pose has no influence. // A stream can't be stored in an array, so create a read-only stream on each pose when you mix it. ref RigDefinition rig = ref output.RigDefinition; int streamSize = rig.Bindings.StreamSize; Core.PoseMixer mixer = default; mixer.Begin(ref output); for (int i = 0; i < positions.Length; ++i) { AnimationStream pose = AnimationStream.CreateReadOnly(ref rig, poses.GetSubArray(i * streamSize, streamSize)); mixer.Add(ref output, pose, weights[i]); } mixer.End(ref output, default);}
Constructors
Constructor | Description |
|---|---|
| FreeformBlendSpace2DData(Unity.Collections.NativeArray{Unity.Mathematics.float2},Unity.Animations.FreeformBlendSpace2DMode,Unity.Collections.Allocator) | Precomputes the data of a freeform blend space. |
Properties
Property | Description |
|---|---|
| Count | The number of animations in the blend space. |
| IsCreated | Whether the data holds allocated memory. |
| Mode | The algorithm this data was precomputed for. |
Methods
Method | Description |
|---|---|
| Dispose | Releases the memory that the data holds. |