# -*- coding: utf-8 -*-
"""만든 OBJ를 되읽어 수치 확인 + 3면도 PNG."""
import numpy as np, trimesh
import matplotlib; matplotlib.use('Agg')
import matplotlib.pyplot as plt
SCR = r'C:\Users\user\AppData\Local\Temp\claude\E-----Claude--20260728-claude-code-2-1-219\8defc145-8ae5-48d0-9058-355f3d9ae8ed\scratchpad'
OBJ = r'E:\도진팩토리\3D스캔및티칭시스템\fab_models\E500PRO_부재시범.obj'
m = trimesh.load(OBJ, force='mesh')
print('verts=%d faces=%d watertight=%s volume=%.0f mm3' % (len(m.vertices), len(m.faces), m.is_watertight, m.volume))
print('bounds min', np.round(m.bounds[0], 3), 'max', np.round(m.bounds[1], 3))
print('extents mm', np.round(m.extents, 3))
print('Z extent == 12 ?', abs(m.extents[2]-12.0) < 1e-6)

V = m.vertices; F = m.faces
fig, axs = plt.subplots(3, 1, figsize=(13, 11))
for ax, (i, j, nm) in zip(axs, [(0,1,'TOP  (XY) - 홀/컷아웃 보이는 면'), (0,2,'FRONT (XZ)'), (1,2,'SIDE (YZ)')]):
    # 실루엣 대신 삼각형 엣지를 그려 홀이 보이게
    segs = []
    for f in F:
        for a, b in ((0,1),(1,2),(2,0)):
            segs.append([V[f[a]][[i,j]], V[f[b]][[i,j]]])
    from matplotlib.collections import LineCollection
    ax.add_collection(LineCollection(segs, colors='k', linewidths=0.25))
    ax.set_aspect('equal'); ax.autoscale()
    ax.set_title(nm, fontsize=10)
out = SCR + r'\obj_3view.png'
plt.tight_layout(); plt.savefig(out, dpi=130); print('PNG ->', out)
