"""A battery-like watertight solid (stand-in for the DeWalt scan): a body, a narrower upper block and two side rails
on it (sharp edges and steps), in mm, z up. Writes ../meshes/battery_stepped.ply."""
from pathlib import Path

import manifold3d as m3
import numpy as np
import trimesh


def box(sx, sy, sz, x=0.0, y=0.0, z=0.0):
    return m3.Manifold.cube([sx, sy, sz]).translate([x - sx / 2, y - sy / 2, z])


body = box(115, 80, 45)                      # the cell pack
top = box(90, 60, 25, x=-8, z=45)           # the narrower block that slides into the tool
rails = box(90, 6, 8, x=-8, y=-33, z=62) + box(90, 6, 8, x=-8, y=33, z=62)  # the guide rails along its sides
latch = box(14, 30, 10, x=44, z=45)         # the release button block at the front
solid = body + top + rails + latch
mesh = solid.to_mesh()
t = trimesh.Trimesh(np.asarray(mesh.vert_properties)[:, :3], np.asarray(mesh.tri_verts), process=True)
out = Path(__file__).resolve().parent.parent / "meshes" / "battery_stepped.ply"
t.export(out)
print(out, t.is_watertight, t.extents)
