|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.IO; |
4 | 4 | using System.Runtime.InteropServices; |
@@ -177,10 +177,10 @@ public teAnimation(Stream stream, bool keepOpen = false) { |
177 | 177 | } |
178 | 178 |
|
179 | 179 | 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 |
180 | 181 | for (int j = 0; j < infoTable.PositionCount; j++) { |
181 | | - break; // todo: fix position frames |
182 | 182 | int frame = System.Math.Abs(positionIndices[j]) % InfoTableSize; |
183 | | - boneAnimation.Positions[frame] = ReadPosition(reader); |
| 183 | + boneAnimation.Positions[frame] = ReadPosition(reader, useNewFormat); |
184 | 184 | } |
185 | 185 |
|
186 | 186 | reader.BaseStream.Position = rotationDataPos; |
@@ -212,13 +212,23 @@ private static teQuat ReadRotation(BinaryReader reader) { |
212 | 212 | /// </summary> |
213 | 213 | /// <param name="reader">Source reader</param> |
214 | 214 | /// <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(); |
220 | 220 |
|
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 | + } |
222 | 232 | } |
223 | 233 |
|
224 | 234 | /// <summary> |
|
0 commit comments