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>
131 lines
6.8 KiB
TypeScript
131 lines
6.8 KiB
TypeScript
import { expect, test, type Page } from "@playwright/test";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { exposeWebTools, observeNative } from "../fixtures/native-ui-workflow";
|
|
|
|
const root = path.resolve(import.meta.dirname, "../../..");
|
|
const outputDir = path.join(root, "tests/golden/WEB-MATERIAL-UNDO-REDO-20261122");
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
|
|
type Material = { id: string; name: string; baseColor: number[]; metallic: number; roughness: number };
|
|
type SceneSnapshot = { revision: number; materials: Material[] };
|
|
|
|
async function readSnapshot(page: Page): Promise<SceneSnapshot> {
|
|
return page.evaluate(() => new Promise<SceneSnapshot>((resolve, reject) => {
|
|
const worker = (window as unknown as { __nativeWorkflowEngine: Worker }).__nativeWorkflowEngine;
|
|
const requestId = `undo-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
const timer = setTimeout(() => { worker.removeEventListener("message", onMessage); reject(new Error("snapshot timeout")); }, 30_000);
|
|
const onMessage = ({ data }: MessageEvent) => {
|
|
if (data?.requestId !== requestId) return;
|
|
clearTimeout(timer);
|
|
worker.removeEventListener("message", onMessage);
|
|
resolve(data?.result?.snapshot as SceneSnapshot);
|
|
};
|
|
worker.addEventListener("message", onMessage);
|
|
worker.postMessage({ requestId, command: { type: "snapshot" } });
|
|
}));
|
|
}
|
|
|
|
async function setInputValue(page: Page, label: string, value: string): Promise<void> {
|
|
await page.locator(`[aria-label="${label}"]`).first().evaluate((element, next) => {
|
|
const input = element as HTMLInputElement;
|
|
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(input, next);
|
|
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
}, value);
|
|
}
|
|
|
|
async function materialNamed(page: Page, name: string): Promise<Material | undefined> {
|
|
return (await readSnapshot(page)).materials.find((material) => material.name === name);
|
|
}
|
|
|
|
test("material Principled edits and rename participate in native undo/redo", async ({ page }) => {
|
|
test.setTimeout(300_000);
|
|
const downloads: string[] = [];
|
|
page.on("download", (download) => downloads.push(download.suggestedFilename()));
|
|
await observeNative(page);
|
|
await page.goto("/?ui=web");
|
|
await page.getByTestId("blend-file-input").setInputFiles(path.join(root, "tests/files/web/basic_scene.blend"));
|
|
await expect(page.getByTestId("engine-status")).toContainText(/SceneIR r\d+/, { timeout: 120_000 });
|
|
await exposeWebTools(page);
|
|
|
|
await page.getByRole("button", { name: "添加", exact: true }).click();
|
|
await page.getByRole("menuitem", { name: "网格", exact: true }).click();
|
|
await page.getByRole("menuitem", { name: "猴头", exact: true }).click();
|
|
await expect(page.getByTestId("engine-status")).toContainText(/mesh\.primitive_monkey_add/, { timeout: 120_000 });
|
|
await page.getByRole("button", { name: "新增槽", exact: true }).click();
|
|
await expect(page.getByLabel("材质名称")).toBeVisible({ timeout: 60_000 });
|
|
|
|
/* Rename first so the material is unambiguous, then record its untouched
|
|
* Principled values as the undo baseline. */
|
|
const nameInput = page.getByLabel("材质名称");
|
|
await nameInput.fill("UndoGold");
|
|
await nameInput.press("Enter");
|
|
await expect.poll(async () => Boolean(await materialNamed(page, "UndoGold")), { timeout: 60_000 }).toBe(true);
|
|
const baseline = (await materialNamed(page, "UndoGold"))!;
|
|
const baselineRevision = (await readSnapshot(page)).revision;
|
|
|
|
/* Apply the gold preset through the panel. */
|
|
await setInputValue(page, "材质基础色", "#ffd700");
|
|
await setInputValue(page, "材质粗糙度", "0.2");
|
|
await setInputValue(page, "材质金属度", "1");
|
|
await page.getByRole("button", { name: "应用 Principled", exact: true }).click();
|
|
await expect.poll(async () => Math.round(((await materialNamed(page, "UndoGold"))?.metallic ?? -1) * 100), { timeout: 60_000 }).toBe(100);
|
|
const applied = (await materialNamed(page, "UndoGold"))!;
|
|
const appliedRevision = (await readSnapshot(page)).revision;
|
|
expect(appliedRevision).toBeGreaterThan(baselineRevision);
|
|
expect(applied.roughness).toBeCloseTo(0.2, 2);
|
|
applied.baseColor.slice(0, 3).forEach((component, index) => expect(component).toBeCloseTo([1, 0.679, 0][index], 2));
|
|
|
|
/* Undo restores the pre-edit Principled values (same material id/name). */
|
|
await page.getByRole("button", { name: "撤销" }).click();
|
|
await expect.poll(async () => {
|
|
const material = await materialNamed(page, "UndoGold");
|
|
return material ? Math.round(material.metallic * 100) : -1;
|
|
}, { timeout: 60_000 }).toBe(Math.round(baseline.metallic * 100));
|
|
const undone = (await materialNamed(page, "UndoGold"))!;
|
|
expect(undone.id).toBe(baseline.id);
|
|
expect(undone.roughness).toBeCloseTo(baseline.roughness, 3);
|
|
undone.baseColor.forEach((component, index) => expect(component).toBeCloseTo(baseline.baseColor[index], 3));
|
|
|
|
/* Redo reapplies the gold preset exactly. */
|
|
await page.getByRole("button", { name: "重做" }).click();
|
|
await expect.poll(async () => Math.round(((await materialNamed(page, "UndoGold"))?.metallic ?? -1) * 100), { timeout: 60_000 }).toBe(100);
|
|
const redone = (await materialNamed(page, "UndoGold"))!;
|
|
expect(redone.roughness).toBeCloseTo(0.2, 2);
|
|
redone.baseColor.slice(0, 3).forEach((component, index) => expect(component).toBeCloseTo(applied.baseColor[index], 3));
|
|
|
|
/* Rename is also one undo step: undo returns the previous name, redo the new one. */
|
|
await nameInput.fill("UndoGoldRenamed");
|
|
await nameInput.press("Enter");
|
|
await expect.poll(async () => Boolean(await materialNamed(page, "UndoGoldRenamed")), { timeout: 60_000 }).toBe(true);
|
|
const renamed = (await materialNamed(page, "UndoGoldRenamed"))!;
|
|
await page.getByRole("button", { name: "撤销" }).click();
|
|
await expect.poll(async () => Boolean(await materialNamed(page, "UndoGold")), { timeout: 60_000 }).toBe(true);
|
|
expect(await materialNamed(page, "UndoGoldRenamed")).toBeUndefined();
|
|
await page.getByRole("button", { name: "重做" }).click();
|
|
await expect.poll(async () => Boolean(await materialNamed(page, "UndoGoldRenamed")), { timeout: 60_000 }).toBe(true);
|
|
expect((await materialNamed(page, "UndoGoldRenamed"))!.id).toBe(renamed.id);
|
|
|
|
const final = await readSnapshot(page);
|
|
expect(downloads).toEqual([]);
|
|
fs.writeFileSync(path.join(outputDir, "material-undo-redo.json"), JSON.stringify({
|
|
schemaVersion: 1,
|
|
browser: "chromium",
|
|
storage: "OPFS",
|
|
fixture: "tests/files/web/basic_scene.blend",
|
|
workflow: "new material slot -> rename -> apply gold Principled -> 撤销/重做 -> rename -> 撤销/重做",
|
|
baselineRevision,
|
|
appliedRevision,
|
|
finalRevision: final.revision,
|
|
baseline,
|
|
applied,
|
|
undone,
|
|
redone,
|
|
renamedId: renamed.id,
|
|
downloads,
|
|
status: "PASS",
|
|
acceptance: "NOT_CLAIMED",
|
|
}, null, 2));
|
|
});
|