Skip to content

Commit cb29af8

Browse files
Rigneryretenai
authored andcommitted
Fixed animation bones positions
1 parent d61f97f commit cb29af8

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

DataTool/SaveLogic/Combo.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
@@ -218,8 +218,6 @@ public static void SaveAnimation(ICLIFlags flags, string path, SaveContext conte
218218
skipEffect = extractFlags.SkipAnimationEffects;
219219
}
220220

221-
skip = skip || !Debugger.IsAttached; // todo: ow2 is anim positions are bugged
222-
223221
FindLogic.Combo.AnimationAsset animationInfo = context.m_info.m_animations[animation];
224222
if (!skip) {
225223
using Stream animStream = OpenFile(animation);

TankLib/teAnimation.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Runtime.InteropServices;
@@ -177,10 +177,10 @@ public teAnimation(Stream stream, bool keepOpen = false) {
177177
}
178178

179179
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
180181
for (int j = 0; j < infoTable.PositionCount; j++) {
181-
break; // todo: fix position frames
182182
int frame = System.Math.Abs(positionIndices[j]) % InfoTableSize;
183-
boneAnimation.Positions[frame] = ReadPosition(reader);
183+
boneAnimation.Positions[frame] = ReadPosition(reader, useNewFormat);
184184
}
185185

186186
reader.BaseStream.Position = rotationDataPos;
@@ -212,13 +212,23 @@ private static teQuat ReadRotation(BinaryReader reader) {
212212
/// </summary>
213213
/// <param name="reader">Source reader</param>
214214
/// <returns>Position value</returns>
215-
private static teVec3 ReadPosition(BinaryReader reader) {
216-
float x = (float) reader.ReadHalf();
217-
float y = (float) reader.ReadHalf();
218-
float z = (float) reader.ReadHalf();
219-
// TODO: frame 1+n is relative to previous frame? (delta?)
215+
private static teVec3 ReadPosition(BinaryReader reader, bool newFormat) {
216+
if (newFormat) {
217+
float x = (float) reader.ReadHalf();
218+
float y = (float) reader.ReadHalf();
219+
float z = (float) reader.ReadHalf();
220220

221-
return new teVec3(x / 32f, y / 32f, z / 32f); // <-- sometimes 32 is not the constant?
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();
223+
224+
return new teVec3(x / 32f, y / 32f, z / 32f);
225+
} else {
226+
float x = reader.ReadSingle();
227+
float y = reader.ReadSingle();
228+
float z = reader.ReadSingle();
229+
230+
return new teVec3(x, y, z);
231+
}
222232
}
223233

224234
/// <summary>

TankLib/teTexture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Linq;
44
using System.Runtime.InteropServices;

0 commit comments

Comments
 (0)