Vertex placement and unit scale
64-bitMoves every mesh vertex to where the file places it and converts it to the part's unit.
p′ = (M · p) ÷ w × s; s = meters per file unit × 1000
One 64-bit expression per coordinate. The scale s is 1 when the file's unit is µm, mm, cm, m, in or ft, and the part then takes that unit; otherwise it is the file's meters per unit times 1000. A weight w that evaluates to 0 falls back to 1 through the || operator.
const s = unitOk ? 1 : scene.units.metres * 1000; // other units: into millimetres
const P = [], T = [];
const facts = { objects: 0, cached: scene.report.surfaces.cached, ours: Object.values(scene.report.surfaces.ours).reduce((a, n) => a + n, 0), curves: scene.report.curves, hidden: 0 };
const hiddenLayer = (it) => it.layer >= 0 && scene.layers[it.layer] && !scene.layers[it.layer].visible;
const put = (items, M, depth) => {
for (const it of items) {
if (it.hidden || hiddenLayer(it)) { if (it.kind !== 'curve') facts.hidden++; continue; }
if (it.kind === 'mesh') {
const base = P.length / 3, p = it.positions;
for (let i = 0; i < p.length; i += 3) {
const x = p[i], y = p[i + 1], z = p[i + 2];
const w = M[12] * x + M[13] * y + M[14] * z + M[15] || 1;
P.push((M[0] * x + M[1] * y + M[2] * z + M[3]) / w * s, (M[4] * x + M[5] * y + M[6] * z + M[7]) / w * s, (M[8] * x + M[9] * y + M[10] * z + M[11]) / w * s);
}
for (let i = 0; i < it.indices.length; i++) T.push(base + it.indices[i]);
if (T.length / 3 > MAX_TRIS) throw new Mesh3dmError('mesh.err.too_many', { max: MAX_TRIS });
facts.objects++;
} else if (it.kind === 'instance' && depth < MAX_DEPTH) {
const b = scene.blocks.get(it.block);
if (b) put(b.items, mul(M, it.xform), depth + 1);
}
}
};
put(scene.items, I, 0);