import { BufferGeometry, Float32BufferAttribute, Uint32BufferAttribute } from "three";
import { build_tetrahedral_mesh_geometry_lines } from "./build_tetrahedral_mesh_geometry_lines.js";

/**
 * Useful as a visualisation tool, to display tetrahedral mesh.
 * This is "LINE_LIST" render type geometry.
 * @param {TetrahedralMesh} tetrahedra
 * @param {Float32Array|number[]} points
 * @return {BufferGeometry} three.js BufferGeometry, intended to be used with Lines mesh
 */
export function build_tetrahedral_mesh_buffer_geometry(
    tetrahedra,
    points
) {

    const point_count = points.length / 3;

    const lines = build_tetrahedral_mesh_geometry_lines(tetrahedra, point_count);

    const geometry = new BufferGeometry();

    geometry.setIndex(new Uint32BufferAttribute(lines, 1, false));
    geometry.setAttribute('position', new Float32BufferAttribute(points, 3, false));
    return geometry;
}
