File size: 1,551 Bytes
c941945 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # Copyright (c) 2026, dishsim project.
# SPDX-License-Identifier: BSD-3-Clause
"""Export ``geometry.build_components()`` to ``../components.json`` (2026-10-21).
The runtime (``dishsim_frigidaire.geometry.components``) reads this file instead of rebuilding the meshes: per
component its mass, visual meshes (material, points, faces), wire paths ``[name, path, radius]``, solids, sites and
site quaternions. JSON keeps every float exactly (repr round trip). Normals are not exported (nothing reads them).
code/util/run_py.sh data/assets/frigidaire_fdpc4221as/source/export_components.py
"""
import json
from pathlib import Path
from geometry import build_components
def plain(value):
return json.loads(json.dumps(value, default=lambda o: o.tolist() if hasattr(o, "tolist") else str(o)))
def export(path):
out = {name: {"mass": c["mass"],
"meshes": {key: {"material": m.material, "points": plain(m.points), "faces": plain(m.faces)}
for key, m in c["meshes"].items()},
"wires": [[key, plain(p), float(r)] for key, p, r in c["wires"]],
"solids": plain(c["solids"]), "sites": plain(c.get("sites", {})),
"site_quats": plain(c.get("site_quats", {}))}
for name, c in build_components().items()}
Path(path).write_text(json.dumps(out))
return path
if __name__ == "__main__":
target = export(Path(__file__).resolve().parents[1] / "components.json")
print(f"[RESULT] PASS {target} ({target.stat().st_size} bytes)")
|