import Vector3 from "../Vector3.js";

const v3_scratch_1 = new Vector3();
const v3_scratch_2 = new Vector3();

/**
 *
 * @param {number[]} output 3x3 rotation matrix
 * @param {Vector3} forward
 * @param {Vector3} up_dir
 */
export function m3_make_rotation_TBN(output, forward, up_dir) {
    output[6] = forward.x;
    output[7] = forward.y;
    output[8] = forward.z;

    v3_scratch_2.set(output[6], output[7], output[8]);
    v3_scratch_1.crossVectors(up_dir, v3_scratch_2);
    v3_scratch_1.normalize();

    output[0] = v3_scratch_1.x;
    output[1] = v3_scratch_1.y;
    output[2] = v3_scratch_1.z;

    v3_scratch_1.crossVectors(v3_scratch_2, v3_scratch_1);
    v3_scratch_1.normalize();

    output[3] = v3_scratch_1.x;
    output[4] = v3_scratch_1.y;
    output[5] = v3_scratch_1.z;
}