krishnax12/watchy-eink-smartwatch
Unfinished prototype (not production-ready): 4 native DRC errors, 2 display-flex intersections, and missing antenna radiator copper remain
- Version
- 1.2.7
- License
- MIT
- Stars
- 1
scripts/measure-step-models.cjs
// Raw STEP geometry only: these bounds do not certify viewer transforms or fit.
const fs = require("node:fs");
const path = require("node:path");
function measureMesh(mesh) {
const min = [Infinity, Infinity, Infinity];
const max = [-Infinity, -Infinity, -Infinity];
const vertices = mesh.attributes.position.array;
for (let i = 0; i < vertices.length; i++) {
const axis = i % 3;
min[axis] = Math.min(min[axis], vertices[i]);
max[axis] = Math.max(max[axis], vertices[i]);
}
return { name: mesh.name, min, max };
}
async function main() {
const occt = await require("occt-import-js")();
const models = [];
for (const file of fs
.readdirSync("assets")
.filter((file) => file.endsWith(".step"))) {
const result = occt.ReadStepFile(
fs.readFileSync(path.join("assets", file)),
{
linearUnit: "millimeter",
},
);
if (!result.success) throw new Error(`Cannot parse ${file}`);
const meshes = result.meshes.map(measureMesh);
const min = [0, 1, 2].map((axis) =>
Math.min(...meshes.map((mesh) => mesh.min[axis])),
);
const max = [0, 1, 2].map((axis) =>
Math.max(...meshes.map((mesh) => mesh.max[axis])),
);
models.push({
file,
min,
max,
size: max.map((value, axis) => value - min[axis]),
meshes,
});
console.log(
file,
max.map((value, axis) => (value - min[axis]).toFixed(3)).join(" × "),
);
}
fs.writeFileSync(
"reports/step-model-measurements.json",
JSON.stringify(models, null, 2),
);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});