main
John Lauer
Save native two-sided contact artwork and recorded GLB material correction; qualification remains open
57e2489
#!/usr/bin/env python3
"""Isolate opaque ink/substrate materials without changing any mesh bytes."""
import copy,json,re,hashlib
from pathlib import Path
from glb_shape_helpers import read_glb,write_glb
R=Path(__file__).resolve().parents[1];O=R/'mechanical/board23-review';source=O/'board23.glb';g,b=read_glb(source);before=copy.deepcopy(g);changes=[]
for mesh in g['meshes']:
role=(mesh.get('extras') or {}).get('adomBoardLayer')
if not role:
m=re.search(r'_(PCB|silkscreen)(?:[-_.]\d+)?$',mesh.get('name',''),re.I);role=m.group(1).lower() if m else None
if role not in ['pcb','silkscreen']:continue
for prim in mesh['primitives']:
old=prim['material'];mat=copy.deepcopy(g['materials'][old]);mat['name']='OpaqueReview_'+role;mat.setdefault('pbrMetallicRoughness',{}).setdefault('baseColorFactor',[1,1,1,1])[3]=1;mat['alphaMode']='OPAQUE';prim['material']=len(g['materials']);g['materials'].append(mat);changes.append(dict(role=role,mesh=mesh.get('name'),oldMaterial=old,newMaterial=prim['material']))
assert {c['role'] for c in changes}=={'pcb','silkscreen'}
out=O/'board23-opaque-review.glb';write_glb(out,g,b)
report=dict(sourceSha256=hashlib.sha256(source.read_bytes()).hexdigest(),outputSha256=hashlib.sha256(out.read_bytes()).hexdigest(),binaryBufferUnchanged=True,nodesUnchanged=g['nodes']==before['nodes'],accessorsUnchanged=g['accessors']==before['accessors'],changes=changes,status='visual experiment, not source release');(O/'opaque-material-review.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report,indent=2))