circuit-json-to-gltf 0.0.113 → 0.0.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -70,8 +70,13 @@ convertCircuitJsonToGltf(circuitJson: CircuitJson, options?: ConversionOptions):
70
70
  - `drawFauxBoard`: Draw a fallback board if no `pcb_board` or `pcb_panel` is present - default: false
71
71
  - `includeModels`: Whether to load external 3D models - default: true
72
72
  - `modelCache`: Map for caching loaded models
73
- - `backgroundColor`: Background color for board rendering
74
- - `showBoundingBoxes`: Show bounding boxes for debugging
73
+ - `backgroundColor`: Board texture background color
74
+ - `boardSideColor`: Physical substrate/edge color (defaults to `backgroundColor` when customized)
75
+ - `copperColor`: Exposed copper color in board textures
76
+ - `silkscreenColor`: Silkscreen color in board textures
77
+ - `solderMaskWithCopperColor`: Color of traces and copper covered by solder mask
78
+ - `drillColor`: Drill opening color in board textures
79
+ - `showBoundingBoxes`: Show bounding boxes for debugging (default: `false`)
75
80
  - `projectBaseUrl`: Optional base URL used to resolve `node_modules` model assets via `/package_files/download`
76
81
  - `authHeaders`: Optional auth headers for model downloads, e.g. `{ Authorization: "Bearer ..." }`
77
82
 
