Files
workinf_Blender_Wasm/tools/web/generate-ply-capability-fixtures.py
mes123456 380cbed4ff
Some checks are pending
M6 deployable RC / quick (push) Waiting to run
M6 deployable RC / chromium (push) Blocked by required conditions
M6 deployable RC / release (push) Blocked by required conditions
Checkpoint web parity through Chromium input tasks
2026-08-19 10:39:03 -04:00

73 lines
4.1 KiB
Python

"""Generate pinned Blender 5.2 ASCII and binary little-endian PLY fixtures for M12-07G."""
import hashlib
import json
import struct
import sys
from pathlib import Path
import bpy
def sha256_file(path):
digest = hashlib.sha256()
with open(path, "rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def text(value):
return value.decode("utf-8") if isinstance(value, bytes) else value
def runtime_identity():
binary = Path(bpy.app.binary_path)
return {"blenderVersion": text(bpy.app.version_string), "versionTuple": list(bpy.app.version), "buildDate": text(bpy.app.build_date), "buildTime": text(bpy.app.build_time), "buildHash": text(bpy.app.build_hash), "buildBranch": text(bpy.app.build_branch), "buildPlatform": text(bpy.app.build_platform), "buildType": text(bpy.app.build_type), "binarySha256": sha256_file(binary)}
def create_scene():
bpy.ops.wm.read_factory_settings(use_empty=True)
mesh = bpy.data.meshes.new("M12 PLY Capability Mesh")
mesh.from_pydata([(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 1.0, 0.0), (-1.0, 1.0, 0.0)], [], [(0, 1, 2), (0, 2, 3)])
mesh.update()
obj = bpy.data.objects.new("M12 PLY Capability", mesh)
bpy.context.scene.collection.objects.link(obj)
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
def export_ply(path, ascii_format):
result = bpy.ops.wm.ply_export(filepath=str(path), ascii_format=ascii_format, export_selected_objects=True, export_uv=False, export_normals=True, export_colors="NONE", export_triangulated_mesh=True, forward_axis="NEGATIVE_Z", up_axis="Y", global_scale=1.0)
if "FINISHED" not in result:
raise RuntimeError("Blender PLY export did not finish: %s" % (result,))
def parse_header(path):
payload = path.read_bytes()
end = payload.find(b"end_header\n")
if end < 0:
raise RuntimeError("PLY header missing end_header")
header = payload[: end + len(b"end_header\n")].decode("ascii")
lines = header.splitlines()
format_line = next(line for line in lines if line.startswith("format "))
elements = [{"name": parts[1], "count": int(parts[2])} for line in lines if (parts := line.split()) and parts[0] == "element"]
return {"format": format_line.split()[1], "elements": elements, "headerBytes": len(header.encode("ascii")), "byteLength": len(payload)}
def main(output_dir, report_path):
output_dir = Path(output_dir).resolve(); report_path = Path(report_path).resolve(); output_dir.mkdir(parents=True, exist_ok=True); report_path.parent.mkdir(parents=True, exist_ok=True)
create_scene()
ascii_path = output_dir / "capability-ascii.ply"; binary_path = output_dir / "capability-binary-le.ply"
export_ply(ascii_path, True); export_ply(binary_path, False)
files = [{"name": item.name, "byteLength": item.stat().st_size, "sha256": sha256_file(item)} for item in (ascii_path, binary_path)]
report = {"schemaVersion": 1, "task": "M12-07G", "operation": "DESKTOP_PLY_ASCII_BINARY_LE_CAPABILITY", "runtime": runtime_identity(), "sourceAnchor": "blender-5.2.0/source/blender/io/ply", "operator": "wm.ply_export", "settings": {"exportSelectedObjects": True, "exportNormals": True, "exportUV": False, "exportColors": "NONE", "exportTriangulatedMesh": True, "forwardAxis": "NEGATIVE_Z", "upAxis": "Y", "globalScale": 1.0}, "variants": [{"id": "PLY_ASCII", "asciiFormat": True, "file": ascii_path.name, "semantic": parse_header(ascii_path)}, {"id": "PLY_BINARY_LITTLE_ENDIAN", "asciiFormat": False, "file": binary_path.name, "semantic": parse_header(binary_path)}], "files": files, "nextTask": "M12-07H"}
report_path.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8")
print("ply-capability-fixtures-generated ascii=%s binary=%s next=%s" % (report["variants"][0]["semantic"]["format"], report["variants"][1]["semantic"]["format"], report["nextTask"]))
if __name__ == "__main__":
args = sys.argv[sys.argv.index("--") + 1 :] if "--" in sys.argv else []
if len(args) != 2: raise SystemExit("usage: blender --background --python generate-ply-capability-fixtures.py -- OUTPUT_DIR REPORT")
main(args[0], args[1])