@tscircuit/3d-viewer 0.0.569 → 0.0.571

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 +126 -50
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -26526,14 +26526,14 @@ var QFN = ({
26526
26526
  /* @__PURE__ */ jsx2(Colorize, { color: "grey", children: /* @__PURE__ */ jsx2(
26527
26527
  Cuboid,
26528
26528
  {
26529
- center: { x: 0, y: 0, z: bodyThickness / 2 },
26529
+ center: [0, 0, bodyThickness / 2],
26530
26530
  size: [bodyWidth, bodyLength10, bodyThickness]
26531
26531
  }
26532
26532
  ) }),
26533
26533
  pinPositions.map((p, i) => /* @__PURE__ */ jsx2(
26534
26534
  Cuboid,
26535
26535
  {
26536
- center: { x: p.x, y: p.y, z: thermalPadThickness / 2 },
26536
+ center: [p.x, p.y, thermalPadThickness / 2],
26537
26537
  size: [p.pw, p.pl, thermalPadThickness]
26538
26538
  },
26539
26539
  i
@@ -26541,7 +26541,7 @@ var QFN = ({
26541
26541
  thermalPadSize?.length !== void 0 && thermalPadSize?.width !== void 0 && /* @__PURE__ */ jsx2(
26542
26542
  Cuboid,
26543
26543
  {
26544
- center: { x: 0, y: 0, z: thermalPadThickness / 2 },
26544
+ center: [0, 0, thermalPadThickness / 2],
26545
26545
  size: [
26546
26546
  thermalPadSize.width,
26547
26547
  thermalPadSize.length,
@@ -26941,7 +26941,14 @@ var FemaleHeader = ({
26941
26941
  bodyWidth = pitch,
26942
26942
  flipZ
26943
26943
  }) => {
26944
- const pinThickness = innerDiameter / 1.5;
26944
+ const effectiveInnerDiameter = innerDiameter || 0.945;
26945
+ const pinThickness = effectiveInnerDiameter / 1.5;
26946
+ const socketWidth = effectiveInnerDiameter;
26947
+ const socketEntryWidth = socketWidth * 1.8;
26948
+ const socketEntryHeight = Math.min(bodyHeight * 0.18, pitch * 0.24);
26949
+ const socketDepth = bodyHeight + 0.1;
26950
+ const socketCenterZ = flipZ(z21 + socketDepth / 2);
26951
+ const socketEntryBaseZ = z21 + bodyHeight - socketEntryHeight;
26945
26952
  const gapWidth = pinThickness * 1.6;
26946
26953
  return /* @__PURE__ */ jsxs(Fragment2, { children: [
26947
26954
  /* @__PURE__ */ jsx2(Colorize, { color: "#1a1a1a", children: /* @__PURE__ */ jsxs(Subtract, { children: [
@@ -26953,21 +26960,29 @@ var FemaleHeader = ({
26953
26960
  center: [x, y, flipZ(z21 + bodyHeight / 2)]
26954
26961
  }
26955
26962
  ),
26956
- innerDiameter ? /* @__PURE__ */ jsx2(
26957
- Cylinder,
26958
- {
26959
- height: bodyHeight + 0.1,
26960
- radius: innerDiameter / 2,
26961
- center: [x, y, flipZ(z21 + bodyHeight / 2)],
26962
- color: "#222"
26963
- }
26964
- ) : /* @__PURE__ */ jsx2(
26963
+ /* @__PURE__ */ jsx2(
26965
26964
  Cuboid,
26966
26965
  {
26967
- size: [gapWidth, gapWidth, bodyHeight],
26968
- center: [x, y, flipZ(z21 + bodyHeight / 2)]
26966
+ size: [socketWidth, socketWidth, socketDepth],
26967
+ center: [x, y, socketCenterZ]
26969
26968
  }
26970
- )
26969
+ ),
26970
+ /* @__PURE__ */ jsxs(Hull, { children: [
26971
+ /* @__PURE__ */ jsx2(
26972
+ Cuboid,
26973
+ {
26974
+ size: [socketWidth, socketWidth, 0.01],
26975
+ center: [x, y, flipZ(socketEntryBaseZ)]
26976
+ }
26977
+ ),
26978
+ /* @__PURE__ */ jsx2(
26979
+ Cuboid,
26980
+ {
26981
+ size: [socketEntryWidth, socketEntryWidth, 0.01],
26982
+ center: [x, y, flipZ(z21 + bodyHeight)]
26983
+ }
26984
+ )
26985
+ ] })
26971
26986
  ] }) }),
26972
26987
  /* @__PURE__ */ jsxs(Colorize, { color: "silver", children: [
26973
26988
  /* @__PURE__ */ jsxs(Hull, { children: [
@@ -31190,12 +31205,15 @@ function GltfModel({
31190
31205
  useEffect7(() => {
31191
31206
  if (!model) return;
31192
31207
  model.traverse((child) => {
31193
- if (child instanceof THREE7.Mesh && child.material instanceof THREE7.MeshStandardMaterial) {
31208
+ if (!(child instanceof THREE7.Mesh)) return;
31209
+ const materials = Array.isArray(child.material) ? child.material : [child.material];
31210
+ for (const material of materials) {
31211
+ if (!(material instanceof THREE7.MeshStandardMaterial)) continue;
31194
31212
  if (isHovered) {
31195
- child.material.emissive.setHex(255);
31196
- child.material.emissiveIntensity = 0.2;
31213
+ material.emissive.setHex(255);
31214
+ material.emissiveIntensity = 0.2;
31197
31215
  } else {
31198
- child.material.emissiveIntensity = 0;
31216
+ material.emissiveIntensity = 0;
31199
31217
  }
31200
31218
  }
31201
31219
  });
@@ -31471,6 +31489,9 @@ function MixedStlModel({
31471
31489
 
31472
31490
  // src/three-components/StepModel.tsx
31473
31491
  import { useEffect as useEffect10, useState as useState6 } from "react";
31492
+ import { GLTFExporter } from "three-stdlib";
31493
+
31494
+ // src/three-components/step-mesh-to-group.ts
31474
31495
  import {
31475
31496
  BufferGeometry as BufferGeometry2,
31476
31497
  Color as Color3,
@@ -31479,7 +31500,88 @@ import {
31479
31500
  Mesh as Mesh6,
31480
31501
  MeshStandardMaterial as MeshStandardMaterial5
31481
31502
  } from "three";
31482
- import { GLTFExporter } from "three-stdlib";
31503
+ var DEFAULT_COLOR = new Color3(0.82, 0.82, 0.82);
31504
+ var createMaterial = (color) => new MeshStandardMaterial5({
31505
+ color: color ? new Color3(color[0], color[1], color[2]) : DEFAULT_COLOR
31506
+ });
31507
+ function applyFaceColorGroups(geometry, mesh) {
31508
+ const defaultMaterial = createMaterial(mesh.color);
31509
+ const brepFaces = mesh.brep_faces ?? [];
31510
+ if (brepFaces.length === 0) {
31511
+ return [defaultMaterial];
31512
+ }
31513
+ const sortedBrepFaces = brepFaces.length > 1 ? [...brepFaces].sort((a, b) => a.first - b.first) : brepFaces;
31514
+ const materials = [defaultMaterial];
31515
+ const materialIndexByColor = /* @__PURE__ */ new Map();
31516
+ const triangleCount = mesh.index.array.length / 3;
31517
+ let triangleIndex = 0;
31518
+ let faceIndex = 0;
31519
+ const getMaterialIndexForFace = (color) => {
31520
+ if (!color) return 0;
31521
+ const key = color.join(",");
31522
+ const existingIndex = materialIndexByColor.get(key);
31523
+ if (existingIndex !== void 0) {
31524
+ return existingIndex;
31525
+ }
31526
+ const nextIndex = materials.length;
31527
+ materials.push(createMaterial(color));
31528
+ materialIndexByColor.set(key, nextIndex);
31529
+ return nextIndex;
31530
+ };
31531
+ while (triangleIndex < triangleCount) {
31532
+ const currentFace = sortedBrepFaces[faceIndex];
31533
+ let lastTriangleExclusive = triangleCount;
31534
+ let materialIndex = 0;
31535
+ if (currentFace) {
31536
+ if (triangleIndex < currentFace.first) {
31537
+ lastTriangleExclusive = currentFace.first;
31538
+ } else {
31539
+ lastTriangleExclusive = currentFace.last + 1;
31540
+ materialIndex = getMaterialIndexForFace(currentFace.color);
31541
+ faceIndex += 1;
31542
+ }
31543
+ }
31544
+ if (lastTriangleExclusive > triangleIndex) {
31545
+ geometry.addGroup(
31546
+ triangleIndex * 3,
31547
+ (lastTriangleExclusive - triangleIndex) * 3,
31548
+ materialIndex
31549
+ );
31550
+ }
31551
+ triangleIndex = lastTriangleExclusive;
31552
+ }
31553
+ return materials;
31554
+ }
31555
+ function occtMeshesToGroup(meshes) {
31556
+ const group = new Group3();
31557
+ for (const mesh of meshes) {
31558
+ const positions = mesh.attributes.position?.array ?? [];
31559
+ const indices = mesh.index?.array ?? [];
31560
+ if (!positions.length || !indices.length) {
31561
+ continue;
31562
+ }
31563
+ const geometry = new BufferGeometry2();
31564
+ geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
31565
+ const normals = mesh.attributes.normal?.array ?? [];
31566
+ if (normals.length) {
31567
+ geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
31568
+ } else {
31569
+ geometry.computeVertexNormals();
31570
+ }
31571
+ geometry.setIndex(indices);
31572
+ geometry.clearGroups();
31573
+ const materials = applyFaceColorGroups(geometry, mesh);
31574
+ const threeMesh = new Mesh6(
31575
+ geometry,
31576
+ materials.length > 1 ? materials : materials[0]
31577
+ );
31578
+ threeMesh.name = mesh.name;
31579
+ group.add(threeMesh);
31580
+ }
31581
+ return group;
31582
+ }
31583
+
31584
+ // src/three-components/StepModel.tsx
31483
31585
  import { jsx as jsx9 } from "react/jsx-runtime";
31484
31586
  var occtImportPromise;
31485
31587
  var OCCT_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";
@@ -31505,32 +31607,6 @@ async function loadOcctImport() {
31505
31607
  }
31506
31608
  return occtImportPromise;
31507
31609
  }
31508
- function occtMeshesToGroup(meshes) {
31509
- const group = new Group3();
31510
- for (const mesh of meshes) {
31511
- const positions = mesh.attributes.position?.array ?? [];
31512
- const indices = mesh.index?.array ?? [];
31513
- if (!positions.length || !indices.length) {
31514
- continue;
31515
- }
31516
- const geometry = new BufferGeometry2();
31517
- geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
31518
- const normals = mesh.attributes.normal?.array ?? [];
31519
- if (normals.length) {
31520
- geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
31521
- } else {
31522
- geometry.computeVertexNormals();
31523
- }
31524
- geometry.setIndex(indices);
31525
- const material = new MeshStandardMaterial5({
31526
- color: mesh.color ? new Color3(mesh.color[0], mesh.color[1], mesh.color[2]) : new Color3(0.82, 0.82, 0.82)
31527
- });
31528
- const threeMesh = new Mesh6(geometry, material);
31529
- threeMesh.name = mesh.name;
31530
- group.add(threeMesh);
31531
- }
31532
- return group;
31533
- }
31534
31610
  async function convertStepUrlToGlb(stepUrl) {
31535
31611
  const response = await fetch(stepUrl);
31536
31612
  if (!response.ok) {
@@ -31562,7 +31638,7 @@ async function convertStepUrlToGlb(stepUrl) {
31562
31638
  });
31563
31639
  return glb;
31564
31640
  }
31565
- var CACHE_PREFIX = "step-glb-cache:";
31641
+ var CACHE_PREFIX = "step-glb-cache:v2:";
31566
31642
  function arrayBufferToBase64(buffer) {
31567
31643
  const bytes = new Uint8Array(buffer);
31568
31644
  const chunkSize = 32768;
@@ -32322,7 +32398,7 @@ import * as THREE20 from "three";
32322
32398
  // package.json
32323
32399
  var package_default = {
32324
32400
  name: "@tscircuit/3d-viewer",
32325
- version: "0.0.568",
32401
+ version: "0.0.570",
32326
32402
  main: "./dist/index.js",
32327
32403
  module: "./dist/index.js",
32328
32404
  type: "module",
@@ -32383,7 +32459,7 @@ var package_default = {
32383
32459
  "bun-match-svg": "^0.0.9",
32384
32460
  "bun-types": "1.2.1",
32385
32461
  debug: "^4.4.0",
32386
- "jscad-electronics": "^0.0.133",
32462
+ "jscad-electronics": "^0.0.138",
32387
32463
  "jscad-planner": "^0.0.13",
32388
32464
  jsdom: "^26.0.0",
32389
32465
  "manifold-3d": "^3.2.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/3d-viewer",
3
- "version": "0.0.569",
3
+ "version": "0.0.571",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",
@@ -61,7 +61,7 @@
61
61
  "bun-match-svg": "^0.0.9",
62
62
  "bun-types": "1.2.1",
63
63
  "debug": "^4.4.0",
64
- "jscad-electronics": "^0.0.133",
64
+ "jscad-electronics": "^0.0.138",
65
65
  "jscad-planner": "^0.0.13",
66
66
  "jsdom": "^26.0.0",
67
67
  "manifold-3d": "^3.2.1",