Files
workinf_Blender_Wasm/tools/web/check-action-slot-unassign-from-id-desktop.py
mes123456 9f43244982
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
Continue Blender Web parity task handoff
2026-08-23 05:47:21 -04:00

131 lines
5.6 KiB
Python

#!/usr/bin/env python3
import hashlib
import json
import os
import pathlib
import sys
import tempfile
import bpy
OBJECT_NAME = "WebGapAnimUnassignIdObject"
ACTION_NAME = "WebGapAnimUnassignIdAction"
SLOT_IDENTIFIER = "OBWebGapUnassignIdSlot"
def action_report(obj):
action = obj.animation_data.action if obj and obj.animation_data else None
channels = []
if action is not None:
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"], value["frames"], value["values"]))
return channels
def state_report():
obj = bpy.data.objects.get(OBJECT_NAME)
if obj is None or obj.animation_data is None:
raise RuntimeError("slot_unassign_from_id fixture object or animation data is missing")
action = obj.animation_data.action
slot = obj.animation_data.action_slot
return {
"activeObject": bpy.context.view_layer.objects.active.name if bpy.context.view_layer.objects.active else None,
"action": action.name if action else None,
"actionSlot": slot.identifier if slot else None,
"actionSlotHandle": int(obj.animation_data.action_slot_handle),
"lastSlotIdentifier": obj.animation_data.last_slot_identifier,
"channels": action_report(obj),
}
def is_unassigned(state):
return state["action"] == ACTION_NAME and state["actionSlot"] is None and state["actionSlotHandle"] == 0 and state["lastSlotIdentifier"] == SLOT_IDENTIFIER
def run_operator(obj):
window = bpy.context.window
screen = window.screen
area = next((candidate for candidate in screen.areas if candidate.height >= 200), None)
region = next((candidate for candidate in area.regions if candidate.type == "WINDOW"), None) if area else None
override = {"window": window, "screen": screen, "area": area, "region": region, "animated_id": obj}
with bpy.context.temp_override(**{key: value for key, value in override.items() if value is not None}):
poll = bool(bpy.ops.anim.slot_unassign_from_id.poll())
if not poll:
raise RuntimeError("ANIM_OT_slot_unassign_from_id poll failed")
result = bpy.ops.anim.slot_unassign_from_id()
if result != {"FINISHED"}:
raise RuntimeError(f"ANIM_OT_slot_unassign_from_id returned {result}")
return poll, result
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit("usage: blender -b --factory-startup --python check-action-slot-unassign-from-id-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)
obj = bpy.data.objects.get(OBJECT_NAME)
before = state_report()
preserved = is_unassigned(before)
if preserved:
poll = True
result = {"FINISHED"}
else:
if before["action"] != ACTION_NAME or before["actionSlot"] != SLOT_IDENTIFIER or before["actionSlotHandle"] == 0 or before["lastSlotIdentifier"] != SLOT_IDENTIFIER:
raise RuntimeError(f"slot_unassign_from_id source state is wrong: {before}")
poll, result = run_operator(obj)
after = state_report()
if not is_unassigned(after):
raise RuntimeError(f"slot_unassign_from_id did not clear the assigned slot: {after}")
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-slot-unassign-id-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.slot_unassign_from_id 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-00209",
"operation": "ANIM_SLOT_UNASSIGN_FROM_ID_DESKTOP",
"fixture": str(fixture),
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
"before": before,
"after": reopened,
"poll": poll,
"operatorStatus": "FINISHED",
"mainMutation": "ID_SLOT_UNASSIGNED" if not preserved else "NONE_ALREADY_UNASSIGNED",
"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-slot-unassign-from-id-desktop-ok poll=true status=FINISHED mainMutation=id_slot_unassigned saveReopen=exact")
finally:
temporary_path.unlink(missing_ok=True)
if __name__ == "__main__":
try:
main()
except Exception as error:
print(f"anim-slot-unassign-from-id-desktop-failed: {error}")
raise SystemExit(1)