Advance deduplicated paint capability coverage
This commit is contained in:
60
web/tests/e2e/wbv2-paint-attributes-production.spec.ts
Normal file
60
web/tests/e2e/wbv2-paint-attributes-production.spec.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const root = path.resolve(import.meta.dirname, "../../..");
|
||||
const evidenceRoot = path.join(root, "tests/golden/WBV2-P16-002");
|
||||
const colorFixture = fs.readFileSync(path.join(root, "tests/files/web/attribute_scene.blend"));
|
||||
const weightFixture = fs.readFileSync(path.join(root, "tests/files/web/rigged_shape_scene.blend"));
|
||||
const fixtureSha256 = (bytes: Buffer) => crypto.createHash("sha256").update(bytes).digest("hex");
|
||||
|
||||
test("WBV2-P16-002 binds paint attributes to compiled WASM Main", async ({ page }) => {
|
||||
test.setTimeout(120_000);
|
||||
await page.goto("/");
|
||||
const result = await page.evaluate(async ({ colorBytes, weightBytes }) => {
|
||||
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
|
||||
const digest = async (value: ArrayBuffer): Promise<string> => { const hash = await crypto.subtle.digest("SHA-256", value); return Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join(""); };
|
||||
const colorClient = new WebEngineClient({ timeoutMs: 30_000 });
|
||||
const weightClient = new WebEngineClient({ timeoutMs: 30_000 });
|
||||
try {
|
||||
const colorOpened = await colorClient.openBlend(Uint8Array.from(colorBytes).buffer);
|
||||
const colorMesh = colorOpened.snapshot.meshes.find((mesh) => mesh.id === "mesh:AttributeMesh")!;
|
||||
const colorBefore = colorOpened.snapshot.revision;
|
||||
const colorValues = Array.from({ length: colorMesh.cornerCount * 4 }, (_, index) => [0.125, 0.375, 0.625, 0.875][index % 4]);
|
||||
const colorEdit = await colorClient.applyCommand({ type: "setVertexColors", meshId: colorMesh.id, attributeName: "WebPaintColor", domain: "CORNER", indices: Array.from({ length: colorMesh.cornerCount }, (_, index) => index), colors: colorValues } as any);
|
||||
const colorUndo = await colorClient.applyCommand({ type: "undo" });
|
||||
const colorRedo = await colorClient.applyCommand({ type: "redo" });
|
||||
const colorMalformed = await colorClient.applyCommand({ type: "setVertexColors", meshId: colorMesh.id, attributeName: "WebPaintColor", domain: "CORNER", indices: [colorMesh.cornerCount + 1], colors: [0, 0, 0, 1] } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
|
||||
const colorAfterMalformed = await colorClient.snapshot();
|
||||
const colorMeshAfterEdit = colorEdit.snapshot.meshes.find((mesh) => mesh.id === colorMesh.id)!;
|
||||
const colorBufferAfterEdit = colorEdit.geometryBuffers.find((buffer) => buffer.meshId === colorMesh.id);
|
||||
const colorSaved = await colorClient.saveBlend();
|
||||
const colorReopened = new WebEngineClient({ timeoutMs: 30_000 });
|
||||
const colorReopenResult = await colorReopened.openBlend(colorSaved);
|
||||
const colorBufferAfterReopen = colorReopenResult.geometryBuffers.find((buffer) => buffer.meshId === colorMesh.id);
|
||||
const colorMeshAfter = colorReopenResult.snapshot.meshes.find((mesh) => mesh.id === colorMesh.id)!;
|
||||
|
||||
const weightOpened = await weightClient.openBlend(Uint8Array.from(weightBytes).buffer);
|
||||
const weightBefore = weightOpened.snapshot.revision;
|
||||
const weightEdit = await weightClient.applyCommand({ type: "setVertexWeights", objectId: "object:RiggedShapeObject", vertexGroup: "WebPaintGroup", indices: [0, 1], values: [0.75, 0.25], normalize: false } as any);
|
||||
const weightNormalize = await weightClient.applyCommand({ type: "setVertexWeights", objectId: "object:RiggedShapeObject", vertexGroup: "WebPaintGroup", indices: [2], values: [0.5], normalize: true } as any);
|
||||
const weightUndo = await weightClient.applyCommand({ type: "undo" });
|
||||
const weightRedo = await weightClient.applyCommand({ type: "redo" });
|
||||
const weightSaved = await weightClient.saveBlend();
|
||||
const weightReopened = new WebEngineClient({ timeoutMs: 30_000 });
|
||||
const weightReopenResult = await weightReopened.openBlend(weightSaved);
|
||||
const weightedMesh = weightReopenResult.snapshot.meshes.find((mesh) => mesh.id === "mesh:RiggedShapeMesh")!;
|
||||
const groupIndex = weightedMesh.skinWeights?.boneNames.indexOf("WebPaintGroup") ?? -1;
|
||||
const vertexWeight = (vertex: number) => { if (groupIndex < 0 || !weightedMesh.skinWeights) return 0; const offset = vertex * 4; const slot = weightedMesh.skinWeights.indices.slice(offset, offset + 4).findIndex((value) => value === groupIndex); return slot < 0 ? 0 : weightedMesh.skinWeights.weights[offset + slot]; };
|
||||
const normalizedSum = weightedMesh.skinWeights?.weights.slice(8, 12).reduce((sum, value) => sum + value, 0) ?? 0;
|
||||
const output = { browser: "chromium", color: { baseRevision: colorBefore, revisions: [colorBefore, colorEdit.snapshot.revision, colorUndo.snapshot.revision, colorRedo.snapshot.revision], cornerCount: colorMesh.cornerCount, firstColor: colorBufferAfterEdit?.colors ? Array.from(new Float32Array(colorBufferAfterEdit.colors).slice(0, 4)) : undefined, malformed: colorMalformed, malformedRevisionPreserved: colorAfterMalformed.snapshot.revision === colorRedo.snapshot.revision, savedSha256: await digest(colorSaved), reopenedRevision: colorReopenResult.snapshot.revision, reopenedColors: colorBufferAfterReopen?.colors ? Array.from(new Float32Array(colorBufferAfterReopen.colors).slice(0, 4)) : undefined }, weight: { baseRevision: weightBefore, revisions: [weightBefore, weightEdit.snapshot.revision, weightNormalize.snapshot.revision, weightUndo.snapshot.revision, weightRedo.snapshot.revision], groupIndex, vertex0: vertexWeight(0), vertex1: vertexWeight(1), vertex2: vertexWeight(2), normalizedSum, savedSha256: await digest(weightSaved), saveReopen: weightReopenResult.snapshot.revision === 1 } };
|
||||
colorReopened.terminate(); weightReopened.terminate();
|
||||
return output;
|
||||
} finally { colorClient.terminate(); weightClient.terminate(); }
|
||||
}, { colorBytes: Array.from(colorFixture), weightBytes: Array.from(weightFixture) });
|
||||
fs.mkdirSync(evidenceRoot, { recursive: true });
|
||||
const output = process.env.WBV2_PAINT_REPORT ?? "paint-attributes-production.json";
|
||||
fs.writeFileSync(path.join(evidenceRoot, output), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P16-002", operation: "PAINT_ATTRIBUTES_ENGINE_CHROMIUM", queueMutation: false, sourceFixtures: { colorSha256: fixtureSha256(colorFixture), weightSha256: fixtureSha256(weightFixture) }, ...result }, null, 2)}\n`);
|
||||
expect(result.browser).toBe("chromium"); expect(result.color.revisions).toEqual([1, 2, 3, 4]); expect(result.weight.revisions).toEqual([1, 2, 3, 4, 5]); expect(result.color.malformed.code).not.toBe("NO_ERROR"); expect(result.color.malformedRevisionPreserved).toBe(true); expect(result.color.firstColor).toEqual([0.125, 0.375, 0.625, 0.875]); expect(result.color.reopenedRevision).toBe(1); expect(result.weight.groupIndex).toBeGreaterThanOrEqual(0); expect(result.weight.vertex0).toBeCloseTo(0.75, 4); expect(result.weight.vertex1).toBeCloseTo(0.25, 4); expect(result.weight.normalizedSum).toBeCloseTo(1, 4); expect(result.weight.saveReopen).toBe(true);
|
||||
});
|
||||
Reference in New Issue
Block a user