@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
39 lines (29 loc) • 1.09 kB
JavaScript
import { array_copy } from "../../../../core/collection/array/array_copy.js";
import { geometry_construct_triangle_normal } from "../geometry_construct_triangle_normal.js";
const scratch_v3 = new Float64Array(3);
/**
* @param {Array.<number>|Float32Array} positions
* @param {Array.<number>|Float32Array} normals
* @param {number} vertex_count
*/
export function geometry_compute_vertex_normals_unindexed(
positions,
normals,
vertex_count
) {
for (let i = 0; i < vertex_count; i += 3) {
// each sequential 3 vertices make up a unique triangle
const a = i;
const b = i + 1;
const c = i + 2;
geometry_construct_triangle_normal(
scratch_v3, 0,
a, b, c, positions
);
// accumulate
array_copy(scratch_v3, 0, normals, a * 3, 3);
array_copy(scratch_v3, 0, normals, b * 3, 3);
array_copy(scratch_v3, 0, normals, c * 3, 3);
}
// no need to normalize, that's already handled during normal construction for each triangle
}