-
Notifications
You must be signed in to change notification settings - Fork 97
/
Animation.cs
58 lines (51 loc) · 2.22 KB
/
Animation.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
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace SaintCoinach.Graphics.Viewer {
using SharpDX;
using Interop;
public class Animation {
#region Interop
static class Interop {
[DllImport("hkAnimationInterop.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern float getDuration(IntPtr ptr);
[DllImport("hkAnimationInterop.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern float getFrameDuration(IntPtr ptr);
[DllImport("hkAnimationInterop.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int getNumFrames(IntPtr ptr);
[DllImport("hkAnimationInterop.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int getPose(IntPtr ptr, float timestamp, [In, Out] InteropTransform[] output);
}
#endregion
#region Fields
private IntPtr _UnmanagedPtr;
#endregion
#region Properties
public AnimationContainer Container { get; private set; }
public float Duration { get; private set; }
public float FrameDuration { get; private set; }
public int FrameCount { get; private set; }
public string Name { get; private set; }
#endregion
#region Constructor
internal Animation(AnimationContainer container, IntPtr ptr, string name) {
Container = container;
_UnmanagedPtr = ptr;
Name = name;
Duration = HavokInterop.Execute(() => Interop.getDuration(_UnmanagedPtr));
FrameCount = HavokInterop.Execute(() => Interop.getNumFrames(_UnmanagedPtr));
FrameDuration = Duration / FrameCount;
}
#endregion
#region Get
public Matrix[] GetPose(float timestamp) {
var transforms = new InteropTransform[Container.Skeleton.BoneCount];
HavokInterop.Execute(() => Interop.getPose(_UnmanagedPtr, timestamp, transforms));
return transforms.Select(t => t.ToTransformationMatrix()).ToArray();
}
#endregion
}
}