circuit-json-to-gltf 0.0.144 → 0.0.145

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.
Files changed (2) hide show
  1. package/dist/index.js +91 -103
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18399,7 +18399,8 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
18399
18399
  drillColor
18400
18400
  };
18401
18401
  const pcbPanel = db.pcb_panel?.list?.()[0];
18402
- const pcbBoard = db.pcb_board?.list?.()[0];
18402
+ const pcbBoards = db.pcb_board?.list?.() ?? [];
18403
+ const pcbBoard = pcbBoards[0];
18403
18404
  const pcbComponents = db.pcb_component?.list?.() ?? [];
18404
18405
  const bends = inputCircuitJson.filter(
18405
18406
  (e) => e.type === "pcb_bend"
@@ -18469,81 +18470,96 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
18469
18470
  panelBox.color = resolvedPcbColor;
18470
18471
  }
18471
18472
  boxes.push(panelBox);
18472
- } else if (pcbBoard) {
18473
- const pcbHoles = db.pcb_hole?.list?.() ?? [];
18474
- const pcbPlatedHoles = db.pcb_plated_hole?.list?.() ?? [];
18475
- const pcbCutouts = db.pcb_cutout?.list?.() ?? [];
18476
- const boardCutouts = filterCutoutsForBoard(pcbCutouts, pcbBoard);
18477
- const boardMesh = createBoardMesh(pcbBoard, {
18478
- thickness: effectiveBoardThickness,
18479
- holes: pcbHoles,
18480
- platedHoles: pcbPlatedHoles,
18481
- cutouts: boardCutouts,
18482
- drillQuality: boardDrillQuality
18483
- });
18484
- const meshWidth = boardMesh.boundingBox.max.x - boardMesh.boundingBox.min.x;
18485
- const meshHeight = boardMesh.boundingBox.max.z - boardMesh.boundingBox.min.z;
18486
- let foldedBoardMesh = boardMesh;
18487
- if (foldPcbs && bends.length) {
18488
- const foldResult = tryCreatePcbFold(bends, effectiveBoardThickness, {
18489
- // Match flex-utils' getCadFoldContext: translate circuit-world XY mm
18490
- // into board-local +Z-up points before the shared surface deformation.
18491
- outline: pcbBoard.outline?.map((point) => ({
18492
- x: point.x - pcbBoard.center.x,
18493
- y: point.y - pcbBoard.center.y
18494
- }))
18473
+ } else if (pcbBoards.length) {
18474
+ for (const pcbBoard2 of pcbBoards) {
18475
+ const effectiveBoardThickness2 = pcbBoard2.thickness ?? boardThickness;
18476
+ const boardCircuitJson = circuitJson.filter((element) => {
18477
+ if (element.type === "pcb_board")
18478
+ return element.pcb_board_id === pcbBoard2.pcb_board_id;
18479
+ if (!element.type.startsWith("pcb_")) return true;
18480
+ if (element.pcb_board_id)
18481
+ return element.pcb_board_id === pcbBoard2.pcb_board_id;
18482
+ return pcbBoards.length === 1 || element.subcircuit_id === pcbBoard2.subcircuit_id;
18495
18483
  });
18496
- if (foldResult.ok) {
18497
- const meshResult = tryFoldBoardMesh(boardMesh, foldResult.value);
18498
- if (meshResult.ok) {
18499
- fold = foldResult.value;
18500
- foldedBoardMesh = meshResult.value;
18484
+ const boardDb = cju(boardCircuitJson);
18485
+ const pcbHoles = boardDb.pcb_hole?.list?.() ?? [];
18486
+ const pcbPlatedHoles = boardDb.pcb_plated_hole?.list?.() ?? [];
18487
+ const pcbCutouts = boardDb.pcb_cutout?.list?.() ?? [];
18488
+ const boardCutouts = filterCutoutsForBoard(pcbCutouts, pcbBoard2);
18489
+ const boardMesh = createBoardMesh(pcbBoard2, {
18490
+ thickness: effectiveBoardThickness2,
18491
+ holes: pcbHoles,
18492
+ platedHoles: pcbPlatedHoles,
18493
+ cutouts: boardCutouts,
18494
+ drillQuality: boardDrillQuality
18495
+ });
18496
+ const meshWidth = boardMesh.boundingBox.max.x - boardMesh.boundingBox.min.x;
18497
+ const meshHeight = boardMesh.boundingBox.max.z - boardMesh.boundingBox.min.z;
18498
+ let foldedBoardMesh = boardMesh;
18499
+ if (foldPcbs && bends.length) {
18500
+ const foldResult = tryCreatePcbFold(bends, effectiveBoardThickness2, {
18501
+ // Match flex-utils' getCadFoldContext: translate circuit-world XY mm
18502
+ // into board-local +Z-up points before the shared surface deformation.
18503
+ outline: pcbBoard2.outline?.map((point) => ({
18504
+ x: point.x - pcbBoard2.center.x,
18505
+ y: point.y - pcbBoard2.center.y
18506
+ }))
18507
+ });
18508
+ if (foldResult.ok) {
18509
+ const meshResult = tryFoldBoardMesh(boardMesh, foldResult.value);
18510
+ if (meshResult.ok) {
18511
+ fold = foldResult.value;
18512
+ foldedBoardMesh = meshResult.value;
18513
+ } else {
18514
+ reportFoldIssue(
18515
+ `PCB board ${pcbBoard2.pcb_board_id}`,
18516
+ meshResult.issue
18517
+ );
18518
+ }
18501
18519
  } else {
18502
18520
  reportFoldIssue(
18503
- `PCB board ${pcbBoard.pcb_board_id}`,
18504
- meshResult.issue
18521
+ `PCB board ${pcbBoard2.pcb_board_id}`,
18522
+ foldResult.issue
18505
18523
  );
18506
18524
  }
18507
- } else {
18508
- reportFoldIssue(`PCB board ${pcbBoard.pcb_board_id}`, foldResult.issue);
18509
18525
  }
18510
- }
18511
- const boardBox = {
18512
- center: {
18513
- x: pcbBoard.center.x,
18514
- y: 0,
18515
- z: pcbBoard.center.y
18516
- },
18517
- size: {
18518
- x: Number.isFinite(meshWidth) ? meshWidth : pcbBoard.width,
18519
- y: effectiveBoardThickness,
18520
- z: Number.isFinite(meshHeight) ? meshHeight : pcbBoard.height
18521
- },
18522
- mesh: foldedBoardMesh,
18523
- color: resolvedPcbColor,
18524
- sideColor: resolvedBoardSideColor
18525
- };
18526
- if (shouldRenderTextures && textureResolution > 0) {
18527
- try {
18528
- const textures = await renderBoardTextures(circuitJson, {
18529
- resolution: textureResolution,
18530
- showPcbNotes,
18531
- ...boardTextureColors
18532
- });
18533
- boardBox.texture = {
18534
- top: textures.top,
18535
- bottom: textures.bottom
18536
- };
18537
- } catch (error) {
18538
- console.warn("Failed to render board textures:", error);
18526
+ const boardBox = {
18527
+ center: {
18528
+ x: pcbBoard2.center.x,
18529
+ y: 0,
18530
+ z: pcbBoard2.center.y
18531
+ },
18532
+ size: {
18533
+ x: Number.isFinite(meshWidth) ? meshWidth : pcbBoard2.width,
18534
+ y: effectiveBoardThickness2,
18535
+ z: Number.isFinite(meshHeight) ? meshHeight : pcbBoard2.height
18536
+ },
18537
+ mesh: foldedBoardMesh,
18538
+ color: resolvedPcbColor,
18539
+ sideColor: resolvedBoardSideColor
18540
+ };
18541
+ if (shouldRenderTextures && textureResolution > 0) {
18542
+ try {
18543
+ const textures = await renderBoardTextures(boardCircuitJson, {
18544
+ resolution: textureResolution,
18545
+ showPcbNotes,
18546
+ ...boardTextureColors
18547
+ });
18548
+ boardBox.texture = {
18549
+ top: textures.top,
18550
+ bottom: textures.bottom
18551
+ };
18552
+ } catch (error) {
18553
+ console.warn("Failed to render board textures:", error);
18554
+ boardBox.color = resolvedPcbColor;
18555
+ }
18556
+ } else {
18539
18557
  boardBox.color = resolvedPcbColor;
18540
18558
  }
18541
- } else {
18542
- boardBox.color = resolvedPcbColor;
18559
+ if (fold && boardBox.mesh)
18560
+ boardBox.size = getBoundingBoxSize(boardBox.mesh.boundingBox);
18561
+ boxes.push(boardBox);
18543
18562
  }
18544
- if (fold && boardBox.mesh)
18545
- boardBox.size = getBoundingBoxSize(boardBox.mesh.boundingBox);
18546
- boxes.push(boardBox);
18547
18563
  } else if (drawFauxBoard) {
18548
18564
  const hasComponentBounds = pcbComponents.length > 0;
18549
18565
  const componentBounds = hasComponentBounds ? findBoundsAndCenter(pcbComponents) : null;
@@ -19289,9 +19305,11 @@ var GLTFBuilder = class {
19289
19305
  }
19290
19306
  const materials = [];
19291
19307
  if (topTriangles.length > 0 && box.texture?.top) {
19308
+ const textureIndex = await this.addTextureFromDataUrl(box.texture.top);
19292
19309
  const topMaterialIndex = this.addMaterial({
19293
19310
  name: `TopMaterial_${this.materials.length}`,
19294
19311
  pbrMetallicRoughness: {
19312
+ ...textureIndex !== -1 ? { baseColorTexture: { index: textureIndex } } : {},
19295
19313
  baseColorFactor: [1, 1, 1, 1],
19296
19314
  metallicFactor: 0,
19297
19315
  roughnessFactor: 0.8
@@ -19299,24 +19317,17 @@ var GLTFBuilder = class {
19299
19317
  alphaMode: "OPAQUE",
19300
19318
  doubleSided: true
19301
19319
  });
19302
- const textureIndex = await this.addTextureFromDataUrl(box.texture.top);
19303
- if (textureIndex !== -1) {
19304
- const material = this.materials[topMaterialIndex];
19305
- if (material.pbrMetallicRoughness) {
19306
- material.pbrMetallicRoughness.baseColorTexture = {
19307
- index: textureIndex
19308
- };
19309
- }
19310
- }
19311
19320
  materials.push({
19312
19321
  triangles: topTriangles,
19313
19322
  materialIndex: topMaterialIndex
19314
19323
  });
19315
19324
  }
19316
19325
  if (bottomTriangles.length > 0 && box.texture?.bottom) {
19326
+ const textureIndex = await this.addTextureFromDataUrl(box.texture.bottom);
19317
19327
  const bottomMaterialIndex = this.addMaterial({
19318
19328
  name: `BottomMaterial_${this.materials.length}`,
19319
19329
  pbrMetallicRoughness: {
19330
+ ...textureIndex !== -1 ? { baseColorTexture: { index: textureIndex } } : {},
19320
19331
  // baseColorFactor: [ 0.04,
19321
19332
  // 0.16,
19322
19333
  // 0.08, 1.0],
@@ -19326,15 +19337,6 @@ var GLTFBuilder = class {
19326
19337
  alphaMode: "OPAQUE",
19327
19338
  doubleSided: true
19328
19339
  });
19329
- const textureIndex = await this.addTextureFromDataUrl(box.texture.bottom);
19330
- if (textureIndex !== -1) {
19331
- const material = this.materials[bottomMaterialIndex];
19332
- if (material.pbrMetallicRoughness) {
19333
- material.pbrMetallicRoughness.baseColorTexture = {
19334
- index: textureIndex
19335
- };
19336
- }
19337
- }
19338
19340
  materials.push({
19339
19341
  triangles: bottomTriangles,
19340
19342
  materialIndex: bottomMaterialIndex
@@ -19455,47 +19457,33 @@ var GLTFBuilder = class {
19455
19457
  const faceMeshes = createBoxMeshByFaces(box.size);
19456
19458
  const faceMaterials = {};
19457
19459
  if (box.texture?.top) {
19460
+ const textureIndex = await this.addTextureFromDataUrl(box.texture.top);
19458
19461
  const topMaterialIndex = this.addMaterial({
19459
19462
  name: `TopMaterial_${this.materials.length}`,
19460
19463
  pbrMetallicRoughness: {
19464
+ ...textureIndex !== -1 ? { baseColorTexture: { index: textureIndex } } : {},
19461
19465
  baseColorFactor: [0.04, 0.16, 0.08, 1],
19462
19466
  metallicFactor: 0,
19463
19467
  roughnessFactor: 0.8
19464
19468
  },
19465
19469
  alphaMode: "OPAQUE"
19466
19470
  });
19467
- const textureIndex = await this.addTextureFromDataUrl(box.texture.top);
19468
- if (textureIndex !== -1) {
19469
- const material = this.materials[topMaterialIndex];
19470
- if (material.pbrMetallicRoughness) {
19471
- material.pbrMetallicRoughness.baseColorTexture = {
19472
- index: textureIndex
19473
- };
19474
- }
19475
- }
19476
19471
  faceMaterials.top = topMaterialIndex;
19477
19472
  } else {
19478
19473
  faceMaterials.top = defaultMaterialIndex;
19479
19474
  }
19480
19475
  if (box.texture?.bottom) {
19476
+ const textureIndex = await this.addTextureFromDataUrl(box.texture.bottom);
19481
19477
  const bottomMaterialIndex = this.addMaterial({
19482
19478
  name: `BottomMaterial_${this.materials.length}`,
19483
19479
  pbrMetallicRoughness: {
19480
+ ...textureIndex !== -1 ? { baseColorTexture: { index: textureIndex } } : {},
19484
19481
  baseColorFactor: [0.04, 0.16, 0.08, 1],
19485
19482
  metallicFactor: 0,
19486
19483
  roughnessFactor: 0.8
19487
19484
  },
19488
19485
  alphaMode: "OPAQUE"
19489
19486
  });
19490
- const textureIndex = await this.addTextureFromDataUrl(box.texture.bottom);
19491
- if (textureIndex !== -1) {
19492
- const material = this.materials[bottomMaterialIndex];
19493
- if (material.pbrMetallicRoughness) {
19494
- material.pbrMetallicRoughness.baseColorTexture = {
19495
- index: textureIndex
19496
- };
19497
- }
19498
- }
19499
19487
  faceMaterials.bottom = bottomMaterialIndex;
19500
19488
  } else {
19501
19489
  faceMaterials.bottom = defaultMaterialIndex;
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.144",
5
+ "version": "0.0.145",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/tscircuit/circuit-json-to-gltf.git"