|
7 | 7 |
|
8 | 8 | namespace UnityGLTF.Interactivity.Playback |
9 | 9 | { |
10 | | - public struct BezierInterpolateData |
11 | | - { |
12 | | - public IPointer pointer; |
13 | | - public float duration; |
14 | | - public float2 cp0; |
15 | | - public float2 cp1; |
16 | | - public NodeEngineCancelToken cancellationToken; |
17 | | - } |
18 | | - |
19 | 10 | public static partial class Helpers |
20 | 11 | { |
21 | | - public static async Task<bool> InterpolateAsync<T,V>(T from, T to, Action<T> setter, Func<T, T, float, T> evaluator, float duration, V cancellationToken) where V : struct, ICancelToken |
22 | | - { |
23 | | - for (float t = 0f; t < 1f; t += Time.deltaTime / duration) |
24 | | - { |
25 | | - if (cancellationToken.isCancelled) |
26 | | - return false; |
27 | | - |
28 | | - setter(evaluator(from, to, t)); |
29 | | - await Task.Yield(); |
30 | | - } |
31 | | - |
32 | | - return true; |
33 | | - } |
34 | | - |
35 | | - public static async Task<bool> LinearInterpolateAsync<T,V>(T to, Pointer<T> pointer, float duration, V cancellationToken) where V : struct, ICancelToken |
36 | | - { |
37 | | - return await InterpolateAsync(pointer.getter(), to, pointer.setter, pointer.evaluator, duration, cancellationToken); |
38 | | - } |
39 | | - |
40 | | - public static async Task<bool> InterpolateBezierAsync<T>(Property<T> to, BezierInterpolateData d) |
41 | | - { |
42 | | - var v = to.value; |
43 | | - return await InterpolateBezierAsync(v, d); |
44 | | - } |
45 | | - |
46 | | - public static async Task<bool> InterpolateBezierAsync<T>(T to, BezierInterpolateData d) |
47 | | - { |
48 | | - var p = (Pointer<T>)d.pointer; |
49 | | - |
50 | | - var evaluator = new Func<T, T, float, T>((a, b, t) => p.evaluator(a, b, CubicBezier(t, d.cp0, d.cp1).y)); |
51 | | - |
52 | | - return await InterpolateAsync(p.getter(), to, p.setter, evaluator, d.duration, d.cancellationToken); |
53 | | - } |
54 | | - |
55 | 12 | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
56 | 13 | public static float2 CubicBezier(float t, float2 cp0, float2 cp1) |
57 | 14 | { |
|
0 commit comments