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

113 lines
6.0 KiB
JavaScript
Raw 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
/**
* Ask the real page what is actually painted at a place, instead of trusting
* the DOM order.
*
* node tools/web/probe-ui-paint.mjs --port 5186 --url "/?ui=web" \
* [--blend <file|->] [--workspace Rendering] [--selector '<css>'] [--point x,y] [--json]
*
* For each selector it prints the element's box, which elements are on top of
* its centre and of its top strip, and the nearest scroll containers. That is
* enough to tell "the component did not render" from "the component rendered
* but something absolutely positioned is covering it".
*
* Written after a capture showed a toolbar box at y 58–83 while the quick
* toolbar's buttons were painted there: the toolbar existed and was invisible.
*/
import path from "node:path";
import {parseArgs, waitForServer, launchBrowser, newPage, openFile, waitScene} from "./course/lib/lesson-recorder.mjs";
// parseArgs only knows the course runner's flags, so tool-specific options are
// read here rather than 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 args = parseArgs();
const BASE = `http://127.0.0.1:${args.port}`;
const URL_PATH = opt("url", "/?ui=web");
const BLEND = opt("blend", null);
const WORKSPACE = opt("workspace", "");
const SELECTORS = opt("selector", '[data-testid="render-result-view"]').split(",").map((item) => item.trim()).filter(Boolean);
const POINTS = opt("point", "").split(";").map((item) => item.trim()).filter(Boolean);
// Selectors clicked in order before measuring, so the page can be driven into
// the state under test (open a panel, start a render) without a bespoke script.
const CLICKS = opt("click", "").split(";").map((item) => item.trim()).filter(Boolean);
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();
await page.goto(`${BASE}${URL_PATH}`, {waitUntil: "domcontentloaded"});
await page.locator("main.blender-app").waitFor({timeout: 180_000});
if (BLEND && BLEND !== "-") {
await openFile(page, path.resolve(BLEND));
await waitScene(page, {objects: Number(args.objects ?? 7), timeout: 180_000});
}
if (WORKSPACE) {
await page.waitForFunction(() => [...document.querySelectorAll(".workspace-tab")].some((tab) => tab.getAttribute("aria-current") !== null), null, {timeout: 90_000});
await page.evaluate((name) => {
const tab = [...document.querySelectorAll(".workspace-tab")].find((element) => element.textContent === name);
if (tab instanceof HTMLElement) tab.click();
}, WORKSPACE);
await page.waitForTimeout(1500);
}
for (const selector of CLICKS) {
const target = page.locator(selector).first();
await target.waitFor({timeout: 120_000});
await target.click({force: true});
await page.waitForTimeout(Number(opt("settle", 1500)));
}
const result = await page.evaluate(({selectors, points}) => {
const describe = (element) => {
if (!element) return null;
const style = getComputedStyle(element);
return {tag: element.tagName, className: typeof element.className === "string" ? element.className : "", id: element.id || undefined,
text: (element.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 40)};
};
const box = (element) => { const rect = element.getBoundingClientRect(); return {x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height), top: Math.round(rect.top), bottom: Math.round(rect.bottom)}; };
const scrollChain = (element) => {
const chain = [];
for (let node = element.parentElement; node && node !== document.documentElement; node = node.parentElement) {
const style = getComputedStyle(node);
if (style.overflowY === "auto" || style.overflowY === "scroll") chain.push({...describe(node), scrollTop: node.scrollTop, clientHeight: node.clientHeight, scrollHeight: node.scrollHeight});
}
return chain;
};
const report = {selectors: {}, points: {}};
for (const selector of selectors) {
const element = document.querySelector(selector);
if (!element) { report.selectors[selector] = {missing: true}; continue; }
const rect = box(element);
const centre = document.elementsFromPoint(rect.x + rect.width / 2, Math.min(rect.y + rect.height / 2, window.innerHeight - 2));
const strip = document.elementsFromPoint(rect.x + Math.min(rect.width / 2, 300), Math.min(rect.y + 4, window.innerHeight - 2));
report.selectors[selector] = {
box: rect,
coveredAtCentre: !centre.includes(element),
coveredAtTop: !strip.includes(element),
onTopAtCentre: centre.slice(0, 4).map(describe),
onTopAtTop: strip.slice(0, 4).map(describe),
scrollChain: scrollChain(element),
};
}
for (const point of points) {
const [x, y] = point.split(",").map(Number);
report.points[point] = document.elementsFromPoint(x, y).slice(0, 5).map(describe);
}
return report;
}, {selectors: SELECTORS, points: POINTS});
if (args.json) console.log(JSON.stringify(result, null, 2));
else {
for (const [selector, info] of Object.entries(result.selectors)) {
console.log(selector);
if (info.missing) { console.log(" missing"); continue; }
console.log(` box x${info.box.x} y${info.box.y} ${info.box.width}×${info.box.height}`);
console.log(` covered at top: ${info.coveredAtTop}${info.coveredAtTop ? ` by ${info.onTopAtTop.map((item) => `${item.tag}.${item.className.split(" ")[0] ?? ""}`).join(" > ")}` : ""}`);
console.log(` covered at centre: ${info.coveredAtCentre}`);
for (const scroller of info.scrollChain) console.log(` scroller ${scroller.tag}.${scroller.className.split(" ")[0] ?? ""} scrollTop=${scroller.scrollTop} ${scroller.clientHeight}/${scroller.scrollHeight}`);
}
for (const [point, stack] of Object.entries(result.points)) console.log(`${point}: ${stack.map((item) => `${item.tag}.${item.className.split(" ")[0] ?? ""}`).join(" > ")}`);
}
await context.close();
await browser.close();