#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy def rounded(value): return round(float(value), 6) def material_report(): material = bpy.data.materials.get("WBV2P3001PrincipledMaterial") cube = bpy.data.objects.get("WBV2P3001MaterialCube") if material is None or cube is None or cube.type != "MESH" or not material.use_nodes: raise RuntimeError("MATERIAL_INVALID: material fixture is missing") principled = material.node_tree.nodes.get("Principled BSDF") if principled is None: raise RuntimeError("MATERIAL_INVALID: Principled BSDF is missing") uv_layer = cube.data.uv_layers.active if uv_layer is None: raise RuntimeError("MATERIAL_INVALID: active UV layer is missing") uv_values = [rounded(value) for loop in uv_layer.data for value in loop.uv] return { "materialId": "material:" + material.name, "materialName": material.name, "baseColor": [rounded(value) for value in principled.inputs["Base Color"].default_value], "roughness": rounded(principled.inputs["Roughness"].default_value), "metallic": rounded(principled.inputs["Metallic"].default_value), "ior": rounded(principled.inputs["IOR"].default_value), "nodeTypes": sorted(node.bl_idname for node in material.node_tree.nodes), "unsupportedNode": "ShaderNodeTexNoise" in [node.bl_idname for node in material.node_tree.nodes], "uvLayerNames": [layer.name for layer in cube.data.uv_layers], "activeUVMap": uv_layer.name, "uvHash": hashlib.sha256(json.dumps(uv_values, separators=(",", ":")).encode()).hexdigest(), "uvValueCount": len(uv_values), } def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-wbv2-p3-001-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 = material_report() descriptor, temporary = tempfile.mkstemp(prefix="wbv2-p3-001-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 = material_report() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after: raise RuntimeError(f"MATERIAL_INVALID: desktop save/reopen drift: {before} != {after}") report = { "schemaVersion": 1, "task": "WBV2-P3-001", "operation": "MATERIAL_PBR_UV_DESKTOP", "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "material": after, "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("wbv2-p3-001-desktop-ok material=%s uv=%s unsupported=retained saveReopen=exact" % (after["materialId"], after["activeUVMap"])) if __name__ == "__main__": main()