@tscircuit/3d-viewer 0.0.529 → 0.0.531

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 +102 -99
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -28769,7 +28769,7 @@ import * as THREE16 from "three";
28769
28769
  // package.json
28770
28770
  var package_default = {
28771
28771
  name: "@tscircuit/3d-viewer",
28772
- version: "0.0.528",
28772
+ version: "0.0.530",
28773
28773
  main: "./dist/index.js",
28774
28774
  module: "./dist/index.js",
28775
28775
  type: "module",
@@ -28799,7 +28799,7 @@ var package_default = {
28799
28799
  "@jscad/regl-renderer": "^2.6.12",
28800
28800
  "@jscad/stl-serializer": "^2.1.20",
28801
28801
  "circuit-json": "^0.0.391",
28802
- "circuit-to-canvas": "^0.0.89",
28802
+ "circuit-to-canvas": "^0.0.90",
28803
28803
  "react-hot-toast": "^2.6.0",
28804
28804
  three: "^0.165.0",
28805
28805
  "three-stdlib": "^2.36.0",
@@ -31915,10 +31915,44 @@ function createPanelOutlineTextureForLayer({
31915
31915
 
31916
31916
  // src/utils/trace-texture.ts
31917
31917
  import * as THREE21 from "three";
31918
- import { su as su7 } from "@tscircuit/circuit-json-util";
31918
+ import { CircuitToCanvasDrawer } from "circuit-to-canvas";
31919
+ import { getElementRenderLayers, su as su7 } from "@tscircuit/circuit-json-util";
31920
+
31921
+ // src/utils/trace-layer-segments.ts
31919
31922
  function isWireRoutePoint(point) {
31920
31923
  return point && point.route_type === "wire" && typeof point.layer === "string" && typeof point.width === "number";
31921
31924
  }
31925
+ function splitTraceIntoLayerSegments(trace, layer) {
31926
+ const segments = [];
31927
+ let currentRoute = [];
31928
+ const pushCurrentSegment = () => {
31929
+ if (currentRoute.length < 2) {
31930
+ currentRoute = [];
31931
+ return;
31932
+ }
31933
+ segments.push({
31934
+ ...trace,
31935
+ pcb_trace_id: `${trace.pcb_trace_id}_${layer}_${segments.length}`,
31936
+ route: currentRoute
31937
+ });
31938
+ currentRoute = [];
31939
+ };
31940
+ for (const point of trace.route) {
31941
+ if (!isWireRoutePoint(point)) {
31942
+ pushCurrentSegment();
31943
+ continue;
31944
+ }
31945
+ if (point.layer !== layer) {
31946
+ pushCurrentSegment();
31947
+ continue;
31948
+ }
31949
+ currentRoute.push(point);
31950
+ }
31951
+ pushCurrentSegment();
31952
+ return segments;
31953
+ }
31954
+
31955
+ // src/utils/trace-texture.ts
31922
31956
  function createTraceTextureForLayer({
31923
31957
  layer,
31924
31958
  circuitJson,
@@ -31927,14 +31961,15 @@ function createTraceTextureForLayer({
31927
31961
  traceTextureResolution
31928
31962
  }) {
31929
31963
  const pcbTraces = su7(circuitJson).pcb_trace.list();
31930
- const allPcbVias = su7(circuitJson).pcb_via.list();
31931
- const allPcbPlatedHoles = su7(
31932
- circuitJson
31933
- ).pcb_plated_hole.list();
31934
- const tracesOnLayer = pcbTraces.filter(
31935
- (t) => t.route.some((p) => isWireRoutePoint(p) && p.layer === layer)
31936
- );
31964
+ const pcbVias = su7(circuitJson).pcb_via.list();
31965
+ const pcbPlatedHoles = su7(circuitJson).pcb_plated_hole.list();
31966
+ const pcbRenderLayer = layer === "top" ? "top_copper" : "bottom_copper";
31967
+ const tracesOnLayer = pcbTraces.filter((trace) => getElementRenderLayers(trace).includes(pcbRenderLayer)).flatMap((trace) => splitTraceIntoLayerSegments(trace, layer));
31937
31968
  if (tracesOnLayer.length === 0) return null;
31969
+ const platedHolesOnLayer = pcbPlatedHoles.filter(
31970
+ (hole) => hole.layers.includes(layer)
31971
+ );
31972
+ const elementsToDraw = [...tracesOnLayer, ...pcbVias, ...platedHolesOnLayer];
31938
31973
  const boardOutlineBounds = calculateOutlineBounds(boardData);
31939
31974
  const canvas = document.createElement("canvas");
31940
31975
  const canvasWidth = Math.floor(
@@ -31951,82 +31986,51 @@ function createTraceTextureForLayer({
31951
31986
  ctx.translate(0, canvasHeight);
31952
31987
  ctx.scale(1, -1);
31953
31988
  }
31954
- tracesOnLayer.forEach((trace) => {
31955
- let firstPoint = true;
31956
- ctx.beginPath();
31957
- ctx.strokeStyle = traceColor;
31958
- ctx.lineCap = "round";
31959
- ctx.lineJoin = "round";
31960
- let currentLineWidth = 0;
31961
- for (const point of trace.route) {
31962
- if (!isWireRoutePoint(point) || point.layer !== layer) {
31963
- if (!firstPoint) ctx.stroke();
31964
- firstPoint = true;
31965
- continue;
31966
- }
31967
- const pcbX = point.x;
31968
- const pcbY = point.y;
31969
- currentLineWidth = point.width * traceTextureResolution;
31970
- ctx.lineWidth = currentLineWidth;
31971
- const canvasX = (pcbX - boardOutlineBounds.minX) * traceTextureResolution;
31972
- const canvasY = (boardOutlineBounds.maxY - pcbY) * traceTextureResolution;
31973
- if (firstPoint) {
31974
- ctx.moveTo(canvasX, canvasY);
31975
- firstPoint = false;
31976
- } else {
31977
- ctx.lineTo(canvasX, canvasY);
31989
+ const transparent = "rgba(0,0,0,0)";
31990
+ const drawer = new CircuitToCanvasDrawer(ctx);
31991
+ drawer.configure({
31992
+ colorOverrides: {
31993
+ copper: {
31994
+ top: traceColor,
31995
+ bottom: traceColor,
31996
+ inner1: traceColor,
31997
+ inner2: traceColor,
31998
+ inner3: traceColor,
31999
+ inner4: traceColor,
32000
+ inner5: traceColor,
32001
+ inner6: traceColor
32002
+ },
32003
+ copperPour: { top: transparent, bottom: transparent },
32004
+ drill: transparent,
32005
+ boardOutline: transparent,
32006
+ substrate: transparent,
32007
+ keepout: transparent,
32008
+ fabricationNote: transparent,
32009
+ courtyard: { top: transparent, bottom: transparent },
32010
+ silkscreen: { top: transparent, bottom: transparent },
32011
+ soldermask: { top: transparent, bottom: transparent },
32012
+ soldermaskWithCopperUnderneath: {
32013
+ top: transparent,
32014
+ bottom: transparent
32015
+ },
32016
+ soldermaskOverCopper: {
32017
+ top: transparent,
32018
+ bottom: transparent
31978
32019
  }
31979
32020
  }
31980
- if (!firstPoint) {
31981
- ctx.stroke();
31982
- }
31983
32021
  });
31984
- ctx.globalCompositeOperation = "destination-out";
31985
- ctx.fillStyle = "black";
31986
- allPcbVias.forEach((via) => {
31987
- const canvasX = (via.x - boardOutlineBounds.minX) * traceTextureResolution;
31988
- const canvasY = (boardOutlineBounds.maxY - via.y) * traceTextureResolution;
31989
- const canvasRadius = via.outer_diameter / 2 * traceTextureResolution;
31990
- ctx.beginPath();
31991
- ctx.arc(canvasX, canvasY, canvasRadius, 0, 2 * Math.PI, false);
31992
- ctx.fill();
32022
+ drawer.setCameraBounds({
32023
+ minX: boardOutlineBounds.minX,
32024
+ maxX: boardOutlineBounds.maxX,
32025
+ minY: boardOutlineBounds.minY,
32026
+ maxY: boardOutlineBounds.maxY
31993
32027
  });
31994
- allPcbPlatedHoles.forEach((ph) => {
31995
- if (ph.layers.includes(layer) && ph.shape === "circle") {
31996
- const canvasX = (ph.x - boardOutlineBounds.minX) * traceTextureResolution;
31997
- const canvasY = (boardOutlineBounds.maxY - ph.y) * traceTextureResolution;
31998
- const canvasRadius = ph.outer_diameter / 2 * traceTextureResolution;
31999
- ctx.beginPath();
32000
- ctx.arc(canvasX, canvasY, canvasRadius, 0, 2 * Math.PI, false);
32001
- ctx.fill();
32002
- } else if (ph.layers.includes(layer) && ph.shape === "rotated_pill_hole_with_rect_pad") {
32003
- const canvasX = (ph.x - boardOutlineBounds.minX) * traceTextureResolution;
32004
- const canvasY = (boardOutlineBounds.maxY - ph.y) * traceTextureResolution;
32005
- const padWidth = (ph.rect_pad_width ?? ph.hole_width ?? 0) * traceTextureResolution;
32006
- const padHeight = (ph.rect_pad_height ?? ph.hole_height ?? 0) * traceTextureResolution;
32007
- const rectCcwRotationDeg = ph.rect_ccw_rotation || 0;
32008
- const rectRotation = -rectCcwRotationDeg;
32009
- if (rectRotation) {
32010
- ctx.save();
32011
- ctx.translate(canvasX, canvasY);
32012
- ctx.rotate(rectRotation * Math.PI / 180);
32013
- ctx.beginPath();
32014
- ctx.rect(-padWidth / 2, -padHeight / 2, padWidth, padHeight);
32015
- ctx.fill();
32016
- ctx.restore();
32017
- } else {
32018
- ctx.beginPath();
32019
- ctx.rect(
32020
- canvasX - padWidth / 2,
32021
- canvasY - padHeight / 2,
32022
- padWidth,
32023
- padHeight
32024
- );
32025
- ctx.fill();
32026
- }
32027
- }
32028
+ drawer.drawElements(elementsToDraw, {
32029
+ layers: [pcbRenderLayer],
32030
+ drawSoldermask: false,
32031
+ drawSoldermaskTop: false,
32032
+ drawSoldermaskBottom: false
32028
32033
  });
32029
- ctx.globalCompositeOperation = "source-over";
32030
32034
  const texture = new THREE21.CanvasTexture(canvas);
32031
32035
  texture.generateMipmaps = true;
32032
32036
  texture.minFilter = THREE21.LinearMipmapLinearFilter;
@@ -32040,7 +32044,7 @@ function createTraceTextureForLayer({
32040
32044
  import * as THREE22 from "three";
32041
32045
 
32042
32046
  // src/textures/copper-text/copper-text-drawing.ts
32043
- import { CircuitToCanvasDrawer } from "circuit-to-canvas";
32047
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer2 } from "circuit-to-canvas";
32044
32048
  var setDrawerBounds = (drawer, bounds) => {
32045
32049
  drawer.setCameraBounds({
32046
32050
  minX: bounds.minX,
@@ -32057,7 +32061,7 @@ var drawCopperTextLayer = ({
32057
32061
  copperColor
32058
32062
  }) => {
32059
32063
  const renderLayer = layer === "top" ? "top_copper" : "bottom_copper";
32060
- const drawer = new CircuitToCanvasDrawer(ctx);
32064
+ const drawer = new CircuitToCanvasDrawer2(ctx);
32061
32065
  drawer.configure({
32062
32066
  colorOverrides: {
32063
32067
  copper: {
@@ -32085,7 +32089,7 @@ var drawCopperTextLayer = ({
32085
32089
  maskCanvas.height = ctx.canvas.height;
32086
32090
  const maskCtx = maskCanvas.getContext("2d");
32087
32091
  if (!maskCtx) return;
32088
- const knockoutCutoutDrawer = new CircuitToCanvasDrawer(maskCtx);
32092
+ const knockoutCutoutDrawer = new CircuitToCanvasDrawer2(maskCtx);
32089
32093
  knockoutCutoutDrawer.configure({
32090
32094
  colorOverrides: {
32091
32095
  copper: {
@@ -32161,7 +32165,7 @@ function createCopperTextTextureForLayer({
32161
32165
  import * as THREE23 from "three";
32162
32166
 
32163
32167
  // src/textures/fabrication-note/fabrication-note-drawing.ts
32164
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer2 } from "circuit-to-canvas";
32168
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer3 } from "circuit-to-canvas";
32165
32169
 
32166
32170
  // src/utils/units.ts
32167
32171
  var MM_PER_INCH = 25.4;
@@ -32259,7 +32263,7 @@ var drawFabricationNoteLayer = ({
32259
32263
  }) => {
32260
32264
  const renderLayer = `${layer}_fabrication_note`;
32261
32265
  const normalizedElements = elements.map(normalizeFabricationElement);
32262
- const drawer = new CircuitToCanvasDrawer2(ctx);
32266
+ const drawer = new CircuitToCanvasDrawer3(ctx);
32263
32267
  drawer.configure({
32264
32268
  colorOverrides: {
32265
32269
  copper: {
@@ -32398,7 +32402,7 @@ function createFabricationNoteTextureForLayer({
32398
32402
  import * as THREE24 from "three";
32399
32403
 
32400
32404
  // src/textures/pcb-note/pcb-note-drawing.ts
32401
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer3 } from "circuit-to-canvas";
32405
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer4 } from "circuit-to-canvas";
32402
32406
  var TRANSPARENT2 = "rgba(0,0,0,0)";
32403
32407
  var setDrawerBounds3 = (drawer, bounds) => {
32404
32408
  drawer.setCameraBounds({
@@ -32477,7 +32481,7 @@ var drawPcbNoteLayer = ({
32477
32481
  elements
32478
32482
  }) => {
32479
32483
  const normalizedElements = elements.map(normalizePcbNoteElement);
32480
- const drawer = new CircuitToCanvasDrawer3(ctx);
32484
+ const drawer = new CircuitToCanvasDrawer4(ctx);
32481
32485
  drawer.configure({
32482
32486
  colorOverrides: {
32483
32487
  copper: {
@@ -32559,7 +32563,7 @@ function createPcbNoteTextureForLayer({
32559
32563
  import * as THREE25 from "three";
32560
32564
 
32561
32565
  // src/textures/silkscreen/silkscreen-drawing.ts
32562
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer4 } from "circuit-to-canvas";
32566
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer5 } from "circuit-to-canvas";
32563
32567
  var FABRICATION_NOTE_COLOR2 = "rgb(255,243,204)";
32564
32568
  var TRANSPARENT3 = "rgba(0,0,0,0)";
32565
32569
  var setDrawerBounds4 = (drawer, bounds) => {
@@ -32578,7 +32582,7 @@ var drawSilkscreenLayer = ({
32578
32582
  silkscreenColor
32579
32583
  }) => {
32580
32584
  const renderLayer = layer === "top" ? "top_silkscreen" : "bottom_silkscreen";
32581
- const drawer = new CircuitToCanvasDrawer4(ctx);
32585
+ const drawer = new CircuitToCanvasDrawer5(ctx);
32582
32586
  drawer.configure({
32583
32587
  colorOverrides: {
32584
32588
  copper: {
@@ -32678,7 +32682,7 @@ function createSilkscreenTextureForLayer({
32678
32682
  import * as THREE26 from "three";
32679
32683
 
32680
32684
  // src/textures/soldermask/soldermask-drawing.ts
32681
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer5 } from "circuit-to-canvas";
32685
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer6 } from "circuit-to-canvas";
32682
32686
  var toRgb = (colorArr) => {
32683
32687
  const [r = 0, g = 0, b = 0] = colorArr;
32684
32688
  return `rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(
@@ -32714,7 +32718,7 @@ var drawSoldermaskLayer = ({
32714
32718
  }) => {
32715
32719
  const palette = getSoldermaskPalette(boardMaterial);
32716
32720
  const copperRenderLayer = layer === "top" ? "top_copper" : "bottom_copper";
32717
- const drawer = new CircuitToCanvasDrawer5(ctx);
32721
+ const drawer = new CircuitToCanvasDrawer6(ctx);
32718
32722
  drawer.configure({
32719
32723
  colorOverrides: {
32720
32724
  copper: {
@@ -32758,7 +32762,7 @@ var drawSoldermaskLayer = ({
32758
32762
  if (uncoveredPours.length > 0) {
32759
32763
  ctx.save();
32760
32764
  ctx.globalCompositeOperation = "destination-out";
32761
- const cutoutDrawer = new CircuitToCanvasDrawer5(ctx);
32765
+ const cutoutDrawer = new CircuitToCanvasDrawer6(ctx);
32762
32766
  cutoutDrawer.configure({
32763
32767
  colorOverrides: {
32764
32768
  copper: {
@@ -32820,7 +32824,7 @@ function createSoldermaskTextureForLayer({
32820
32824
  import * as THREE27 from "three";
32821
32825
 
32822
32826
  // src/textures/through-hole/through-hole-drawing.ts
32823
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer6 } from "circuit-to-canvas";
32827
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer7 } from "circuit-to-canvas";
32824
32828
  var setDrawerBounds6 = (drawer, bounds) => {
32825
32829
  drawer.setCameraBounds({
32826
32830
  minX: bounds.minX,
@@ -32838,7 +32842,7 @@ var drawThroughHoleLayer = ({
32838
32842
  }) => {
32839
32843
  const renderLayer = layer === "top" ? "top_copper" : "bottom_copper";
32840
32844
  const transparent = "rgba(0,0,0,0)";
32841
- const drawer = new CircuitToCanvasDrawer6(ctx);
32845
+ const drawer = new CircuitToCanvasDrawer7(ctx);
32842
32846
  drawer.configure({
32843
32847
  colorOverrides: {
32844
32848
  copper: {
@@ -32966,8 +32970,7 @@ function createCombinedBoardTextures({
32966
32970
  traceTextureResolution,
32967
32971
  visibility
32968
32972
  }) {
32969
- const traceColorWithMask = toRgb2(colors.fr4TracesWithMaskGreen);
32970
- const traceColorWithoutMask = toRgb2(colors.fr4TracesWithoutMaskTan);
32973
+ const traceColor = toRgb2(colors.copper);
32971
32974
  const silkscreenColor = "rgb(255,255,255)";
32972
32975
  const copperColor = toRgb2(colors.copper);
32973
32976
  const showBoardBody = visibility?.boardBody ?? true;
@@ -32985,7 +32988,7 @@ function createCombinedBoardTextures({
32985
32988
  layer,
32986
32989
  circuitJson,
32987
32990
  boardData,
32988
- traceColor: showMask ? traceColorWithMask : traceColorWithoutMask,
32991
+ traceColor,
32989
32992
  traceTextureResolution
32990
32993
  }) : null;
32991
32994
  const copperTextTexture = showCopper ? createCopperTextTextureForLayer({
@@ -33060,7 +33063,7 @@ function createCombinedBoardTextures({
33060
33063
 
33061
33064
  // src/textures/create-copper-pour-texture-for-layer.ts
33062
33065
  import * as THREE29 from "three";
33063
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer7 } from "circuit-to-canvas";
33066
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer8 } from "circuit-to-canvas";
33064
33067
 
33065
33068
  // src/geoms/brep-converter.ts
33066
33069
  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.529",
3
+ "version": "0.0.531",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",
@@ -30,7 +30,7 @@
30
30
  "@jscad/regl-renderer": "^2.6.12",
31
31
  "@jscad/stl-serializer": "^2.1.20",
32
32
  "circuit-json": "^0.0.391",
33
- "circuit-to-canvas": "^0.0.89",
33
+ "circuit-to-canvas": "^0.0.90",
34
34
  "react-hot-toast": "^2.6.0",
35
35
  "three": "^0.165.0",
36
36
  "three-stdlib": "^2.36.0",