4 using System.Collections.Generic;
5 using SiliconStudio.Core.Collections;
6 using SiliconStudio.Core.Mathematics;
8 namespace SiliconStudio.
Paradox.DataModel
27 internal FastListStruct<EvaluatorChannel> Channels =
new FastListStruct<EvaluatorChannel>(4);
39 internal void Initialize(AnimationClip clip, List<AnimationBlender.Channel> channels)
41 this.BlenderChannels = channels;
46 if (clip.OptimizedCurvesFloat != null)
48 if (curveEvaluatorOptimizedFloat == null)
49 curveEvaluatorOptimizedFloat =
new AnimationCurveEvaluatorOptimizedFloatGroup();
50 curveEvaluatorOptimizedFloat.Initialize(clip.OptimizedCurvesFloat);
53 if (clip.OptimizedCurvesVector3 != null)
55 if (curveEvaluatorOptimizedVector3 == null)
56 curveEvaluatorOptimizedVector3 =
new AnimationCurveEvaluatorOptimizedVector3Group();
57 curveEvaluatorOptimizedVector3.Initialize(clip.OptimizedCurvesVector3);
60 if (clip.OptimizedCurvesQuaternion != null)
62 if (curveEvaluatorOptimizedQuaternion == null)
63 curveEvaluatorOptimizedQuaternion =
new AnimationCurveEvaluatorOptimizedQuaternionGroup();
64 curveEvaluatorOptimizedQuaternion.Initialize(clip.OptimizedCurvesQuaternion);
68 for (
int index = 0; index < channels.Count; index++)
70 var channel = channels[index];
71 AddChannel(ref channel);
75 internal void Cleanup()
77 if (curveEvaluatorOptimizedVector3 != null)
78 curveEvaluatorOptimizedVector3.Cleanup();
79 if (curveEvaluatorOptimizedQuaternion != null)
80 curveEvaluatorOptimizedQuaternion.Cleanup();
83 BlenderChannels = null;
89 fixed (byte* structures = result.Data)
92 for (
int index = 0; index < Channels.Count; index++)
95 var channel = Channels.Items[index];
97 var structureStart = (
float*)(structures + channel.Offset);
100 *structureStart = channel.Factor;
103 if (curveEvaluatorOptimizedVector3 != null)
105 curveEvaluatorOptimizedVector3.Evaluate(newTime, (IntPtr)structures);
108 if (curveEvaluatorOptimizedQuaternion != null)
110 curveEvaluatorOptimizedQuaternion.Evaluate(newTime, (IntPtr)structures);
114 curveEvaluatorFloat.Evaluate(newTime, (IntPtr)structures);
115 curveEvaluatorVector3.Evaluate(newTime, (IntPtr)structures);
116 curveEvaluatorQuaternion.Evaluate(newTime, (IntPtr)structures);
122 fixed (byte* structures = result.Data)
124 for (
int index = 0; index < Channels.Count; index++)
126 var channel = Channels.Items[index];
129 channel.Curve.AddValue(newTime, (IntPtr)(structures + channel.Offset));
141 bool itemFound = clip.Channels.TryGetValue(channel.PropertyName, out clipChannel);
145 if (clipChannel.CurveIndex != -1)
147 curve = clip.Curves[clipChannel.CurveIndex];
148 if (clipChannel.ElementType == typeof(
Vector3))
149 curveEvaluatorVector3.AddChannel(curve, channel.Offset +
sizeof(
float));
150 else if (clipChannel.ElementType == typeof(
Quaternion))
151 curveEvaluatorQuaternion.AddChannel(curve, channel.Offset +
sizeof(float));
153 throw new NotImplementedException(
"Can't create evaluator with this type of curve channel.");
157 if (clipChannel.ElementType == typeof(
Vector3))
158 curveEvaluatorOptimizedVector3.AddChannel(channel.PropertyName, channel.Offset +
sizeof(float));
159 else if (clipChannel.ElementType == typeof(
Quaternion))
160 curveEvaluatorOptimizedQuaternion.AddChannel(channel.PropertyName, channel.Offset +
sizeof(float));
164 Channels.Add(
new EvaluatorChannel { Offset = channel.Offset, Curve = curve, Factor = itemFound ? 1.0f : 0.0f });
167 internal struct EvaluatorChannel
170 public AnimationCurve Curve;
Represents a three dimensional mathematical vector.
An aggregation of AnimationCurve with their channel names.
Represents a four dimensional mathematical quaternion.
unsafe void Compute(CompressedTimeSpan newTime, AnimationClipResult result)
unsafe void AddCurveValues(CompressedTimeSpan newTime, AnimationClipResult result)
Untyped base class for animation curves.
Performs animation blending. For now, all AnimationClip must target the same skeleton.
Evaluates AnimationClip to a AnimationClipResult at a given time.