Files
workinf_Blender_Wasm/tools/web/check-material-desktop.py
mes123456 10640aeb3c
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
Govern task context and advance execution pointer
2026-08-20 06:02:43 -04:00

87 lines
3.3 KiB
Python

#!/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 socket_value(node, name, fallback):
socket = node.inputs.get(name)
if socket is None:
return fallback
value = socket.default_value
if hasattr(value, "__len__"):
return [rounded(item) for item in value]
return rounded(value)
def material_report():
material = bpy.data.materials.get("WebGapMaterial")
if material is None or not material.use_nodes:
raise RuntimeError("WebGapMaterial node tree is missing")
nodes = material.node_tree.nodes
principled = nodes.get("Principled BSDF")
if principled is None:
raise RuntimeError("WebGapMaterial Principled node is missing")
return {
"id": "material:WebGapMaterial",
"name": material.name,
"baseColor": socket_value(principled, "Base Color", [0.8, 0.8, 0.8, 1.0]),
"roughness": socket_value(principled, "Roughness", 0.4),
"metallic": socket_value(principled, "Metallic", 0.0),
"emissionColor": socket_value(principled, "Emission Color", [0.0, 0.0, 0.0, 1.0]),
"alpha": socket_value(principled, "Alpha", 1.0),
"ior": socket_value(principled, "IOR", 1.45),
"specularIORLevel": socket_value(principled, "Specular IOR Level", 0.5),
"transmissionWeight": socket_value(principled, "Transmission Weight", 0.0),
"coatWeight": socket_value(principled, "Coat Weight", 0.0),
"coatRoughness": socket_value(principled, "Coat Roughness", 0.03),
"emissionStrength": socket_value(principled, "Emission Strength", 1.0),
"nodeTypes": sorted(node.bl_idname for node in nodes),
"linkCount": len(material.node_tree.links),
}
def main() -> None:
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit("usage: blender -b --python check-material-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="m16-material-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 save/reopen drift: {before} != {after}")
report = {
"schemaVersion": 1,
"task": "M16-GAP-00013",
"operation": "MATERIAL_DATABLOCK_DESKTOP",
"fixture": str(fixture),
"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(f"material-desktop-ok id={after['id']} nodes={len(after['nodeTypes'])} links={after['linkCount']} saveReopen=exact")
if __name__ == "__main__":
main()