main
John Lauer Add KiCad symbol and footprint, viewers, provenance, README, models.json and verification log 354b2dd 11h ago
#!/usr/bin/env python3
"""Physical materials for the MLX90614 TO-39 GLB, per part (node names come from the STEP assembly).
step2glb writes base colours only (glTF then defaults to metallic 1, roughness 1).
  body            -> "Adom.Can (nickel-plated steel)": metallic 1.0, roughness 0.30
  pins            -> "Adom.Leads (tin)": metallic 1.0, roughness 0.35
  beads           -> "Adom.Glass beads": metallic 0.0, roughness 0.15
  window          -> "Adom.Optics (dark)": metallic 0.0, roughness 0.4
  Adom.LaserEtch  -> "Adom.LaserEtch (dark laser mark)": metallic 0.2, roughness 0.8
Geometry and node transforms are untouched.  usage: materials_to39.py in.glb [out.glb]"""
import sys
from pygltflib import GLTF2
SPEC = {"body": ("Adom.Can (nickel-plated steel)", 1.0, 0.30, [0.62, 0.62, 0.60, 1.0]),
        "pins": ("Adom.Leads (tin)", 1.0, 0.35, [0.72, 0.72, 0.70, 1.0]),
        "beads": ("Adom.Glass beads", 0.0, 0.15, None),
        "window": ("Adom.Optics (dark)", 0.0, 0.40, None),
        "Adom.LaserEtch": ("Adom.LaserEtch (dark laser mark)", 0.2, 0.80, None)}
src = sys.argv[1]; out = sys.argv[2] if len(sys.argv) > 2 else src
g = GLTF2().load(src)
seen = set()
for n in g.nodes:
    if n.mesh is None: continue
    key = next((k for k in SPEC if (n.name or "").startswith(k)), None)
    if key is None: continue
    for p in g.meshes[n.mesh].primitives:
        name, metal, rough, col = SPEC[key]
        m = g.materials[p.material]; pbr = m.pbrMetallicRoughness
        pbr.metallicFactor, pbr.roughnessFactor = metal, rough
        if col: pbr.baseColorFactor = col
        m.name = name; seen.add(key)
missing = [k for k in ("body", "pins") if k not in seen]
if missing: sys.exit(f"ERROR: no {missing} node in {src}")
g.save(out); print("OK", out, sorted(seen))