Govern task context and advance execution pointer
This commit is contained in:
73
tools/web/check-mesh-desktop.py
Normal file
73
tools/web/check-mesh-desktop.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/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 mesh_report():
|
||||
mesh = bpy.data.meshes.get("WebGapMesh")
|
||||
if mesh is None:
|
||||
raise RuntimeError("WebGapMesh is missing")
|
||||
mesh.calc_loop_triangles()
|
||||
positions = [rounded(value) for vertex in mesh.vertices for value in vertex.co]
|
||||
indices = [index for triangle in mesh.loop_triangles for index in triangle.vertices]
|
||||
uv_layer = mesh.uv_layers.get("WebGapUV")
|
||||
uvs = [rounded(value) for loop in uv_layer.data for value in loop.uv] if uv_layer else []
|
||||
return {
|
||||
"id": "mesh:WebGapMesh",
|
||||
"name": mesh.name,
|
||||
"vertexCount": len(mesh.vertices),
|
||||
"edgeCount": len(mesh.edges),
|
||||
"faceCount": len(mesh.polygons),
|
||||
"cornerCount": len(mesh.loops),
|
||||
"triangleCount": len(mesh.loop_triangles),
|
||||
"positions": positions,
|
||||
"indices": indices,
|
||||
"uvLayers": [layer.name for layer in mesh.uv_layers],
|
||||
"uvs": uvs,
|
||||
}
|
||||
|
||||
|
||||
def main() -> None:
|
||||
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
||||
if len(arguments) != 2:
|
||||
raise SystemExit("usage: blender -b --python check-mesh-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 = mesh_report()
|
||||
descriptor, temporary = tempfile.mkstemp(prefix="m16-mesh-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 = mesh_report()
|
||||
finally:
|
||||
pathlib.Path(temporary).unlink(missing_ok=True)
|
||||
if before != after:
|
||||
raise RuntimeError(f"mesh save/reopen drift: {before} != {after}")
|
||||
report = {
|
||||
"schemaVersion": 1,
|
||||
"task": "M16-GAP-00014",
|
||||
"operation": "MESH_DATABLOCK_DESKTOP",
|
||||
"fixture": str(fixture),
|
||||
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
||||
"mesh": 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"mesh-desktop-ok id={after['id']} vertices={after['vertexCount']} triangles={after['triangleCount']} saveReopen=exact")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user