#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy def oid(obj): return "object:" + obj.name def cid(collection): return "collection:" + collection.name def vector(values): return [round(float(value), 6) for value in values] def report(): scene = bpy.context.scene parent = bpy.data.objects.get("WBV2P2002Parent") child = bpy.data.objects.get("WBV2P2002Child") source = bpy.data.collections.get("WBV2P2002Source") target = bpy.data.collections.get("WBV2P2002Target") if None in (parent, child, source, target): raise RuntimeError("OBJECT_TRANSFORM_INVALID: fixture datablock is missing") return { "scene": {"id": "scene:" + scene.name, "name": scene.name}, "objects": { "parent": { "id": oid(parent), "dataId": "mesh:" + parent.data.name, "translation": vector(parent.location), "rotationEuler": vector(parent.rotation_euler), "scale": vector(parent.scale), "parentId": None, "worldTranslation": vector(parent.matrix_world.translation), }, "child": { "id": oid(child), "dataId": "mesh:" + child.data.name, "translation": vector(child.location), "rotationEuler": vector(child.rotation_euler), "scale": vector(child.scale), "parentId": oid(child.parent), "worldTranslation": vector(child.matrix_world.translation), }, }, "collections": { "source": {"id": cid(source), "objectIds": [oid(obj) for obj in source.objects]}, "target": {"id": cid(target), "objectIds": [oid(obj) for obj in target.objects]}, }, "selection": {"activeObjectId": oid(bpy.context.view_layer.objects.active), "selectedObjectIds": sorted(oid(obj) for obj in bpy.context.selected_objects), "revision": 1}, } def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-wbv2-p2-002-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 = report() descriptor, temporary = tempfile.mkstemp(prefix="wbv2-p2-002-reopen-", suffix=".blend", dir=fixture.parent) 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 = report() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after: raise RuntimeError(f"OBJECT_TRANSFORM_INVALID: desktop save/reopen drift: {before} != {after}") value = { "schemaVersion": 1, "task": "WBV2-P2-002", "operation": "OBJECT_TRANSFORM_HIERARCHY_DESKTOP", "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "scene": after, "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string, } output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(value, indent=2, sort_keys=True) + "\n", encoding="utf-8") print(f"wbv2-p2-002-desktop-ok parent={after['objects']['parent']['id']} child={after['objects']['child']['id']} worldChild={after['objects']['child']['worldTranslation']} saveReopen=exact") if __name__ == "__main__": main()