/**
 * Perform matrix multiplication on a 3d vector
 * @param {number[]|Float32Array} output
 * @param {number} output_offset
 * @param {number[]|Float32Array} input
 * @param {number} input_offset
 * @param {number[]|Float32Array} m4
 */
export function v3_matrix4_multiply(
    output, output_offset,
    input, input_offset,
    m4
) {
    const x = input[input_offset];
    const y = input[input_offset + 1];
    const z = input[input_offset + 2];

    const w = 1 / (m4[3] * x + m4[7] * y + m4[11] * z + m4[15]);

    const _x = (m4[0] * x + m4[4] * y + m4[8] * z + m4[12]) * w;
    const _y = (m4[1] * x + m4[5] * y + m4[9] * z + m4[13]) * w;
    const _z = (m4[2] * x + m4[6] * y + m4[10] * z + m4[14]) * w;

    output[output_offset] = _x;
    output[output_offset + 1] = _y;
    output[output_offset + 2] = _z;
}