Files
workinf_Blender_Wasm/tools/web/complete/probe-autokey.mjs
mes123456 87e3f7207d
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): expose auto-keying preferences
The insert-keyframe path already existed but both preferences were marked
unsupported and hidden. Enable useAutoKeying and keyframeInterpolation;
verified g transform inserts location/rotation/scale F-Curves.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-14 06:40:38 +08:00

87 lines
4.0 KiB
JavaScript

#!/usr/bin/env node
/**
* Focused case: edit mode -> select all -> UV -> 展开(角度) on a mesh.
*
* node tools/web/complete/probe-autokey.mjs --base-url http://127.0.0.1:5176
*/
import { ASSETS, parseArgs, launchBrowser, newPage, openApp, openFile, waitScene } from "../course/lib/lesson-recorder.mjs";
const args = parseArgs();
const BASE = args.baseUrl || "http://127.0.0.1:5176";
const browser = await launchBrowser(args.gpu);
const { context, page, consoleErrors } = await newPage(browser, {});
page.setDefaultTimeout(90_000);
await page.addInitScript(() => {
const NativeWorker = window.Worker;
window.__probeWorkers = [];
window.__probeMessages = [];
window.Worker = class extends NativeWorker {
constructor(...params) {
super(...params);
window.__probeWorkers.push(this);
this.addEventListener("message", (event) => window.__probeMessages.push(event.data));
}
};
});
const log = (...parts) => console.log(new Date().toISOString().slice(11, 19), ...parts);
const python = async (source) => {
const requestId = `probe-${Date.now()}-${Math.random().toString(36).slice(2)}`;
return await page.evaluate(({ requestId, source }) => new Promise((resolve) => {
const started = Date.now();
const read = () => {
const hit = window.__probeMessages.find((message) => message && message.requestId === requestId && message.kind === "result");
if (hit) { clearInterval(timer); resolve(hit); return; }
if (Date.now() - started > 240000) { clearInterval(timer); resolve({ timeout: true }); }
};
const timer = setInterval(read, 250);
for (const worker of window.__probeWorkers) worker.postMessage({ requestId, command: { type: "jsonCommand", cmd: "pythonExec", params: { source, filename: "ProbeAutoKey.py", console: false } } });
}), { requestId, source }, { timeout: 300_000 });
};
const autoKeyState = async () => {
const result = await python(`
import bpy, json
obj = bpy.context.view_layer.objects.active
action = obj.animation_data.action if obj.animation_data else None
curves = []
if action:
for layer in action.layers:
for strip in layer.strips:
for bag in getattr(strip, 'channelbags', []):
for curve in bag.fcurves:
curves.append({'path': curve.data_path, 'index': curve.array_index, 'keys': len(curve.keyframe_points)})
print('AUTOKEY ' + json.dumps({'object': obj.name, 'location': [round(value, 4) for value in obj.location], 'fcurves': curves}))
`);
const out = result?.result?.json;
const status = await page.evaluate(() => document.querySelector('[data-testid="engine-status"]')?.textContent ?? "");
return { state: out?.state, output: out?.output, error: out?.error, status };
};
const menu = async (label, item) => {
await page.getByRole("button", { name: label, exact: true }).click();
await page.getByRole("menuitem", { name: item, exact: true }).click();
};
try {
await openApp(page, BASE);
await openFile(page, ASSETS.studio);
await waitScene(page, { objects: 6, timeout: 240_000 });
log("before", JSON.stringify(await autoKeyState()));
await menu("编辑", "偏好设置");
await page.getByRole("dialog", { name: "Web Blender 偏好设置" }).waitFor({ timeout: 30_000 });
await page.getByRole("button", { name: "动画", exact: true }).click();
const autoKey = page.getByRole("checkbox", { name: "自动关键帧", exact: true });
await autoKey.waitFor({ timeout: 30_000 });
log("checkbox", JSON.stringify({ checked: await autoKey.isChecked(), disabled: await autoKey.isDisabled() }));
await autoKey.check();
await page.getByRole("button", { name: "关闭偏好设置", exact: true }).click();
await page.waitForTimeout(800);
await page.keyboard.press("g");
await page.waitForTimeout(2500);
log("after g", JSON.stringify(await autoKeyState()));
} catch (error) {
log("probe error", error instanceof Error ? error.message : String(error));
log("state", JSON.stringify(await autoKeyState().catch(() => null)));
} finally {
log("consoleErrors", JSON.stringify(consoleErrors.slice(-10)));
await context.close();
await browser.close();
}