78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import sys
|
|
import tempfile
|
|
|
|
import bpy
|
|
|
|
|
|
def rounded(values):
|
|
return [round(float(value), 6) for value in values]
|
|
|
|
|
|
def lattice_report():
|
|
lattice = bpy.data.lattices.get("WebGapLattice")
|
|
if lattice is None:
|
|
raise RuntimeError("WebGapLattice is missing")
|
|
return {
|
|
"id": "lattice:WebGapLattice",
|
|
"name": lattice.name,
|
|
"dimensions": [lattice.points_u, lattice.points_v, lattice.points_w],
|
|
"pointCount": len(lattice.points),
|
|
"interpolation": [
|
|
lattice.interpolation_type_u,
|
|
lattice.interpolation_type_v,
|
|
lattice.interpolation_type_w,
|
|
],
|
|
"useOutside": bool(lattice.use_outside),
|
|
"activePoint": -1,
|
|
"vertexGroup": lattice.vertex_group,
|
|
"points": [
|
|
{
|
|
"coDeform": rounded(point.co_deform),
|
|
"weight": round(float(point.weight_softbody), 6),
|
|
"selected": bool(point.select),
|
|
}
|
|
for point in lattice.points
|
|
],
|
|
}
|
|
|
|
|
|
def main() -> None:
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --python check-lattice-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 = lattice_report()
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-lattice-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 = lattice_report()
|
|
finally:
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if before != after:
|
|
raise RuntimeError(f"lattice save/reopen drift: {before} != {after}")
|
|
report = {
|
|
"schemaVersion": 1,
|
|
"task": "M16-GAP-00010",
|
|
"operation": "LATTICE_DATABLOCK_DESKTOP",
|
|
"fixture": str(fixture),
|
|
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
|
"lattice": 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"lattice-desktop-ok points={after['pointCount']} saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|