package/dist/index.d.ts CHANGED
@@ -12,6 +12,11 @@ interface ConversionOptions {
12
12
  includeModels?: boolean;
13
13
  modelCache?: Map<string, STLMesh | OBJMesh>;
14
14
  backgroundColor?: string;
15
+ boardSideColor?: Color;
16
+ copperColor?: string;
17
+ silkscreenColor?: string;
18
+ solderMaskWithCopperColor?: string;
19
+ drillColor?: string;
15
20
  showBoundingBoxes?: boolean;
16
21
  coordinateTransform?: CoordinateTransformConfig;
17
22
  projectBaseUrl?: string;
@@ -74,6 +79,7 @@ interface Box3D {
74
79
  size: Size3;
75
80
  rotation?: Point3;
76
81
  color?: Color;
82
+ sideColor?: Color;
77
83
  texture?: {
78
84
  top?: string;
79
85
  bottom?: string;
@@ -121,8 +127,12 @@ interface GLTFExportOptions {
121
127
  }
122
128
  interface CircuitTo3DOptions {
123
129
  pcbColor?: Color;
130
+ boardSideColor?: Color;
124
131
  componentColor?: Color;
125
132
  copperColor?: Color;
133
+ silkscreenColor?: string;
134
+ solderMaskWithCopperColor?: string;
135
+ drillColor?: string;
126
136
  boardThickness?: number;
127
137
  boardDrillQuality?: "high" | "fast";
128
138
  drawFauxBoard?: boolean;
@@ -141,16 +151,14 @@ interface BoardRenderOptions {
141
151
  backgroundColor?: string;
142
152
  copperColor?: string;
143
153
  silkscreenColor?: string;
154
+ solderMaskWithCopperColor?: string;
144
155
  padColor?: string;
145
156
  drillColor?: string;
146
157
  showPcbNotes?: boolean;
147
158
  }
148
159
 
149
160
  declare function renderBoardLayer(circuitJson: CircuitJson, options: BoardRenderOptions): Promise<string>;
150
- declare function renderBoardTextures(circuitJson: CircuitJson, { resolution, showPcbNotes }: {
151
- resolution?: number | undefined;
152
- showPcbNotes?: boolean | undefined;
153
- }): Promise<{
161
+ declare function renderBoardTextures(circuitJson: CircuitJson, { resolution, backgroundColor, copperColor, silkscreenColor, solderMaskWithCopperColor, drillColor, showPcbNotes, }: Omit<BoardRenderOptions, "layer">): Promise<{
154
162
  top: string;
155
163
  bottom: string;
156
164
  }>;
package/dist/index.js CHANGED
@@ -16530,6 +16530,7 @@ async function renderBoardLayer(circuitJson, options) {
16530
16530
  backgroundColor = "transparent",
16531
16531
  copperColor = "#ffe066",
16532
16532
  silkscreenColor = "#ffffff",
16533
+ solderMaskWithCopperColor = "#69e778ff",
16533
16534
  drillColor = "rgba(0,0,0,0.5)",
16534
16535
  showPcbNotes = false
16535
16536
  } = options;
@@ -16550,8 +16551,8 @@ async function renderBoardLayer(circuitJson, options) {
16550
16551
  bottom: silkscreenColor
16551
16552
  },
16552
16553
  soldermaskWithCopperUnderneath: {
16553
- top: "#69e778ff",
16554
- bottom: "#69e778ff"
16554
+ top: solderMaskWithCopperColor,
16555
+ bottom: solderMaskWithCopperColor
16555
16556
  },
16556
16557
  drill: drillColor
16557
16558
  }
@@ -16607,19 +16608,33 @@ async function convertSvgToCanvasBrowser(svgString, resolution, backgroundColor)
16607
16608
  img.src = svgDataUrl;
16608
16609
  });
16609
16610
  }
16610
- async function renderBoardTextures(circuitJson, { resolution = 1024, showPcbNotes = false }) {
16611
+ async function renderBoardTextures(circuitJson, {
16612
+ resolution = 1024,
16613
+ backgroundColor = "#0F3812",
16614
+ copperColor,
16615
+ silkscreenColor,
16616
+ solderMaskWithCopperColor,
16617
+ drillColor,
16618
+ showPcbNotes = false
16619
+ }) {
16611
16620
  const top = await renderBoardLayer(circuitJson, {
16612
16621
  layer: "top",
16613
16622
  resolution,
16614
- backgroundColor: "#0F3812",
16615
- // Green PCB background
16623
+ backgroundColor,
16624
+ copperColor,
16625
+ silkscreenColor,
16626
+ solderMaskWithCopperColor,
16627
+ drillColor,
16616
16628
  showPcbNotes
16617
16629
  });
16618
16630
  const bottom = await renderBoardLayer(circuitJson, {
16619
16631
  layer: "bottom",
16620
16632
  resolution,
16621
- backgroundColor: "#0F3812",
16622
- // Darker green for bottom layer
16633
+ backgroundColor,
16634
+ copperColor,
16635
+ silkscreenColor,
16636
+ solderMaskWithCopperColor,
16637
+ drillColor,
16623
16638
  showPcbNotes
16624
16639
  });
16625
16640
  return { top, bottom };
@@ -16647,8 +16662,12 @@ function convertCadSizeToSceneSize(size) {
16647
16662
  async function convertCircuitJsonTo3D(circuitJson, options = {}) {
16648
16663
  const {
16649
16664
  pcbColor = "rgba(0,140,0,0.8)",
16665
+ boardSideColor,
16650
16666
  componentColor = "rgba(128,128,128,0.5)",
16651
16667
  copperColor = "#C87B4B",
16668
+ silkscreenColor,
16669
+ solderMaskWithCopperColor,
16670
+ drillColor,
16652
16671
  boardThickness = DEFAULT_BOARD_THICKNESS,
16653
16672
  boardDrillQuality = "fast",
16654
16673
  drawFauxBoard = false,
@@ -16657,12 +16676,20 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
16657
16676
  textureResolution = 1024,
16658
16677
  showPcbNotes = false,
16659
16678
  coordinateTransform,
16660
- showBoundingBoxes = true,
16679
+ showBoundingBoxes = false,
16661
16680
  projectBaseUrl,
16662
16681
  authHeaders
16663
16682
  } = options;
16664
16683
  const db = cju(circuitJson);
16665
16684
  const boxes = [];
16685
+ const resolvedBoardSideColor = boardSideColor ?? (options.pcbColor !== void 0 ? pcbColor : void 0);
16686
+ const boardTextureColors = {
16687
+ ...typeof options.pcbColor === "string" ? { backgroundColor: options.pcbColor } : {},
16688
+ ...typeof options.copperColor === "string" ? { copperColor: options.copperColor } : {},
16689
+ silkscreenColor,
16690
+ solderMaskWithCopperColor,
16691
+ drillColor
16692
+ };
16666
16693
  const pcbPanel = db.pcb_panel?.list?.()[0];
16667
16694
  const pcbBoard = db.pcb_board?.list?.()[0];
16668
16695
  const pcbComponents = db.pcb_component?.list?.() ?? [];
@@ -16693,13 +16720,15 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
16693
16720
  z: Number.isFinite(meshHeight) ? meshHeight : pcbPanel.height
16694
16721
  },
16695
16722
  mesh: panelMesh,
16696
- color: pcbColor
16723
+ color: pcbColor,
16724
+ sideColor: resolvedBoardSideColor
16697
16725
  };
16698
16726
  if (shouldRenderTextures && textureResolution > 0) {
16699
16727
  try {
16700
16728
  const textures = await renderBoardTextures(circuitJson, {
16701
16729
  resolution: textureResolution,
16702
- showPcbNotes
16730
+ showPcbNotes,
16731
+ ...boardTextureColors
16703
16732
  });
16704
16733
  panelBox.texture = {
16705
16734
  top: textures.top,
@@ -16739,13 +16768,15 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
16739
16768
  z: Number.isFinite(meshHeight) ? meshHeight : pcbBoard.height
16740
16769
  },
16741
16770
  mesh: boardMesh,
16742
- color: pcbColor
16771
+ color: pcbColor,
16772
+ sideColor: resolvedBoardSideColor
16743
16773
  };
16744
16774
  if (shouldRenderTextures && textureResolution > 0) {
16745
16775
  try {
16746
16776
  const textures = await renderBoardTextures(circuitJson, {
16747
16777
  resolution: textureResolution,
16748
- showPcbNotes
16778
+ showPcbNotes,
16779
+ ...boardTextureColors
16749
16780
  });
16750
16781
  boardBox.texture = {
16751
16782
  top: textures.top,
@@ -16783,7 +16814,8 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
16783
16814
  y: effectiveBoardThickness,
16784
16815
  z: fauxHeight
16785
16816
  },
16786
- color: pcbColor
16817
+ color: pcbColor,
16818
+ sideColor: resolvedBoardSideColor
16787
16819
  };
16788
16820
  if (shouldRenderTextures && textureResolution > 0) {
16789
16821
  try {
@@ -16803,7 +16835,8 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
16803
16835
  ];
16804
16836
  const textures = await renderBoardTextures(fauxBoardCircuitJson, {
16805
16837
  resolution: textureResolution,
16806
- showPcbNotes
16838
+ showPcbNotes,
16839
+ ...boardTextureColors
16807
16840
  });
16808
16841
  fauxBoardBox.texture = {
16809
16842
  top: textures.top,
@@ -17880,7 +17913,7 @@ var GLTFBuilder = class {
17880
17913
  });
17881
17914
  }
17882
17915
  if (sideTriangles.length > 0) {
17883
- const sideMaterialIndex = this.addMaterial({
17916
+ const sideMaterialIndex = box.sideColor ? this.addMaterialFromColor({ color: box.sideColor }) : this.addMaterial({
17884
17917
  name: `GreenSideMaterial_${this.materials.length}`,
17885
17918
  pbrMetallicRoughness: {
17886
17919
  baseColorFactor: [0.04, 0.16, 0.08, 1],
@@ -18037,20 +18070,19 @@ var GLTFBuilder = class {
18037
18070
  } else {
18038
18071
  faceMaterials.bottom = defaultMaterialIndex;
18039
18072
  }
18040
- const greenMaterialIndex = this.addMaterial({
18073
+ const sideMaterialIndex = box.sideColor ? this.addMaterialFromColor({ color: box.sideColor }) : this.addMaterial({
18041
18074
  name: `GreenSideMaterial_${this.materials.length}`,
18042
18075
  pbrMetallicRoughness: {
18043
18076
  baseColorFactor: [0.04, 0.16, 0.08, 1],
18044
- // Green color for PCB sides
18045
18077
  metallicFactor: 0,
18046
18078
  roughnessFactor: 0.8
18047
18079
  },
18048
18080
  alphaMode: "OPAQUE"
18049
18081
  });
18050
- faceMaterials.front = greenMaterialIndex;
18051
- faceMaterials.back = greenMaterialIndex;
18052
- faceMaterials.left = greenMaterialIndex;
18053
- faceMaterials.right = greenMaterialIndex;
18082
+ faceMaterials.front = sideMaterialIndex;
18083
+ faceMaterials.back = sideMaterialIndex;
18084
+ faceMaterials.left = sideMaterialIndex;
18085
+ faceMaterials.right = sideMaterialIndex;
18054
18086
  const meshIndex = this.meshes.length;
18055
18087
  const primitives = [];
18056
18088
  for (const [faceName, faceData] of Object.entries(faceMeshes)) {
@@ -18636,6 +18668,11 @@ async function convertCircuitJsonToGltf(circuitJson, options = {}) {
18636
18668
  includeModels = true,
18637
18669
  modelCache,
18638
18670
  backgroundColor,
18671
+ boardSideColor,
18672
+ copperColor,
18673
+ silkscreenColor,
18674
+ solderMaskWithCopperColor,
18675
+ drillColor,
18639
18676
  showBoundingBoxes = false
18640
18677
  } = options;
18641
18678
  const scene3D = await convertCircuitJsonTo3D(circuitJson, {
@@ -18644,6 +18681,12 @@ async function convertCircuitJsonToGltf(circuitJson, options = {}) {
18644
18681
  showPcbNotes,
18645
18682
  boardDrillQuality,
18646
18683
  drawFauxBoard,
18684
+ pcbColor: backgroundColor,
18685
+ boardSideColor,
18686
+ copperColor,
18687
+ silkscreenColor,
18688
+ solderMaskWithCopperColor,
18689
+ drillColor,
18647
18690
  coordinateTransform: options.coordinateTransform,
18648
18691
  showBoundingBoxes,
18649
18692
  projectBaseUrl: options.projectBaseUrl,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "circuit-json-to-gltf",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.113",
5
+ "version": "0.0.115",
6
6
  "scripts": {
7
7
  "test": "bun test tests/",
8
8
  "test:playwright": "playwright test",