pixalynx/cm5-minimal-carrier

A 4-layer Raspberry Pi CM5 carrier board routes USB‑C 5V power through an RT9742 load switch with TVS protection and capacitive filtering, while providing ESD-protected HDMI output, CM5 connectors, test points, and ground/power planes.

Version
0.1.1
License
unset
Stars
0

scripts/prepare-cad.py

"""Embed normalized preview meshes, retaining original STEP assets for KiCad."""
import pathlib,base64,json,re
R=pathlib.Path(__file__).resolve().parents[1]
output=json.loads((R/'models/catalog.json').read_text())
for name,model in output.items():
 for field,ext in [('objUrl','.obj'),('mtlUrl','.mtl')]:
  path=R/'models'/model['file'].replace('.step',ext)
  content=path.read_bytes()
  if field=='objUrl':
   # tsCircuit's OBJ loader consumes EasyEDA-style inline material blocks;
   # model_mtl_url alone is not loaded. Keep the separate MTL for other tools.
   mtl=path.with_suffix('.mtl').read_text()
   blocks=re.findall(r'newmtl\s[\s\S]*?(?=\nnewmtl\s|\Z)',mtl)
   content=('\n'.join(block.rstrip()+'\nendmtl' for block in blocks)+'\n').encode()+content
  model[field]='data:text/plain;base64,'+base64.b64encode(content).decode()
 model['cadRotation']=[0,0,0]
 model['cadOffset']=[0,0,0]
(R/'lib/cad-models.json').write_text(json.dumps(output,separators=(',',':'))+'\n')
print('Embedded 3D models for all 15 carrier components')