arx-convert
Version:
Converts various Arx Fatalis formats to JSON or YAML and back
67 lines • 2.55 kB
JavaScript
import { BinaryIO } from '../common/BinaryIO.js';
import { KEEP_ZERO_BYTES } from '../common/constants.js';
import { concatArrayBuffers } from '../common/helpers.js';
import { NewKeyFrame } from './NewKeyFrame.js';
import { OldKeyFrame } from './OldKeyFrame.js';
import { TeaHeader } from './TeaHeader.js';
export class TEA {
static load(decompressedFile) {
const file = new BinaryIO(decompressedFile);
const { numberOfKeyFrames, numberOfGroups, ...header } = TeaHeader.readFrom(file);
if (header.version < 2014) {
throw new Error(`Invalid TEA version ${header.version}`);
}
const data = {
header,
keyframes: [],
};
for (let i = 0; i < numberOfKeyFrames; i++) {
console.log(i, file.position);
let keyframe;
if (header.version >= 2015) {
keyframe = NewKeyFrame.readFrom(file);
}
else {
keyframe = OldKeyFrame.readFrom(file);
}
data.keyframes.push(keyframe);
if (keyframe.key_move) {
keyframe.translate = file.readVector3();
}
if (keyframe.key_orient) {
file.position = file.position + 8; // theo angle
keyframe.quat = file.readQuat();
}
if (keyframe.key_morph) {
file.position = file.position + 16; // thea morph
}
for (let j = 0; j < numberOfGroups; j++) {
// theo groupanim
const group = {
key: file.readInt32() !== 0,
angle: file.readString(8, KEEP_ZERO_BYTES), // ignored
quat: file.readQuat(),
translate: file.readVector3(),
zoom: file.readVector3(),
};
// TODO: create groups and fill it in with group data
}
const numberOfSamples = file.readInt32();
if (numberOfSamples !== -1) {
const sample = {
name: file.readString(256, KEEP_ZERO_BYTES),
size: file.readInt32(),
};
keyframe.sample = sample;
file.position = file.position + sample.size;
}
console.log(keyframe);
}
file.position = file.position + 4; // num_sfx?
return data;
}
static save(json) {
return concatArrayBuffers([]);
}
}
//# sourceMappingURL=TEA.js.map