#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy TEXT_NAME = "WBV2-P1-002-SceneIRContract" def read_contract(): text = bpy.data.texts.get(TEXT_NAME) if text is None: raise RuntimeError("SCENEIR_CONTRACT_INVALID: contract text is missing") source = text.as_string() return source, json.loads(source) def scene_summary(): obj = bpy.data.objects.get("WBV2P1002CubeObject") if obj is None or obj.type != "MESH": raise RuntimeError("SCENEIR_CONTRACT_INVALID: cube object is missing") mesh = obj.data mesh.calc_loop_triangles() positions = [value for vertex in mesh.vertices for value in vertex.co] normalized_positions = [int(value) if value == int(value) else round(value, 6) for value in positions] return { "objectId": "object:" + obj.name, "meshId": "mesh:" + mesh.name, "vertexCount": len(mesh.vertices), "triangleCount": len(mesh.loop_triangles), "positionHash": hashlib.sha256(json.dumps(normalized_positions, separators=(",", ":")).encode("utf-8")).hexdigest(), } def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-wbv2-p1-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=False) source, before = read_contract() summary = scene_summary() descriptor, temporary = tempfile.mkstemp(prefix="wbv2-p1-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=False) after_source, after = read_contract() after_summary = scene_summary() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after or source != after_source or summary != after_summary: raise RuntimeError("SCENEIR_CONTRACT_INVALID: desktop save/reopen drift") value = { "schemaVersion": 1, "task": "WBV2-P1-002", "operation": "SCENEIR_STABLE_IDS_BINARY_DELTA_DESKTOP", "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "contract": after, "summary": after_summary, "sourceSha256": hashlib.sha256(after_source.encode("utf-8")).hexdigest(), "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-p1-002-desktop-ok mesh={after_summary['meshId']} vertices={after_summary['vertexCount']} triangles={after_summary['triangleCount']} saveReopen=exact") if __name__ == "__main__": main()