Triangles of a referenced object
64-bitThe target's triangles in the modified mesh's space, for booleans and similar modifiers.
q = (toLocal × placement) × p
The two matrices are multiplied first and each point is transformed once. Positions are collected in a plain array and copied to a Float64Array.
/** Triangles of a definition (what shows: a mesh with its modifiers, a group's faces and what is placed in it), in `into`'s space. */
function trisOf(model, def, toLocal) {
const pos = [], tri = [];
model.walk((d, m) => {
const M = mmul(toLocal, m);
if (d.mesh) {
const s = d.shown, T = s.triangulate(), base = pos.length / 3, map = new Int32Array(s.nv).fill(-1);
let k = 0;
for (let v = 0; v < s.nv; v++) if (!s.vertDead(v)) { map[v] = base + k++; const q = apply(M, [s.P[v * 3], s.P[v * 3 + 1], s.P[v * 3 + 2]]); pos.push(q[0], q[1], q[2]); }
for (let i = 0; i < T.n * 3; i++) tri.push(map[s.hV[T.tri[i]]]);
return;
}
// push/pull faces through the kernel's own triangles (holes handled there)
for (const f of d.faces.values()) {
if (f.hidden) continue;
for (const t of faceTris(d, f)) { const b = pos.length / 3; for (const v of t) { const q = apply(M, d.verts.get(v)); pos.push(q[0], q[1], q[2]); } tri.push(b, b + 1, b + 2); }
}
}, def, ident());
return { pos: Float64Array.from(pos), tri: Uint32Array.from(tri) };
}