@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
74 lines (61 loc) • 1.51 kB
JavaScript
/**
*
* @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 deserializeAABB3Encoded_v0(buffer, box, x0, y0, z0, x1, y1, z1) {
const header = buffer.readUint8();
//compute value ranges
const xD = x1 - x0;
const yD = y1 - y0;
const zD = z1 - z0;
let qx0;
let qx1;
let qy0;
let qy1;
let qz0;
let qz1;
if ((header & 1) === 0) {
const _x0 = buffer.readUint16();
qx0 = (_x0 / 65535) * xD + x0;
} else {
qx0 = x0;
}
if ((header & 2) === 0) {
const _x1 = buffer.readUint16();
qx1 = (_x1 / 65535) * xD + x0;
} else {
qx1 = x1;
}
if ((header & 4) === 0) {
const _y0 = buffer.readUint16();
qy0 = (_y0 / 65535) * yD + y0;
} else {
qy0 = y0;
}
if ((header & 8) === 0) {
const _y1 = buffer.readUint16();
qy1 = (_y1 / 65535) * yD + y0;
} else {
qy1 = y1;
}
if ((header & 16) === 0) {
const _z0 = buffer.readUint16();
qz0 = (_z0 / 65535) * zD + z0;
} else {
qz0 = z0;
}
if ((header & 32) === 0) {
const _z1 = buffer.readUint16();
qz1 = (_z1 / 65535) * zD + z0;
} else {
qz1 = z1;
}
box.setBounds(qx0, qy0, qz0, qx1, qy1, qz1);
}