-
-
Notifications
You must be signed in to change notification settings - Fork 911
/
AnimationCurveEvaluatorDirectVector4Group.cs
56 lines (50 loc) · 2.47 KB
/
AnimationCurveEvaluatorDirectVector4Group.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using Stride.Core.Mathematics;
namespace Stride.Animations
{
public class AnimationCurveEvaluatorDirectVector4Group : AnimationCurveEvaluatorDirectBlittableGroupBase<Vector4>
{
protected unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
{
SetTime(ref channel, newTime);
var currentTime = channel.CurrentTime;
var currentIndex = channel.CurrentIndex;
var keyFrames = channel.Curve.KeyFrames;
var keyFramesItems = keyFrames.Items;
var keyFramesCount = keyFrames.Count;
// Extract data
int timeStart = keyFrames[currentIndex + 0].Time.Ticks;
int timeEnd = keyFrames[currentIndex + 1].Time.Ticks;
// Compute interpolation factor and avoid NaN operations when timeStart >= timeEnd
float t = (timeEnd <= timeStart) ? 0 : ((float)currentTime.Ticks - (float)timeStart) / ((float)timeEnd - (float)timeStart);
if (channel.InterpolationType == AnimationCurveInterpolationType.Cubic)
{
Interpolator.Vector4.Cubic(
ref keyFramesItems[currentIndex > 0 ? currentIndex - 1 : 0].Value,
ref keyFramesItems[currentIndex].Value,
ref keyFramesItems[currentIndex + 1].Value,
ref keyFramesItems[currentIndex + 2 >= keyFramesCount ? currentIndex + 1 : currentIndex + 2].Value,
t,
out *(Vector4*)(location + channel.Offset));
}
else if (channel.InterpolationType == AnimationCurveInterpolationType.Linear)
{
Interpolator.Vector4.Linear(
ref keyFramesItems[currentIndex].Value,
ref keyFramesItems[currentIndex + 1].Value,
t,
out *(Vector4*)(location + channel.Offset));
}
else if (channel.InterpolationType == AnimationCurveInterpolationType.Constant)
{
*(Vector4*)(location + channel.Offset) = keyFrames[currentIndex].Value;
}
else
{
throw new NotImplementedException();
}
}
}
}