by adom
0402 Thick Film Resistor · 4.7 kΩ ±1% · 1/16 W
master
John Lauer
WS2812B standard: metal terminals, datasheet PDF, distributors, verification log, 3D models record, solder balls, outli…
0262513
17d ago
#!/usr/bin/env python3
"""Make the terminal metal read as metal in every GLB of a component page (hero, chip GLBs, scenes).
STEP colours carry no metalness, so step2glb writes the tinned terminals (sRGB 0.80, 0.81, 0.83; linear
0.604, 0.621, 0.656) as a plain grey. This sets every material of that colour (the castellations, bottom pads,
top-side terminals, lead-frame stubs) to metallicFactor 0.9, roughnessFactor 0.25: bright tinned metal against
the white insulation. Idempotent. usage: glb_post_metal.py FILE.glb [...]"""
import json, struct, sys
METAL = (0.6038, 0.6209, 0.6559)
def read_glb(p):
b = open(p, "rb").read(); n = struct.unpack("<I", b[12:16])[0]; js = json.loads(b[20:20 + n]); o = 20 + n
return js, b[o:]
for p in sys.argv[1:]:
js, rest = read_glb(p); n = 0
for m in js.get("materials", []):
pbr = m.setdefault("pbrMetallicRoughness", {}); c = (pbr.get("baseColorFactor") or [1, 1, 1, 1])[:3]
if max(abs(a - b) for a, b in zip(c, METAL)) < 2e-3 or m.get("name") == "terminal_tinned":
pbr.update(metallicFactor=0.9, roughnessFactor=0.25); n += 1
j = json.dumps(js, separators=(",", ":")).encode(); j += b" " * (-len(j) % 4)
body = struct.pack("<II", len(j), 0x4E4F534A) + j + rest
open(p, "wb").write(struct.pack("<III", 0x46546C67, 2, 12 + len(body)) + body)
print(json.dumps(dict(glb=p, metal_materials=n)))