laureen
Publish static Space from 6953707
b968036
Raw History Blame Contribute Delete
620 Bytes
export function sampleEmotion(frames, time) {
let index = 0;
while (index + 1 < frames.length && frames[index + 1].t <= time) index++;
const a = frames[index], b = frames[Math.min(index + 1, frames.length - 1)];
const mix = b.t > a.t ? Math.max(0, Math.min(1, (time - a.t) / (b.t - a.t))) : 0;
const frame = { ...a };
for (const key of ["neck", "head_pitch", "head_yaw", "head_roll", "body_pitch", "body_roll", "body_z", "mouth"]) frame[key] = (a[key] || 0) + ((b[key] || 0) - (a[key] || 0)) * mix;
frame.twist = (a.twist || [0, 0, 0]).map((v, i) => v + ((b.twist?.[i] || 0) - v) * mix);
return frame;
}