main
John Lauer 3D model rev B: molded package + lens cavity + RGB/IC dies + terminals + pin-1 notch (AI-created, CadQuery; bbox/verifi… e9e9df5
#!/usr/bin/env python3
"""
Dialight 587-1024-147F — improved AI-created 3D model (rev B).
2.0x2.0x0.9mm 2020 addressable RGB LED:
  - molded epoxy package with a recessed lens cavity on top
  - clear lens over the cavity
  - R/G/B emitter dies + tiny control-IC die visible in the cavity
  - 4 terminals (pad 1 DOUT at -x,-y with pin-1 chamfer marker)
Geometry per Dialight datasheet "587-1024-147F Addressable RGB" (rev Jan 2024):
  p.1 body 2.0x2.0x0.9, terminals 0.6x0.6 on 1.4mm pitch (centers +/-0.70).
  Lens/cavity/dies are AI approximations for a recognisable part look — recorded
  as such in the page provenance (no manufacturer CAD exists).
Outputs: 587-1024-147f.step (multi-body), 587-1024-147f.glb (with materials),
         render-iso.png / render-top.png (verification views)
"""
import cadquery as cq
import math

BODY = 2.0
H = 0.9
BEV = 0.12          # edge chamfer on the molded body
TERM = 0.6
TERM_PITCH_HALF = 0.70
TERM_H = 0.08       # terminal standoff
CAV = 1.30          # lens cavity width
CAV_DEPTH = 0.28
DIE = 0.22

# ---- molded body with cavity
body = (
    cq.Workplane("XY")
    .box(BODY, BODY, H, centered=(True, True, False))
    .edges("|Z")
    .chamfer(BEV / 2)
)
cavity = (
    cq.Workplane("XY")
    .box(CAV, CAV, CAV_DEPTH, centered=(True, True, False))
    .translate((0, 0, H - CAV_DEPTH))
)
body = body.cut(cavity)

# ---- dies in the cavity: R, G, B emitters in a row + IC die beside
dies = []
for k, dx in enumerate((-0.36, 0.0, 0.36)):
    dies.append(
        cq.Workplane("XY")
        .box(DIE, DIE * 1.6, 0.06, centered=(True, True, False))
        .translate((dx, -0.18, H - CAV_DEPTH))
    )
ic = (
    cq.Workplane("XY")
    .box(0.5, 0.34, 0.06, centered=(True, True, False))
    .translate((0.05, 0.32, H - CAV_DEPTH))
)
dies.append(ic)
die_assy = dies[0]
for d in dies[1:]:
    die_assy = die_assy.union(d)

# ---- clear lens over the cavity (slightly domed top)
lens = (
    cq.Workplane("XY")
    .box(CAV + 0.06, CAV + 0.06, 0.10, centered=(True, True, False))
    .translate((0, 0, H - 0.10))
)
dome = (
    cq.Workplane("XY")
    .sphere(1.1)
    .translate((0, 0, H - 1.05))
)
lens_dome = lens.intersect(dome) if True else lens
try:
    lens = lens.intersect(dome)
except Exception:
    pass

# ---- terminals: 4 pads 0.6x0.6 at (+/-0.70, +/-0.70), 0.08 standoff
terms = []
for sx in (-1, 1):
    for sy in (-1, 1):
        terms.append(
            cq.Workplane("XY")
            .box(TERM, TERM, TERM_H + 0.02, centered=(True, True, False))
            .translate((sx * TERM_PITCH_HALF, sy * TERM_PITCH_HALF, -TERM_H))
        )
term_assy = terms[0]
for t in terms[1:]:
    term_assy = term_assy.union(t)

# ---- pin-1 marker: small chamfered corner notch on the package top at (-x,-y)
mark = (
    cq.Workplane("XY")
    .box(0.22, 0.22, 0.04, centered=(True, True, False))
    .translate((-BODY / 2 + 0.18, -BODY / 2 + 0.18, H - 0.04))
)
body = body.cut(mark)

# ---- assemble with colors (per-solid colour attributes for STEP/GLB)
asm = cq.Assembly()
asm.add(body, name="package", color=cq.Color(0.05, 0.05, 0.06))
asm.add(lens, name="lens", color=cq.Color(0.85, 0.92, 0.98, 0.35))
rgb = [(0.9, 0.05, 0.05), (0.05, 0.75, 0.15), (0.1, 0.25, 0.95)]
for k, dx in enumerate((-0.36, 0.0, 0.36)):
    asm.add(dies[k], name=f"die_{'RGB'[k]}", color=cq.Color(*rgb[k]))
asm.add(ic, name="die_ic", color=cq.Color(0.55, 0.55, 0.6))
asm.add(term_assy, name="terminals", color=cq.Color(0.85, 0.8, 0.65))

asm.export("/home/adom/project/adom-led-grid/parts/dialight-587-1024-147f/page/587-1024-147f.step")
asm.export("/home/adom/project/adom-led-grid/parts/dialight-587-1024-147f/page/587-1024-147f.glb")

# ---- verification renders
try:
    from cadquery import exporters
    for name, proj in [("iso", (1, -1, 1)), ("top", (0, 0, 1))]:
        exporters.export(
            asm,
            f"/home/adom/project/adom-led-grid/parts/dialight-587-1024-147f/page/render-{name}.svg",
            opt={"projectionDir": proj, "width": 600, "height": 480, "showAxes": False},
        )
        print("rendered", name)
except Exception as e:
    print("render skipped:", e)

# ---- bbox check
bb = asm.toCompound().BoundingBox()
print("bbox x", round(bb.xlen, 3), "y", round(bb.ylen, 3), "z", round(bb.zlen, 3),
      "floor", round(bb.zmin, 3), "top", round(bb.zmax, 3))