UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

43 lines (37 loc) 1.1 kB
/** * * @param {BinaryBuffer} buffer * @param {AABB3} box * @param {number} x0 * @param {number} y0 * @param {number} z0 * @param {number} x1 * @param {number} y1 * @param {number} z1 */ export function serializeAABB3Quantized16Uint( buffer, box, x0, y0, z0, x1, y1, z1 ) { //compute value ranges const dx = x1 - x0; const dy = y1 - y0; const dz = z1 - z0; // scale delta to Uin16 range, and avoid division by 0 const mx = dx > 0 ? 65535 / dx : 0; const my = dy > 0 ? 65535 / dy : 0; const mz = dz > 0 ? 65535 / dz : 0; //quantize all values const _x0 = Math.floor((box.x0 - x0) * mx); const _y0 = Math.floor((box.y0 - y0) * my); const _z0 = Math.floor((box.z0 - z0) * mz); const _x1 = Math.ceil((box.x1 - x0) * mx); const _y1 = Math.ceil((box.y1 - y0) * my); const _z1 = Math.ceil((box.z1 - z0) * mz); buffer.writeUint16(_x0); buffer.writeUint16(_y0); buffer.writeUint16(_z0); buffer.writeUint16(_x1); buffer.writeUint16(_y1); buffer.writeUint16(_z1); }