import { Matrix4, Shape, ShapeBufferGeometry } from "three";

/**
 *
 * @param {number[]} cutout
 * @return {THREE.BufferGeometry}
 */
export function build_geometry_from_cutout_shape(cutout) {

    const shape = new Shape();

    shape.moveTo(cutout[0], cutout[1]);

    for (let i = 2; i < cutout.length; i += 2) {
        shape.lineTo(cutout[i], cutout[i + 1]);
    }

    shape.closePath();

    const geometry = new ShapeBufferGeometry(shape);

    // move shape by 0.5 to center on origin
    const attribute = geometry.getAttribute('position');

    const mat = new Matrix4();
    mat.makeTranslation(-0.5, -0.5, 0);

    attribute.applyMatrix4(mat);
    //

    return geometry;
}
