master
John Lauer MPN laser etch on the side face (window kept clear) 1f2f3d4 20d ago
#!/usr/bin/env python3
"""Hero PNG for an LED page with the shared Ray-layout template (hero-proposals/_tools/hero_template.html, LED copy
hero_template_led.html adds the optional lens glow). Usage: make_led_hero.py SLUG MPN LENS_R,G,B GLB OUT [json-extra]"""
import json, sys, os, subprocess
LP = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
slug, mpn, lens, glb, out = sys.argv[1:6]; extra = json.loads(sys.argv[6]) if len(sys.argv) > 6 else {}
p = json.load(open(f'{LP}/{slug}/page.json')); comp = p['component']
hexs = '#%02X%02X%02X' % tuple(round(float(v) * 255) for v in lens.split(','))
cfg = dict(glb=glb, dir=[-0.9, -1.3, 1.1], dist=7.6, title=p['title'].split(' - ')[0], mpn=mpn, cat=p['brief'],
           mfr=f"{comp['manufacturer']}  •  {comp['package']}", pill='ADOM BASIC PART',
           foot='Manufacturer datasheet   ·   KiCad library CAD, coloured lens   ·   virtual MPN mark on the side   ·   Adom Wiki',
           lens=hexs, emis=0.0, lensEnv=0.25, noToneMap=False, exposure=0.62)
cfg.update(extra)
html = open(f'{LP}/tools/hero_template_led.html').read().replace('__CFG__', json.dumps(cfg, ensure_ascii=False))
open(f'{LP}/work/{slug}.hero.html', 'w').write(html)
json.dump(cfg, open(f'{LP}/work/{slug}.hero.cfg.json', 'w'), indent=1, ensure_ascii=False)
r = subprocess.run(['node', f'{LP}/_tools/shoot_hero.js', f'http://127.0.0.1:8793/work/{slug}.hero.html', out], capture_output=True, text=True, timeout=200)
print(slug, r.returncode, r.stdout[-300:], r.stderr[-300:])