abse/gameboy-advance

Validates and exports a four-layer Game Boy–style PCB assembly with RP2350 MCU, 32MB flash, USB-C, LCD and speaker connectors, battery buck-boost power, buttons, and verified routing, connectivity, clearances, CAD models, and physical DRC.

Version
0.0.39
License
unset
Stars
0

checks/usb-cad-validation.ts

PCBPCB preview for checks/usb-cad-validation.ts
SchematicSchematic preview for checks/usb-cad-validation.ts
import {convertCircuitJsonTo3D,convertSceneToGLTF} from 'circuit-json-to-gltf'
const c=await Bun.file('dist/index/circuit.json').json();const cad=c.find((e:any)=>e.type==='cad_component'&&e.source_component_id==='source_component_5');const model=Bun.file('imports/TYPE_C_31_M_12/TYPE_C_31_M_12.obj');cad.model_obj_url='data:text/plain;base64,'+Buffer.from(await model.arrayBuffer()).toString('base64');const filtered=c.filter((e:any)=>e.type==='pcb_board'||e.source_component_id==='source_component_5'||e.pcb_component_id==='pcb_component_5');const scene=await convertCircuitJsonTo3D(filtered,{renderBoardTextures:false});const mesh=scene.boxes.find((b:any)=>b.mesh?.triangles.length>=18000)?.mesh;if(!mesh||mesh.triangles.length<18000)throw Error('Imported mesh missing');await Bun.write('dist/index/usb-cad-validation.json',JSON.stringify({importedMeshTriangles:mesh.triangles.length,boxCount:scene.boxes.length,modelOrigin:cad.model_origin_position,modelPosition:cad.position},null,2));console.log('Imported mesh triangles',mesh.triangles.length);const out=await convertSceneToGLTF(scene,{binary:true});if(!(out instanceof ArrayBuffer))throw Error('Expected GLB');await Bun.write('dist/index/usb-imported-model.glb',out);console.log('Imported model GLB exported',out.byteLength)