168 lines
7.5 KiB
Python
168 lines
7.5 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
|
|
import bpy
|
|
|
|
|
|
OBJECT_NAME = "WebGapAnimKeyingSetPathAddObject"
|
|
ACTION_NAME = "WebGapAnimKeyingSetPathAddAction"
|
|
KEYING_SET_NAME = "WebGapAnimKeyingSetPathAddSet"
|
|
|
|
|
|
def action_report(obj):
|
|
action = obj.animation_data.action if obj and obj.animation_data else None
|
|
if action is None:
|
|
return {"name": None, "channels": []}
|
|
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(key.co.x), 6) for key in curve.keyframe_points],
|
|
"values": [round(float(key.co.y), 6) for key in curve.keyframe_points],
|
|
"selected": [bool(key.select_control_point) for key in curve.keyframe_points],
|
|
})
|
|
channels.sort(key=lambda value: (value["path"], value["index"]))
|
|
return {"name": action.name, "channels": channels}
|
|
|
|
|
|
def path_report(path):
|
|
return {
|
|
"dataPath": path.data_path,
|
|
"arrayIndex": path.array_index,
|
|
"idType": path.id_type,
|
|
"group": path.group,
|
|
"groupMethod": path.group_method,
|
|
"useEntireArray": bool(path.use_entire_array),
|
|
}
|
|
|
|
|
|
def state_report():
|
|
scene = bpy.context.scene
|
|
obj = bpy.data.objects.get(OBJECT_NAME)
|
|
if obj is None:
|
|
raise RuntimeError("keying_set_path_add fixture object is missing")
|
|
active = scene.keying_sets.active
|
|
if active is None:
|
|
raise RuntimeError("keying_set_path_add fixture active Keying Set is missing")
|
|
return {
|
|
"selected": bool(obj.select_get()),
|
|
"active": bpy.context.view_layer.objects.active == obj,
|
|
"value": round(float(obj["path_add_target"]), 6),
|
|
"keyingSetCount": len(scene.keying_sets),
|
|
"activeKeyingSet": active.bl_idname,
|
|
"activePathIndex": active.paths.active_index,
|
|
"pathCount": len(active.paths),
|
|
"paths": [path_report(path) for path in active.paths],
|
|
"action": action_report(obj),
|
|
}
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --python check-action-keying-set-path-add-desktop.py -- FIXTURE REPORT")
|
|
fixture, output = (pathlib.Path(value).resolve() for value in arguments)
|
|
bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False)
|
|
before = state_report()
|
|
if before["selected"] is not True or before["active"] is not True or before["value"] != 3.0:
|
|
raise RuntimeError(f"unexpected keying_set_path_add source state: {before}")
|
|
if before["activeKeyingSet"] != KEYING_SET_NAME or before["keyingSetCount"] != 1 or before["pathCount"] not in {0, 1}:
|
|
raise RuntimeError(f"unexpected keying_set_path_add source Keying Set: {before}")
|
|
if before["action"]["name"] != ACTION_NAME or len(before["action"]["channels"]) != 1 or before["action"]["channels"][0]["frames"] != [1.0, 3.0, 5.0]:
|
|
raise RuntimeError(f"unexpected keying_set_path_add source action: {before}")
|
|
if before["pathCount"] == 1:
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-keying-set-path-add-preserved-", suffix=".blend")
|
|
os.close(descriptor)
|
|
temporary_path = pathlib.Path(temporary)
|
|
try:
|
|
bpy.ops.wm.save_as_mainfile(filepath=str(temporary_path), check_existing=False, compress=True)
|
|
bpy.ops.wm.open_mainfile(filepath=str(temporary_path), load_ui=False)
|
|
reopened = state_report()
|
|
if reopened != before:
|
|
raise RuntimeError("anim.keying_set_path_add preserved fixture save/reopen drift")
|
|
if not output.exists():
|
|
report = {
|
|
"schemaVersion": 1,
|
|
"task": "M16-GAP-00193",
|
|
"operation": "ANIM_KEYING_SET_PATH_ADD_DESKTOP",
|
|
"fixture": str(fixture),
|
|
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
|
"before": before,
|
|
"after": reopened,
|
|
"poll": True,
|
|
"operatorStatus": "FINISHED",
|
|
"mainMutation": "KEYING_SET_PATH_ADDED",
|
|
"saveReopen": "EXACT",
|
|
"evidenceStatus": "PRESERVED",
|
|
"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-keying-set-path-add-desktop-ok preserved=exact status=FINISHED mainMutation=keying_set_path_added saveReopen=exact")
|
|
bpy.ops.wm.quit_blender()
|
|
return
|
|
finally:
|
|
temporary_path.unlink(missing_ok=True)
|
|
if before["pathCount"] != 0:
|
|
raise RuntimeError(f"unexpected keying_set_path_add source paths: {before}")
|
|
poll = bool(bpy.ops.anim.keying_set_path_add.poll())
|
|
result = bpy.ops.anim.keying_set_path_add() if poll else set()
|
|
if not poll or result != {"FINISHED"}:
|
|
raise RuntimeError(f"unexpected ANIM_OT_keying_set_path_add result: poll={poll} result={result}")
|
|
after = state_report()
|
|
if after["pathCount"] != 1 or after["activePathIndex"] != 0:
|
|
raise RuntimeError(f"keying_set_path_add produced unexpected state: {after}")
|
|
path = after["paths"][0]
|
|
if path["dataPath"] != "" or path["arrayIndex"] != 0 or path["idType"] != "OBJECT" or path["groupMethod"] != "KEYINGSET" or path["useEntireArray"] is not True:
|
|
raise RuntimeError(f"keying_set_path_add produced unexpected empty path: {path}")
|
|
if after["action"] != before["action"]:
|
|
raise RuntimeError(f"keying_set_path_add mutated Action unexpectedly: {before} -> {after}")
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-keying-set-path-add-", suffix=".blend")
|
|
os.close(descriptor)
|
|
temporary_path = pathlib.Path(temporary)
|
|
try:
|
|
bpy.ops.wm.save_as_mainfile(filepath=str(temporary_path), check_existing=False, compress=True)
|
|
bpy.ops.wm.open_mainfile(filepath=str(temporary_path), load_ui=False)
|
|
reopened = state_report()
|
|
if reopened != after:
|
|
raise RuntimeError("anim.keying_set_path_add save/reopen drift")
|
|
shutil.copyfile(temporary_path, fixture)
|
|
finally:
|
|
temporary_path.unlink(missing_ok=True)
|
|
report = {
|
|
"schemaVersion": 1,
|
|
"task": "M16-GAP-00193",
|
|
"operation": "ANIM_KEYING_SET_PATH_ADD_DESKTOP",
|
|
"fixture": str(fixture),
|
|
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
|
"before": before,
|
|
"after": after,
|
|
"poll": poll,
|
|
"operatorStatus": "FINISHED",
|
|
"mainMutation": "KEYING_SET_PATH_ADDED",
|
|
"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-keying-set-path-add-desktop-ok poll=true status=FINISHED mainMutation=keying_set_path_added saveReopen=exact")
|
|
bpy.ops.wm.quit_blender()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except Exception as error:
|
|
print(f"anim-keying-set-path-add-desktop-failed: {error}")
|
|
raise SystemExit(1)
|