dishsim-assets / frigidaire_fdpc4221as /source /export_components.py
shu4dev's picture
Six flat asset folders with their generators (code repo refactor, section 1) (part 8)
c941945 verified
Raw History Blame Contribute Delete
1.55 kB
# 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)")