@tscircuit/3d-viewer 0.0.525 → 0.0.526

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 +39 -254
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -28768,7 +28768,7 @@ import * as THREE16 from "three";
28768
28768
  // package.json
28769
28769
  var package_default = {
28770
28770
  name: "@tscircuit/3d-viewer",
28771
- version: "0.0.524",
28771
+ version: "0.0.525",
28772
28772
  main: "./dist/index.js",
28773
28773
  module: "./dist/index.js",
28774
28774
  type: "module",
@@ -28798,7 +28798,7 @@ var package_default = {
28798
28798
  "@jscad/regl-renderer": "^2.6.12",
28799
28799
  "@jscad/stl-serializer": "^2.1.20",
28800
28800
  "circuit-json": "^0.0.372",
28801
- "circuit-to-canvas": "^0.0.81",
28801
+ "circuit-to-canvas": "^0.0.83",
28802
28802
  "react-hot-toast": "^2.6.0",
28803
28803
  three: "^0.165.0",
28804
28804
  "three-stdlib": "^2.36.0",
@@ -31737,7 +31737,7 @@ import { su as su8 } from "@tscircuit/circuit-json-util";
31737
31737
  import { useEffect as useEffect23, useMemo as useMemo19 } from "react";
31738
31738
 
31739
31739
  // src/textures/create-combined-board-textures.ts
31740
- import * as THREE28 from "three";
31740
+ import * as THREE27 from "three";
31741
31741
 
31742
31742
  // node_modules/@tscircuit/math-utils/dist/chunk-5N7UJNVK.js
31743
31743
  var getBoundsFromPoints = (points) => {
@@ -32233,227 +32233,11 @@ function createCopperTextTextureForLayer({
32233
32233
  return texture;
32234
32234
  }
32235
32235
 
32236
- // src/textures/create-copper-pour-texture-for-layer.ts
32237
- import * as THREE23 from "three";
32238
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer2 } from "circuit-to-canvas";
32239
-
32240
- // src/geoms/brep-converter.ts
32241
- var import_primitives7 = __toESM(require_primitives(), 1);
32242
- var import_booleans5 = __toESM(require_booleans(), 1);
32243
- function segmentToPoints(p1, p2, bulge, arcSegments) {
32244
- if (!bulge || Math.abs(bulge) < 1e-9) {
32245
- return [];
32246
- }
32247
- const theta = 4 * Math.atan(bulge);
32248
- const dx = p2[0] - p1[0];
32249
- const dy = p2[1] - p1[1];
32250
- const dist = Math.sqrt(dx * dx + dy * dy);
32251
- if (dist < 1e-9) return [];
32252
- const radius = Math.abs(dist / (2 * Math.sin(theta / 2)));
32253
- const m = Math.sqrt(Math.max(0, radius * radius - dist / 2 * (dist / 2)));
32254
- const midPoint = [(p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2];
32255
- const ux = dx / dist;
32256
- const uy = dy / dist;
32257
- const nx = -uy;
32258
- const ny = ux;
32259
- const centerX = midPoint[0] + nx * m * Math.sign(bulge);
32260
- const centerY = midPoint[1] + ny * m * Math.sign(bulge);
32261
- const startAngle = Math.atan2(p1[1] - centerY, p1[0] - centerX);
32262
- const points = [];
32263
- const numSteps = Math.max(
32264
- 2,
32265
- Math.ceil(arcSegments * Math.abs(theta) / (Math.PI * 2) * 4)
32266
- );
32267
- const angleStep = theta / numSteps;
32268
- for (let i = 1; i < numSteps; i++) {
32269
- const angle = startAngle + angleStep * i;
32270
- points.push([
32271
- centerX + radius * Math.cos(angle),
32272
- centerY + radius * Math.sin(angle)
32273
- ]);
32274
- }
32275
- return points;
32276
- }
32277
- function ringToPoints(ring, arcSegments) {
32278
- const allPoints = [];
32279
- const vertices = ring.vertices;
32280
- for (let i = 0; i < vertices.length; i++) {
32281
- const p1 = vertices[i];
32282
- const p2 = vertices[(i + 1) % vertices.length];
32283
- allPoints.push([p1.x, p1.y]);
32284
- if (p1.bulge) {
32285
- const arcPoints = segmentToPoints(
32286
- [p1.x, p1.y],
32287
- [p2.x, p2.y],
32288
- p1.bulge,
32289
- arcSegments
32290
- );
32291
- allPoints.push(...arcPoints);
32292
- }
32293
- }
32294
- return allPoints;
32295
- }
32296
-
32297
- // src/textures/create-copper-pour-texture-for-layer.ts
32298
- function drawPolygon({
32299
- ctx,
32300
- points,
32301
- canvasXFromPcb,
32302
- canvasYFromPcb
32303
- }) {
32304
- if (points.length < 3) return;
32305
- ctx.beginPath();
32306
- points.forEach((point, index2) => {
32307
- const canvasX = canvasXFromPcb(point[0]);
32308
- const canvasY = canvasYFromPcb(point[1]);
32309
- if (index2 === 0) {
32310
- ctx.moveTo(canvasX, canvasY);
32311
- } else {
32312
- ctx.lineTo(canvasX, canvasY);
32313
- }
32314
- });
32315
- ctx.closePath();
32316
- ctx.fill();
32317
- }
32318
- function drawBrepShape({
32319
- ctx,
32320
- pour,
32321
- canvasXFromPcb,
32322
- canvasYFromPcb
32323
- }) {
32324
- const brepShape = pour.brep_shape;
32325
- if (!brepShape || !brepShape.outer_ring) return;
32326
- const outerRingPoints = ringToPoints(brepShape.outer_ring, 32);
32327
- if (outerRingPoints.length >= 3) {
32328
- drawPolygon({
32329
- ctx,
32330
- points: outerRingPoints,
32331
- canvasXFromPcb,
32332
- canvasYFromPcb
32333
- });
32334
- }
32335
- if (brepShape.inner_rings && brepShape.inner_rings.length > 0) {
32336
- ctx.globalCompositeOperation = "destination-out";
32337
- for (const innerRing of brepShape.inner_rings) {
32338
- const innerRingPoints = ringToPoints(innerRing, 32);
32339
- if (innerRingPoints.length >= 3) {
32340
- drawPolygon({
32341
- ctx,
32342
- points: innerRingPoints,
32343
- canvasXFromPcb,
32344
- canvasYFromPcb
32345
- });
32346
- }
32347
- }
32348
- ctx.globalCompositeOperation = "source-over";
32349
- }
32350
- }
32351
- function createCopperPourTextureForLayer({
32352
- layer,
32353
- circuitJson,
32354
- boardData,
32355
- traceTextureResolution = TRACE_TEXTURE_RESOLUTION
32356
- }) {
32357
- const copperPours = circuitJson.filter(
32358
- (e) => e.type === "pcb_copper_pour"
32359
- );
32360
- const pcbRenderLayer = layer === "top" ? "top_copper" : "bottom_copper";
32361
- const poursOnLayer = copperPours.filter((p) => p.layer === layer);
32362
- if (poursOnLayer.length === 0) return null;
32363
- const boardOutlineBounds = calculateOutlineBounds(boardData);
32364
- const canvas = document.createElement("canvas");
32365
- const canvasWidth = Math.floor(
32366
- boardOutlineBounds.width * traceTextureResolution
32367
- );
32368
- const canvasHeight = Math.floor(
32369
- boardOutlineBounds.height * traceTextureResolution
32370
- );
32371
- canvas.width = canvasWidth;
32372
- canvas.height = canvasHeight;
32373
- const ctx = canvas.getContext("2d");
32374
- if (!ctx) return null;
32375
- if (layer === "bottom") {
32376
- ctx.translate(0, canvasHeight);
32377
- ctx.scale(1, -1);
32378
- }
32379
- const canvasXFromPcb = (pcbX) => (pcbX - boardOutlineBounds.minX) * traceTextureResolution;
32380
- const canvasYFromPcb = (pcbY) => (boardOutlineBounds.maxY - pcbY) * traceTextureResolution;
32381
- const rectAndPolygonPours = poursOnLayer.filter(
32382
- (pour) => pour.shape === "rect" || pour.shape === "polygon"
32383
- );
32384
- const brepPours = poursOnLayer.filter((pour) => pour.shape === "brep");
32385
- if (rectAndPolygonPours.length > 0) {
32386
- const drawer = new CircuitToCanvasDrawer2(ctx);
32387
- drawer.setCameraBounds({
32388
- minX: boardOutlineBounds.minX,
32389
- maxX: boardOutlineBounds.maxX,
32390
- minY: boardOutlineBounds.minY,
32391
- maxY: boardOutlineBounds.maxY
32392
- });
32393
- const coveredPours = rectAndPolygonPours.filter(
32394
- (p) => p.covered_with_solder_mask !== false
32395
- );
32396
- const uncoveredPours = rectAndPolygonPours.filter(
32397
- (p) => p.covered_with_solder_mask === false
32398
- );
32399
- const coveredColor = `rgb(${colors.fr4TracesWithMaskGreen.map((c) => c * 255).join(",")})`;
32400
- const uncoveredColor = `rgb(${colors.copper.map((c) => c * 255).join(",")})`;
32401
- if (coveredPours.length > 0) {
32402
- drawer.configure({
32403
- colorOverrides: {
32404
- copper: {
32405
- top: coveredColor,
32406
- bottom: coveredColor,
32407
- inner1: coveredColor,
32408
- inner2: coveredColor,
32409
- inner3: coveredColor,
32410
- inner4: coveredColor,
32411
- inner5: coveredColor,
32412
- inner6: coveredColor
32413
- }
32414
- }
32415
- });
32416
- drawer.drawElements(coveredPours, { layers: [pcbRenderLayer] });
32417
- }
32418
- if (uncoveredPours.length > 0) {
32419
- drawer.configure({
32420
- colorOverrides: {
32421
- copper: {
32422
- top: uncoveredColor,
32423
- bottom: uncoveredColor,
32424
- inner1: uncoveredColor,
32425
- inner2: uncoveredColor,
32426
- inner3: uncoveredColor,
32427
- inner4: uncoveredColor,
32428
- inner5: uncoveredColor,
32429
- inner6: uncoveredColor
32430
- }
32431
- }
32432
- });
32433
- drawer.drawElements(uncoveredPours, { layers: [pcbRenderLayer] });
32434
- }
32435
- }
32436
- for (const pour of brepPours) {
32437
- const covered = pour.covered_with_solder_mask !== false;
32438
- const colorArr = covered ? colors.fr4TracesWithMaskGreen : colors.copper;
32439
- const copperColor = `rgb(${colorArr[0] * 255}, ${colorArr[1] * 255}, ${colorArr[2] * 255})`;
32440
- ctx.fillStyle = copperColor;
32441
- drawBrepShape({ ctx, pour, canvasXFromPcb, canvasYFromPcb });
32442
- }
32443
- const texture = new THREE23.CanvasTexture(canvas);
32444
- texture.generateMipmaps = true;
32445
- texture.minFilter = THREE23.LinearMipmapLinearFilter;
32446
- texture.magFilter = THREE23.LinearFilter;
32447
- texture.anisotropy = 16;
32448
- texture.needsUpdate = true;
32449
- return texture;
32450
- }
32451
-
32452
32236
  // src/textures/create-fabrication-note-texture-for-layer.ts
32453
- import * as THREE24 from "three";
32237
+ import * as THREE23 from "three";
32454
32238
 
32455
32239
  // src/textures/fabrication-note/fabrication-note-drawing.ts
32456
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer3 } from "circuit-to-canvas";
32240
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer2 } from "circuit-to-canvas";
32457
32241
 
32458
32242
  // src/utils/units.ts
32459
32243
  var MM_PER_INCH = 25.4;
@@ -32551,7 +32335,7 @@ var drawFabricationNoteLayer = ({
32551
32335
  }) => {
32552
32336
  const renderLayer = `${layer}_fabrication_note`;
32553
32337
  const normalizedElements = elements.map(normalizeFabricationElement);
32554
- const drawer = new CircuitToCanvasDrawer3(ctx);
32338
+ const drawer = new CircuitToCanvasDrawer2(ctx);
32555
32339
  drawer.configure({
32556
32340
  colorOverrides: {
32557
32341
  copper: {
@@ -32677,20 +32461,20 @@ function createFabricationNoteTextureForLayer({
32677
32461
  bounds,
32678
32462
  elements
32679
32463
  });
32680
- const texture = new THREE24.CanvasTexture(canvas);
32464
+ const texture = new THREE23.CanvasTexture(canvas);
32681
32465
  texture.generateMipmaps = true;
32682
- texture.minFilter = THREE24.LinearMipmapLinearFilter;
32683
- texture.magFilter = THREE24.LinearFilter;
32466
+ texture.minFilter = THREE23.LinearMipmapLinearFilter;
32467
+ texture.magFilter = THREE23.LinearFilter;
32684
32468
  texture.anisotropy = 16;
32685
32469
  texture.needsUpdate = true;
32686
32470
  return texture;
32687
32471
  }
32688
32472
 
32689
32473
  // src/textures/create-pcb-note-texture-for-layer.ts
32690
- import * as THREE25 from "three";
32474
+ import * as THREE24 from "three";
32691
32475
 
32692
32476
  // src/textures/pcb-note/pcb-note-drawing.ts
32693
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer4 } from "circuit-to-canvas";
32477
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer3 } from "circuit-to-canvas";
32694
32478
  var TRANSPARENT2 = "rgba(0,0,0,0)";
32695
32479
  var setDrawerBounds3 = (drawer, bounds) => {
32696
32480
  drawer.setCameraBounds({
@@ -32769,7 +32553,7 @@ var drawPcbNoteLayer = ({
32769
32553
  elements
32770
32554
  }) => {
32771
32555
  const normalizedElements = elements.map(normalizePcbNoteElement);
32772
- const drawer = new CircuitToCanvasDrawer4(ctx);
32556
+ const drawer = new CircuitToCanvasDrawer3(ctx);
32773
32557
  drawer.configure({
32774
32558
  colorOverrides: {
32775
32559
  copper: {
@@ -32838,20 +32622,20 @@ function createPcbNoteTextureForLayer({
32838
32622
  bounds,
32839
32623
  elements
32840
32624
  });
32841
- const texture = new THREE25.CanvasTexture(canvas);
32625
+ const texture = new THREE24.CanvasTexture(canvas);
32842
32626
  texture.generateMipmaps = true;
32843
- texture.minFilter = THREE25.LinearMipmapLinearFilter;
32844
- texture.magFilter = THREE25.LinearFilter;
32627
+ texture.minFilter = THREE24.LinearMipmapLinearFilter;
32628
+ texture.magFilter = THREE24.LinearFilter;
32845
32629
  texture.anisotropy = 16;
32846
32630
  texture.needsUpdate = true;
32847
32631
  return texture;
32848
32632
  }
32849
32633
 
32850
32634
  // src/textures/create-silkscreen-texture-for-layer.ts
32851
- import * as THREE26 from "three";
32635
+ import * as THREE25 from "three";
32852
32636
 
32853
32637
  // src/textures/silkscreen/silkscreen-drawing.ts
32854
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer5 } from "circuit-to-canvas";
32638
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer4 } from "circuit-to-canvas";
32855
32639
  var FABRICATION_NOTE_COLOR2 = "rgb(255,243,204)";
32856
32640
  var TRANSPARENT3 = "rgba(0,0,0,0)";
32857
32641
  var setDrawerBounds4 = (drawer, bounds) => {
@@ -32870,7 +32654,7 @@ var drawSilkscreenLayer = ({
32870
32654
  silkscreenColor
32871
32655
  }) => {
32872
32656
  const renderLayer = layer === "top" ? "top_silkscreen" : "bottom_silkscreen";
32873
- const drawer = new CircuitToCanvasDrawer5(ctx);
32657
+ const drawer = new CircuitToCanvasDrawer4(ctx);
32874
32658
  drawer.configure({
32875
32659
  colorOverrides: {
32876
32660
  copper: {
@@ -32957,20 +32741,20 @@ function createSilkscreenTextureForLayer({
32957
32741
  elements,
32958
32742
  silkscreenColor
32959
32743
  });
32960
- const texture = new THREE26.CanvasTexture(canvas);
32744
+ const texture = new THREE25.CanvasTexture(canvas);
32961
32745
  texture.generateMipmaps = true;
32962
- texture.minFilter = THREE26.LinearMipmapLinearFilter;
32963
- texture.magFilter = THREE26.LinearFilter;
32746
+ texture.minFilter = THREE25.LinearMipmapLinearFilter;
32747
+ texture.magFilter = THREE25.LinearFilter;
32964
32748
  texture.anisotropy = 16;
32965
32749
  texture.needsUpdate = true;
32966
32750
  return texture;
32967
32751
  }
32968
32752
 
32969
32753
  // src/textures/create-soldermask-texture-for-layer.ts
32970
- import * as THREE27 from "three";
32754
+ import * as THREE26 from "three";
32971
32755
 
32972
32756
  // src/textures/soldermask/soldermask-drawing.ts
32973
- import { CircuitToCanvasDrawer as CircuitToCanvasDrawer6 } from "circuit-to-canvas";
32757
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer5 } from "circuit-to-canvas";
32974
32758
  var toRgb = (colorArr) => {
32975
32759
  const [r = 0, g = 0, b = 0] = colorArr;
32976
32760
  return `rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(
@@ -33006,7 +32790,7 @@ var drawSoldermaskLayer = ({
33006
32790
  }) => {
33007
32791
  const palette = getSoldermaskPalette(boardMaterial);
33008
32792
  const copperRenderLayer = layer === "top" ? "top_copper" : "bottom_copper";
33009
- const drawer = new CircuitToCanvasDrawer6(ctx);
32793
+ const drawer = new CircuitToCanvasDrawer5(ctx);
33010
32794
  drawer.configure({
33011
32795
  colorOverrides: {
33012
32796
  copper: {
@@ -33050,7 +32834,7 @@ var drawSoldermaskLayer = ({
33050
32834
  if (uncoveredPours.length > 0) {
33051
32835
  ctx.save();
33052
32836
  ctx.globalCompositeOperation = "destination-out";
33053
- const cutoutDrawer = new CircuitToCanvasDrawer6(ctx);
32837
+ const cutoutDrawer = new CircuitToCanvasDrawer5(ctx);
33054
32838
  cutoutDrawer.configure({
33055
32839
  colorOverrides: {
33056
32840
  copper: {
@@ -33099,10 +32883,10 @@ function createSoldermaskTextureForLayer({
33099
32883
  elements,
33100
32884
  boardMaterial: boardData.material
33101
32885
  });
33102
- const texture = new THREE27.CanvasTexture(canvas);
32886
+ const texture = new THREE26.CanvasTexture(canvas);
33103
32887
  texture.generateMipmaps = true;
33104
- texture.minFilter = THREE27.LinearMipmapLinearFilter;
33105
- texture.magFilter = THREE27.LinearFilter;
32888
+ texture.minFilter = THREE26.LinearMipmapLinearFilter;
32889
+ texture.magFilter = THREE26.LinearFilter;
33106
32890
  texture.anisotropy = 16;
33107
32891
  texture.needsUpdate = true;
33108
32892
  return texture;
@@ -33140,10 +32924,10 @@ var createCombinedTexture = ({
33140
32924
  const image = texture.image;
33141
32925
  ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
33142
32926
  });
33143
- const combinedTexture = new THREE28.CanvasTexture(canvas);
32927
+ const combinedTexture = new THREE27.CanvasTexture(canvas);
33144
32928
  combinedTexture.generateMipmaps = false;
33145
- combinedTexture.minFilter = THREE28.LinearFilter;
33146
- combinedTexture.magFilter = THREE28.LinearFilter;
32929
+ combinedTexture.minFilter = THREE27.LinearFilter;
32930
+ combinedTexture.magFilter = THREE27.LinearFilter;
33147
32931
  combinedTexture.premultiplyAlpha = true;
33148
32932
  combinedTexture.anisotropy = 16;
33149
32933
  combinedTexture.needsUpdate = true;
@@ -33184,12 +32968,6 @@ function createCombinedBoardTextures({
33184
32968
  copperColor,
33185
32969
  traceTextureResolution
33186
32970
  }) : null;
33187
- const copperPourTexture = showCopper ? createCopperPourTextureForLayer({
33188
- layer,
33189
- circuitJson,
33190
- boardData,
33191
- traceTextureResolution
33192
- }) : null;
33193
32971
  const padTexture = showCopper ? createPadTextureForLayer({
33194
32972
  layer,
33195
32973
  circuitJson,
@@ -33224,7 +33002,6 @@ function createCombinedBoardTextures({
33224
33002
  }) : null;
33225
33003
  return createCombinedTexture({
33226
33004
  textures: [
33227
- copperPourTexture,
33228
33005
  traceTexture,
33229
33006
  padTexture,
33230
33007
  soldermaskTexture,
@@ -33245,6 +33022,14 @@ function createCombinedBoardTextures({
33245
33022
  };
33246
33023
  }
33247
33024
 
33025
+ // src/textures/create-copper-pour-texture-for-layer.ts
33026
+ import * as THREE28 from "three";
33027
+ import { CircuitToCanvasDrawer as CircuitToCanvasDrawer6 } from "circuit-to-canvas";
33028
+
33029
+ // src/geoms/brep-converter.ts
33030
+ var import_primitives7 = __toESM(require_primitives(), 1);
33031
+ var import_booleans5 = __toESM(require_booleans(), 1);
33032
+
33248
33033
  // src/textures/create-three-texture-meshes.ts
33249
33034
  import * as THREE29 from "three";
33250
33035
  function createTexturePlane(config, boardData) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/3d-viewer",
3
- "version": "0.0.525",
3
+ "version": "0.0.526",
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.372",
33
- "circuit-to-canvas": "^0.0.81",
33
+ "circuit-to-canvas": "^0.0.83",
34
34
  "react-hot-toast": "^2.6.0",
35
35
  "three": "^0.165.0",
36
36
  "three-stdlib": "^2.36.0",