loading frame by frame data batch file working, need to reimplement keyframes
parent
b4c6ad200a
commit
951e140129
44
script.js
44
script.js
|
|
@ -110,17 +110,18 @@ window.onload = () => {
|
||||||
function parseAnimFile(buffer) {
|
function parseAnimFile(buffer) {
|
||||||
console.log("decoding anim file");
|
console.log("decoding anim file");
|
||||||
const view = new DataView(buffer.buffer);
|
const view = new DataView(buffer.buffer);
|
||||||
|
console.log(view);
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
|
|
||||||
// 1. Parse header
|
// 1. Parse header
|
||||||
const magic = String.fromCharCode(...buffer.slice(offset, offset + 4));
|
const magic = String.fromCharCode(...buffer.slice(offset, offset + 4));
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
const frameCount = view.getUint16(4, true);
|
const frameCount = view.getUint16(offset, true); offset += 2;
|
||||||
const version = view.getUint8(6);
|
const version = view.getUint8(offset++);
|
||||||
const frameRate = view.getUint8(7);
|
const frameRate = view.getUint8(offset++);
|
||||||
|
|
||||||
offset += 8; // reserved
|
offset += 8; // skip reserved
|
||||||
|
|
||||||
if (magic !== "ANIM" || version !== 1) {
|
if (magic !== "ANIM" || version !== 1) {
|
||||||
throw new Error("Invalid animation file");
|
throw new Error("Invalid animation file");
|
||||||
|
|
@ -141,38 +142,19 @@ window.onload = () => {
|
||||||
frames.push(positions);
|
frames.push(positions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Parse keyframe count
|
console.log(frames);
|
||||||
const keyframeCount = view.getUint16(offset, true); offset += 2;
|
|
||||||
|
|
||||||
|
// 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 {
|
return {
|
||||||
header: { magic, version, frameCount, frameRate },
|
header: { magic, version, frameCount, frameRate },
|
||||||
frames,
|
frames
|
||||||
dialKeyframes
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue