48 lines
2.0 KiB
Python
48 lines
2.0 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 report():
|
|
obj = bpy.data.objects.get("WebGapObject")
|
|
if obj is None:
|
|
raise RuntimeError("WebGapObject is missing")
|
|
return {"id": "object:WebGapObject", "name": obj.name, "type": obj.type, "visible": not obj.hide_get(), "selectable": not obj.hide_select, "location": [rounded(v) for v in obj.location], "rotationEuler": [rounded(v) for v in obj.rotation_euler], "scale": [rounded(v) for v in obj.scale], "parent": obj.parent.name if obj.parent else None}
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --python check-object-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 = report()
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-object-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 = report()
|
|
finally:
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if before != after:
|
|
raise RuntimeError(f"object save/reopen drift: {before} != {after}")
|
|
value = {"schemaVersion": 1, "task": "M16-GAP-00017", "operation": "OBJECT_DATABLOCK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "object": 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"object-desktop-ok id={after['id']} type={after['type']} saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|