import { UvEncoder } from "./UvEncoder.js";
import { vec3 } from "gl-matrix";

export class HemiOctahedralUvEncoder extends UvEncoder {
    uv_to_unit(output, input) {
        const px = input[0] - input[1];
        const pz = -1 + input[0] + input[1];

        const abs_x = Math.abs(px);
        const abs_z = Math.abs(pz);

        const r_y = 1 - (abs_x + abs_z);

        output[0] = px;
        output[1] = r_y;
        output[2] = pz;

        vec3.normalize(output, output);
    }
}
