The modifier merge ran after refresh_scene_from_main round-tripped Main through the blend format, which dropped the DEG tag issued by the setter, so DEG_get_evaluated kept publishing the previous COW copy: Ratio 0.1 was visible in Main and in the snapshot parameters while triangleCount and python to_mesh() stayed at the add-time 968 until an external update_tag()+view_layer.update(). - engine: tag every modifier owner with DEG_id_tag_update_ex(state->main, ID_RECALC_ALL) before merge evaluation and update through BKE_scene_graph_update_tagged (same call ViewLayer.update uses). - tests: mode menu items are menuitemcheckbox; select-all lives in the header 选择 ▸ 全部 menu, not 网格 ▸ 选择工具. - runner: archive per-case evidence JSON under artifacts/evidence; checker reads fixtures.desktopOracle instead of a missing top-level key. - docs: record the root cause, fix and receipt MESH-DECIMATE-HEADED-20261129-012441. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
419 lines
24 KiB
TypeScript
419 lines
24 KiB
TypeScript
import { expect, test, type Page, type TestInfo } from "@playwright/test";
|
||
import fs from 'node:fs';
|
||
import path from 'node:path';
|
||
import { observeNative, performNativeAction } from '../fixtures/native-ui-workflow';
|
||
import { webMain } from '../fixtures/console-main-workflow';
|
||
import { openFromUI, pythonReply } from '../fixtures/wasm-console-workflow';
|
||
import { nativeRequest, queryNativeJSON, waitNativeModal } from '../fixtures/native-modeling-workflow';
|
||
|
||
/* Headed Decimate (triangle simplification) suite on the monkey-head GLB.
|
||
* Two desktop entries are exercised end to end:
|
||
* 1. Preferences ▸ Modifier ▸ Add Modifier ▸ Generate ▸ Decimate ▸ Ratio
|
||
* (`web/engine` modifier stack evaluated into the viewport geometry).
|
||
* 2. Edit Mode ▸ Mesh ▸ Clean Up ▸ Decimate Geometry ▸ Ratio
|
||
* (`bpy.ops.mesh.decimate`, which scales the selected triangles).
|
||
* Desktop parity comes from `tests/golden/MESH-DECIMATE-DESKTOP/desktop-decimate.json`
|
||
* when the golden generator has been run; the geometry bounds below hold either way. */
|
||
const root = path.resolve(import.meta.dirname, "../../..");
|
||
const STUDIO = process.env.DEC_BASE_BLEND ?? path.join(root, "web/app/public/tutorial/pbr/studio.blend");
|
||
const MONKEY = process.env.DEC_MONKEY_GLB ?? path.join(root, "re/猴头.glb");
|
||
const GOLDEN = process.env.DECIMATE_DESKTOP_GOLDEN ?? path.join(root, "tests/golden/MESH-DECIMATE-DESKTOP/desktop-decimate.json");
|
||
|
||
function desktopOracle(): any | null {
|
||
if (!fs.existsSync(GOLDEN)) return null;
|
||
return JSON.parse(fs.readFileSync(GOLDEN, "utf8"));
|
||
}
|
||
|
||
async function sceneStats(page: Page) {
|
||
const text = await page.getByTestId('scene-stats').textContent();
|
||
const read = (key: string) => {
|
||
const match = new RegExp(`${key} (\\d+)`).exec(text ?? '');
|
||
return match ? Number(match[1]) : NaN;
|
||
};
|
||
return { text: text ?? '', objects: read('Objects'), vertices: read('Vertices'), faces: read('Faces') };
|
||
}
|
||
|
||
async function selectViaOutliner(page: Page, name: string): Promise<void> {
|
||
/* hasText/filter would match the wrapping Scene Collection branch; the leaf
|
||
* row carries the object name as its aria-label, so match that exactly. */
|
||
const item = page.getByRole('treeitem', { name, exact: true }).first();
|
||
await expect(item).toBeVisible({ timeout: 30000 });
|
||
await item.click();
|
||
await expect(item).toHaveAttribute('aria-selected', 'true', { timeout: 15000 });
|
||
}
|
||
|
||
/** Open the studio, then import the monkey GLB through the product's own input. */
|
||
async function openStudioAndImport(page: Page, native: boolean, testInfo: TestInfo) {
|
||
expect(fs.existsSync(STUDIO), `base blend missing: ${STUDIO}`).toBe(true);
|
||
expect(fs.existsSync(MONKEY), `monkey GLB missing: ${MONKEY}`).toBe(true);
|
||
await openFromUI(page, () => page.getByTestId('blend-file-input').setInputFiles(STUDIO));
|
||
await expect(page.getByTestId('engine-status')).toContainText('SceneIR', { timeout: 120000 });
|
||
const baseline = await webMain(page);
|
||
const baselineIds = new Set(baseline.nodes.map((node: any) => node.id));
|
||
const baseCount = (await sceneStats(page)).objects;
|
||
expect(baseCount).toBeGreaterThan(0);
|
||
if (native) {
|
||
await performNativeAction(page, { type: 'jsonCommand', jsonCommand: 'importScene' }, () => page.getByTestId('blend-file-input').setInputFiles(MONKEY));
|
||
}
|
||
else {
|
||
await page.getByTestId('blend-file-input').setInputFiles(MONKEY);
|
||
}
|
||
await expect.poll(async () => {
|
||
const main = await webMain(page);
|
||
return {
|
||
count: (await sceneStats(page)).objects,
|
||
imported: /Engine: GLB imported/.test(await page.getByTestId('engine-status').textContent() ?? ''),
|
||
added: main.nodes.filter((node: any) => !baselineIds.has(node.id)).length,
|
||
};
|
||
}, { timeout: 180000 }).toEqual({ count: baseCount + 1, imported: true, added: 1 });
|
||
const main = await webMain(page);
|
||
const added = main.nodes.filter((node: any) => !baselineIds.has(node.id));
|
||
expect(added).toHaveLength(1);
|
||
const imported = added[0] as { id: string; name: string; type: string };
|
||
expect(imported.type).toBe('MESH');
|
||
if (!native) await expect(page.getByRole('treeitem').filter({ hasText: imported.name }).first()).toBeVisible({ timeout: 30000 });
|
||
fs.writeFileSync(testInfo.outputPath(`monkey-imported-${native ? 'native' : 'web'}.json`), JSON.stringify({ studio: STUDIO, monkey: MONKEY, baseCount, imported }, null, 2));
|
||
return { imported, baseCount };
|
||
}
|
||
|
||
/** Worker-published snapshot; nodes and meshes share one revision. */
|
||
async function engineSnapshot(page: Page) {
|
||
const response = await nativeRequest(page, { type: 'snapshot' }, 180000);
|
||
const snapshot = response.result?.snapshot;
|
||
expect(snapshot, 'snapshot command must return a snapshot').toBeTruthy();
|
||
return snapshot as any;
|
||
}
|
||
|
||
async function meshOf(page: Page, name: string) {
|
||
const snapshot = await engineSnapshot(page);
|
||
const node = snapshot.nodes.find((item: any) => item.name === name);
|
||
expect(node, `${name} must exist in the snapshot`).toBeDefined();
|
||
const mesh = snapshot.meshes.find((item: any) => item.id === node.dataId);
|
||
expect(mesh, `${name} must own mesh ${node.dataId}`).toBeDefined();
|
||
return { snapshot, node, mesh };
|
||
}
|
||
|
||
/** pythonExec that is allowed to change Main; returns the parsed stdout payload.
|
||
* A previous native desktop gesture is retired on the next frame, and the engine
|
||
* refuses edits until then (NATIVE_GESTURE_ACTIVE); wait for that frame. */
|
||
async function pythonRun(page: Page, source: string, timeoutMs = 180000) {
|
||
for (let attempt = 0; ; attempt += 1) {
|
||
try {
|
||
const response = await nativeRequest(page, { type: 'jsonCommand', cmd: 'pythonExec', params: { source: `exec(${JSON.stringify(source)}, {'__name__': '__wbv2_decimate__'})`, filename: 'M2Decimate.py', console: false } }, timeoutMs);
|
||
const reply = await pythonReply(page);
|
||
expect(reply, 'pythonExec must publish a console reply').not.toBeNull();
|
||
expect(reply!.requestId).toBe(response.requestId);
|
||
expect(reply!.state, reply!.output).toBe('DONE');
|
||
return { revision: reply!.revision, changed: reply!.changed, value: JSON.parse(reply!.output) };
|
||
}
|
||
catch (error) {
|
||
if (attempt >= 20 || !/NATIVE_GESTURE_ACTIVE/.test((error as Error).message ?? '')) throw error;
|
||
await waitNativeModal(page, false);
|
||
await page.waitForTimeout(120);
|
||
}
|
||
}
|
||
}
|
||
|
||
const selectObject = (name: string) => `
|
||
import bpy
|
||
o = bpy.data.objects[${JSON.stringify(name)}]
|
||
if bpy.context.object and bpy.context.object.mode != 'OBJECT':
|
||
bpy.ops.object.mode_set(mode='OBJECT')
|
||
bpy.ops.object.select_all(action='DESELECT')
|
||
o.select_set(True)
|
||
bpy.context.view_layer.objects.active = o
|
||
`;
|
||
|
||
const modifierScript = (name: string, ratio: number) => `${selectObject(name)}
|
||
import json
|
||
def triangles():
|
||
dg = bpy.context.evaluated_depsgraph_get()
|
||
dg.update()
|
||
ev = o.evaluated_get(dg)
|
||
evaluated = ev.to_mesh()
|
||
evaluated.calc_loop_triangles()
|
||
count = len(evaluated.loop_triangles)
|
||
ev.to_mesh_clear()
|
||
return count
|
||
for existing in list(o.modifiers):
|
||
o.modifiers.remove(existing)
|
||
before = triangles()
|
||
modifier = o.modifiers.new(name='Decimate', type='DECIMATE')
|
||
modifier.decimate_type = 'COLLAPSE'
|
||
modifier.ratio = ${ratio}
|
||
bpy.context.view_layer.update()
|
||
after = triangles()
|
||
print(json.dumps({'before': before, 'after': after, 'ratio': modifier.ratio, 'modifiers': [m.type for m in o.modifiers]}))
|
||
`;
|
||
|
||
const removeModifiers = (name: string) => `${selectObject(name)}
|
||
import json
|
||
def triangles():
|
||
dg = bpy.context.evaluated_depsgraph_get()
|
||
dg.update()
|
||
ev = o.evaluated_get(dg)
|
||
evaluated = ev.to_mesh()
|
||
evaluated.calc_loop_triangles()
|
||
count = len(evaluated.loop_triangles)
|
||
ev.to_mesh_clear()
|
||
return count
|
||
for existing in list(o.modifiers):
|
||
o.modifiers.remove(existing)
|
||
bpy.context.view_layer.update()
|
||
print(json.dumps({'triangleCount': triangles(), 'modifiers': [m.type for m in o.modifiers]}))
|
||
`;
|
||
|
||
const editDecimateScript = (name: string, ratio: number) => `${selectObject(name)}
|
||
import json
|
||
mesh = o.data
|
||
mesh.calc_loop_triangles()
|
||
before_faces = len(mesh.polygons)
|
||
before_triangles = len(mesh.loop_triangles)
|
||
bpy.ops.object.mode_set(mode='EDIT')
|
||
try:
|
||
bpy.ops.mesh.select_all(action='SELECT')
|
||
operator = bpy.ops.mesh.decimate(ratio=${ratio})
|
||
finally:
|
||
bpy.ops.object.mode_set(mode='OBJECT')
|
||
mesh = o.data
|
||
mesh.calc_loop_triangles()
|
||
print(json.dumps({'operator': list(operator), 'beforeFaces': before_faces, 'beforeTriangles': before_triangles, 'faces': len(mesh.polygons), 'triangles': len(mesh.loop_triangles), 'mode': o.mode}))
|
||
`;
|
||
|
||
const shot = async (page: Page, testInfo: TestInfo, name: string) => {
|
||
const file = testInfo.outputPath(`${name}.png`);
|
||
await page.screenshot({ path: file });
|
||
await testInfo.attach(name, { path: file, contentType: 'image/png' });
|
||
};
|
||
|
||
const record = (testInfo: TestInfo, file: string, evidence: Record<string, unknown>) => { fs.writeFileSync(testInfo.outputPath(file), JSON.stringify(evidence, null, 2)); };
|
||
|
||
/* Desktop applies the modifier to the evaluated mesh only; the original mesh is unchanged. */
|
||
function expectModifierRatio(actual: { before: number; after: number }, ratio: number, tolerance: number) {
|
||
expect(actual.before).toBeGreaterThan(0);
|
||
const kept = actual.after / actual.before;
|
||
expect(kept, `modifier kept ${actual.after}/${actual.before} triangles at ratio ${ratio}`).toBeGreaterThan(ratio - tolerance);
|
||
expect(kept).toBeLessThan(ratio + tolerance);
|
||
}
|
||
|
||
test('[dec-monkey-modifier-web] 猴头:修改器 ▸ 添加修改器 ▸ 生成 ▸ 简化,Ratio 0.1 进入视口、应用与撤销(有头)', async ({ page }, testInfo) => {
|
||
test.setTimeout(420_000);
|
||
const evidence: Record<string, unknown> = {};
|
||
const save = () => record(testInfo, 'decimate-modifier-web.json', evidence);
|
||
await observeNative(page); await page.goto('/?ui=web');
|
||
await expect.poll(() => page.evaluate(() => Array.isArray((window as any).__nativeWorkflowMain?.nodes)), { timeout: 60000 }).toBe(true);
|
||
const { imported } = await openStudioAndImport(page, false, testInfo); evidence.imported = imported;
|
||
await selectViaOutliner(page, imported.name);
|
||
const statsBefore = await sceneStats(page); evidence.statsBefore = statsBefore;
|
||
const baseline = await meshOf(page, imported.name); evidence.baseline = { triangleCount: baseline.mesh.triangleCount, faceCount: baseline.mesh.faceCount };
|
||
expect(baseline.mesh.triangleCount).toBeGreaterThan(0);
|
||
|
||
/* G2: the grouped desktop entry must exist and dispatch the stack command. */
|
||
await page.getByRole('tab', { name: '修改器' }).click();
|
||
const addMenu = page.getByRole('button', { name: '添加修改器', exact: true });
|
||
await expect(addMenu).toBeVisible({ timeout: 20000 });
|
||
await addMenu.click();
|
||
await page.getByRole('menuitem', { name: '生成', exact: true }).click();
|
||
await page.getByRole('menuitem', { name: '简化 (Decimate)', exact: true }).click();
|
||
const row = page.locator('.modifier-row').filter({ hasText: 'DECIMATE' }).first();
|
||
await expect(row).toBeVisible({ timeout: 60000 });
|
||
await expect.poll(async () => (await meshOf(page, imported.name)).mesh.modifierStack?.length ?? 0, { timeout: 60000 }).toBe(1);
|
||
const added = await meshOf(page, imported.name); evidence.added = added.mesh.modifierStack;
|
||
const modifier = added.mesh.modifierStack[0];
|
||
expect(modifier.type).toBe('DECIMATE');
|
||
expect(modifier.evaluationStatus).toBe('EVALUATED');
|
||
expect(added.mesh.geometryEvaluated).toBe(true);
|
||
|
||
/* Ratio lives in the modifier's editable parameters; discover the label from
|
||
* the protocol metadata instead of hard-coding a localized string. */
|
||
const ratio = (modifier.editableParameters ?? []).find((field: any) => field.key === 'ratio');
|
||
expect(ratio, 'Decimate must expose the ratio parameter').toBeDefined();
|
||
const label = ratio.label ?? ratio.key;
|
||
const ratioInput = row.getByRole('spinbutton', { name: label, exact: true });
|
||
await expect(ratioInput).toBeVisible({ timeout: 20000 });
|
||
await ratioInput.fill('0.1');
|
||
await ratioInput.press('Enter');
|
||
|
||
/* G1: the evaluated stack drives the viewport geometry and the status counts. */
|
||
const reduced = await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 180000 }).toBeLessThanOrEqual(Math.ceil(baseline.mesh.triangleCount * 0.15)).then(async () => (await meshOf(page, imported.name)).mesh);
|
||
expectModifierRatio({ before: reduced.baseTriangleCount, after: reduced.triangleCount }, 0.1, 0.05);
|
||
expect(reduced.geometryEvaluated).toBe(true);
|
||
expect(reduced.modifierStack[0].evaluationStatus).toBe('EVALUATED');
|
||
await expect.poll(async () => (await sceneStats(page)).faces, { timeout: 120000 }).toBeLessThan(statsBefore.faces);
|
||
const statsReduced = await sceneStats(page); evidence.statsReduced = statsReduced;
|
||
await shot(page, testInfo, 'web-01-ratio-0.1');
|
||
|
||
const oracle = desktopOracle();
|
||
evidence.oracle = oracle ? { ratio: oracle.modifier?.ratio, before: oracle.modifier?.trianglesBefore, after: oracle.modifier?.trianglesAfter } : 'missing';
|
||
if (oracle?.modifier) {
|
||
expect(Math.abs(reduced.triangleCount / reduced.baseTriangleCount - oracle.modifier.trianglesAfter / oracle.modifier.trianglesBefore)).toBeLessThanOrEqual(0.03);
|
||
}
|
||
|
||
/* Removing the modifier must restore the untouched mesh, not a stale bake. */
|
||
const name = modifier.name;
|
||
await row.getByRole('button', { name: `Remove ${name}`, exact: true }).click();
|
||
await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 120000 }).toBe(baseline.mesh.triangleCount);
|
||
await expect.poll(async () => (await meshOf(page, imported.name)).mesh.modifierStack?.length ?? 0, { timeout: 60000 }).toBe(0);
|
||
await expect.poll(async () => (await sceneStats(page)).faces, { timeout: 120000 }).toBe(statsBefore.faces);
|
||
evidence.removed = await meshOf(page, imported.name).then(({ mesh }) => ({ triangleCount: mesh.triangleCount, baseTriangleCount: mesh.baseTriangleCount }));
|
||
|
||
/* Re-add and Apply: the stack empties and the reduced geometry is baked in. */
|
||
await addMenu.click();
|
||
await page.getByRole('menuitem', { name: '生成', exact: true }).click();
|
||
await page.getByRole('menuitem', { name: '简化 (Decimate)', exact: true }).click();
|
||
const rowAgain = page.locator('.modifier-row').filter({ hasText: 'DECIMATE' }).first();
|
||
await expect(rowAgain).toBeVisible({ timeout: 60000 });
|
||
const readd = await meshOf(page, imported.name);
|
||
const readdRatio = (readd.mesh.modifierStack[0].editableParameters ?? []).find((field: any) => field.key === 'ratio');
|
||
const readdInput = rowAgain.getByRole('spinbutton', { name: readdRatio.label ?? readdRatio.key, exact: true });
|
||
await readdInput.fill('0.1'); await readdInput.press('Enter');
|
||
await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 180000 }).toBeLessThanOrEqual(Math.ceil(baseline.mesh.triangleCount * 0.15));
|
||
const reapplied = await meshOf(page, imported.name);
|
||
const bakedTarget = reapplied.mesh.triangleCount;
|
||
const applyName = reapplied.mesh.modifierStack[0].name;
|
||
await rowAgain.getByRole('button', { name: `Apply ${applyName}`, exact: true }).click();
|
||
await expect.poll(async () => (await meshOf(page, imported.name)).mesh.modifierStack?.length ?? 0, { timeout: 120000 }).toBe(0);
|
||
await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 120000 }).toBe(bakedTarget);
|
||
evidence.applied = { triangleCount: bakedTarget };
|
||
await shot(page, testInfo, 'web-02-applied');
|
||
|
||
/* One global undo restores the pre-apply geometry. */
|
||
await page.locator('canvas.viewport-canvas').focus();
|
||
for (let attempt = 0; attempt < 2; attempt++) {
|
||
await page.keyboard.press('Control+z');
|
||
const restored = await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 20000 }).toBe(baseline.mesh.triangleCount).then(() => true).catch(() => false);
|
||
if (restored) break;
|
||
await page.waitForTimeout(2000);
|
||
}
|
||
const undone = await meshOf(page, imported.name);
|
||
evidence.undone = { triangleCount: undone.mesh.triangleCount, baseTriangleCount: undone.mesh.baseTriangleCount };
|
||
expect(undone.mesh.triangleCount).toBe(baseline.mesh.triangleCount);
|
||
save();
|
||
});
|
||
|
||
test('[dec-monkey-modifier-native] 猴头:原生表面 Decimate 修改器求值与桌面参考一致(有头)', async ({ page }, testInfo) => {
|
||
test.setTimeout(420_000);
|
||
const evidence: Record<string, unknown> = {};
|
||
const save = () => record(testInfo, 'decimate-modifier-native.json', evidence);
|
||
await observeNative(page); await page.goto('/');
|
||
await expect.poll(() => page.evaluate(() => Array.isArray((window as any).__nativeWorkflowMain?.nodes)), { timeout: 60000 }).toBe(true);
|
||
const { imported } = await openStudioAndImport(page, true, testInfo); evidence.imported = imported;
|
||
|
||
const added = await pythonRun(page, modifierScript(imported.name, 0.1));
|
||
evidence.added = added.value;
|
||
expect(added.value.modifiers).toEqual(['DECIMATE']);
|
||
expectModifierRatio(added.value, 0.1, 0.05);
|
||
|
||
/* Stage A: the published mesh carries the evaluated triangles and counts. */
|
||
await expect.poll(async () => {
|
||
const { mesh } = await meshOf(page, imported.name);
|
||
return { evaluated: mesh.geometryEvaluated === true, status: mesh.modifierStack?.[0]?.evaluationStatus, triangles: mesh.triangleCount };
|
||
}, { timeout: 180000 }).toMatchObject({ evaluated: true, status: 'EVALUATED', triangles: added.value.after });
|
||
const published = await meshOf(page, imported.name); evidence.published = { triangleCount: published.mesh.triangleCount, baseTriangleCount: published.mesh.baseTriangleCount, faceCount: published.mesh.faceCount };
|
||
expect(published.mesh.baseTriangleCount).toBe(added.value.before);
|
||
expectModifierRatio({ before: published.mesh.baseTriangleCount, after: published.mesh.triangleCount }, 0.1, 0.05);
|
||
|
||
const oracle = desktopOracle();
|
||
evidence.oracle = oracle?.modifier ?? 'missing';
|
||
if (oracle?.modifier) {
|
||
const webKept = published.mesh.triangleCount / Math.max(1, published.mesh.baseTriangleCount);
|
||
expect(Math.abs(webKept - oracle.modifier.trianglesAfter / oracle.modifier.trianglesBefore)).toBeLessThanOrEqual(0.03);
|
||
expect(Math.abs(published.mesh.baseTriangleCount - oracle.modifier.trianglesBefore) / Math.max(1, oracle.modifier.trianglesBefore)).toBeLessThanOrEqual(0.02);
|
||
}
|
||
await shot(page, testInfo, 'native-01-modifier-0.1');
|
||
|
||
const removed = await pythonRun(page, removeModifiers(imported.name));
|
||
evidence.removed = removed.value;
|
||
expect(removed.value.modifiers).toEqual([]);
|
||
await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 120000 }).toBe(added.value.before);
|
||
save();
|
||
});
|
||
|
||
test('[dec-monkey-edit-web] 猴头:编辑模式 ▸ 网格 ▸ 清理 ▸ 简化几何,Ratio 0.5 生效且一次撤销恢复(有头)', async ({ page }, testInfo) => {
|
||
test.setTimeout(420_000);
|
||
const evidence: Record<string, unknown> = {};
|
||
const save = () => record(testInfo, 'decimate-edit-web.json', evidence);
|
||
await observeNative(page); await page.goto('/?ui=web');
|
||
await expect.poll(() => page.evaluate(() => Array.isArray((window as any).__nativeWorkflowMain?.nodes)), { timeout: 60000 }).toBe(true);
|
||
const { imported } = await openStudioAndImport(page, false, testInfo); evidence.imported = imported;
|
||
await selectViaOutliner(page, imported.name);
|
||
const statsBefore = await sceneStats(page); evidence.statsBefore = statsBefore;
|
||
const baseline = await meshOf(page, imported.name);
|
||
const triangleBefore = baseline.mesh.triangleCount;
|
||
expect(triangleBefore).toBeGreaterThan(0);
|
||
|
||
/* Enter Edit Mode through the mode chip, then select all through 选择 ▸ 全部. */
|
||
await page.getByRole('button', { name: 'Object Mode', exact: true }).click();
|
||
await page.getByRole('menuitemcheckbox', { name: '编辑模式', exact: true }).click();
|
||
const meshMenu = page.getByRole('button', { name: '网格', exact: true });
|
||
await expect(meshMenu).toBeVisible({ timeout: 60000 });
|
||
await page.getByRole('button', { name: '选择', exact: true }).click();
|
||
await page.getByRole('menuitem', { name: '全部', exact: true }).click();
|
||
|
||
/* G3: Mesh ▸ Clean Up ▸ Decimate Geometry. */
|
||
await meshMenu.click();
|
||
await page.getByRole('menuitem', { name: '清理', exact: true }).click();
|
||
await page.getByRole('menuitem', { name: '简化几何…', exact: true }).click();
|
||
const dialog = page.getByRole('dialog', { name: '简化几何(Decimate Geometry)' });
|
||
await expect(dialog).toBeVisible({ timeout: 20000 });
|
||
await dialog.getByRole('spinbutton', { name: '简化几何比例', exact: true }).fill('0.5');
|
||
await dialog.getByRole('button', { name: '简化几何', exact: true }).click();
|
||
await expect(dialog).toHaveCount(0, { timeout: 20000 });
|
||
await expect(page.getByTestId('engine-status')).toContainText('mesh.decimate', { timeout: 180000 });
|
||
|
||
/* Leave Edit Mode; the snapshot then carries the decimated triangles. */
|
||
await page.getByRole('button', { name: 'Edit Mode', exact: true }).click();
|
||
await page.getByRole('menuitemcheckbox', { name: '物体模式', exact: true }).click();
|
||
await expect(page.getByRole('button', { name: 'Object Mode', exact: true })).toBeVisible({ timeout: 60000 });
|
||
const decimated = await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 180000 }).toBeLessThanOrEqual(Math.ceil(triangleBefore * 0.65)).then(async () => (await meshOf(page, imported.name)).mesh);
|
||
const kept = decimated.triangleCount / triangleBefore;
|
||
evidence.decimated = { triangleBefore, triangleAfter: decimated.triangleCount, kept };
|
||
expect(kept).toBeGreaterThan(0.3);
|
||
expect(kept).toBeLessThan(0.7);
|
||
const oracle = desktopOracle();
|
||
evidence.oracle = oracle?.edit ?? 'missing';
|
||
if (oracle?.edit) expect(Math.abs(kept - oracle.edit.trianglesAfter / oracle.edit.trianglesBefore)).toBeLessThanOrEqual(0.03);
|
||
await shot(page, testInfo, 'web-03-edit-decimate');
|
||
|
||
/* A single undo restores the selected triangles (desktop history semantics). */
|
||
await page.locator('canvas.viewport-canvas').focus();
|
||
for (let attempt = 0; attempt < 2; attempt++) {
|
||
await page.keyboard.press('Control+z');
|
||
const restored = await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 20000 }).toBe(triangleBefore).then(() => true).catch(() => false);
|
||
if (restored) break;
|
||
await page.waitForTimeout(2000);
|
||
}
|
||
const undone = await meshOf(page, imported.name);
|
||
evidence.undone = { triangleCount: undone.mesh.triangleCount };
|
||
expect(undone.mesh.triangleCount).toBe(triangleBefore);
|
||
save();
|
||
});
|
||
|
||
test('[dec-monkey-edit-native] 猴头:原生 bpy.ops.mesh.decimate ratio 0.5 与桌面参考一致(有头)', async ({ page }, testInfo) => {
|
||
test.setTimeout(420_000);
|
||
const evidence: Record<string, unknown> = {};
|
||
const save = () => record(testInfo, 'decimate-edit-native.json', evidence);
|
||
await observeNative(page); await page.goto('/');
|
||
await expect.poll(() => page.evaluate(() => Array.isArray((window as any).__nativeWorkflowMain?.nodes)), { timeout: 60000 }).toBe(true);
|
||
const { imported } = await openStudioAndImport(page, true, testInfo); evidence.imported = imported;
|
||
|
||
const handled = await pythonRun(page, editDecimateScript(imported.name, 0.5));
|
||
evidence.handled = handled.value;
|
||
expect(handled.value.operator).toEqual(['FINISHED']);
|
||
expect(handled.value.mode).toBe('OBJECT');
|
||
const kept = handled.value.triangles / handled.value.beforeTriangles;
|
||
expect(kept).toBeGreaterThan(0.3);
|
||
expect(kept).toBeLessThan(0.7);
|
||
const oracle = desktopOracle();
|
||
evidence.oracle = oracle?.edit ?? 'missing';
|
||
if (oracle?.edit) {
|
||
expect(Math.abs(kept - oracle.edit.trianglesAfter / oracle.edit.trianglesBefore)).toBeLessThanOrEqual(0.03);
|
||
expect(Math.abs(handled.value.beforeTriangles - oracle.edit.trianglesBefore) / Math.max(1, oracle.edit.trianglesBefore)).toBeLessThanOrEqual(0.02);
|
||
}
|
||
await expect.poll(async () => (await meshOf(page, imported.name)).mesh.triangleCount, { timeout: 180000 }).toBe(handled.value.triangles);
|
||
await shot(page, testInfo, 'native-02-edit-decimate');
|
||
save();
|
||
});
|
||
|
||
void queryNativeJSON;
|