"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.linksToGeometry = exports.linkToGeometry = exports.extrudeToGeometryBuffer = exports.toGeometryBuffer = void 0;
/*
 * @Description  :
 * @Author       : 赵耀圣
 * @Q群           : 632839661
 * @Date         : 2020-12-10 15:01:42
 * @LastEditTime : 2021-03-11 10:54:11
 * @FilePath     : \cga.js\src\extends\geometryaid.ts
 */
var mesh_1 = require("../render/mesh");
var extrude_1 = require("../alg/extrude");
var trianglution_1 = require("../alg/trianglution");
var array_1 = require("../utils/array");
function toGeometryBuffer(geo) {
    var buffer = (0, mesh_1.toGeoBuffer)(geo.position, geo.index, geo.uv);
    return buffer;
}
exports.toGeometryBuffer = toGeometryBuffer;
/**
 * shape 挤压后转几何体
 * @param {*} shape
 * @param {*} arg_path
 * @param {*} options
 */
function extrudeToGeometryBuffer(shape, arg_path, options) {
    var extrudeRes = (0, extrude_1.extrude_obsolete)(shape, arg_path, options);
    return (0, mesh_1.toGeoBuffer)(extrudeRes.vertices, extrudeRes.index, extrudeRes.uvs);
}
exports.extrudeToGeometryBuffer = extrudeToGeometryBuffer;
/**
 * 两个轮廓缝合
 * @param {*} shape
 * @param {*} arg_path
 * @param {*} options
 * @param {*} material
 */
function linkToGeometry(shape, shape1, axisPlane, shapeClose) {
    if (axisPlane === void 0) { axisPlane = trianglution_1.AxisPlane.XY; }
    if (shapeClose === void 0) { shapeClose = false; }
    var geo = (0, extrude_1.linkSides)({ shapes: [shape, shape1], shapeClosed: shapeClose, orgShape: shape, axisPlane: axisPlane });
    var geometry = toGeometryBuffer(geo);
    return geometry;
}
exports.linkToGeometry = linkToGeometry;
/**
 * 多个轮廓缝合
 * @param shapes
 * @param isClose
 * @param material
 */
function linksToGeometry(shapes, pathClosed, shapeClosed) {
    if (pathClosed === void 0) { pathClosed = true; }
    if (shapeClosed === void 0) { shapeClosed = true; }
    var vertices = (0, array_1.flat)(shapes);
    (0, mesh_1.indexable)(vertices);
    var geo = (0, extrude_1.linkSides)({ shapes: shapes, shapeClosed: pathClosed, orgShape: shapes[0] });
    var geometry = toGeometryBuffer(geo);
    return geometry;
}
exports.linksToGeometry = linksToGeometry;
// /**
//  * 三角剖分后转成几何体
//  * 只考虑XY平面
//  * @param {*} boundary 
//  * @param {*} hole 
//  * @param {*} options 
//  */
// export function trianglutionToGeometryBuffer(boundary: any, holes: any[] = [], options: any = { normal: Vec3.UnitZ }) {
//     var triangles = triangulation(boundary, holes, options)
//     var vertices = [...boundary, ...flat(holes)]
//     var uvs: any = [];
//     vertices.reduce((acc, v) => {
//         acc.push(v.x, v.y);
//         return acc;
//     }, uvs);
//     var geometry = toGeometryBuffer(vertices, triangles, uvs);
//     return geometry;
// }
