#!/usr/bin/env node // Generates production-line-assembly.html from line-spec + exported STLs. import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const here = path.dirname(fileURLToPath(import.meta.url)); const webRoot = path.resolve(here, "../.."); const spec = JSON.parse(fs.readFileSync(path.join(here, "line-spec.json"), "utf8")); const outFile = path.join(webRoot, "teaching", "cases", "production-line-assembly.html"); fs.copyFileSync(path.join(here, "line-spec.json"), path.join(webRoot, "teaching", "cases", "production-line-spec.json")); const parts = spec.models.flatMap(model => model.parts.map(part => ({ partName: part.partName, model: model.name, modelLabel: model.label, color: part.color, worldBBox: part.worldBBox, }))); const models = spec.models.map(model => ({ name: model.name, label: model.label })); const groundModels = new Set(["GroundPlane", "Plane", "Plane001"]); const machineParts = parts.filter(part => !groundModels.has(part.model)); const machineBox = [0, 1, 2].map(axis => Math.min(...machineParts.map(part => part.worldBBox[axis]))) .concat([0, 1, 2].map(axis => Math.max(...machineParts.map(part => part.worldBBox[axis + 3])))); const html = `
左键旋转 · 滚轮缩放 · 右键平移
`; fs.writeFileSync(outFile, html); console.log(JSON.stringify({ ok: true, outFile, parts: parts.length, models: models.length }));