loading frame by frame data batch file working, need to reimplement keyframes

node_mode
Jake 2025-09-28 15:28:10 +08:00
parent b4c6ad200a
commit 951e140129
1 changed files with 13 additions and 31 deletions

View File

@ -110,17 +110,18 @@ window.onload = () => {
function parseAnimFile(buffer) {
console.log("decoding anim file");
const view = new DataView(buffer.buffer);
console.log(view);
let offset = 0;
// 1. Parse header
const magic = String.fromCharCode(...buffer.slice(offset, offset + 4));
offset += 4;
const frameCount = view.getUint16(4, true);
const version = view.getUint8(6);
const frameRate = view.getUint8(7);
const frameCount = view.getUint16(offset, true); offset += 2;
const version = view.getUint8(offset++);
const frameRate = view.getUint8(offset++);
offset += 8; // reserved
offset += 8; // skip reserved
if (magic !== "ANIM" || version !== 1) {
throw new Error("Invalid animation file");
@ -141,38 +142,19 @@ window.onload = () => {
frames.push(positions);
}
// 3. Parse keyframe count
const keyframeCount = view.getUint16(offset, true); offset += 2;
console.log(frames);
// Populate from parsed animation frames
frames.forEach((positions, frameIndex) => {
positions.forEach((val, motorId) => {
dialKeyframes[motorId][frameIndex] = val;
});
});
//const dialKeyframes = Array.from({ length: 5 }, () => ({}));
console.log("keyframecount:" + keyframeCount, offset);
for (let i = 0; i < keyframeCount; i++) {
console.log(view.getUint8(offset++));
console.log(view.getUint16(offset, true));
offset += 2;
console.log(view.getUint16(offset, true));
offset += 2;
// const motorId = view.getUint8(offset++);
// const frame = view.getUint16(offset, true); offset += 2;
// const position = view.getUint16(offset, true); offset += 2;
// console.log({motorId, frame, position});
// if (motorId >= 0 && motorId < dialKeyframes.length) {
// dialKeyframes[motorId][frame] = position;
// } else {
// console.warn(`Invalid motorId: ${motorId}`);
// }
}
console.log(dialKeyframes);
return {
header: { magic, version, frameCount, frameRate },
frames,
dialKeyframes
frames
};
}