#!/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 settings_report(): settings = bpy.data.particles.get("WebGapParticleSettings") if settings is None: raise RuntimeError("WebGapParticleSettings is missing") return { "id": "particle-settings:" + settings.name, "name": settings.name, "type": int({"EMITTER": 0, "HAIR": 1}.get(settings.type, -1)), "from": int({"FACE": 0, "VERT": 1, "VOLUME": 2}.get(settings.emit_from, -1)), "distribution": int({"JIT": 0, "RAND": 1, "GRID": 2}.get(settings.distribution, -1)), "physicsType": int({"NEWTON": 0, "KEYED": 1, "BOIDS": 2, "NO": 3}.get(settings.physics_type, -1)), "totalParticles": int(settings.count), "start": rounded(settings.frame_start), "end": rounded(settings.frame_end), "lifetime": rounded(settings.lifetime), "size": rounded(settings.particle_size), "drawSize": rounded(settings.display_size), } def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-particle-settings-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 = settings_report() descriptor, temporary = tempfile.mkstemp(prefix="m16-particle-settings-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 = settings_report() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after: raise RuntimeError(f"particle settings save/reopen drift: {before} != {after}") report = { "schemaVersion": 1, "task": "M16-GAP-00018", "operation": "PARTICLE_SETTINGS_DATABLOCK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "particleSettings": 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"particle-settings-desktop-ok id={after['id']} count={after['totalParticles']} saveReopen=exact") if __name__ == "__main__": main()