import bpy, sys, math
from collections import defaultdict
a=sys.argv[sys.argv.index("--")+1:]
bpy.ops.wm.read_factory_settings(use_empty=True); bpy.ops.import_scene.gltf(filepath=a[0])
o=[x for x in bpy.context.scene.objects if x.type=="MESH"][0]; mw=o.matrix_world; vs=[mw@v.co for v in o.data.vertices]
def clusters(pts,cell=0.04):
    grid=defaultdict(list)
    for p in pts: grid[(int(math.floor(p.x/cell)),int(math.floor(p.y/cell)))].append(p)
    seen=set(); out=[]
    for k in grid:
        if k in seen: continue
        st=[k]; seen.add(k); acc=[]
        while st:
            c=st.pop(); acc+=grid[c]
            for dx in (-1,0,1):
                for dy in (-1,0,1):
                    nb=(c[0]+dx,c[1]+dy)
                    if nb in grid and nb not in seen: seen.add(nb); st.append(nb)
        out.append(acc)
    return sorted(out,key=lambda c:-len(c))
for z in (-0.68,-0.58,-0.48):
    cs=clusters([p for p in vs if abs(p.z-z)<0.03])
    print("LEGS z=%.2f:"%z, " ".join("(%.2f,%.2f)n%d"%(sum(p.x for p in c)/len(c),sum(p.y for p in c)/len(c),len(c)) for c in cs[:8]))
# wing membranes: thin, outside the body; find their inner edge (root) per side
body=[p for p in vs if -0.45<p.z<0.35]
for side,f in (("L",lambda p:p.x>0.25),("R",lambda p:p.x<-0.5)):
    w=[p for p in vs if f(p) and p.z>-0.05]
    inner=sorted(w,key=lambda p:abs(p.x))[:max(5,len(w)//20)]
    n=len(inner); print("WING %s n=%d root~(%.2f %.2f %.2f) tip x=%.2f"%(side,len(w),sum(p.x for p in inner)/n,sum(p.y for p in inner)/n,sum(p.z for p in inner)/n,max((abs(p.x) for p in w))))
# body column extents
for z in (0.3,0.15,0.0,-0.15,-0.3,-0.42):
    s=[p for p in vs if abs(p.z-z)<0.02 and -0.52<p.x<0.24]
    if s: print("BODY z=%.2f x %.2f..%.2f y %.2f..%.2f"%(z,min(p.x for p in s),max(p.x for p in s),min(p.y for p in s),max(p.y for p in s)))
