|
| 1 | +import * as geom3 from "@jscad/modeling/src/geometries/geom3" |
| 2 | +import measureBoundingBox from "@jscad/modeling/src/measurements/measureBoundingBox" |
| 3 | +import { subtract } from "@jscad/modeling/src/operations/booleans" |
| 4 | +import { rotateX } from "@jscad/modeling/src/operations/transforms" |
| 5 | +import type { PcbBoard, PcbHole, PcbPanel, PcbPlatedHole } from "circuit-json" |
| 6 | +import type { STLMesh } from "../types" |
| 7 | +import { batchedUnion } from "./batched-union" |
| 8 | +import type { BoardCutout } from "./pcb-board-cutouts" |
| 9 | +import { createCutoutGeoms } from "./pcb-board-cutouts" |
| 10 | +import { |
| 11 | + createBoardOutlineGeom, |
| 12 | + createBoundingBox, |
| 13 | + createHoleGeoms, |
| 14 | + geom3ToTriangles, |
| 15 | +} from "./pcb-board-geometry" |
| 16 | + |
| 17 | +export const cutBoardMeshOutsideBoardBoundary = ({ |
| 18 | + board, |
| 19 | + center, |
| 20 | + thickness, |
| 21 | + holes, |
| 22 | + platedHoles, |
| 23 | + cutouts, |
| 24 | + segments, |
| 25 | +}: { |
| 26 | + board: PcbPanel | PcbBoard |
| 27 | + center: { x: number; y: number } |
| 28 | + thickness: number |
| 29 | + holes: PcbHole[] |
| 30 | + platedHoles: PcbPlatedHole[] |
| 31 | + cutouts: BoardCutout[] |
| 32 | + segments: number |
| 33 | +}): STLMesh => { |
| 34 | + let boardGeom = createBoardOutlineGeom(board, center, thickness) |
| 35 | + const subtractGeoms = [ |
| 36 | + ...createHoleGeoms(center, thickness, holes, platedHoles, segments), |
| 37 | + ...createCutoutGeoms(center, thickness, cutouts, segments), |
| 38 | + ] |
| 39 | + |
| 40 | + if (subtractGeoms.length > 0) { |
| 41 | + boardGeom = subtract(boardGeom, batchedUnion(subtractGeoms)) |
| 42 | + } |
| 43 | + |
| 44 | + boardGeom = rotateX(-Math.PI / 2, boardGeom) |
| 45 | + |
| 46 | + const polygons = geom3.toPolygons(boardGeom) |
| 47 | + return { |
| 48 | + triangles: geom3ToTriangles(boardGeom, polygons), |
| 49 | + boundingBox: createBoundingBox(measureBoundingBox(boardGeom)), |
| 50 | + } |
| 51 | +} |
0 commit comments