70 lines
3.1 KiB
JavaScript
70 lines
3.1 KiB
JavaScript
// E03: build CabinetA (8 teaching parts) from line-spec and save E03.
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { createSceneRunner } from "../../../carrier-course/lib/scene.mjs";
|
|
import { saveCheckpoint } from "../../../carrier-course/lib/ui-actions.mjs";
|
|
import { createBuilder } from "../../lib/build.mjs";
|
|
import { newDocument, spec } from "../../lib/ui.mjs";
|
|
import { checkLineCheckpoint } from "../../lib/line-precision.mjs";
|
|
|
|
const MODEL = "CabinetA";
|
|
|
|
export async function run({ page, rec, script, stillsDir, rawDir, webRoot }) {
|
|
const scene = createSceneRunner({ rec, page, script });
|
|
const shot = name => rec.shot(stillsDir, name);
|
|
const log = [];
|
|
const logStep = entry => {
|
|
log.push({ at: new Date().toISOString(), ...entry });
|
|
fs.writeFileSync(path.join(rawDir, "live-log.json"), `${JSON.stringify(log, null, 2)}\n`);
|
|
};
|
|
const model = spec().models.find(item => item.name === MODEL);
|
|
const parts = model.parts;
|
|
const names = parts.map(part => part.partName);
|
|
const builder = createBuilder({ page, rec, logStep });
|
|
|
|
await scene("S00", async () => { await shot("S00-title"); });
|
|
|
|
await scene("S01", async () => {
|
|
await newDocument(page);
|
|
logStep({ step: "document", labels: await builder.labels() });
|
|
await shot("S01-document");
|
|
});
|
|
|
|
const build = async part => {
|
|
const dims = part.fcLocalDims;
|
|
if (part.primitive === "cylinder") {
|
|
const radius = Math.max(0.1, dims[0] / 2);
|
|
const position = [part.center[0], part.center[1], part.position[2]];
|
|
await builder.createCylinder(part.partName, radius, dims[2], position);
|
|
} else {
|
|
await builder.createBox(part.partName, dims, part.position);
|
|
}
|
|
await builder.setColor(part.partName, part.color);
|
|
logStep({ step: "part", name: part.partName, dims, position: part.position, color: part.color });
|
|
};
|
|
|
|
for (let sceneIndex = 0; sceneIndex < 4; sceneIndex++) {
|
|
const slice = parts.slice(sceneIndex * 2, sceneIndex * 2 + 2);
|
|
await scene(`S0${sceneIndex + 2}`, async () => {
|
|
for (const part of slice) await build(part);
|
|
await shot(`S0${sceneIndex + 2}-parts`);
|
|
});
|
|
}
|
|
|
|
await scene("S06", async () => {
|
|
const saved = await saveCheckpoint({ page, rec, webRoot, episode: "E03", rawDir,
|
|
checkpointDir: path.join(webRoot, "tools", "line-course", "checkpoints"), expectedLabels: names });
|
|
logStep({ step: "checkpoint", ...saved });
|
|
const precision = await checkLineCheckpoint(saved.checkpoint ?? path.join(webRoot, "tools", "line-course", "checkpoints", "E03.FCStd"), names);
|
|
fs.writeFileSync(path.join(rawDir, "E03-precision.json"), `${JSON.stringify(precision, null, 2)}\n`);
|
|
if (!precision.ok) throw new Error(`precision failed: ${JSON.stringify({ extra: precision.extra,
|
|
models: precision.models.filter(item => !item.ok),
|
|
failures: precision.results.filter(item => !item.ok) })}`);
|
|
fs.writeFileSync(path.join(rawDir, "E03-state.json"), `${JSON.stringify({
|
|
schema: "freecad-web-line-course/E03/state/v1",
|
|
generatedAt: new Date().toISOString(), model: MODEL, parts: names, precision, log,
|
|
}, null, 2)}\n`);
|
|
await shot("S06-recap");
|
|
});
|
|
}
|