main
John Lauer Restore both manufacturer terminal occurrences; verify Z-up seating and simplify hero polarity cues c746816
#!/usr/bin/env python3
"""Verify decoded GLB terminal vertices in world coordinates, including instancing transforms."""
from pathlib import Path
import json,struct,numpy as np
P=Path(__file__).resolve().parents[2]
def check(path):
 b=path.read_bytes();n=struct.unpack_from('<I',b,12)[0];j=json.loads(b[20:20+n]);data=b[28+n:]
 def acc(i):
  a=j['accessors'][i];v=j['bufferViews'][a['bufferView']];c={'SCALAR':1,'VEC3':3}[a['type']];dt={5126:'<f4',5122:'<i2',5123:'<u2',5125:'<u4',5121:'u1'}[a['componentType']];dtype=np.dtype(dt);off=v.get('byteOffset',0)+a.get('byteOffset',0);stride=v.get('byteStride',c*dtype.itemsize);ar=np.ndarray((a['count'],c),dtype=dtype,buffer=data,offset=off,strides=(stride,dtype.itemsize)).astype(float)
  if a.get('normalized') and a['componentType']==5122:ar=np.maximum(ar/32767,-1)
  return ar
 def mat(n):
  if 'matrix' in n:return np.array(n['matrix']).reshape(4,4).T
  m=np.eye(4);x,y,z,w=n.get('rotation',[0,0,0,1]);m[:3,:3]=np.array([[1-2*(y*y+z*z),2*(x*y-z*w),2*(x*z+y*w)],[2*(x*y+z*w),1-2*(x*x+z*z),2*(y*z-x*w)],[2*(x*z-y*w),2*(y*z+x*w),1-2*(x*x+y*y)]])@np.diag(n.get('scale',[1,1,1]));m[:3,3]=n.get('translation',[0,0,0]);return m
 terminals=[]
 def walk(i,m):
  n=j['nodes'][i];m=m@mat(n)
  if n.get('name') in ['NAUO3','NAUO4']:
   pts=np.concatenate([acc(p['attributes']['POSITION']) for p in j['meshes'][n['mesh']]['primitives']]);pts=(np.c_[pts,np.ones(len(pts))]@m.T)[:,:3]*1000;bb=np.r_[pts.min(0),pts.max(0)];terminals.append(bb)
  for c in n.get('children',[]):walk(c,m)
 for i in j['scenes'][j.get('scene',0)]['nodes']:walk(i,np.eye(4))
 assert len(terminals)==2
 terminals.sort(key=lambda b:b[0]);expected=[[-3.65,-.325,0,-.6,.325,1],[.6,-.325,0,3.65,.325,1]]
 for b,e in zip(terminals,expected):assert np.max(np.abs(b-e))<.001,(path,b,e)
 return {'status':'PASS','terminal_bounds_mm':[np.round(x,6).tolist() for x in terminals],'tolerance_mm':.001}
r={fn:check(P/fn) for fn in ['eee-fk1v470p.glb','eee-fk1v470p-etched.glb','eee-fk1v470p-hero.glb']};(P/'provenance/glb-terminal-verification.json').write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r))