Files
workinf_Blender_Wasm/tools/web/check-action-view-selected-desktop.py
mes123456 46c9ebfcb6
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
Capture M16 gap execution artifacts
2026-08-21 21:09:40 -04:00

114 lines
4.4 KiB
Python

#!/usr/bin/env python3
import hashlib
import json
import os
import pathlib
import sys
import tempfile
import bpy
def action_channels(action):
channels = []
for layer in action.layers:
for strip in layer.strips:
for bag in strip.channelbags:
for curve in bag.fcurves:
channels.append({
"path": curve.data_path,
"index": curve.array_index,
"frames": [round(float(keyframe.co.x), 6) for keyframe in curve.keyframe_points],
"selected": [bool(keyframe.select_control_point) for keyframe in curve.keyframe_points],
})
channels.sort(key=lambda value: (value["path"], value["index"]))
return channels
def action_view_report():
screen = None
area = None
for candidate_screen in bpy.data.screens:
candidate_area = next(
(candidate for candidate in candidate_screen.areas
if candidate.type == "DOPESHEET_EDITOR" and candidate.spaces.active.ui_mode == "ACTION"),
None,
)
if candidate_area is not None:
screen, area = candidate_screen, candidate_area
break
if area is None:
raise RuntimeError("Action Editor area is missing")
region = next((candidate for candidate in area.regions if candidate.type == "WINDOW"), None)
if region is None:
raise RuntimeError("Action Editor window region is missing")
view = region.view2d
xmin, ymin = view.region_to_view(0, 0)
xmax, ymax = view.region_to_view(region.width - 1, region.height - 1)
obj = bpy.data.objects.get("WebGapActionViewSelectedObject")
if obj is None or obj.animation_data is None or obj.animation_data.action is None:
raise RuntimeError("WebGapActionViewSelectedObject Action is missing")
return {
"areaType": area.type,
"uiMode": area.spaces.active.ui_mode,
"action": {
"name": obj.animation_data.action.name,
"channels": action_channels(obj.animation_data.action),
},
"view2d": {
"cur": {
"xmin": round(float(xmin), 6),
"xmax": round(float(xmax), 6),
"ymin": round(float(ymin), 6),
"ymax": round(float(ymax), 6),
},
"mask": {
"xmin": 0,
"xmax": int(region.width - 1),
"ymin": 0,
"ymax": int(region.height - 1),
},
},
}
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit("usage: blender -b --python check-action-view-selected-desktop.py -- FIXTURE REPORT")
fixture, output = (pathlib.Path(value).resolve() for value in arguments)
bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=True)
before = action_view_report()
expected = [[False, True, False]] * 3
if before["action"]["name"] != "WebGapActionViewSelectedObjectAction" or [channel["selected"] for channel in before["action"]["channels"]] != expected:
raise RuntimeError(f"unexpected action.view_selected result: {before}")
descriptor, temporary = tempfile.mkstemp(prefix="m16-action-view-selected-reopen-", suffix=".blend")
os.close(descriptor)
try:
bpy.ops.wm.save_as_mainfile(filepath=temporary, check_existing=False, compress=True)
bpy.ops.wm.open_mainfile(filepath=temporary, load_ui=True)
after = action_view_report()
finally:
pathlib.Path(temporary).unlink(missing_ok=True)
if before != after:
raise RuntimeError(f"action.view_selected save/reopen drift: {before} != {after}")
report = {
"schemaVersion": 1,
"task": "M16-GAP-00149",
"operation": "ACTION_VIEW_SELECTED_DESKTOP",
"fixture": str(fixture),
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
"selectedFrame": 3,
"action": after["action"],
"view2d": after["view2d"],
"saveReopen": "EXACT",
"blenderVersion": bpy.app.version_string,
}
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8")
print("action-view-selected-desktop-ok channels=3 selectedFrame=3 view2d=exact saveReopen=exact")
if __name__ == "__main__":
main()