25 lines
1.7 KiB
Python
25 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib
|
|
import json
|
|
import pathlib
|
|
import sys
|
|
import tempfile
|
|
import os
|
|
import bpy
|
|
|
|
def report():
|
|
camera = bpy.data.cameras.get("WebGapCamera")
|
|
if camera is None: raise RuntimeError("WebGapCamera is missing")
|
|
return {"name": camera.name, "type": camera.type, "lens": round(float(camera.lens), 6), "clipStart": round(float(camera.clip_start), 6), "clipEnd": round(float(camera.clip_end), 6), "sensorWidth": round(float(camera.sensor_width), 6)}
|
|
|
|
def main():
|
|
args = sys.argv[sys.argv.index("--") + 1:]
|
|
if len(args) != 2: raise SystemExit("usage: blender -b --python check-camera-desktop.py -- FIXTURE REPORT")
|
|
fixture, output = (pathlib.Path(value).resolve() for value in args)
|
|
bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False); before = report(); descriptor, temporary = tempfile.mkstemp(prefix="m16-camera-reopen-", suffix=".blend"); 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 = report()
|
|
finally: pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if before != after: raise RuntimeError(f"camera save/reopen drift: {before} != {after}")
|
|
value = {"schemaVersion": 1, "task": "M16-GAP-00004", "operation": "CAMERA_DATABLOCK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "camera": after, "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"camera-desktop-ok name={after['name']} lens={after['lens']} saveReopen=exact")
|
|
if __name__ == "__main__": main()
|