by adom
2020 Addressable RGB LED · 800 Kbps single-line cascade · 16 mA per channel (V1.0 sheet), 12 mA from V1.2
master
John Lauer
Metal finishing for every GLB; models.json front = the side-wall mark's face
c72418c
16d ago
#!/usr/bin/env python3
"""Make the terminal metal read as metal in every GLB of the WS2812B-2020 page (hero, chip GLB, 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 and 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)))