8
8
namespace TankLib {
9
9
/// <summary>Tank Animation, type 006</summary>
10
10
public class teAnimation {
11
+ [ Flags ]
12
+ public enum AnimFlags : ushort {
13
+ // todo
14
+ }
15
+
16
+ [ Flags ]
17
+ public enum InfoTableFlags : ushort {
18
+ // todo
19
+ LegacyPositionFormat = 0x200 ,
20
+ }
21
+
11
22
/// <summary>Animation header</summary>
12
23
[ StructLayout ( LayoutKind . Sequential , Pack = 4 ) ]
13
24
public struct AnimHeader {
@@ -20,7 +31,7 @@ public struct AnimHeader {
20
31
public ushort BoneCount ;
21
32
22
33
/// <summary>Unknown flags</summary>
23
- public ushort Flags ;
34
+ public AnimFlags Flags ;
24
35
25
36
public ushort Unknown1 ;
26
37
@@ -82,7 +93,7 @@ public struct InfoTable {
82
93
public ushort RotationCount ;
83
94
84
95
/// <summary>Unknown flags</summary>
85
- public ushort Flags ;
96
+ public InfoTableFlags Flags ;
86
97
87
98
/// <summary>Offset to scale indices</summary>
88
99
public int ScaleIndicesOffset ;
@@ -145,6 +156,8 @@ public teAnimation(Stream stream, bool keepOpen = false) {
145
156
InfoTables = new InfoTable [ Header . BoneCount ] ;
146
157
BoneAnimations = new BoneAnimation [ Header . BoneCount ] ;
147
158
159
+ // todo: read data for non-bone animations
160
+
148
161
for ( int boneIndex = 0 ; boneIndex < Header . BoneCount ; boneIndex ++ ) {
149
162
long streamPos = reader . BaseStream . Position ;
150
163
InfoTable infoTable = reader . Read < InfoTable > ( ) ;
@@ -177,7 +190,7 @@ public teAnimation(Stream stream, bool keepOpen = false) {
177
190
}
178
191
179
192
reader . BaseStream . Position = positionDataPos ;
180
- bool useNewFormat = ( infoTable . Flags & 512 ) == 0 ; // If this flag isn't set, use the new 10 bytes format, otherwise use the 12 bytes one
193
+ bool useNewFormat = ( infoTable . Flags & InfoTableFlags . LegacyPositionFormat ) == 0 ; // If this flag isn't set, use the new 10 bytes format, otherwise use the 12 bytes one
181
194
for ( int j = 0 ; j < infoTable . PositionCount ; j ++ ) {
182
195
int frame = System . Math . Abs ( positionIndices [ j ] ) % InfoTableSize ;
183
196
boneAnimation . Positions [ frame ] = ReadPosition ( reader , useNewFormat ) ;
@@ -218,8 +231,11 @@ private static teVec3 ReadPosition(BinaryReader reader, bool newFormat) {
218
231
float y = ( float ) reader . ReadHalf ( ) ;
219
232
float z = ( float ) reader . ReadHalf ( ) ;
220
233
221
- // 32bits value here, tried float, int32, 2x halfs, 2x int16, 4x byte, didn't find anything that would make sense
222
- float unknown = ( float ) reader . ReadSingle ( ) ;
234
+ uint packedData = reader . ReadUInt32 ( ) ;
235
+ // var unkX = packedData & 0x3FF;
236
+ // var unkY = (packedData >> 10) & 0x3FF; // <-- sometimes this value changes with no changes to any component. a single bit gets flipped.
237
+ // var unkZ = (packedData >> 20) & 0x3FF; // <-- changes wildly, indicating that my bit shifting/masking is wrong
238
+ // var unk = packedData >> 30; // ????
223
239
224
240
return new teVec3 ( x / 32f , y / 32f , z / 32f ) ;
225
241
} else {
0 commit comments