Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-environment-lighting-production.spec.ts
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

151 lines
9.1 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-ENVIRONMENT-LIGHTING-20261122");
fs.mkdirSync(outputDir, { recursive: true });
type SceneSnapshot = {
revision: number;
worlds: Array<{ id: string; color: number[]; environmentStrength?: number | null; environmentImageId?: string | null }>;
images: Array<{ id: string; name: string }>;
};
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 = `env-${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);
}
test("environment lighting: Material Preview studio light, Scene World, world colour and strength", async ({ page }) => {
test.setTimeout(300_000);
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);
const canvas = page.locator("canvas[data-studio-lighting]").first();
/* The materials case default is Material Preview: light from the built-in
* studio environment, like the desktop Material Preview. */
await expect.poll(() => canvas.getAttribute("data-preview-environment"), { timeout: 60_000 }).toMatch(/^studio-(fallback|exr)$/);
/* The studio light is the desktop `forest.exr` decoded to exact float32
* pixels; the pixel-block hash and sample pixels must match the manifest
* produced by tools/web/import-studiolight-world.py. */
const studioManifest = JSON.parse(fs.readFileSync(path.join(root, "web/app/public/lights/forest.json"), "utf8"));
await expect.poll(() => page.evaluate(() => (window as unknown as { __webStudioEnvironment?: { pixelsSha256?: string } }).__webStudioEnvironment?.pixelsSha256 ?? ""), { timeout: 120_000 }).toBe(studioManifest.pixelsSha256);
const studioEnvironment = await page.evaluate(() => (window as unknown as { __webStudioEnvironment?: unknown }).__webStudioEnvironment) as { width: number; height: number; samples: number[][] };
expect(studioEnvironment.width).toBe(studioManifest.width);
expect(studioEnvironment.height).toBe(studioManifest.height);
expect(studioEnvironment.samples).toEqual(studioManifest.samples);
await expect.poll(() => canvas.getAttribute("data-preview-environment"), { timeout: 60_000 }).toBe("studio-exr");
/* The desktop Viewport Shading studio-light list has eight worlds
* (`studiolights/world/*.exr`); each selection must load that dataset
* pixel-for-pixel, not just the default forest. */
const lightManifests = fs.readdirSync(path.join(root, "web/app/public/lights"))
.filter((file) => file.endsWith(".json"))
.map((file) => JSON.parse(fs.readFileSync(path.join(root, "web/app/public/lights", file), "utf8")))
.sort((left, right) => String(left.name).localeCompare(String(right.name)));
expect(lightManifests.map((manifest) => manifest.name)).toEqual(["city", "courtyard", "forest", "interior", "night", "studio", "sunrise", "sunset"]);
for (const manifest of lightManifests) {
await page.getByLabel("studio 环境").selectOption(manifest.name);
await expect.poll(() => page.evaluate(() => (window as unknown as { __webStudioEnvironment?: { name?: string } }).__webStudioEnvironment?.name ?? ""), { timeout: 120_000 }).toBe(manifest.name);
await expect.poll(() => page.evaluate(() => (window as unknown as { __webStudioEnvironment?: { pixelsSha256?: string } }).__webStudioEnvironment?.pixelsSha256 ?? ""), { timeout: 120_000 }).toBe(manifest.pixelsSha256);
await expect(canvas).toHaveAttribute("data-studio-light", manifest.name);
}
await page.getByLabel("studio 环境").selectOption("forest");
await expect.poll(() => page.evaluate(() => (window as unknown as { __webStudioEnvironment?: { name?: string } }).__webStudioEnvironment?.name ?? ""), { timeout: 120_000 }).toBe("forest");
/* Scene World uses the world environment instead. */
const sceneWorld = page.getByLabel("场景世界");
await sceneWorld.check();
await expect.poll(() => canvas.getAttribute("data-preview-environment"), { timeout: 60_000 }).toBe("world");
await page.getByRole("tab").filter({ hasText: "世界环境" }).click();
const worldPanel = page.getByTestId("world-workbench");
await expect(worldPanel).toBeVisible({ timeout: 30_000 });
await setInputValue(page, "环境强度", "2.5");
await expect.poll(async () => {
const world = (await readSnapshot(page)).worlds[0];
return world?.environmentStrength ?? -1;
}, { timeout: 60_000 }).toBeCloseTo(2.5, 2);
/* World environment edits participate in undo/redo. */
await page.getByRole("button", { name: "撤销" }).click();
await expect.poll(async () => (await readSnapshot(page)).worlds[0]?.environmentStrength ?? -1, { timeout: 60_000 }).toBeCloseTo(1, 2);
await page.getByRole("button", { name: "重做" }).click();
await expect.poll(async () => (await readSnapshot(page)).worlds[0]?.environmentStrength ?? -1, { timeout: 60_000 }).toBeCloseTo(2.5, 2);
await setInputValue(page, "环境颜色", "#ff8000");
await expect.poll(async () => {
const world = (await readSnapshot(page)).worlds[0];
return world?.color.map((component) => Number(component.toFixed(3))).join(",") ?? "";
}, { timeout: 60_000 }).toBe("1,0.216,0");
/* Environment image: import an image and use it as the world environment. */
await page.getByLabel("加载环境贴图").setInputFiles(path.join(root, "tests/files/web/m12_obj_multi_v1/m12_obj_texture.png"));
await expect.poll(async () => (await readSnapshot(page)).images.some((candidate) => candidate.name === "m12_obj_texture"), { timeout: 120_000 }).toBe(true);
const environmentImage = (await readSnapshot(page)).images.find((candidate) => candidate.name === "m12_obj_texture")!;
await page.getByLabel("环境贴图", { exact: true }).selectOption(environmentImage.id);
await expect.poll(async () => (await readSnapshot(page)).worlds[0]?.environmentImageId ?? "", { timeout: 60_000 }).toBe(environmentImage.id);
await expect.poll(() => canvas.getAttribute("data-ibl-status"), { timeout: 120_000 }).toBe("ready");
/* Desktop rotates the HDRI with a Mapping node into Environment Texture Vector. */
await setInputValue(page, "环境旋转", "90");
await expect.poll(async () => {
const rotation = (await readSnapshot(page)).worlds[0]?.environmentRotation;
return rotation === undefined || rotation === null ? -999 : Number(rotation.toFixed(3));
}, { timeout: 60_000 }).toBeCloseTo(Math.PI / 2, 2);
await setInputValue(page, "环境旋转", "0");
await page.getByLabel("环境贴图", { exact: true }).selectOption("");
await expect.poll(async () => (await readSnapshot(page)).worlds[0]?.environmentImageId ?? null, { timeout: 60_000 }).toBeNull();
/* Turning Scene World back off restores the studio environment. */
await sceneWorld.uncheck();
await expect.poll(() => canvas.getAttribute("data-preview-environment"), { timeout: 60_000 }).toBe("studio-exr");
const snapshot = await readSnapshot(page);
fs.writeFileSync(path.join(outputDir, "environment-lighting.json"), JSON.stringify({
schemaVersion: 1,
browser: "chromium",
storage: "OPFS",
workflow: "Material Preview studio environment -> Scene World -> world colour #ff8000 -> strength 2.5 -> environment image -> back to studio",
sceneWorldEnvironment: "world",
studioEnvironment: "studio-exr",
studioEnvironmentSource: "web/app/public/lights/forest.json",
studioEnvironmentPixelsSha256: studioManifest.pixelsSha256,
studioEnvironmentSamples: studioEnvironment.samples,
environmentImage: environmentImage.id,
environmentIblStatus: "ready",
world: snapshot.worlds[0],
snapshotRevision: snapshot.revision,
status: "PASS",
acceptance: "NOT_CLAIMED",
}, null, 2));
});