75 lines
2.7 KiB
Python
75 lines
2.7 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 light_report():
|
|
light = bpy.data.lights.get("WebGapLight")
|
|
if light is None:
|
|
raise RuntimeError("WebGapLight is missing")
|
|
return {
|
|
"id": "light:WebGapLight",
|
|
"name": light.name,
|
|
"lightType": {"POINT": 0, "SUN": 1, "SPOT": 2, "AREA": 4}[light.type],
|
|
"color": [rounded(value) for value in light.color],
|
|
"energy": rounded(light.energy),
|
|
"exposure": rounded(light.exposure),
|
|
"temperature": rounded(light.temperature),
|
|
"useTemperature": bool(light.use_temperature),
|
|
"castsShadow": bool(light.use_shadow),
|
|
"radius": rounded(light.shadow_soft_size),
|
|
"spotAngle": rounded(getattr(light, "spot_size", 0.785398)),
|
|
"spotBlend": rounded(getattr(light, "spot_blend", 0.15)),
|
|
"areaShape": {"POINT": 0, "DISK": 0, "RECTANGLE": 1, "ELLIPSE": 2}[light.shape] if light.type == "AREA" else 0,
|
|
"areaSize": rounded(light.size),
|
|
"areaSizeY": rounded(light.size_y),
|
|
"areaSpread": rounded(light.spread),
|
|
"sunAngle": rounded(getattr(light, "angle", 0.00918)),
|
|
}
|
|
|
|
|
|
def main() -> None:
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --python check-light-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 = light_report()
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-light-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 = light_report()
|
|
finally:
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if before != after:
|
|
raise RuntimeError(f"light save/reopen drift: {before} != {after}")
|
|
report = {
|
|
"schemaVersion": 1,
|
|
"task": "M16-GAP-00012",
|
|
"operation": "LIGHT_DATABLOCK_DESKTOP",
|
|
"fixture": str(fixture),
|
|
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
|
"light": 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"light-desktop-ok id={after['id']} type={after['lightType']} energy={after['energy']} saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|