@tscircuit/3d-viewer 0.0.523 → 0.0.524

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 +289 -121
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -14245,7 +14245,7 @@ var require_browser = __commonJS({
14245
14245
 
14246
14246
  // src/CadViewer.tsx
14247
14247
  import { useState as useState36, useCallback as useCallback21, useRef as useRef26, useEffect as useEffect44 } from "react";
14248
- import * as THREE37 from "three";
14248
+ import * as THREE38 from "three";
14249
14249
 
14250
14250
  // src/CadViewerJscad.tsx
14251
14251
  import { su as su11 } from "@tscircuit/circuit-json-util";
@@ -28483,7 +28483,7 @@ import * as THREE16 from "three";
28483
28483
  // package.json
28484
28484
  var package_default = {
28485
28485
  name: "@tscircuit/3d-viewer",
28486
- version: "0.0.522",
28486
+ version: "0.0.523",
28487
28487
  main: "./dist/index.js",
28488
28488
  module: "./dist/index.js",
28489
28489
  type: "module",
@@ -31452,7 +31452,7 @@ import { su as su8 } from "@tscircuit/circuit-json-util";
31452
31452
  import { useEffect as useEffect23, useMemo as useMemo19 } from "react";
31453
31453
 
31454
31454
  // src/textures/create-combined-board-textures.ts
31455
- import * as THREE27 from "three";
31455
+ import * as THREE28 from "three";
31456
31456
 
31457
31457
  // node_modules/@tscircuit/math-utils/dist/chunk-5N7UJNVK.js
31458
31458
  var getBoundsFromPoints = (points) => {
@@ -32401,12 +32401,11 @@ function createFabricationNoteTextureForLayer({
32401
32401
  return texture;
32402
32402
  }
32403
32403
 
32404
- // src/textures/create-silkscreen-texture-for-layer.ts
32404
+ // src/textures/create-pcb-note-texture-for-layer.ts
32405
32405
  import * as THREE25 from "three";
32406
32406
 
32407
- // src/textures/silkscreen/silkscreen-drawing.ts
32407
+ // src/textures/pcb-note/pcb-note-drawing.ts
32408
32408
  import { CircuitToCanvasDrawer as CircuitToCanvasDrawer4 } from "circuit-to-canvas";
32409
- var FABRICATION_NOTE_COLOR2 = "rgb(255,243,204)";
32410
32409
  var TRANSPARENT2 = "rgba(0,0,0,0)";
32411
32410
  var setDrawerBounds3 = (drawer, bounds) => {
32412
32411
  drawer.setCameraBounds({
@@ -32416,14 +32415,75 @@ var setDrawerBounds3 = (drawer, bounds) => {
32416
32415
  maxY: bounds.maxY
32417
32416
  });
32418
32417
  };
32419
- var drawSilkscreenLayer = ({
32418
+ var normalizePcbNoteElement = (element) => {
32419
+ if (element.type === "pcb_note_line") {
32420
+ return {
32421
+ ...element,
32422
+ x1: coerceDimensionToMm(element.x1, 0),
32423
+ y1: coerceDimensionToMm(element.y1, 0),
32424
+ x2: coerceDimensionToMm(element.x2, 0),
32425
+ y2: coerceDimensionToMm(element.y2, 0),
32426
+ stroke_width: coerceDimensionToMm(element.stroke_width, 0.1)
32427
+ };
32428
+ }
32429
+ if (element.type === "pcb_note_rect") {
32430
+ return {
32431
+ ...element,
32432
+ center: {
32433
+ x: coerceDimensionToMm(element.center.x, 0),
32434
+ y: coerceDimensionToMm(element.center.y, 0)
32435
+ },
32436
+ width: coerceDimensionToMm(element.width, 0),
32437
+ height: coerceDimensionToMm(element.height, 0),
32438
+ stroke_width: coerceDimensionToMm(element.stroke_width, 0.1),
32439
+ corner_radius: coerceDimensionToMm(element.corner_radius, 0)
32440
+ };
32441
+ }
32442
+ if (element.type === "pcb_note_text") {
32443
+ return {
32444
+ ...element,
32445
+ anchor_position: {
32446
+ x: coerceDimensionToMm(element.anchor_position.x, 0),
32447
+ y: coerceDimensionToMm(element.anchor_position.y, 0)
32448
+ },
32449
+ font_size: coerceDimensionToMm(element.font_size, 1)
32450
+ };
32451
+ }
32452
+ if (element.type === "pcb_note_path") {
32453
+ return {
32454
+ ...element,
32455
+ route: element.route.map((point) => ({
32456
+ ...point,
32457
+ x: coerceDimensionToMm(point.x, 0),
32458
+ y: coerceDimensionToMm(point.y, 0)
32459
+ })),
32460
+ stroke_width: coerceDimensionToMm(element.stroke_width, 0.1)
32461
+ };
32462
+ }
32463
+ if (element.type === "pcb_note_dimension") {
32464
+ return {
32465
+ ...element,
32466
+ from: {
32467
+ x: coerceDimensionToMm(element.from.x, 0),
32468
+ y: coerceDimensionToMm(element.from.y, 0)
32469
+ },
32470
+ to: {
32471
+ x: coerceDimensionToMm(element.to.x, 0),
32472
+ y: coerceDimensionToMm(element.to.y, 0)
32473
+ },
32474
+ font_size: coerceDimensionToMm(element.font_size, 1),
32475
+ arrow_size: coerceDimensionToMm(element.arrow_size, 1),
32476
+ offset_distance: coerceDimensionToMm(element.offset_distance, 0)
32477
+ };
32478
+ }
32479
+ return element;
32480
+ };
32481
+ var drawPcbNoteLayer = ({
32420
32482
  ctx,
32421
- layer,
32422
32483
  bounds,
32423
- elements,
32424
- silkscreenColor
32484
+ elements
32425
32485
  }) => {
32426
- const renderLayer = layer === "top" ? "top_silkscreen" : "bottom_silkscreen";
32486
+ const normalizedElements = elements.map(normalizePcbNoteElement);
32427
32487
  const drawer = new CircuitToCanvasDrawer4(ctx);
32428
32488
  drawer.configure({
32429
32489
  colorOverrides: {
@@ -32437,29 +32497,130 @@ var drawSilkscreenLayer = ({
32437
32497
  inner5: TRANSPARENT2,
32438
32498
  inner6: TRANSPARENT2
32439
32499
  },
32440
- copperPour: {
32441
- top: TRANSPARENT2,
32442
- bottom: TRANSPARENT2
32443
- },
32500
+ copperPour: { top: TRANSPARENT2, bottom: TRANSPARENT2 },
32444
32501
  drill: TRANSPARENT2,
32445
32502
  boardOutline: TRANSPARENT2,
32446
32503
  substrate: TRANSPARENT2,
32447
32504
  keepout: TRANSPARENT2,
32448
- courtyard: {
32505
+ courtyard: { top: TRANSPARENT2, bottom: TRANSPARENT2 },
32506
+ soldermask: { top: TRANSPARENT2, bottom: TRANSPARENT2 },
32507
+ soldermaskWithCopperUnderneath: {
32449
32508
  top: TRANSPARENT2,
32450
32509
  bottom: TRANSPARENT2
32451
32510
  },
32452
- soldermask: {
32511
+ soldermaskOverCopper: {
32453
32512
  top: TRANSPARENT2,
32454
32513
  bottom: TRANSPARENT2
32455
32514
  },
32515
+ silkscreen: { top: TRANSPARENT2, bottom: TRANSPARENT2 },
32516
+ fabricationNote: TRANSPARENT2
32517
+ }
32518
+ });
32519
+ setDrawerBounds3(drawer, bounds);
32520
+ drawer.drawElements(normalizedElements);
32521
+ };
32522
+
32523
+ // src/textures/create-pcb-note-texture-for-layer.ts
32524
+ var isPcbNoteElement = (element, layer) => {
32525
+ if (!("layer" in element) || element.layer !== layer) return false;
32526
+ return element.type.startsWith("pcb_note_");
32527
+ };
32528
+ function createPcbNoteTextureForLayer({
32529
+ layer,
32530
+ circuitJson,
32531
+ boardData,
32532
+ traceTextureResolution = TRACE_TEXTURE_RESOLUTION
32533
+ }) {
32534
+ const elements = circuitJson.filter(
32535
+ (element) => isPcbNoteElement(element, layer)
32536
+ );
32537
+ if (elements.length === 0) return null;
32538
+ const bounds = getSoldermaskRenderBounds(circuitJson, boardData);
32539
+ const canvasWidth = Math.floor(bounds.width * traceTextureResolution);
32540
+ const canvasHeight = Math.floor(bounds.height * traceTextureResolution);
32541
+ if (canvasWidth <= 0 || canvasHeight <= 0) return null;
32542
+ const canvas = document.createElement("canvas");
32543
+ canvas.width = canvasWidth;
32544
+ canvas.height = canvasHeight;
32545
+ const ctx = canvas.getContext("2d");
32546
+ if (!ctx) return null;
32547
+ if (layer === "bottom") {
32548
+ ctx.translate(0, canvasHeight);
32549
+ ctx.scale(1, -1);
32550
+ }
32551
+ drawPcbNoteLayer({
32552
+ ctx,
32553
+ bounds,
32554
+ elements
32555
+ });
32556
+ const texture = new THREE25.CanvasTexture(canvas);
32557
+ texture.generateMipmaps = true;
32558
+ texture.minFilter = THREE25.LinearMipmapLinearFilter;
32559
+ texture.magFilter = THREE25.LinearFilter;
32560
+ texture.anisotropy = 16;
32561
+ texture.needsUpdate = true;
32562
+ return texture;
32563
+ }
32564
+
32565
+ // src/textures/create-silkscreen-texture-for-layer.ts
32566
+ import * as THREE26 from "three";
32567
+
32568
+ // src/textures/silkscreen/silkscreen-drawing.ts
32569
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer5 } from "circuit-to-canvas";
32570
+ var FABRICATION_NOTE_COLOR2 = "rgb(255,243,204)";
32571
+ var TRANSPARENT3 = "rgba(0,0,0,0)";
32572
+ var setDrawerBounds4 = (drawer, bounds) => {
32573
+ drawer.setCameraBounds({
32574
+ minX: bounds.minX,
32575
+ maxX: bounds.maxX,
32576
+ minY: bounds.minY,
32577
+ maxY: bounds.maxY
32578
+ });
32579
+ };
32580
+ var drawSilkscreenLayer = ({
32581
+ ctx,
32582
+ layer,
32583
+ bounds,
32584
+ elements,
32585
+ silkscreenColor
32586
+ }) => {
32587
+ const renderLayer = layer === "top" ? "top_silkscreen" : "bottom_silkscreen";
32588
+ const drawer = new CircuitToCanvasDrawer5(ctx);
32589
+ drawer.configure({
32590
+ colorOverrides: {
32591
+ copper: {
32592
+ top: TRANSPARENT3,
32593
+ bottom: TRANSPARENT3,
32594
+ inner1: TRANSPARENT3,
32595
+ inner2: TRANSPARENT3,
32596
+ inner3: TRANSPARENT3,
32597
+ inner4: TRANSPARENT3,
32598
+ inner5: TRANSPARENT3,
32599
+ inner6: TRANSPARENT3
32600
+ },
32601
+ copperPour: {
32602
+ top: TRANSPARENT3,
32603
+ bottom: TRANSPARENT3
32604
+ },
32605
+ drill: TRANSPARENT3,
32606
+ boardOutline: TRANSPARENT3,
32607
+ substrate: TRANSPARENT3,
32608
+ keepout: TRANSPARENT3,
32609
+ courtyard: {
32610
+ top: TRANSPARENT3,
32611
+ bottom: TRANSPARENT3
32612
+ },
32613
+ soldermask: {
32614
+ top: TRANSPARENT3,
32615
+ bottom: TRANSPARENT3
32616
+ },
32456
32617
  soldermaskWithCopperUnderneath: {
32457
- top: TRANSPARENT2,
32458
- bottom: TRANSPARENT2
32618
+ top: TRANSPARENT3,
32619
+ bottom: TRANSPARENT3
32459
32620
  },
32460
32621
  soldermaskOverCopper: {
32461
- top: TRANSPARENT2,
32462
- bottom: TRANSPARENT2
32622
+ top: TRANSPARENT3,
32623
+ bottom: TRANSPARENT3
32463
32624
  },
32464
32625
  silkscreen: {
32465
32626
  top: silkscreenColor,
@@ -32468,7 +32629,7 @@ var drawSilkscreenLayer = ({
32468
32629
  fabricationNote: FABRICATION_NOTE_COLOR2
32469
32630
  }
32470
32631
  });
32471
- setDrawerBounds3(drawer, bounds);
32632
+ setDrawerBounds4(drawer, bounds);
32472
32633
  drawer.drawElements(elements, {
32473
32634
  layers: [renderLayer]
32474
32635
  });
@@ -32478,7 +32639,7 @@ var drawSilkscreenLayer = ({
32478
32639
  var isSilkscreenElement = (element, layer) => {
32479
32640
  if (!("layer" in element) || element.layer !== layer) return false;
32480
32641
  const elementType = element.type;
32481
- return elementType.startsWith("pcb_silkscreen_") || elementType === "pcb_note_line";
32642
+ return elementType.startsWith("pcb_silkscreen_");
32482
32643
  };
32483
32644
  function createSilkscreenTextureForLayer({
32484
32645
  layer,
@@ -32511,20 +32672,20 @@ function createSilkscreenTextureForLayer({
32511
32672
  elements,
32512
32673
  silkscreenColor
32513
32674
  });
32514
- const texture = new THREE25.CanvasTexture(canvas);
32675
+ const texture = new THREE26.CanvasTexture(canvas);
32515
32676
  texture.generateMipmaps = true;
32516
- texture.minFilter = THREE25.LinearMipmapLinearFilter;
32517
- texture.magFilter = THREE25.LinearFilter;
32677
+ texture.minFilter = THREE26.LinearMipmapLinearFilter;
32678
+ texture.magFilter = THREE26.LinearFilter;
32518
32679
  texture.anisotropy = 16;
32519
32680
  texture.needsUpdate = true;
32520
32681
  return texture;
32521
32682
  }
32522
32683
 
32523
32684
  // src/textures/create-soldermask-texture-for-layer.ts
32524
- import * as THREE26 from "three";
32685
+ import * as THREE27 from "three";
32525
32686
 
32526
32687
  // src/textures/soldermask/soldermask-drawing.ts
32527
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer5 } from "circuit-to-canvas";
32688
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer6 } from "circuit-to-canvas";
32528
32689
  var toRgb = (colorArr) => {
32529
32690
  const [r = 0, g = 0, b = 0] = colorArr;
32530
32691
  return `rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(
@@ -32543,7 +32704,7 @@ var getSoldermaskPalette = (material) => {
32543
32704
  transparent: "rgba(0,0,0,0)"
32544
32705
  };
32545
32706
  };
32546
- var setDrawerBounds4 = (drawer, bounds) => {
32707
+ var setDrawerBounds5 = (drawer, bounds) => {
32547
32708
  drawer.setCameraBounds({
32548
32709
  minX: bounds.minX,
32549
32710
  maxX: bounds.maxX,
@@ -32560,7 +32721,7 @@ var drawSoldermaskLayer = ({
32560
32721
  }) => {
32561
32722
  const palette = getSoldermaskPalette(boardMaterial);
32562
32723
  const copperRenderLayer = layer === "top" ? "top_copper" : "bottom_copper";
32563
- const drawer = new CircuitToCanvasDrawer5(ctx);
32724
+ const drawer = new CircuitToCanvasDrawer6(ctx);
32564
32725
  drawer.configure({
32565
32726
  colorOverrides: {
32566
32727
  copper: {
@@ -32591,7 +32752,7 @@ var drawSoldermaskLayer = ({
32591
32752
  }
32592
32753
  }
32593
32754
  });
32594
- setDrawerBounds4(drawer, bounds);
32755
+ setDrawerBounds5(drawer, bounds);
32595
32756
  drawer.drawElements(elements, {
32596
32757
  layers: [copperRenderLayer],
32597
32758
  drawSoldermask: true,
@@ -32604,7 +32765,7 @@ var drawSoldermaskLayer = ({
32604
32765
  if (uncoveredPours.length > 0) {
32605
32766
  ctx.save();
32606
32767
  ctx.globalCompositeOperation = "destination-out";
32607
- const cutoutDrawer = new CircuitToCanvasDrawer5(ctx);
32768
+ const cutoutDrawer = new CircuitToCanvasDrawer6(ctx);
32608
32769
  cutoutDrawer.configure({
32609
32770
  colorOverrides: {
32610
32771
  copper: {
@@ -32619,7 +32780,7 @@ var drawSoldermaskLayer = ({
32619
32780
  }
32620
32781
  }
32621
32782
  });
32622
- setDrawerBounds4(cutoutDrawer, bounds);
32783
+ setDrawerBounds5(cutoutDrawer, bounds);
32623
32784
  cutoutDrawer.drawElements(uncoveredPours, { layers: [copperRenderLayer] });
32624
32785
  ctx.restore();
32625
32786
  }
@@ -32653,10 +32814,10 @@ function createSoldermaskTextureForLayer({
32653
32814
  elements,
32654
32815
  boardMaterial: boardData.material
32655
32816
  });
32656
- const texture = new THREE26.CanvasTexture(canvas);
32817
+ const texture = new THREE27.CanvasTexture(canvas);
32657
32818
  texture.generateMipmaps = true;
32658
- texture.minFilter = THREE26.LinearMipmapLinearFilter;
32659
- texture.magFilter = THREE26.LinearFilter;
32819
+ texture.minFilter = THREE27.LinearMipmapLinearFilter;
32820
+ texture.magFilter = THREE27.LinearFilter;
32660
32821
  texture.anisotropy = 16;
32661
32822
  texture.needsUpdate = true;
32662
32823
  return texture;
@@ -32694,10 +32855,10 @@ var createCombinedTexture = ({
32694
32855
  const image = texture.image;
32695
32856
  ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
32696
32857
  });
32697
- const combinedTexture = new THREE27.CanvasTexture(canvas);
32858
+ const combinedTexture = new THREE28.CanvasTexture(canvas);
32698
32859
  combinedTexture.generateMipmaps = false;
32699
- combinedTexture.minFilter = THREE27.LinearFilter;
32700
- combinedTexture.magFilter = THREE27.LinearFilter;
32860
+ combinedTexture.minFilter = THREE28.LinearFilter;
32861
+ combinedTexture.magFilter = THREE28.LinearFilter;
32701
32862
  combinedTexture.premultiplyAlpha = true;
32702
32863
  combinedTexture.anisotropy = 16;
32703
32864
  combinedTexture.needsUpdate = true;
@@ -32764,6 +32925,12 @@ function createCombinedBoardTextures({
32764
32925
  boardData,
32765
32926
  traceTextureResolution
32766
32927
  }) : null;
32928
+ const pcbNoteTexture = showSilkscreen ? createPcbNoteTextureForLayer({
32929
+ layer,
32930
+ circuitJson,
32931
+ boardData,
32932
+ traceTextureResolution
32933
+ }) : null;
32767
32934
  const panelOutlineTexture = showBoardBody ? createPanelOutlineTextureForLayer({
32768
32935
  layer,
32769
32936
  circuitJson,
@@ -32779,6 +32946,7 @@ function createCombinedBoardTextures({
32779
32946
  copperTextTexture,
32780
32947
  silkscreenTexture,
32781
32948
  fabricationNoteTexture,
32949
+ pcbNoteTexture,
32782
32950
  panelOutlineTexture
32783
32951
  ],
32784
32952
  boardData,
@@ -32793,7 +32961,7 @@ function createCombinedBoardTextures({
32793
32961
  }
32794
32962
 
32795
32963
  // src/textures/create-three-texture-meshes.ts
32796
- import * as THREE28 from "three";
32964
+ import * as THREE29 from "three";
32797
32965
  function createTexturePlane(config, boardData) {
32798
32966
  const {
32799
32967
  texture,
@@ -32805,15 +32973,15 @@ function createTexturePlane(config, boardData) {
32805
32973
  } = config;
32806
32974
  if (!texture) return null;
32807
32975
  const boardOutlineBounds = calculateOutlineBounds(boardData);
32808
- const planeGeom = new THREE28.PlaneGeometry(
32976
+ const planeGeom = new THREE29.PlaneGeometry(
32809
32977
  boardOutlineBounds.width,
32810
32978
  boardOutlineBounds.height
32811
32979
  );
32812
- const material = new THREE28.MeshBasicMaterial({
32980
+ const material = new THREE29.MeshBasicMaterial({
32813
32981
  map: texture,
32814
32982
  transparent: true,
32815
32983
  alphaTest: 0.08,
32816
- side: THREE28.DoubleSide,
32984
+ side: THREE29.DoubleSide,
32817
32985
  depthWrite: true,
32818
32986
  polygonOffset: usePolygonOffset,
32819
32987
  polygonOffsetFactor: usePolygonOffset ? -4 : 0,
@@ -32821,7 +32989,7 @@ function createTexturePlane(config, boardData) {
32821
32989
  polygonOffsetUnits: usePolygonOffset ? -4 : 0,
32822
32990
  opacity: isFaux ? FAUX_BOARD_OPACITY : 1
32823
32991
  });
32824
- const mesh = new THREE28.Mesh(planeGeom, material);
32992
+ const mesh = new THREE29.Mesh(planeGeom, material);
32825
32993
  mesh.position.set(
32826
32994
  boardOutlineBounds.centerX,
32827
32995
  boardOutlineBounds.centerY,
@@ -32866,7 +33034,7 @@ function createTextureMeshes(textures, boardData, pcbThickness, isFaux = false)
32866
33034
  }
32867
33035
 
32868
33036
  // src/three-components/JscadBoardTextures.tsx
32869
- import * as THREE29 from "three";
33037
+ import * as THREE30 from "three";
32870
33038
 
32871
33039
  // src/utils/layer-texture-resolution.ts
32872
33040
  var DEFAULT_MAX_TEXTURE_PIXELS = 4e6;
@@ -32962,7 +33130,7 @@ function JscadBoardTextures({
32962
33130
  const typedMaterial = material;
32963
33131
  for (const prop of textureProps) {
32964
33132
  const texture = typedMaterial[prop];
32965
- if (texture && texture instanceof THREE29.Texture) {
33133
+ if (texture && texture instanceof THREE30.Texture) {
32966
33134
  texture.dispose();
32967
33135
  typedMaterial[prop] = null;
32968
33136
  }
@@ -32972,22 +33140,22 @@ function JscadBoardTextures({
32972
33140
  const createTexturePlane2 = (texture, zOffset, isBottomLayer, name, usePolygonOffset = false, depthWrite = true, renderOrder = 1) => {
32973
33141
  if (!texture) return null;
32974
33142
  const boardOutlineBounds = calculateOutlineBounds(boardData);
32975
- const planeGeom = new THREE29.PlaneGeometry(
33143
+ const planeGeom = new THREE30.PlaneGeometry(
32976
33144
  boardOutlineBounds.width,
32977
33145
  boardOutlineBounds.height
32978
33146
  );
32979
- const material = new THREE29.MeshBasicMaterial({
33147
+ const material = new THREE30.MeshBasicMaterial({
32980
33148
  map: texture,
32981
33149
  transparent: true,
32982
33150
  alphaTest: 0.08,
32983
- side: THREE29.DoubleSide,
33151
+ side: THREE30.DoubleSide,
32984
33152
  depthWrite,
32985
33153
  polygonOffset: usePolygonOffset,
32986
33154
  polygonOffsetFactor: usePolygonOffset ? -4 : 0,
32987
33155
  polygonOffsetUnits: usePolygonOffset ? -4 : 0,
32988
33156
  opacity: isFaux ? FAUX_BOARD_OPACITY : 1
32989
33157
  });
32990
- const mesh = new THREE29.Mesh(planeGeom, material);
33158
+ const mesh = new THREE30.Mesh(planeGeom, material);
32991
33159
  mesh.position.set(
32992
33160
  boardOutlineBounds.centerX,
32993
33161
  boardOutlineBounds.centerY,
@@ -33032,7 +33200,7 @@ function JscadBoardTextures({
33032
33200
  mesh.geometry.dispose();
33033
33201
  if (Array.isArray(mesh.material)) {
33034
33202
  mesh.material.forEach((material) => disposeTextureMaterial(material));
33035
- } else if (mesh.material instanceof THREE29.Material) {
33203
+ } else if (mesh.material instanceof THREE30.Material) {
33036
33204
  disposeTextureMaterial(mesh.material);
33037
33205
  }
33038
33206
  });
@@ -33265,12 +33433,12 @@ var CadViewerJscad = forwardRef3(
33265
33433
  // src/CadViewerManifold.tsx
33266
33434
  import { su as su17 } from "@tscircuit/circuit-json-util";
33267
33435
  import { useEffect as useEffect25, useMemo as useMemo22, useState as useState16 } from "react";
33268
- import * as THREE36 from "three";
33436
+ import * as THREE37 from "three";
33269
33437
 
33270
33438
  // src/hooks/useManifoldBoardBuilder.ts
33271
33439
  import { su as su16 } from "@tscircuit/circuit-json-util";
33272
33440
  import { useEffect as useEffect24, useMemo as useMemo21, useRef as useRef9, useState as useState15 } from "react";
33273
- import * as THREE33 from "three";
33441
+ import * as THREE34 from "three";
33274
33442
 
33275
33443
  // src/utils/manifold/create-manifold-board.ts
33276
33444
  var arePointsClockwise2 = (points) => {
@@ -33612,17 +33780,17 @@ function processNonPlatedHolesForManifold(Manifold, CrossSection, circuitJson, p
33612
33780
 
33613
33781
  // src/utils/manifold/process-plated-holes.ts
33614
33782
  import { su as su14 } from "@tscircuit/circuit-json-util";
33615
- import * as THREE31 from "three";
33783
+ import * as THREE32 from "three";
33616
33784
 
33617
33785
  // src/utils/manifold-mesh-to-three-geometry.ts
33618
- import * as THREE30 from "three";
33786
+ import * as THREE31 from "three";
33619
33787
  function manifoldMeshToThreeGeometry(manifoldMesh) {
33620
- const geometry = new THREE30.BufferGeometry();
33788
+ const geometry = new THREE31.BufferGeometry();
33621
33789
  geometry.setAttribute(
33622
33790
  "position",
33623
- new THREE30.Float32BufferAttribute(manifoldMesh.vertProperties, 3)
33791
+ new THREE31.Float32BufferAttribute(manifoldMesh.vertProperties, 3)
33624
33792
  );
33625
- geometry.setIndex(new THREE30.Uint32BufferAttribute(manifoldMesh.triVerts, 1));
33793
+ geometry.setIndex(new THREE31.Uint32BufferAttribute(manifoldMesh.triVerts, 1));
33626
33794
  if (manifoldMesh.runIndex && manifoldMesh.runIndex.length > 1 && manifoldMesh.runOriginalID) {
33627
33795
  for (let i = 0; i < manifoldMesh.runIndex.length - 1; i++) {
33628
33796
  const start = manifoldMesh.runIndex[i];
@@ -33656,7 +33824,7 @@ var createEllipsePoints = (width10, height10, segments) => {
33656
33824
  }
33657
33825
  return points;
33658
33826
  };
33659
- var COPPER_COLOR = new THREE31.Color(...colors.copper);
33827
+ var COPPER_COLOR = new THREE32.Color(...colors.copper);
33660
33828
  var PLATED_HOLE_LIP_HEIGHT = 0.05;
33661
33829
  var PLATED_HOLE_PAD_THICKNESS = 3e-3;
33662
33830
  var PLATED_HOLE_SURFACE_CLEARANCE = 5e-4;
@@ -34398,7 +34566,7 @@ function processPlatedHolesForManifold(Manifold, CrossSection, circuitJson, pcbT
34398
34566
 
34399
34567
  // src/utils/manifold/process-vias.ts
34400
34568
  import { su as su15 } from "@tscircuit/circuit-json-util";
34401
- import * as THREE32 from "three";
34569
+ import * as THREE33 from "three";
34402
34570
 
34403
34571
  // src/utils/via-geoms.ts
34404
34572
  function createViaCopper2({
@@ -34451,7 +34619,7 @@ function createViaCopper2({
34451
34619
  }
34452
34620
 
34453
34621
  // src/utils/manifold/process-vias.ts
34454
- var COPPER_COLOR2 = new THREE32.Color(...colors.copper);
34622
+ var COPPER_COLOR2 = new THREE33.Color(...colors.copper);
34455
34623
  function processViasForManifold(Manifold, circuitJson, pcbThickness, manifoldInstancesForCleanup, boardClipVolume) {
34456
34624
  const viaBoardDrills = [];
34457
34625
  const pcbVias = su15(circuitJson).pcb_via.list();
@@ -34671,7 +34839,7 @@ var useManifoldBoardBuilder = (manifoldJSModule, circuitJson, visibility) => {
34671
34839
  {
34672
34840
  key: "plated-holes-union",
34673
34841
  geometry: cutPlatedGeom,
34674
- color: new THREE33.Color(
34842
+ color: new THREE34.Color(
34675
34843
  colors.copper[0],
34676
34844
  colors.copper[1],
34677
34845
  colors.copper[2]
@@ -34701,7 +34869,7 @@ var useManifoldBoardBuilder = (manifoldJSModule, circuitJson, visibility) => {
34701
34869
  const matColorArray = boardMaterialColors[boardData.material] ?? colors.fr4Tan;
34702
34870
  currentGeoms.board = {
34703
34871
  geometry: finalBoardGeom,
34704
- color: new THREE33.Color(
34872
+ color: new THREE34.Color(
34705
34873
  matColorArray[0],
34706
34874
  matColorArray[1],
34707
34875
  matColorArray[2]
@@ -34746,11 +34914,11 @@ var useManifoldBoardBuilder = (manifoldJSModule, circuitJson, visibility) => {
34746
34914
  };
34747
34915
 
34748
34916
  // src/utils/manifold/create-three-geometry-meshes.ts
34749
- import * as THREE35 from "three";
34917
+ import * as THREE36 from "three";
34750
34918
 
34751
34919
  // src/utils/create-board-material.ts
34752
- import * as THREE34 from "three";
34753
- var DEFAULT_SIDE = THREE34.DoubleSide;
34920
+ import * as THREE35 from "three";
34921
+ var DEFAULT_SIDE = THREE35.DoubleSide;
34754
34922
  var createBoardMaterial = ({
34755
34923
  material,
34756
34924
  color,
@@ -34758,7 +34926,7 @@ var createBoardMaterial = ({
34758
34926
  isFaux = false
34759
34927
  }) => {
34760
34928
  if (material === "fr4") {
34761
- return new THREE34.MeshPhysicalMaterial({
34929
+ return new THREE35.MeshPhysicalMaterial({
34762
34930
  color,
34763
34931
  side,
34764
34932
  metalness: 0,
@@ -34775,7 +34943,7 @@ var createBoardMaterial = ({
34775
34943
  polygonOffsetUnits: 1
34776
34944
  });
34777
34945
  }
34778
- return new THREE34.MeshStandardMaterial({
34946
+ return new THREE35.MeshStandardMaterial({
34779
34947
  color,
34780
34948
  side,
34781
34949
  flatShading: true,
@@ -34794,12 +34962,12 @@ function createGeometryMeshes(geoms) {
34794
34962
  const meshes = [];
34795
34963
  if (!geoms) return meshes;
34796
34964
  if (geoms.board && geoms.board.geometry) {
34797
- const mesh = new THREE35.Mesh(
34965
+ const mesh = new THREE36.Mesh(
34798
34966
  geoms.board.geometry,
34799
34967
  createBoardMaterial({
34800
34968
  material: geoms.board.material,
34801
34969
  color: geoms.board.color,
34802
- side: THREE35.DoubleSide,
34970
+ side: THREE36.DoubleSide,
34803
34971
  isFaux: geoms.board.isFaux
34804
34972
  })
34805
34973
  );
@@ -34809,11 +34977,11 @@ function createGeometryMeshes(geoms) {
34809
34977
  const createMeshesFromArray = (geomArray) => {
34810
34978
  if (geomArray) {
34811
34979
  geomArray.forEach((comp) => {
34812
- const mesh = new THREE35.Mesh(
34980
+ const mesh = new THREE36.Mesh(
34813
34981
  comp.geometry,
34814
- new THREE35.MeshStandardMaterial({
34982
+ new THREE36.MeshStandardMaterial({
34815
34983
  color: comp.color,
34816
- side: THREE35.DoubleSide,
34984
+ side: THREE36.DoubleSide,
34817
34985
  flatShading: true
34818
34986
  // Consistent with board
34819
34987
  })
@@ -34857,7 +35025,7 @@ var BoardMeshes = ({
34857
35025
  const typedMaterial = material;
34858
35026
  for (const prop of textureProps) {
34859
35027
  const texture = typedMaterial[prop];
34860
- if (texture && texture instanceof THREE36.Texture) {
35028
+ if (texture && texture instanceof THREE37.Texture) {
34861
35029
  texture.dispose();
34862
35030
  typedMaterial[prop] = null;
34863
35031
  }
@@ -41746,7 +41914,7 @@ var KeyboardShortcutsDialog = ({
41746
41914
 
41747
41915
  // src/CadViewer.tsx
41748
41916
  import { jsx as jsx38, jsxs as jsxs11 } from "react/jsx-runtime";
41749
- var DEFAULT_TARGET = new THREE37.Vector3(0, 0, 0);
41917
+ var DEFAULT_TARGET = new THREE38.Vector3(0, 0, 0);
41750
41918
  var INITIAL_CAMERA_POSITION = [5, -5, 5];
41751
41919
  var CadViewerInner = (props) => {
41752
41920
  const [engine, setEngine] = useState36("manifold");
@@ -42013,11 +42181,11 @@ var CadViewer = (props) => {
42013
42181
  // src/convert-circuit-json-to-3d-svg.ts
42014
42182
  var import_debug = __toESM(require_browser(), 1);
42015
42183
  import { su as su18 } from "@tscircuit/circuit-json-util";
42016
- import * as THREE41 from "three";
42184
+ import * as THREE42 from "three";
42017
42185
  import { SVGRenderer } from "three/examples/jsm/renderers/SVGRenderer.js";
42018
42186
 
42019
42187
  // src/utils/create-geometry-from-polygons.ts
42020
- import * as THREE38 from "three";
42188
+ import * as THREE39 from "three";
42021
42189
  import { BufferGeometry as BufferGeometry4, Float32BufferAttribute as Float32BufferAttribute3 } from "three";
42022
42190
  function createGeometryFromPolygons(polygons) {
42023
42191
  const geometry = new BufferGeometry4();
@@ -42031,12 +42199,12 @@ function createGeometryFromPolygons(polygons) {
42031
42199
  ...polygon3.vertices[i + 1]
42032
42200
  // Third vertex
42033
42201
  );
42034
- const v1 = new THREE38.Vector3(...polygon3.vertices[0]);
42035
- const v2 = new THREE38.Vector3(...polygon3.vertices[i]);
42036
- const v3 = new THREE38.Vector3(...polygon3.vertices[i + 1]);
42037
- const normal = new THREE38.Vector3().crossVectors(
42038
- new THREE38.Vector3().subVectors(v2, v1),
42039
- new THREE38.Vector3().subVectors(v3, v1)
42202
+ const v1 = new THREE39.Vector3(...polygon3.vertices[0]);
42203
+ const v2 = new THREE39.Vector3(...polygon3.vertices[i]);
42204
+ const v3 = new THREE39.Vector3(...polygon3.vertices[i + 1]);
42205
+ const normal = new THREE39.Vector3().crossVectors(
42206
+ new THREE39.Vector3().subVectors(v2, v1),
42207
+ new THREE39.Vector3().subVectors(v3, v1)
42040
42208
  ).normalize();
42041
42209
  normals.push(
42042
42210
  normal.x,
@@ -42060,10 +42228,10 @@ function createGeometryFromPolygons(polygons) {
42060
42228
  var import_modeling2 = __toESM(require_src(), 1);
42061
42229
  var import_jscad_planner2 = __toESM(require_dist(), 1);
42062
42230
  var jscadModeling2 = __toESM(require_src(), 1);
42063
- import * as THREE40 from "three";
42231
+ import * as THREE41 from "three";
42064
42232
 
42065
42233
  // src/utils/load-model.ts
42066
- import * as THREE39 from "three";
42234
+ import * as THREE40 from "three";
42067
42235
  import { GLTFLoader as GLTFLoader2 } from "three/examples/jsm/loaders/GLTFLoader.js";
42068
42236
  import { OBJLoader as OBJLoader2 } from "three/examples/jsm/loaders/OBJLoader.js";
42069
42237
  import { STLLoader as STLLoader2 } from "three/examples/jsm/loaders/STLLoader.js";
@@ -42071,12 +42239,12 @@ async function load3DModel(url) {
42071
42239
  if (url.endsWith(".stl")) {
42072
42240
  const loader = new STLLoader2();
42073
42241
  const geometry = await loader.loadAsync(url);
42074
- const material = new THREE39.MeshStandardMaterial({
42242
+ const material = new THREE40.MeshStandardMaterial({
42075
42243
  color: 8947848,
42076
42244
  metalness: 0.5,
42077
42245
  roughness: 0.5
42078
42246
  });
42079
- return new THREE39.Mesh(geometry, material);
42247
+ return new THREE40.Mesh(geometry, material);
42080
42248
  }
42081
42249
  if (url.endsWith(".obj")) {
42082
42250
  const loader = new OBJLoader2();
@@ -42109,9 +42277,9 @@ async function renderComponent(component, scene) {
42109
42277
  }
42110
42278
  if (component.rotation) {
42111
42279
  model.rotation.set(
42112
- THREE40.MathUtils.degToRad(component.rotation.x ?? 0),
42113
- THREE40.MathUtils.degToRad(component.rotation.y ?? 0),
42114
- THREE40.MathUtils.degToRad(component.rotation.z ?? 0)
42280
+ THREE41.MathUtils.degToRad(component.rotation.x ?? 0),
42281
+ THREE41.MathUtils.degToRad(component.rotation.y ?? 0),
42282
+ THREE41.MathUtils.degToRad(component.rotation.z ?? 0)
42115
42283
  );
42116
42284
  }
42117
42285
  scene.add(model);
@@ -42125,13 +42293,13 @@ async function renderComponent(component, scene) {
42125
42293
  );
42126
42294
  if (jscadObject && (jscadObject.polygons || jscadObject.sides)) {
42127
42295
  const threeGeom = convertCSGToThreeGeom(jscadObject);
42128
- const material2 = new THREE40.MeshStandardMaterial({
42296
+ const material2 = new THREE41.MeshStandardMaterial({
42129
42297
  color: 8947848,
42130
42298
  metalness: 0.5,
42131
42299
  roughness: 0.5,
42132
- side: THREE40.DoubleSide
42300
+ side: THREE41.DoubleSide
42133
42301
  });
42134
- const mesh2 = new THREE40.Mesh(threeGeom, material2);
42302
+ const mesh2 = new THREE41.Mesh(threeGeom, material2);
42135
42303
  if (component.position) {
42136
42304
  mesh2.position.set(
42137
42305
  component.position.x ?? 0,
@@ -42141,9 +42309,9 @@ async function renderComponent(component, scene) {
42141
42309
  }
42142
42310
  if (component.rotation) {
42143
42311
  mesh2.rotation.set(
42144
- THREE40.MathUtils.degToRad(component.rotation.x ?? 0),
42145
- THREE40.MathUtils.degToRad(component.rotation.y ?? 0),
42146
- THREE40.MathUtils.degToRad(component.rotation.z ?? 0)
42312
+ THREE41.MathUtils.degToRad(component.rotation.x ?? 0),
42313
+ THREE41.MathUtils.degToRad(component.rotation.y ?? 0),
42314
+ THREE41.MathUtils.degToRad(component.rotation.z ?? 0)
42147
42315
  );
42148
42316
  }
42149
42317
  scene.add(mesh2);
@@ -42160,17 +42328,17 @@ async function renderComponent(component, scene) {
42160
42328
  if (!geom || !geom.polygons && !geom.sides) {
42161
42329
  continue;
42162
42330
  }
42163
- const color = new THREE40.Color(geomInfo.color);
42331
+ const color = new THREE41.Color(geomInfo.color);
42164
42332
  color.convertLinearToSRGB();
42165
42333
  const geomWithColor = { ...geom, color: [color.r, color.g, color.b] };
42166
42334
  const threeGeom = convertCSGToThreeGeom(geomWithColor);
42167
- const material2 = new THREE40.MeshStandardMaterial({
42335
+ const material2 = new THREE41.MeshStandardMaterial({
42168
42336
  vertexColors: true,
42169
42337
  metalness: 0.2,
42170
42338
  roughness: 0.8,
42171
- side: THREE40.DoubleSide
42339
+ side: THREE41.DoubleSide
42172
42340
  });
42173
- const mesh2 = new THREE40.Mesh(threeGeom, material2);
42341
+ const mesh2 = new THREE41.Mesh(threeGeom, material2);
42174
42342
  if (component.position) {
42175
42343
  mesh2.position.set(
42176
42344
  component.position.x ?? 0,
@@ -42180,22 +42348,22 @@ async function renderComponent(component, scene) {
42180
42348
  }
42181
42349
  if (component.rotation) {
42182
42350
  mesh2.rotation.set(
42183
- THREE40.MathUtils.degToRad(component.rotation.x ?? 0),
42184
- THREE40.MathUtils.degToRad(component.rotation.y ?? 0),
42185
- THREE40.MathUtils.degToRad(component.rotation.z ?? 0)
42351
+ THREE41.MathUtils.degToRad(component.rotation.x ?? 0),
42352
+ THREE41.MathUtils.degToRad(component.rotation.y ?? 0),
42353
+ THREE41.MathUtils.degToRad(component.rotation.z ?? 0)
42186
42354
  );
42187
42355
  }
42188
42356
  scene.add(mesh2);
42189
42357
  }
42190
42358
  return;
42191
42359
  }
42192
- const geometry = new THREE40.BoxGeometry(0.5, 0.5, 0.5);
42193
- const material = new THREE40.MeshStandardMaterial({
42360
+ const geometry = new THREE41.BoxGeometry(0.5, 0.5, 0.5);
42361
+ const material = new THREE41.MeshStandardMaterial({
42194
42362
  color: 16711680,
42195
42363
  transparent: true,
42196
42364
  opacity: 0.25
42197
42365
  });
42198
- const mesh = new THREE40.Mesh(geometry, material);
42366
+ const mesh = new THREE41.Mesh(geometry, material);
42199
42367
  if (component.position) {
42200
42368
  mesh.position.set(
42201
42369
  component.position.x ?? 0,
@@ -42216,11 +42384,11 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
42216
42384
  padding = 20,
42217
42385
  zoom = 1.5
42218
42386
  } = options;
42219
- const scene = new THREE41.Scene();
42387
+ const scene = new THREE42.Scene();
42220
42388
  const renderer = new SVGRenderer();
42221
42389
  renderer.setSize(width10, height10);
42222
- renderer.setClearColor(new THREE41.Color(backgroundColor), 1);
42223
- const camera = new THREE41.OrthographicCamera();
42390
+ renderer.setClearColor(new THREE42.Color(backgroundColor), 1);
42391
+ const camera = new THREE42.OrthographicCamera();
42224
42392
  const aspect = width10 / height10;
42225
42393
  const frustumSize = 100;
42226
42394
  const halfFrustumSize = frustumSize / 2 / zoom;
@@ -42234,11 +42402,11 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
42234
42402
  camera.position.set(position.x, position.y, position.z);
42235
42403
  camera.up.set(0, 1, 0);
42236
42404
  const lookAt = options.camera?.lookAt ?? { x: 0, y: 0, z: 0 };
42237
- camera.lookAt(new THREE41.Vector3(lookAt.x, lookAt.y, lookAt.z));
42405
+ camera.lookAt(new THREE42.Vector3(lookAt.x, lookAt.y, lookAt.z));
42238
42406
  camera.updateProjectionMatrix();
42239
- const ambientLight = new THREE41.AmbientLight(16777215, Math.PI / 2);
42407
+ const ambientLight = new THREE42.AmbientLight(16777215, Math.PI / 2);
42240
42408
  scene.add(ambientLight);
42241
- const pointLight = new THREE41.PointLight(16777215, Math.PI / 4);
42409
+ const pointLight = new THREE42.PointLight(16777215, Math.PI / 4);
42242
42410
  pointLight.position.set(-10, -10, 10);
42243
42411
  scene.add(pointLight);
42244
42412
  const components = su18(circuitJson).cad_component.list();
@@ -42249,7 +42417,7 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
42249
42417
  const boardGeom = createBoardGeomFromCircuitJson(circuitJson);
42250
42418
  if (boardGeom) {
42251
42419
  const solderMaskColor = colors.fr4SolderMaskGreen;
42252
- const baseColor = new THREE41.Color(
42420
+ const baseColor = new THREE42.Color(
42253
42421
  solderMaskColor[0],
42254
42422
  solderMaskColor[1],
42255
42423
  solderMaskColor[2]
@@ -42261,28 +42429,28 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
42261
42429
  const material = createBoardMaterial({
42262
42430
  material: boardData?.material,
42263
42431
  color: baseColor,
42264
- side: THREE41.DoubleSide
42432
+ side: THREE42.DoubleSide
42265
42433
  });
42266
- const mesh = new THREE41.Mesh(geometry, material);
42434
+ const mesh = new THREE42.Mesh(geometry, material);
42267
42435
  scene.add(mesh);
42268
42436
  }
42269
42437
  }
42270
- const gridColor = new THREE41.Color(8947848);
42271
- const gridHelper = new THREE41.GridHelper(100, 100, gridColor, gridColor);
42438
+ const gridColor = new THREE42.Color(8947848);
42439
+ const gridHelper = new THREE42.GridHelper(100, 100, gridColor, gridColor);
42272
42440
  gridHelper.rotation.x = Math.PI / 2;
42273
42441
  const materials = Array.isArray(gridHelper.material) ? gridHelper.material : [gridHelper.material];
42274
42442
  for (const mat of materials) {
42275
42443
  mat.transparent = true;
42276
42444
  mat.opacity = 0.3;
42277
- if (mat instanceof THREE41.LineBasicMaterial) {
42445
+ if (mat instanceof THREE42.LineBasicMaterial) {
42278
42446
  mat.color = gridColor;
42279
42447
  mat.vertexColors = false;
42280
42448
  }
42281
42449
  }
42282
42450
  scene.add(gridHelper);
42283
- const box = new THREE41.Box3().setFromObject(scene);
42284
- const center = box.getCenter(new THREE41.Vector3());
42285
- const size4 = box.getSize(new THREE41.Vector3());
42451
+ const box = new THREE42.Box3().setFromObject(scene);
42452
+ const center = box.getCenter(new THREE42.Vector3());
42453
+ const size4 = box.getSize(new THREE42.Vector3());
42286
42454
  scene.position.sub(center);
42287
42455
  const maxDim = Math.max(size4.x, size4.y, size4.z);
42288
42456
  if (maxDim > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/3d-viewer",
3
- "version": "0.0.523",
3
+ "version": "0.0.524",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",