Files
workinf_Blender_Wasm/tools/web/check-render-basics.mjs
mes123456 63db6caf1f
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
feat(web): studio worlds, camera-view/offscreen environment parity, material and undo coverage
Environment lighting:
- ship all eight desktop studiolights/world datasets (WBENV1 float32) and a
  shared loader used by both the main viewport and the offscreen worker
- add the N-panel "studio 环境" selector
- rotate the world background together with the environment
  (backgroundRotation/backgroundIntensity), so camera view and offscreen
  renders match the desktop Mapping-node behaviour

Verification (Chromium, OPFS, NOT_CLAIMED):
- environment lighting + 8 world pixel identity
- camera-view rotation correspondence (camera matrices, 207 samples)
- offscreen vs on-screen background parity after hiding geometry (1305 samples)
- metals case extended with material-field OPFS roundtrip
- material Principled edits and rename undo/redo
- eight studio worlds: pairwise frame differences + luminance rank correlation
- undo history depth capped at 64 steps and undo across OPFS save/reopen

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 09:27:47 +08:00

131 lines
7.0 KiB
JavaScript

#!/usr/bin/env node
/**
* Gate for the beginner render lesson.
*
* node tools/web/check-render-basics.mjs
*
* Checks the capture report, the screenshots and finished frames it produced,
* and the page itself. Two rules exist because a previous tutorial shipped with
* them broken: adjacent screenshots must not be byte-identical, and a "render"
* whose pixels are all transparent is not a picture.
*/
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import {sha256File} from "./lib/image-stats.mjs";
const REPO = path.resolve(import.meta.dirname, "../..");
const GUIDE = path.join(REPO, "web/app/public/tutorial/render-basics");
const HTML = path.join(GUIDE, "index.html");
const CSS = path.join(GUIDE, "basics.css");
const REPORT = path.join(REPO, "tests/golden/RENDER-BASICS-001/capture-report.json");
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
const failures = [];
const check = (label, run) => { try { run(); } catch (error) { failures.push(`${label}: ${error.message}`); } };
const report = JSON.parse(fs.readFileSync(REPORT, "utf8"));
const html = fs.readFileSync(HTML, "utf8");
const css = fs.readFileSync(CSS, "utf8");
// --- capture report -------------------------------------------------------
check("every step passed", () => {
const failed = report.steps.filter((step) => step.status !== "PASS");
assert.equal(failed.length, 0, `failed steps: ${failed.map((step) => `${step.name} (${step.error ?? step.status})`).join("; ")}`);
});
check("step files exist", () => {
for (const step of report.steps) assert.ok(fs.existsSync(step.shot.path), `missing ${step.shot.path}`);
});
check("no stale screenshots", () => {
const listed = new Set(report.steps.map((step) => path.basename(step.shot.path)));
const onDisk = fs.readdirSync(path.join(GUIDE, "steps"));
assert.deepEqual(onDisk.filter((file) => !listed.has(file)), [], "screenshots left over from an earlier run");
});
check("step hashes match the report", () => {
for (const step of report.steps) assert.equal(sha256File(step.shot.path), step.shot.sha256, `hash drifted: ${path.basename(step.shot.path)}`);
});
check("adjacent screenshots differ", () => {
assert.deepEqual(report.duplicateScreenshots, [], "consecutive steps captured the same frame");
});
check("server engines produced real pixels", () => {
assert.equal(report.engines.length, 3, "expected Eevee, Workbench and Cycles");
for (const engine of report.engines) {
assert.equal(engine.status, "PASS", `${engine.engine} ${engine.status}`);
assert.ok(engine.artifact, `${engine.engine} has no artifact`);
assert.ok(engine.pixels && engine.pixels.opaqueRatio > 0.5,
`${engine.engine} wrote a transparent frame (opaqueRatio ${engine.pixels?.opaqueRatio})`);
}
});
check("PBR frame saved", () => {
assert.ok(report.pbr?.artifact?.bytes > 0, "no PBR artifact");
assert.ok(fs.existsSync(report.pbr.artifact.path), `missing ${report.pbr.artifact.path}`);
assert.equal(report.pbr.resolution, 512);
});
check("render result editor showed that frame", () => {
assert.deepEqual([report.renderResultView?.naturalWidth, report.renderResultView?.naturalHeight], [512, 512],
"the editor did not display the 512 frame that was just rendered");
});
// A transparent frame is the defect this gate exists to name, not to hide: the
// report must keep saying so until the embedded engine is fixed.
check("embedded blank frame is recorded", () => {
const engines = report.embeddedEngines ?? [];
const workbench = engines.find((engine) => engine.engine === "BLENDER_WORKBENCH");
const eevee = engines.find((engine) => engine.engine === "BLENDER_EEVEE");
assert.ok(workbench, "embedded Workbench was not measured");
assert.ok(workbench.pixels?.opaqueRatio > 0.5, "embedded Workbench should produce a picture");
assert.ok(eevee, "embedded EEVEE was not measured");
assert.equal(eevee.pixels?.opaqueRatio, 0, "embedded EEVEE now renders pixels — update the lesson's known-gap note");
});
// --- page -----------------------------------------------------------------
check("no inline style or script", () => {
assert.ok(!/<style[\s>]/i.test(html), "page contains <style>");
assert.ok(!/\sstyle\s*=/i.test(html), "page contains an inline style attribute");
assert.ok(!/<script[\s>]/i.test(html), "page contains <script>");
});
// The lesson tells the reader to open http://127.0.0.1:<port>; that is the
// app itself, not an external asset. Anything else off-host is a defect.
check("no remote URLs", () => {
const remote = [...html.matchAll(/https?:\/\/([^\s"'<>]+)/gi)].filter((match) => !/^(127\.0\.0\.1|localhost)(:|\/|$)/i.test(match[1]));
assert.equal(remote.length, 0, `page references ${remote.map((match) => match[0]).join(", ")}`);
});
check("stylesheet is linked, not inlined", () => {
assert.ok(html.includes('href="/tutorial/pbr/render-lesson.css"'), "shared lesson stylesheet missing");
assert.ok(html.includes('href="/tutorial/render-basics/basics.css"'), "lesson stylesheet missing");
assert.ok(css.length > 0, "basics.css is empty");
});
check("every image has alt and exists", () => {
const images = [...html.matchAll(/<img\b[^>]*>/g)].map((match) => match[0]);
assert.ok(images.length >= 10, `only ${images.length} images`);
for (const tag of images) {
const alt = tag.match(/\balt="([^"]*)"/);
assert.ok(alt && alt[1].trim().length >= 8, `missing or empty alt: ${tag.slice(0, 80)}`);
const src = tag.match(/\bsrc="([^"]+)"/)?.[1];
assert.ok(src && src.startsWith("/tutorial/render-basics/"), `unexpected src: ${src}`);
assert.ok(fs.existsSync(path.join(REPO, "web/app/public", src)), `missing image: ${src}`);
}
});
check("anchors resolve", () => {
const ids = new Set([...html.matchAll(/\bid="([^"]+)"/g)].map((match) => match[1]));
for (const match of html.matchAll(/href="#([^"]+)"/g)) assert.ok(ids.has(match[1]), `dangling anchor #${match[1]}`);
});
check("unverified items are labelled", () => {
assert.match(html, /tag-gap/, "no known-gap label on the page");
assert.match(html, /未验证/, "unverified work is not marked");
assert.match(html, /SUCCEEDED[\s\S]{0,200}全透明|全透明[\s\S]{0,200}SUCCEEDED/, "the embedded blank-frame gap is not stated");
});
check("page does not claim acceptance", () => {
assert.ok(!/验收通过|整体完成|全部可用/.test(html), "page claims acceptance");
});
// --- output ---------------------------------------------------------------
const summary = { checkedAt: new Date().toISOString(), report: path.relative(REPO, REPORT), steps: report.steps.length, failures };
fs.mkdirSync(path.dirname(REPORT), { recursive: true });
fs.writeFileSync(path.join(path.dirname(REPORT), "check-report.json"), `${JSON.stringify(summary, null, 2)}\n`);
if (failures.length) {
console.error(`FAIL ${failures.length}`);
for (const failure of failures) console.error(` - ${failure}`);
process.exitCode = 1;
}
else console.log(`PASS ${report.steps.length} steps, ${report.engines.length} server engines, embedded gap recorded`);