@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
33 lines (23 loc) • 810 B
JavaScript
import { bvh32_set_leaf_from_triangle } from "./bvh32_set_leaf_from_triangle.js";
/**
*
* @param {BinaryUint32BVH} bvh
* @param {Float32Array} vertices
* @param {Uint32Array} indices
*/
export function bvh32_from_indexed_geometry(bvh, vertices, indices) {
const triangle_count = indices.length / 3;
bvh.setLeafCount(triangle_count);
bvh.initialize_structure();
for (let i = 0; i < triangle_count; i++) {
const index3 = i * 3;
// read triangle vertex indices
const iA = indices[index3];
const iB = indices[index3 + 1];
const iC = indices[index3 + 2];
bvh32_set_leaf_from_triangle(bvh, i, vertices, iA, iB, iC);
}
// finalize build
// bvh.sort_morton(MATRIX_4_IDENTITY);
bvh.build();
}