Files
workinf_Blender_Wasm/tools/web/complete/probe-texture-paint.mjs
mes123456 9499664892
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
test(web): record texture paint stroke and undo evidence
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-14 07:29:05 +08:00

67 lines
3.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Focused case: import an image, open Texture Paint, paint a stroke, undo it.
*
* node tools/web/complete/probe-texture-paint.mjs --base-url http://127.0.0.1:5176
*/
import path from "node:path";
import { REPO, ASSETS, parseArgs, launchBrowser, newPage, openFile, waitScene, switchWorkspace } from "../course/lib/lesson-recorder.mjs";
const args = parseArgs();
const BASE = args.baseUrl || "http://127.0.0.1:5176";
const texture = path.join(REPO, "web/app/public/tutorial/texture-paint/re-texture-base.png");
const browser = await launchBrowser(args.gpu);
const { context, page, consoleErrors } = await newPage(browser, { baseUrl: BASE });
page.setDefaultTimeout(90_000);
const log = (...parts) => console.log(new Date().toISOString().slice(11, 19), ...parts);
const viewState = async () => page.evaluate(() => {
const view = document.querySelector('[aria-label="Texture Paint"]');
return {
status: document.querySelector('[data-testid="engine-status"]')?.textContent ?? "",
imageSha: view?.getAttribute("data-image-sha") ?? null,
imageId: view?.getAttribute("data-image-id") ?? null,
lastAction: view?.getAttribute("data-last-action") ?? null,
viewStatus: view?.querySelector('output')?.textContent ?? null,
options: Array.from(view?.querySelectorAll('select[aria-label="纹理图像"] option') ?? []).map((option) => ({ value: option.value, text: option.textContent })),
};
});
try {
await openFile(page, ASSETS.studio);
await waitScene(page, { objects: 6, timeout: 240_000 });
const importInput = page.locator('input[accept="image/png,image/jpeg"]').first();
await importInput.setInputFiles(texture);
await page.waitForTimeout(3000);
log("imported", JSON.stringify(await viewState()));
await switchWorkspace(page, "Texture Paint");
const view = page.locator('[aria-label="Texture Paint"]').first();
await view.waitFor({ timeout: 30_000 });
const select = view.locator('select[aria-label="纹理图像"]');
const options = await select.locator('option').evaluateAll((nodes) => nodes.map((node) => node.value).filter(Boolean));
log("options", JSON.stringify(options));
if (!options.length) throw new Error("no packed image available");
await select.selectOption(options.at(-1));
await page.waitForTimeout(4000);
log("loaded", JSON.stringify(await viewState()));
const canvas = view.getByTestId("texture-paint-canvas");
await canvas.waitFor({ timeout: 60_000 });
const box = await canvas.boundingBox();
if (!box) throw new Error("paint canvas has no box");
await page.mouse.move(box.x + box.width / 2 - 30, box.y + box.height / 2);
await page.mouse.down();
await page.mouse.move(box.x + box.width / 2 + 30, box.y + box.height / 2, { steps: 6 });
await page.mouse.up();
await page.waitForTimeout(4000);
log("painted", JSON.stringify(await viewState()));
await view.getByRole("button", { name: "撤销笔画", exact: true }).evaluate((element) => element.click());
await page.waitForTimeout(3000);
log("undone", JSON.stringify(await viewState()));
await page.screenshot({ path: "/tmp/texture-paint.png", fullPage: false });
} catch (error) {
log("probe error", error instanceof Error ? error.message : String(error));
log("state", JSON.stringify(await viewState().catch(() => null)));
} finally {
log("consoleErrors", JSON.stringify(consoleErrors.slice(-8)));
await context.close();
await browser.close();
}