Files
workinf_Blender_Wasm/tools/web/check-pointcloud-desktop.py
mes123456 10640aeb3c
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Govern task context and advance execution pointer
2026-08-20 06:02:43 -04:00

69 lines
2.3 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():
data = bpy.data.pointclouds.get("WebGapPointCloud")
if data is None:
raise RuntimeError("WebGapPointCloud is missing")
positions = [0.0] * (len(data.points) * 3)
data.points.foreach_get("co", positions)
radius = data.attributes.get("radius")
radii = [0.0] * len(data.points)
if radius is not None:
radius.data.foreach_get("value", radii)
return {
"id": "pointcloud:" + data.name,
"name": data.name,
"pointCount": len(data.points),
"controlPoints": [rounded(value) for value in positions],
"radii": [rounded(value) for value in radii],
}
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit("usage: blender -b --python check-pointcloud-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-pointcloud-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"point cloud save/reopen drift: {before} != {after}")
value = {
"schemaVersion": 1,
"task": "M16-GAP-00019",
"operation": "POINT_CLOUD_DATABLOCK_DESKTOP",
"fixture": str(fixture),
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
"pointCloud": 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"pointcloud-desktop-ok id={after['id']} points={after['pointCount']} saveReopen=exact")
if __name__ == "__main__":
main()