Scales the part's mesh for shrinkage or by typed factors and writes it as STL or 3MF.
How the precision is kept
The triangles are scaled in 64-bit by the shared print code, then packed into a Float32Array before either writer runs. Binary STL stores 32-bit coordinates by format. The 3MF writer in print3d.js prints 10 significant digits, but it receives values already narrowed to 32 bits.
Open item. Pack the scaled triangles into a Float64Array so the 3MF file carries the 64-bit coordinates; binary STL stays 32-bit by its format.
Calculations under this policy
3 calculations in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.
print-export.jsPartCraft 0.8.1 32-bit in part3 calculationsReviewed
Tests tools/partcraft-test/test-print-export.mjs
Scaled triangles packed for export
32-bit in part
Turns the scaled triangles back into a mesh for the file writers.
The positions array is a Float32Array, so each scaled coordinate is rounded to 32 bits here. Both the STL and the 3MF file are written from this array. Every triangle gets its own three vertices; nothing is welded.
print-export.js
lines 28 to 32
PartCraft 0.8.1
const meshOf = (tris) => {
const positions = new Float32Array(tris.length * 9), indices = new Uint32Array(tris.length * 3);
tris.forEach((tr, k) => { for (let j = 0; j < 3; j++) { positions.set(tr[j], 9 * k + 3 * j); indices[3 * k + j] = 3 * k + j; } });
return { positions, indices };
};
Triangles of the part's mesh
64-bit
Reads the part's mesh as a list of triangles for the scaling and splitting code.
Copies each corner's three coordinates out of the mesh arrays into plain numbers without arithmetic. The values are as precise as the mesh array they come from.
print-export.js
lines 22 to 27
PartCraft 0.8.1
export function trisOf(mesh) {
const P = mesh.positions, I = mesh.indices, out = new Array(I.length / 3);
const v = (i) => [P[3 * i], P[3 * i + 1], P[3 * i + 2]];
for (let k = 0; k < out.length; k++) out[k] = [v(I[3 * k]), v(I[3 * k + 1]), v(I[3 * k + 2])];
return out;
}
Scaled STL or 3MF file
32-bit in part
Builds the file a person downloads from the Scale for printing dialog.
Hands the 32-bit mesh from meshOf to threeMF or stlBinary in print3d.js and returns the scale factors beside it. The factors come from scaleFactors in 64-bit.
print-export.js
lines 36 to 39
PartCraft 0.8.1
export function scaleFile(mesh, f, { format = 'stl', name = 'part' } = {}) {
const m = scaledMesh(mesh, f), base = safe(name) + '-scaled';
return format === '3mf' ? { name: base + '.3mf', data: threeMF(m, { name: base, app: 'PartCraft' }), factors: scaleFactors(f) } : { name: base + '.stl', data: stlBinary(m), factors: scaleFactors(f) };
}
In detail
Method
The mesh is read as triangles, scaled by scaleTris in print-features.js, packed into a mesh again and written by stlBinary or threeMF in print3d.js.
Number types
Plain 64-bit numbers while scaling; a Float32Array of positions handed to the STL and 3MF writers.
Limits
Coordinates in the scaled 3MF file carry about 7 significant digits.
Approach: 32-bit step, flagged
One step stores or exchanges 32-bit values that reach a number a person reads. It is listed here with its open item, and the step is either moved to 64-bit or the app will warn where the number is read.