-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathKeyFrame.cs
More file actions
116 lines (95 loc) · 2.73 KB
/
KeyFrame.cs
File metadata and controls
116 lines (95 loc) · 2.73 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
namespace SharpNeedle.Framework.Ninja.Csd.Motions;
using SharpNeedle.Structs;
public class KeyFrame : IBinarySerializable
{
public int Frame { get; set; }
public Union Value { get; set; }
public InterpolationType Interpolation { get; set; }
public float InTangent { get; set; }
public float OutTangent { get; set; }
public uint Field14 { get; set; }
public AspectRatioCorrection? Correction { get; set; }
public void Read(BinaryObjectReader reader)
{
Frame = reader.Read<int>();
Value = reader.Read<uint>();
if (reader.OffsetBinaryFormat == OffsetBinaryFormat.U64)
{
Interpolation = (InterpolationType)reader.Read<uint>();
}
else
{
Interpolation = reader.Read<InterpolationType>();
}
InTangent = reader.Read<float>();
OutTangent = reader.Read<float>();
Field14 = reader.Read<uint>();
}
public void Write(BinaryObjectWriter writer)
{
writer.Write(Frame);
writer.Write(Value.Uint);
if(writer.OffsetBinaryFormat == OffsetBinaryFormat.U64)
writer.Write((uint)Interpolation);
else
writer.Write(Interpolation);
writer.Write(InTangent);
writer.Write(OutTangent);
writer.Write(Field14);
}
[StructLayout(LayoutKind.Explicit, Size = 4)]
public struct Union
{
[FieldOffset(0)] public Color<byte> Color;
[FieldOffset(0)] public uint Uint;
[FieldOffset(0)] public float Float;
public Union(Color<byte> value) : this()
{
Color = value;
}
public Union(uint value) : this()
{
Uint = value;
}
public Union(float value) : this()
{
Float = value;
}
public void Set(Color<byte> value)
{
Color = value;
}
public void Set(uint value)
{
Uint = value;
}
public void Set(float value)
{
Float = value;
}
public static implicit operator Union(float value)
{
return new Union(value);
}
public static implicit operator Union(uint value)
{
return new Union(value);
}
public static implicit operator Union(Color<byte> value)
{
return new Union(value);
}
public static implicit operator float(Union value)
{
return value.Float;
}
public static implicit operator uint(Union value)
{
return value.Uint;
}
public static implicit operator Color<byte>(Union value)
{
return value.Color;
}
}
}