Continue Blender Web parity task handoff
This commit is contained in:
97
tools/web/check-action-separate-slots-desktop.py
Normal file
97
tools/web/check-action-separate-slots-desktop.py
Normal file
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python3
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
OBJECTS = ("WebGapAnimSeparateSlotA", "WebGapAnimSeparateSlotB")
|
||||
OLD_ACTION = "WebGapAnimSeparateSlotsAction"
|
||||
|
||||
|
||||
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]})
|
||||
channels.sort(key=lambda value: (value["path"], value["index"]))
|
||||
return {"name": action.name, "channels": channels}
|
||||
|
||||
|
||||
def state_report():
|
||||
objects = {name: bpy.data.objects.get(name) for name in OBJECTS}
|
||||
if any(obj is None for obj in objects.values()):
|
||||
raise RuntimeError("separate_slots fixture objects are missing")
|
||||
return {
|
||||
"activeObject": bpy.context.view_layer.objects.active.name if bpy.context.view_layer.objects.active else None,
|
||||
"objects": {name: action_report(obj) for name, obj in objects.items()},
|
||||
"actions": {action.name: int(action.users) for action in bpy.data.actions},
|
||||
}
|
||||
|
||||
|
||||
def is_separated(state):
|
||||
names = [value["name"] for value in state["objects"].values()]
|
||||
return all(name and name != OLD_ACTION for name in names) and len(set(names)) == 2
|
||||
|
||||
|
||||
def main():
|
||||
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
||||
if len(arguments) != 2:
|
||||
raise SystemExit("usage: blender -b --factory-startup --python check-action-separate-slots-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()
|
||||
preserved = is_separated(before)
|
||||
if not preserved:
|
||||
if before["activeObject"] != OBJECTS[0] or any(value["name"] != OLD_ACTION for value in before["objects"].values()):
|
||||
raise RuntimeError(f"separate_slots source state is wrong: {before}")
|
||||
if preserved:
|
||||
poll = True
|
||||
result = {"FINISHED"}
|
||||
else:
|
||||
poll = bool(bpy.ops.anim.separate_slots.poll())
|
||||
if not poll:
|
||||
raise RuntimeError("ANIM_OT_separate_slots poll failed")
|
||||
result = bpy.ops.anim.separate_slots()
|
||||
if result != {"FINISHED"}:
|
||||
raise RuntimeError(f"ANIM_OT_separate_slots returned {result}")
|
||||
after = state_report()
|
||||
if not is_separated(after):
|
||||
raise RuntimeError(f"separate_slots did not create separate actions: {after}")
|
||||
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-separate-slots-reopen-", 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(f"anim.separate_slots save/reopen drift: {after} != {reopened}")
|
||||
if not preserved:
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(fixture), check_existing=False, compress=True)
|
||||
report = {"schemaVersion": 1, "task": "M16-GAP-00205", "operation": "ANIM_SEPARATE_SLOTS_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "before": before, "after": reopened, "poll": poll, "operatorStatus": "FINISHED", "mainMutation": "SLOTS_SEPARATED" if not preserved else "NONE_ALREADY_SEPARATED", "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string}
|
||||
if preserved:
|
||||
report["evidenceStatus"] = "PRESERVED"
|
||||
if not preserved or not output.exists():
|
||||
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-separate-slots-desktop-ok poll=true status=FINISHED mainMutation=slots_separated saveReopen=exact")
|
||||
finally:
|
||||
temporary_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except Exception as error:
|
||||
print(f"anim-separate-slots-desktop-failed: {error}")
|
||||
raise SystemExit(1)
|
||||
Reference in New Issue
Block a user