112 lines
4.4 KiB
Python
112 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_report(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(curve.select),
|
|
})
|
|
channels.sort(key=lambda value: (value["path"], value["index"]))
|
|
return {"name": action.name, "channels": channels}
|
|
|
|
|
|
def view_report():
|
|
area = None
|
|
for screen in bpy.data.screens:
|
|
area = next(
|
|
(candidate for candidate in screen.areas
|
|
if candidate.type == "DOPESHEET_EDITOR" and candidate.spaces.active.ui_mode == "ACTION"),
|
|
None,
|
|
)
|
|
if area is not None:
|
|
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)
|
|
return {
|
|
"areaType": area.type,
|
|
"uiMode": area.spaces.active.ui_mode,
|
|
"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-channels-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)
|
|
obj = bpy.data.objects.get("WebGapAnimChannelsViewSelectedObject")
|
|
if obj is None or obj.animation_data is None or obj.animation_data.action is None:
|
|
raise RuntimeError("WebGapAnimChannelsViewSelectedObject Action is missing")
|
|
before = {"action": action_report(obj.animation_data.action), **view_report()}
|
|
expected = [1.0, 3.0, 5.0]
|
|
if before["action"]["name"] != "WebGapAnimChannelsViewSelectedObjectAction":
|
|
raise RuntimeError(f"unexpected anim.channels_view_selected action: {before}")
|
|
if len(before["action"]["channels"]) != 3 or any(channel["frames"] != expected or not channel["selected"] for channel in before["action"]["channels"]):
|
|
raise RuntimeError(f"channels were not selected: {before}")
|
|
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-channels-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)
|
|
reopened_obj = bpy.data.objects.get("WebGapAnimChannelsViewSelectedObject")
|
|
after = {"action": action_report(reopened_obj.animation_data.action), **view_report()}
|
|
finally:
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if before != after:
|
|
raise RuntimeError("anim.channels_view_selected save/reopen drift")
|
|
report = {
|
|
"schemaVersion": 1,
|
|
"task": "M16-GAP-00171",
|
|
"operation": "ANIM_CHANNELS_VIEW_SELECTED_DESKTOP",
|
|
"fixture": str(fixture),
|
|
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
|
"selectedChannels": len(after["action"]["channels"]),
|
|
"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("anim-channels-view-selected-desktop-ok selected=3 view2d=exact saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|