import { assert } from "../../../../../../assert.js";
import { bt_mesh_from_indexed_geometry } from "./bt_mesh_from_indexed_geometry.js";

/**
 * Populates supplied topology with data from supplied unindexed geometry (triangles)
 * @param {BinaryTopology} out
 * @param {number[]} vertex_positions
 * @param {number[]} [vertex_normals] Optional vertex normals. Can be skipped.
 */
export function bt_mesh_from_unindexed_geometry(
    out,
    vertex_positions,
    vertex_normals,
) {

    const triangle_count = vertex_positions.length / 9;

    assert.isNonNegativeInteger(triangle_count, 'triangle_count');

    const indices = new Uint32Array(triangle_count * 3);
    for (let i = 0; i < indices.length; i++) {
        indices[i] = i;
    }

    return bt_mesh_from_indexed_geometry(
        out,
        indices,
        vertex_positions,
        vertex_normals
    );
}