MustafaMulla29/rp2040-bldc-motor-controller-new

73×72 mm 4-layer USB‑C PD (5/9/15/20 V) RP2040 controller PCB with protected power switching, MCT8329A sensorless BLDC three-phase MOSFET bridge, USB data/programming, onboard controls, and three motor outputs feeding a 2212 motor through rigid bullet adapters.

Version
0.3.100
License
unset
Stars
0

assembly/generate-adapter-assets.ts

import {rigidAdapterMeshes} from "./models"
import {dimensions} from "./dimensions"
import {mkdir,writeFile} from "node:fs/promises"
import modeling from "@jscad/modeling"
import {convertJscadModelToGltf} from "jscad-to-gltf"
await mkdir(new URL("dist/assets/",import.meta.url),{recursive:true})
{
  const meshes=rigidAdapterMeshes()
  let offset=0,obj="# Rigid BDHI-style adapter; body dimensions UNVERIFIED. Adapter-local +Z toward motor, mm.\nmtllib rigid-adapter.mtl\n"
  for(const [i,mesh] of meshes.entries()) {
    obj+=`o part_${i}\nusemtl ${mesh.material}\n`+mesh.points.map(p=>`v ${p.join(" ")}`).join("\n")+"\n"+
      mesh.faces.map(face=>`f ${face.map(v=>v+offset+1).join(" ")}`).join("\n")+"\n"
    offset+=mesh.points.length
  }
  await writeFile(new URL("dist/assets/rigid-adapter.obj",import.meta.url),obj)
  // Native CAD models use millimetres and +Z above the board. Keep this local
  // frame explicit; the circuit exporter handles CAD-to-viewer coordinates.
  const {geom3,poly3}=modeling.geometries
  const glb=await convertJscadModelToGltf({geometries:meshes.map(mesh=>({
    geom:geom3.create(mesh.faces.map(face=>poly3.create(face.map(i=>mesh.points[i])))),
    color:mesh.material==="gold"?[0.83,0.64,0.22,1]:[0.77,0.17,0.24,1]
  }))},{format:"glb",meshName:"RigidAdapter",axisTransform:"none"})
  await writeFile(new URL("dist/assets/rigid-adapter.glb",import.meta.url),Buffer.from(glb.data as ArrayBuffer))
}
await writeFile(new URL("dist/assets/rigid-adapter.mtl",import.meta.url),"newmtl gold\nKd 0.83 0.64 0.22\nKs 0.8 0.8 0.8\nNs 100\nnewmtl red_sleeve\nKd 0.77 0.17 0.24\nKs 0.03 0.03 0.03\nNs 10\n")
await writeFile(new URL("dist/assets/rigid-adapter.provenance.json",import.meta.url),JSON.stringify({
  generator:"jscad-electronics/cables createCableMeshes; @jscad/modeling primitives",
  contactMeshes:["A-bullet-pin","A-bullet-socket"],
  pr:"https://github.com/tscircuit/jscad-electronics/pull/423",dimensions:dimensions.adapter,
  note:"Motor male bullets and wires are generated separately by native assembly.cable. Adapter end diameters are nominal listing sizes; all other adapter dimensions remain illustrative."
},null,2)+"\n")