Files
workinf_Blender_Wasm/tools/web/probe-web-engine.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

147 lines
8.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* Drive the real Web Blender UI in a headed browser and render one frame per
* engine, then judge the pixels instead of the status line.
*
* node tools/web/probe-web-engine.mjs --port 5186 # in-page WASM (/)
* node tools/web/probe-web-engine.mjs --port 5186 --path server # server Blender (/?ui=web)
* node tools/web/probe-web-engine.mjs --engines BLENDER_EEVEE --console
*
* Options: --port 5184 --gpu hardware|swiftshader --blend <file> --objects 7
* --engines SCENE,BLENDER_WORKBENCH,BLENDER_EEVEE
* --path wasm|server --out /tmp/web-engine-probe --console --json
*
* This replaces probe-wasm-engines.mjs and probe-wasm-eevee-console.mjs: the
* console lines are collected per engine, so "SUCCEEDED with an empty frame"
* comes back with the shader errors that caused it.
*
* Exit code: 0 all engines produced a picture, 1 any engine produced none.
*/
import fs from "node:fs";
import path from "node:path";
import {REPO, parseArgs, waitForServer, launchBrowser, newPage, openFile, waitScene, sha256File} from "./course/lib/lesson-recorder.mjs";
import {imageStats} from "./lib/image-stats.mjs";
// parseArgs only knows the course runner's flags, so tool-specific options are
// read here rather than silently ignored.
const argv = process.argv.slice(2);
const opt = (name, fallback) => { const index = argv.indexOf(`--${name}`); return index >= 0 && argv[index + 1] ? argv[index + 1] : fallback; };
const has = (name) => argv.includes(`--${name}`);
const args = parseArgs();
const BASE = `http://127.0.0.1:${args.port}`;
const BLEND = path.resolve(opt("blend", path.join(REPO, "web/app/public/tutorial/rendering/render-studio.blend")));
const OBJECTS = Number(opt("objects", 7));
const ENGINES = opt("engines", "SCENE,BLENDER_WORKBENCH,BLENDER_EEVEE").split(",").map((name) => name.trim()).filter(Boolean);
const PATH_KIND = opt("path", "wasm");
const OUT = path.resolve(opt("out", "/tmp/web-engine-probe"));
const TARGET = PATH_KIND === "server" ? `${BASE}/?ui=web` : `${BASE}/`;
const TIMEOUT = Number(opt("timeout", 240_000));
fs.mkdirSync(OUT, {recursive: true});
await waitForServer(`${BASE}/`);
const browser = await launchBrowser(args.gpu ?? "hardware");
const {context} = await newPage(browser, {baseUrl: null});
const page = context.pages()[0] ?? await context.newPage();
// Every console message is kept; each engine start clears the buffer so the
// errors printed below belong to that engine's render.
let logs = [];
page.on("console", (message) => logs.push(`[${message.type()}] ${message.text().replace(/\s+/g, " ").slice(0, 400)}`));
page.on("pageerror", (error) => logs.push(`[pageerror] ${String(error).slice(0, 400)}`));
const report = {base: TARGET, blend: BLEND, blendSha256: sha256File(BLEND), path: PATH_KIND, engines: [], status: "PASS", startedAt: new Date().toISOString()};
const openPanel = async () => {
const toggle = page.getByTestId("native-web-tools-toggle");
if (await toggle.count() && await toggle.first().isVisible().catch(() => false)) {
await toggle.first().click({force: true});
await page.waitForTimeout(1500);
}
// On the in-page path the React subtree holding the panel only mounts once a
// render hands the screen back, so the first F12 is what makes it reachable.
if (PATH_KIND === "wasm") {
await page.evaluate(() => { if (document.activeElement instanceof HTMLElement) document.activeElement.blur(); });
await page.keyboard.press("F12");
await page.waitForFunction(() => document.querySelector(".native-render-panel") !== null, null, {timeout: 180_000});
}
const details = page.locator("details.native-render-fallback").first();
await details.waitFor({timeout: 120_000});
if (!(await details.evaluate((element) => element.open))) await details.locator("summary").first().click({force: true});
await page.locator(".native-render-panel").first().waitFor({timeout: 60_000});
};
await page.goto(TARGET, {waitUntil: "domcontentloaded"});
await page.locator("main.blender-app").waitFor({timeout: 180_000});
await openFile(page, BLEND);
await waitScene(page, {objects: OBJECTS, timeout: 180_000});
await page.waitForFunction(() => [...document.querySelectorAll(".workspace-tab")].some((tab) => tab.getAttribute("aria-current") !== null), null, {timeout: 90_000});
await page.evaluate(() => {
const tab = [...document.querySelectorAll(".workspace-tab")].find((element) => element.textContent === "Rendering");
if (tab instanceof HTMLElement) tab.click();
});
await page.waitForTimeout(1500);
await openPanel();
// The shader-compile errors are printed the first time a program is built, which
// on the in-page path happens during the warm-up F12 above. Keep them instead of
// clearing the buffer, and slice per engine so nothing is silently dropped.
const relevant = (line) => /eevee|EEVEE|shader|Shader|GPU|gpu|compute|WebGPU|ERROR|error|unsupported/i.test(line);
report.prelude = logs.filter(relevant).slice(0, 40);
for (const engine of ENGINES) {
const started = Date.now();
const entry = {engine, status: "FAIL"};
const mark = logs.length;
try {
const panel = page.locator(".native-render-panel").first();
await panel.locator('select[aria-label="Engine"]').selectOption(engine);
await panel.getByRole("button", {name: "Render Frame", exact: true}).click();
await page.waitForFunction(() => {
const node = document.querySelector(".native-render-panel");
const text = node?.querySelector(".native-workflow-output")?.textContent ?? "";
if (/FAILED|CANCELLED/.test(text)) return true;
return /SUCCEEDED/.test(text) && node.querySelector(".native-workflow-artifacts a[download]") !== null;
}, null, {timeout: TIMEOUT});
entry.output = ((await panel.locator(".native-workflow-output").first().textContent().catch(() => "")) ?? "").trim();
const links = panel.locator(".native-workflow-artifacts a[download]");
const names = await links.evaluateAll((nodes) => nodes.map((node) => node.getAttribute("download") ?? ""));
const index = names.findIndex((name) => /\.png$/i.test(name));
if (index < 0) throw new Error(`render produced no PNG (artifacts: ${names.join(", ") || "none"})`);
const [download] = await Promise.all([page.waitForEvent("download", {timeout: 60_000}), links.nth(index).click({force: true})]);
const file = path.join(OUT, `${PATH_KIND}-${engine.toLowerCase()}.png`);
await download.saveAs(file);
entry.artifact = {path: file, bytes: fs.statSync(file).size, sha256: sha256File(file)};
entry.pixels = imageStats(file);
entry.status = entry.pixels.verdict === "picture" ? "PASS" : "BLANK";
}
catch (error) { entry.error = String(error?.message ?? error).split("\n")[0]; }
entry.ms = Date.now() - started;
entry.console = logs.slice(mark).filter(relevant).slice(0, 40);
report.engines.push(entry);
if (entry.status !== "PASS") report.status = "FAIL";
}
report.finishedAt = new Date().toISOString();
fs.writeFileSync(path.join(OUT, "probe.json"), `${JSON.stringify(report, null, 2)}\n`);
const unique = (lines) => [...new Set(lines)];
if (args.json) console.log(JSON.stringify(report, null, 2));
else {
for (const entry of report.engines) {
const pixels = entry.pixels ? `${entry.pixels.width}×${entry.pixels.height} opaque ${(entry.pixels.opaqueRatio * 100).toFixed(1)}% maxRGB ${entry.pixels.maxRgb}` : "no frame";
console.log(`${entry.engine.padEnd(18)} ${entry.status.padEnd(6)} ${String(entry.ms).padStart(7)} ms ${pixels}`);
if (entry.error) console.log(` error: ${entry.error}`);
if (has("console") && entry.console.length) for (const line of unique(entry.console)) console.log(` ${line}`);
}
// Shader programs are built once, so the compile errors that explain a blank
// frame are usually printed during warm-up rather than during the engine run.
if (has("console") && report.prelude.length) {
console.log("\nwarm-up console (first render):");
for (const line of unique(report.prelude)) console.log(` ${line}`);
}
console.log(`\n${report.status} — report: ${path.join(OUT, "probe.json")}`);
}
await context.close();
await browser.close();
process.exit(report.status === "PASS" ? 0 : 1);