@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
47 lines (41 loc) • 1.44 kB
JavaScript
import { lerp } from "../../../core/math/lerp.js";
import { BinaryInterpolationAdapter } from "../sim/BinaryInterpolationAdapter.js";
/**
* Componentwise lerp of a 3-Float32 position payload.
*
* Wire layout (matching whatever serialization adapter wrote it):
* - Float32 x
* - Float32 y
* - Float32 z
*
* 12 bytes per snapshot. Pair with a serialization adapter that uses this
* same format (the simplest "naked Vector3" encoding).
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class Vector3InterpolationAdapter extends BinaryInterpolationAdapter {
/**
* @param {BinaryBuffer} out_buffer
* @param {BinaryBuffer} source
* @param {number} first_offset
* @param {number} second_offset
* @param {number} t
*/
interpolate(out_buffer, source, first_offset, second_offset, t) {
source.position = first_offset;
const ax = source.readFloat32();
const ay = source.readFloat32();
const az = source.readFloat32();
source.position = second_offset;
const bx = source.readFloat32();
const by = source.readFloat32();
const bz = source.readFloat32();
const out_x = lerp(ax, bx, t);
const out_y = lerp(ay, by, t);
const out_z = lerp(az, bz, t);
out_buffer.writeFloat32(out_x);
out_buffer.writeFloat32(out_y);
out_buffer.writeFloat32(out_z);
}
}