84 lines
3.2 KiB
Python
84 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib
|
|
import json
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
def graph_record(group):
|
|
sockets = [
|
|
{"name": item.name, "inOut": item.in_out, "socketType": item.socket_type}
|
|
for item in group.interface.items_tree
|
|
if item.item_type == "SOCKET"
|
|
]
|
|
return {
|
|
"name": group.name,
|
|
"type": group.bl_idname,
|
|
"interface": sockets,
|
|
"nodeTypes": sorted(node.bl_idname for node in group.nodes),
|
|
"nodeNames": sorted(node.name for node in group.nodes),
|
|
"linkCount": len(group.links),
|
|
}
|
|
|
|
|
|
def material_record(material):
|
|
tree = material.node_tree
|
|
return {
|
|
"name": material.name,
|
|
"nodeTypes": sorted(node.bl_idname for node in tree.nodes),
|
|
"nodeNames": sorted(node.name for node in tree.nodes),
|
|
"linkCount": len(tree.links),
|
|
}
|
|
|
|
|
|
def state():
|
|
supported = bpy.data.node_groups.get("WBV2P4002SupportedGraph")
|
|
blocked = bpy.data.node_groups.get("WBV2P4002BlockedGraph")
|
|
shader = bpy.data.materials.get("WBV2P4002ShaderMaterial")
|
|
if supported is None or blocked is None or shader is None:
|
|
raise RuntimeError("P4-002 fixture data blocks are missing")
|
|
if not any(modifier.type == "NODES" and modifier.node_group == supported for obj in bpy.data.objects for modifier in obj.modifiers):
|
|
raise RuntimeError("supported Geometry Nodes modifier is missing")
|
|
if not any(modifier.type == "NODES" and modifier.node_group == blocked for obj in bpy.data.objects for modifier in obj.modifiers):
|
|
raise RuntimeError("blocked Geometry Nodes modifier is missing")
|
|
return {
|
|
"graphs": [graph_record(supported), graph_record(blocked)],
|
|
"material": material_record(shader),
|
|
}
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1:]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --factory-startup --python check-wbv2-p4-002-desktop.py -- FIXTURE REPORT")
|
|
fixture, report_path = (pathlib.Path(value).resolve() for value in arguments)
|
|
bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False)
|
|
before = state()
|
|
temporary = fixture.with_name(f"{fixture.stem}-reopen.blend")
|
|
try:
|
|
bpy.ops.wm.save_as_mainfile(filepath=str(temporary), check_existing=False, compress=True)
|
|
bpy.ops.wm.open_mainfile(filepath=str(temporary), load_ui=False)
|
|
after = state()
|
|
finally:
|
|
temporary.unlink(missing_ok=True)
|
|
if before != after:
|
|
raise RuntimeError(f"node graph save/reopen drift: {before} != {after}")
|
|
report = {
|
|
"schemaVersion": 1,
|
|
"task": "WBV2-P4-002",
|
|
"operation": "NODES_ALLOWLIST_DESKTOP",
|
|
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
|
"state": after,
|
|
"saveReopen": "EXACT",
|
|
"blenderVersion": bpy.app.version_string,
|
|
}
|
|
report_path.parent.mkdir(parents=True, exist_ok=True)
|
|
report_path.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
print("wbv2-p4-002-desktop-ok graphs=2 supported=GeometryNodeTransform blocked=GeometryNodeDistributePointsOnFaces shader=ShaderNodeRGB saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|