@tscircuit/3d-viewer 0.0.533 → 0.0.535

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 +69 -114
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -28674,9 +28674,13 @@ var AnyCadComponent = ({
28674
28674
  }, [cad_component.rotation, layer]);
28675
28675
  const adjustedPosition = useMemo8(() => {
28676
28676
  if (!cad_component.position) return void 0;
28677
- let z18 = cad_component.position.z + pcbThickness / 2;
28678
- if (layer === "bottom") {
28679
- z18 = -cad_component.position.z - pcbThickness / 2;
28677
+ let z18;
28678
+ if (layer === "top") {
28679
+ z18 = cad_component.position.z;
28680
+ } else if (layer === "bottom") {
28681
+ z18 = -(cad_component.position.z + pcbThickness);
28682
+ } else {
28683
+ z18 = cad_component.position.z;
28680
28684
  }
28681
28685
  return [cad_component.position.x, cad_component.position.y, z18];
28682
28686
  }, [cad_component.position, layer, pcbThickness]);
@@ -28852,7 +28856,7 @@ import * as THREE16 from "three";
28852
28856
  // package.json
28853
28857
  var package_default = {
28854
28858
  name: "@tscircuit/3d-viewer",
28855
- version: "0.0.532",
28859
+ version: "0.0.534",
28856
28860
  main: "./dist/index.js",
28857
28861
  module: "./dist/index.js",
28858
28862
  type: "module",
@@ -31767,6 +31771,7 @@ function calculateOutlineBounds(boardData) {
31767
31771
 
31768
31772
  // src/utils/pad-texture.ts
31769
31773
  import { su as su5 } from "@tscircuit/circuit-json-util";
31774
+ import { CircuitToCanvasDrawer } from "circuit-to-canvas";
31770
31775
  import * as THREE19 from "three";
31771
31776
  function createPadTextureForLayer({
31772
31777
  layer,
@@ -31778,6 +31783,7 @@ function createPadTextureForLayer({
31778
31783
  const pcbSmtPads = su5(circuitJson).pcb_smtpad.list();
31779
31784
  const smtPadsOnLayer = pcbSmtPads.filter((pad2) => pad2.layer === layer);
31780
31785
  if (smtPadsOnLayer.length === 0) return null;
31786
+ const pcbRenderLayer = layer === "top" ? "top_copper" : "bottom_copper";
31781
31787
  const boardOutlineBounds = calculateOutlineBounds(boardData);
31782
31788
  const canvas = document.createElement("canvas");
31783
31789
  const canvasWidth = Math.floor(
@@ -31794,102 +31800,51 @@ function createPadTextureForLayer({
31794
31800
  ctx.translate(0, canvasHeight);
31795
31801
  ctx.scale(1, -1);
31796
31802
  }
31797
- const canvasXFromPcb = (pcbX) => (pcbX - boardOutlineBounds.minX) * traceTextureResolution;
31798
- const canvasYFromPcb = (pcbY) => (boardOutlineBounds.maxY - pcbY) * traceTextureResolution;
31799
- ctx.fillStyle = copperColor;
31800
- smtPadsOnLayer.forEach((pad2) => {
31801
- if (pad2.shape === "polygon" && pad2.points) {
31802
- ctx.beginPath();
31803
- pad2.points.forEach((point, index2) => {
31804
- const px = canvasXFromPcb(point.x);
31805
- const py = canvasYFromPcb(point.y);
31806
- if (index2 === 0) {
31807
- ctx.moveTo(px, py);
31808
- } else {
31809
- ctx.lineTo(px, py);
31810
- }
31811
- });
31812
- ctx.closePath();
31813
- ctx.fill();
31814
- return;
31815
- }
31816
- if (pad2.x === void 0 || pad2.y === void 0) return;
31817
- const x = pad2.x;
31818
- const y = pad2.y;
31819
- const canvasX = canvasXFromPcb(x);
31820
- const canvasY = canvasYFromPcb(y);
31821
- if (pad2.shape === "rect") {
31822
- const width10 = pad2.width * traceTextureResolution;
31823
- const height10 = pad2.height * traceTextureResolution;
31824
- const rawRadius = extractRectBorderRadius(pad2);
31825
- const borderRadius = clampRectBorderRadius(
31826
- pad2.width,
31827
- pad2.height,
31828
- rawRadius
31829
- ) * traceTextureResolution;
31830
- if (borderRadius > 0) {
31831
- ctx.beginPath();
31832
- ctx.roundRect(
31833
- canvasX - width10 / 2,
31834
- canvasY - height10 / 2,
31835
- width10,
31836
- height10,
31837
- borderRadius
31838
- );
31839
- ctx.fill();
31840
- } else {
31841
- ctx.fillRect(canvasX - width10 / 2, canvasY - height10 / 2, width10, height10);
31803
+ const transparent = "rgba(0,0,0,0)";
31804
+ const drawer = new CircuitToCanvasDrawer(ctx);
31805
+ drawer.configure({
31806
+ colorOverrides: {
31807
+ copper: {
31808
+ top: copperColor,
31809
+ bottom: copperColor,
31810
+ inner1: copperColor,
31811
+ inner2: copperColor,
31812
+ inner3: copperColor,
31813
+ inner4: copperColor,
31814
+ inner5: copperColor,
31815
+ inner6: copperColor
31816
+ },
31817
+ copperPour: { top: transparent, bottom: transparent },
31818
+ drill: transparent,
31819
+ boardOutline: transparent,
31820
+ substrate: transparent,
31821
+ keepout: transparent,
31822
+ fabricationNote: transparent,
31823
+ courtyard: { top: transparent, bottom: transparent },
31824
+ silkscreen: { top: transparent, bottom: transparent },
31825
+ soldermask: { top: transparent, bottom: transparent },
31826
+ soldermaskWithCopperUnderneath: {
31827
+ top: transparent,
31828
+ bottom: transparent
31829
+ },
31830
+ soldermaskOverCopper: {
31831
+ top: transparent,
31832
+ bottom: transparent
31842
31833
  }
31843
- } else if (pad2.shape === "circle") {
31844
- const radius = (pad2.radius ?? pad2.width / 2) * traceTextureResolution;
31845
- ctx.beginPath();
31846
- ctx.arc(canvasX, canvasY, radius, 0, 2 * Math.PI);
31847
- ctx.fill();
31848
- } else if (pad2.shape === "pill" || pad2.shape === "rotated_pill") {
31849
- const width10 = pad2.width * traceTextureResolution;
31850
- const height10 = pad2.height * traceTextureResolution;
31851
- const borderRadius = Math.min(width10, height10) / 2;
31852
- const ccwRotation = pad2.ccw_rotation || 0;
31853
- const rotation = -ccwRotation * (Math.PI / 180);
31854
- if (rotation) {
31855
- ctx.save();
31856
- ctx.translate(canvasX, canvasY);
31857
- ctx.rotate(rotation);
31858
- ctx.beginPath();
31859
- ctx.roundRect(-width10 / 2, -height10 / 2, width10, height10, borderRadius);
31860
- ctx.fill();
31861
- ctx.restore();
31862
- } else {
31863
- ctx.beginPath();
31864
- ctx.roundRect(
31865
- canvasX - width10 / 2,
31866
- canvasY - height10 / 2,
31867
- width10,
31868
- height10,
31869
- borderRadius
31870
- );
31871
- ctx.fill();
31872
- }
31873
- } else if (pad2.shape === "rotated_rect") {
31874
- const width10 = pad2.width * traceTextureResolution;
31875
- const height10 = pad2.height * traceTextureResolution;
31876
- const rawRadius = extractRectBorderRadius(pad2);
31877
- const borderRadius = clampRectBorderRadius(
31878
- pad2.width,
31879
- pad2.height,
31880
- rawRadius
31881
- ) * traceTextureResolution;
31882
- const ccwRotation = pad2.ccw_rotation || 0;
31883
- const rotation = -ccwRotation * (Math.PI / 180);
31884
- ctx.save();
31885
- ctx.translate(canvasX, canvasY);
31886
- ctx.rotate(rotation);
31887
- ctx.beginPath();
31888
- ctx.roundRect(-width10 / 2, -height10 / 2, width10, height10, borderRadius);
31889
- ctx.fill();
31890
- ctx.restore();
31891
31834
  }
31892
31835
  });
31836
+ drawer.setCameraBounds({
31837
+ minX: boardOutlineBounds.minX,
31838
+ maxX: boardOutlineBounds.maxX,
31839
+ minY: boardOutlineBounds.minY,
31840
+ maxY: boardOutlineBounds.maxY
31841
+ });
31842
+ drawer.drawElements(smtPadsOnLayer, {
31843
+ layers: [pcbRenderLayer],
31844
+ drawSoldermask: false,
31845
+ drawSoldermaskTop: false,
31846
+ drawSoldermaskBottom: false
31847
+ });
31893
31848
  const texture = new THREE19.CanvasTexture(canvas);
31894
31849
  texture.generateMipmaps = true;
31895
31850
  texture.minFilter = THREE19.LinearMipmapLinearFilter;
@@ -31980,7 +31935,7 @@ function createPanelOutlineTextureForLayer({
31980
31935
 
31981
31936
  // src/utils/trace-texture.ts
31982
31937
  import * as THREE21 from "three";
31983
- import { CircuitToCanvasDrawer } from "circuit-to-canvas";
31938
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer2 } from "circuit-to-canvas";
31984
31939
  import { getElementRenderLayers, su as su7 } from "@tscircuit/circuit-json-util";
31985
31940
 
31986
31941
  // src/utils/trace-layer-segments.ts
@@ -32052,7 +32007,7 @@ function createTraceTextureForLayer({
32052
32007
  ctx.scale(1, -1);
32053
32008
  }
32054
32009
  const transparent = "rgba(0,0,0,0)";
32055
- const drawer = new CircuitToCanvasDrawer(ctx);
32010
+ const drawer = new CircuitToCanvasDrawer2(ctx);
32056
32011
  drawer.configure({
32057
32012
  colorOverrides: {
32058
32013
  copper: {
@@ -32109,7 +32064,7 @@ function createTraceTextureForLayer({
32109
32064
  import * as THREE22 from "three";
32110
32065
 
32111
32066
  // src/textures/copper-text/copper-text-drawing.ts
32112
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer2 } from "circuit-to-canvas";
32067
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer3 } from "circuit-to-canvas";
32113
32068
  var setDrawerBounds = (drawer, bounds) => {
32114
32069
  drawer.setCameraBounds({
32115
32070
  minX: bounds.minX,
@@ -32126,7 +32081,7 @@ var drawCopperTextLayer = ({
32126
32081
  copperColor
32127
32082
  }) => {
32128
32083
  const renderLayer = layer === "top" ? "top_copper" : "bottom_copper";
32129
- const drawer = new CircuitToCanvasDrawer2(ctx);
32084
+ const drawer = new CircuitToCanvasDrawer3(ctx);
32130
32085
  drawer.configure({
32131
32086
  colorOverrides: {
32132
32087
  copper: {
@@ -32154,7 +32109,7 @@ var drawCopperTextLayer = ({
32154
32109
  maskCanvas.height = ctx.canvas.height;
32155
32110
  const maskCtx = maskCanvas.getContext("2d");
32156
32111
  if (!maskCtx) return;
32157
- const knockoutCutoutDrawer = new CircuitToCanvasDrawer2(maskCtx);
32112
+ const knockoutCutoutDrawer = new CircuitToCanvasDrawer3(maskCtx);
32158
32113
  knockoutCutoutDrawer.configure({
32159
32114
  colorOverrides: {
32160
32115
  copper: {
@@ -32230,7 +32185,7 @@ function createCopperTextTextureForLayer({
32230
32185
  import * as THREE23 from "three";
32231
32186
 
32232
32187
  // src/textures/fabrication-note/fabrication-note-drawing.ts
32233
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer3 } from "circuit-to-canvas";
32188
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer4 } from "circuit-to-canvas";
32234
32189
 
32235
32190
  // src/utils/units.ts
32236
32191
  var MM_PER_INCH = 25.4;
@@ -32328,7 +32283,7 @@ var drawFabricationNoteLayer = ({
32328
32283
  }) => {
32329
32284
  const renderLayer = `${layer}_fabrication_note`;
32330
32285
  const normalizedElements = elements.map(normalizeFabricationElement);
32331
- const drawer = new CircuitToCanvasDrawer3(ctx);
32286
+ const drawer = new CircuitToCanvasDrawer4(ctx);
32332
32287
  drawer.configure({
32333
32288
  colorOverrides: {
32334
32289
  copper: {
@@ -32467,7 +32422,7 @@ function createFabricationNoteTextureForLayer({
32467
32422
  import * as THREE24 from "three";
32468
32423
 
32469
32424
  // src/textures/pcb-note/pcb-note-drawing.ts
32470
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer4 } from "circuit-to-canvas";
32425
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer5 } from "circuit-to-canvas";
32471
32426
  var TRANSPARENT2 = "rgba(0,0,0,0)";
32472
32427
  var setDrawerBounds3 = (drawer, bounds) => {
32473
32428
  drawer.setCameraBounds({
@@ -32546,7 +32501,7 @@ var drawPcbNoteLayer = ({
32546
32501
  elements
32547
32502
  }) => {
32548
32503
  const normalizedElements = elements.map(normalizePcbNoteElement);
32549
- const drawer = new CircuitToCanvasDrawer4(ctx);
32504
+ const drawer = new CircuitToCanvasDrawer5(ctx);
32550
32505
  drawer.configure({
32551
32506
  colorOverrides: {
32552
32507
  copper: {
@@ -32628,7 +32583,7 @@ function createPcbNoteTextureForLayer({
32628
32583
  import * as THREE25 from "three";
32629
32584
 
32630
32585
  // src/textures/silkscreen/silkscreen-drawing.ts
32631
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer5 } from "circuit-to-canvas";
32586
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer6 } from "circuit-to-canvas";
32632
32587
  var FABRICATION_NOTE_COLOR2 = "rgb(255,243,204)";
32633
32588
  var TRANSPARENT3 = "rgba(0,0,0,0)";
32634
32589
  var setDrawerBounds4 = (drawer, bounds) => {
@@ -32647,7 +32602,7 @@ var drawSilkscreenLayer = ({
32647
32602
  silkscreenColor
32648
32603
  }) => {
32649
32604
  const renderLayer = layer === "top" ? "top_silkscreen" : "bottom_silkscreen";
32650
- const drawer = new CircuitToCanvasDrawer5(ctx);
32605
+ const drawer = new CircuitToCanvasDrawer6(ctx);
32651
32606
  drawer.configure({
32652
32607
  colorOverrides: {
32653
32608
  copper: {
@@ -32747,7 +32702,7 @@ function createSilkscreenTextureForLayer({
32747
32702
  import * as THREE26 from "three";
32748
32703
 
32749
32704
  // src/textures/soldermask/soldermask-drawing.ts
32750
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer6 } from "circuit-to-canvas";
32705
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer7 } from "circuit-to-canvas";
32751
32706
  var toRgb = (colorArr) => {
32752
32707
  const [r = 0, g = 0, b = 0] = colorArr;
32753
32708
  return `rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(
@@ -32783,7 +32738,7 @@ var drawSoldermaskLayer = ({
32783
32738
  }) => {
32784
32739
  const palette = getSoldermaskPalette(boardMaterial);
32785
32740
  const copperRenderLayer = layer === "top" ? "top_copper" : "bottom_copper";
32786
- const drawer = new CircuitToCanvasDrawer6(ctx);
32741
+ const drawer = new CircuitToCanvasDrawer7(ctx);
32787
32742
  drawer.configure({
32788
32743
  colorOverrides: {
32789
32744
  copper: {
@@ -32827,7 +32782,7 @@ var drawSoldermaskLayer = ({
32827
32782
  if (uncoveredPours.length > 0) {
32828
32783
  ctx.save();
32829
32784
  ctx.globalCompositeOperation = "destination-out";
32830
- const cutoutDrawer = new CircuitToCanvasDrawer6(ctx);
32785
+ const cutoutDrawer = new CircuitToCanvasDrawer7(ctx);
32831
32786
  cutoutDrawer.configure({
32832
32787
  colorOverrides: {
32833
32788
  copper: {
@@ -32889,7 +32844,7 @@ function createSoldermaskTextureForLayer({
32889
32844
  import * as THREE27 from "three";
32890
32845
 
32891
32846
  // src/textures/through-hole/through-hole-drawing.ts
32892
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer7 } from "circuit-to-canvas";
32847
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer8 } from "circuit-to-canvas";
32893
32848
  var setDrawerBounds6 = (drawer, bounds) => {
32894
32849
  drawer.setCameraBounds({
32895
32850
  minX: bounds.minX,
@@ -32907,7 +32862,7 @@ var drawThroughHoleLayer = ({
32907
32862
  }) => {
32908
32863
  const renderLayer = layer === "top" ? "top_copper" : "bottom_copper";
32909
32864
  const transparent = "rgba(0,0,0,0)";
32910
- const drawer = new CircuitToCanvasDrawer7(ctx);
32865
+ const drawer = new CircuitToCanvasDrawer8(ctx);
32911
32866
  drawer.configure({
32912
32867
  colorOverrides: {
32913
32868
  copper: {
@@ -33128,7 +33083,7 @@ function createCombinedBoardTextures({
33128
33083
 
33129
33084
  // src/textures/create-copper-pour-texture-for-layer.ts
33130
33085
  import * as THREE29 from "three";
33131
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer8 } from "circuit-to-canvas";
33086
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer9 } from "circuit-to-canvas";
33132
33087
 
33133
33088
  // src/geoms/brep-converter.ts
33134
33089
  var import_primitives7 = __toESM(require_primitives(), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/3d-viewer",
3
- "version": "0.0.533",
3
+ "version": "0.0.535",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",