main
John Lauer Family contract: pipeline 1.0.0 that built the three VL53Lx pages 8e4500f
#!/usr/bin/env python3
"""Post-process a service-step2glb GLB: make the hero artwork materials translucent.
usage: glb_alpha.py in.glb out.glb   (teal -> 0.5, white -> 0.3, light grey -> 0.5, all BLEND, double-sided)
"""
import sys, json, struct

def close(c, ref, tol=0.08):
    return all(abs(a - b) < tol for a, b in zip(c[:3], ref))

RULES = [((0.0, 0.72, 0.69), 0.5, "Adom.PadOutlines"), ((0.97, 0.97, 0.97), 0.3, "Adom.Silkscreen"), ((0.86, 0.86, 0.86), 0.5, "Adom.PadLabels")]

def main(src, dst):
    b = open(src, "rb").read()
    magic, ver, length = struct.unpack_from("<4sII", b, 0)
    assert magic == b"glTF"
    off = 12; chunks = []
    while off < len(b):
        clen, ctype = struct.unpack_from("<II", b, off); chunks.append((ctype, b[off + 8: off + 8 + clen])); off += 8 + clen
    js = json.loads(chunks[0][1].decode("utf-8"))
    changed = 0
    for m in js.get("materials", []):
        pbr = m.get("pbrMetallicRoughness", {}); bc = pbr.get("baseColorFactor")
        if not bc:
            continue
        for ref, alpha, name in RULES:
            if close(bc, ref):
                pbr["baseColorFactor"] = [bc[0], bc[1], bc[2], alpha]; m["alphaMode"] = "BLEND"; m["doubleSided"] = True
                m.setdefault("extras", {})["adomArtwork"] = name; changed += 1
    js.setdefault("asset", {}).setdefault("extras", {})["adomHero"] = {"artwork": [r[2] for r in RULES], "note": "hero-only nonphysical layers"}
    data = json.dumps(js, separators=(",", ":")).encode("utf-8")
    data += b" " * ((4 - len(data) % 4) % 4)
    out = struct.pack("<4sII", b"glTF", 2, 0) + struct.pack("<II", len(data), 0x4E4F534A) + data
    for ctype, payload in chunks[1:]:
        payload += b"\0" * ((4 - len(payload) % 4) % 4)
        out += struct.pack("<II", len(payload), ctype) + payload
    out = out[:8] + struct.pack("<I", len(out)) + out[12:]
    open(dst, "wb").write(out)
    print(f"materials adjusted: {changed}, nodes: {len(js.get('nodes', []))}, named: {[n.get('name') for n in js.get('nodes', []) if n.get('name')][:12]}")

if __name__ == "__main__":
    main(sys.argv[1], sys.argv[2])