#!/usr/bin/env node /** * Generate the desktop Blender reference for the headed Decimate suite. * * node tools/web/generate-decimate-golden.mjs [--blender ] [--out ] [--modifier-ratio 0.1] [--edit-ratio 0.5] * * Defaults to the source-built desktop binary at * build_blender_native/bin/blender and writes * tests/golden/MESH-DECIMATE-DESKTOP/desktop-decimate.json. * The record is a golden reference (`acceptance: NOT_CLAIMED`), never a pass claim. */ import { spawn } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const args = process.argv.slice(2); const take = (name, fallback) => { const index = args.indexOf(`--${name}`); return index >= 0 && args[index + 1] ? args[index + 1] : fallback; }; const blender = path.resolve(take("blender", process.env.BLENDER_NATIVE_BIN ?? path.join(REPO_ROOT, "build_blender_native/bin/blender"))); const script = path.join(REPO_ROOT, "tools/web/generate-decimate-golden.py"); const blend = path.resolve(take("blend", path.join(REPO_ROOT, "web/app/public/tutorial/pbr/studio.blend"))); const monkey = path.resolve(take("monkey", path.join(REPO_ROOT, "re/猴头.glb"))); const out = path.resolve(take("out", path.join(REPO_ROOT, "tests/golden/MESH-DECIMATE-DESKTOP/desktop-decimate.json"))); const modifierRatio = take("modifier-ratio", "0.1"); const editRatio = take("edit-ratio", "0.5"); for (const [label, file] of [["blender", blender], ["script", script], ["blend", blend], ["monkey", monkey]]) { if (!fs.existsSync(file)) { console.error(`missing ${label}: ${file}`); process.exit(64); } } const child = spawn(blender, [ "--background", "--factory-startup", "--python", script, "--", "--blend", blend, "--monkey", monkey, "--out", out, "--modifier-ratio", modifierRatio, "--edit-ratio", editRatio, ], { cwd: REPO_ROOT, stdio: "inherit" }); child.on("error", (error) => { console.error(`failed to start blender: ${error.message}`); process.exit(1); }); child.on("exit", (code) => { if (code !== 0) { console.error(`blender exited with ${code}; no golden written`); process.exit(code === null ? 1 : code); } if (!fs.existsSync(out)) { console.error(`blender finished but wrote no golden: ${out}`); process.exit(1); } console.log(JSON.stringify({ status: "WRITTEN", out, blender, blend, monkey, modifierRatio: Number(modifierRatio), editRatio: Number(editRatio) }, null, 2)); });