88namespace TankLib {
99 /// <summary>Tank Animation, type 006</summary>
1010 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+
1122 /// <summary>Animation header</summary>
1223 [ StructLayout ( LayoutKind . Sequential , Pack = 4 ) ]
1324 public struct AnimHeader {
@@ -20,7 +31,7 @@ public struct AnimHeader {
2031 public ushort BoneCount ;
2132
2233 /// <summary>Unknown flags</summary>
23- public ushort Flags ;
34+ public AnimFlags Flags ;
2435
2536 public ushort Unknown1 ;
2637
@@ -82,7 +93,7 @@ public struct InfoTable {
8293 public ushort RotationCount ;
8394
8495 /// <summary>Unknown flags</summary>
85- public ushort Flags ;
96+ public InfoTableFlags Flags ;
8697
8798 /// <summary>Offset to scale indices</summary>
8899 public int ScaleIndicesOffset ;
@@ -145,6 +156,8 @@ public teAnimation(Stream stream, bool keepOpen = false) {
145156 InfoTables = new InfoTable [ Header . BoneCount ] ;
146157 BoneAnimations = new BoneAnimation [ Header . BoneCount ] ;
147158
159+ // todo: read data for non-bone animations
160+
148161 for ( int boneIndex = 0 ; boneIndex < Header . BoneCount ; boneIndex ++ ) {
149162 long streamPos = reader . BaseStream . Position ;
150163 InfoTable infoTable = reader . Read < InfoTable > ( ) ;
@@ -177,7 +190,7 @@ public teAnimation(Stream stream, bool keepOpen = false) {
177190 }
178191
179192 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
181194 for ( int j = 0 ; j < infoTable . PositionCount ; j ++ ) {
182195 int frame = System . Math . Abs ( positionIndices [ j ] ) % InfoTableSize ;
183196 boneAnimation . Positions [ frame ] = ReadPosition ( reader , useNewFormat ) ;
@@ -218,8 +231,11 @@ private static teVec3 ReadPosition(BinaryReader reader, bool newFormat) {
218231 float y = ( float ) reader . ReadHalf ( ) ;
219232 float z = ( float ) reader . ReadHalf ( ) ;
220233
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; // ????
223239
224240 return new teVec3 ( x / 32f , y / 32f , z / 32f ) ;
225241 } else {
0 commit comments