import { TopoMesh } from "../struct/TopoMesh.js";

/**
 *
 * @param {THREE.BufferGeometry} geo
 * @return {TopoMesh}
 */
export function three_buffer_geometry_to_topo_mesh(geo) {
    const topology = new TopoMesh();
    let faces_array;


    const position_attribute = geo.getAttribute('position');

    const geo_index = geo.getIndex();

    if (geo_index !== null) {
        faces_array = geo_index.array;
    } else {
        faces_array = new Uint32Array(position_attribute.count );

        for (let i = 0; i < faces_array.length; i++) {
            faces_array[i] = i;
        }
    }

    topology.build(position_attribute.array, faces_array);

    return topology;
}
