"""Report which faces the closest-mode connector selects for the current Blender layout."""
import numpy as np
import trimesh
import gen_two_servo as g

g.LAYOUT = g.read_layout("two_servo_from_blender.glb")
yoke = trimesh.load("yoke_exact.stl", force="mesh")
holder = trimesh.load("holder_approx_drilled.stl", force="mesh")
Ty, Th = g._mm(g.LAYOUT[0]), g._mm(g.LAYOUT[1])
arm = yoke.vertices[yoke.vertices[:, 0] < g.YOKE_ARM_X]
yf, hf = g._box_faces(arm.min(0), arm.max(0)), g._box_faces(*holder.bounds)
a, b = g._closest_faces(yf, hf, Ty, Th)


def name(n):
    ax = int(np.argmax(np.abs(n)))
    return ("+" if n[ax] > 0 else "-") + "XYZ"[ax]


print("picked yoke face:  ", name(yf[a][2]), "(local face, in yoke frame)")
print("picked holder face:", name(hf[b][2]), "(local face, in holder frame)")
