@tscircuit/3d-viewer 0.0.128 → 0.0.130
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.
- package/dist/index.js +118 -96
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -17411,7 +17411,7 @@ import { Canvas, useFrame as useFrame2 } from "@react-three/fiber";
|
|
|
17411
17411
|
// package.json
|
|
17412
17412
|
var package_default = {
|
|
17413
17413
|
name: "@tscircuit/3d-viewer",
|
|
17414
|
-
version: "0.0.
|
|
17414
|
+
version: "0.0.129",
|
|
17415
17415
|
main: "./dist/index.js",
|
|
17416
17416
|
module: "./dist/index.js",
|
|
17417
17417
|
type: "module",
|
|
@@ -17443,7 +17443,7 @@ var package_default = {
|
|
|
17443
17443
|
"@react-three/drei": "^9.121.4",
|
|
17444
17444
|
"@react-three/fiber": "^8.17.14",
|
|
17445
17445
|
"@tscircuit/core": "^0.0.302",
|
|
17446
|
-
"@tscircuit/props": "^0.0.
|
|
17446
|
+
"@tscircuit/props": "^0.0.143",
|
|
17447
17447
|
"@tscircuit/react-fiber": "^1.2.0",
|
|
17448
17448
|
"@tscircuit/soup-util": "^0.0.41",
|
|
17449
17449
|
"jscad-electronics": "^0.0.23",
|
|
@@ -17595,103 +17595,110 @@ var RotationTracker = () => {
|
|
|
17595
17595
|
});
|
|
17596
17596
|
return /* @__PURE__ */ jsx3(Fragment, {});
|
|
17597
17597
|
};
|
|
17598
|
-
var CadViewerContainer = forwardRef(
|
|
17599
|
-
|
|
17600
|
-
|
|
17601
|
-
|
|
17602
|
-
|
|
17603
|
-
|
|
17604
|
-
|
|
17605
|
-
|
|
17606
|
-
|
|
17607
|
-
|
|
17608
|
-
|
|
17609
|
-
|
|
17610
|
-
|
|
17611
|
-
|
|
17612
|
-
|
|
17613
|
-
|
|
17614
|
-
|
|
17615
|
-
|
|
17616
|
-
|
|
17617
|
-
|
|
17618
|
-
children: [
|
|
17619
|
-
/* @__PURE__ */ jsx3("ambientLight", { intensity: Math.PI / 2 }),
|
|
17620
|
-
/* @__PURE__ */ jsx3(CubeWithLabeledSides, {})
|
|
17621
|
-
]
|
|
17622
|
-
}
|
|
17623
|
-
)
|
|
17624
|
-
}
|
|
17625
|
-
),
|
|
17626
|
-
/* @__PURE__ */ jsxs3(
|
|
17627
|
-
Canvas,
|
|
17628
|
-
{
|
|
17629
|
-
scene: { up: [0, 0, 1] },
|
|
17630
|
-
camera: { up: [0, 0, 1], position: [5, 5, 5] },
|
|
17631
|
-
children: [
|
|
17632
|
-
/* @__PURE__ */ jsx3(RotationTracker, {}),
|
|
17633
|
-
/* @__PURE__ */ jsx3(OrbitControls, { autoRotate: !autoRotateDisabled, autoRotateSpeed: 1 }),
|
|
17634
|
-
/* @__PURE__ */ jsx3("ambientLight", { intensity: Math.PI / 2 }),
|
|
17635
|
-
/* @__PURE__ */ jsx3(
|
|
17636
|
-
"pointLight",
|
|
17637
|
-
{
|
|
17638
|
-
position: [-10, -10, 10],
|
|
17639
|
-
decay: 0,
|
|
17640
|
-
intensity: Math.PI / 4
|
|
17641
|
-
}
|
|
17642
|
-
),
|
|
17643
|
-
/* @__PURE__ */ jsx3(
|
|
17644
|
-
Grid,
|
|
17645
|
-
{
|
|
17646
|
-
rotation: [Math.PI / 2, 0, 0],
|
|
17647
|
-
infiniteGrid: true,
|
|
17648
|
-
cellSize: 1,
|
|
17649
|
-
sectionSize: 10
|
|
17650
|
-
}
|
|
17651
|
-
),
|
|
17652
|
-
/* @__PURE__ */ jsx3("object3D", { ref, children }),
|
|
17653
|
-
hoveredComponent && /* @__PURE__ */ jsx3(
|
|
17654
|
-
Html,
|
|
17598
|
+
var CadViewerContainer = forwardRef(
|
|
17599
|
+
({
|
|
17600
|
+
children,
|
|
17601
|
+
hoveredComponent,
|
|
17602
|
+
initialCameraPosition = [5, 5, 5],
|
|
17603
|
+
autoRotateDisabled
|
|
17604
|
+
}, ref) => {
|
|
17605
|
+
return /* @__PURE__ */ jsxs3("div", { style: { position: "relative", width: "100%", height: "100%" }, children: [
|
|
17606
|
+
/* @__PURE__ */ jsx3(
|
|
17607
|
+
"div",
|
|
17608
|
+
{
|
|
17609
|
+
style: {
|
|
17610
|
+
position: "absolute",
|
|
17611
|
+
top: 0,
|
|
17612
|
+
left: 0,
|
|
17613
|
+
width: 120,
|
|
17614
|
+
height: 120
|
|
17615
|
+
},
|
|
17616
|
+
children: /* @__PURE__ */ jsxs3(
|
|
17617
|
+
Canvas,
|
|
17655
17618
|
{
|
|
17656
|
-
|
|
17657
|
-
|
|
17658
|
-
|
|
17659
|
-
transform: "translate3d(50%, 50%, 0)",
|
|
17660
|
-
backgroundColor: "white",
|
|
17661
|
-
padding: "5px",
|
|
17662
|
-
borderRadius: "3px",
|
|
17663
|
-
pointerEvents: "none",
|
|
17664
|
-
userSelect: "none",
|
|
17665
|
-
WebkitUserSelect: "none",
|
|
17666
|
-
MozUserSelect: "none",
|
|
17667
|
-
msUserSelect: "none"
|
|
17619
|
+
camera: {
|
|
17620
|
+
up: [0, 0, 1],
|
|
17621
|
+
position: [1, 1, 1]
|
|
17668
17622
|
},
|
|
17669
|
-
|
|
17623
|
+
style: { zIndex: 10 },
|
|
17624
|
+
children: [
|
|
17625
|
+
/* @__PURE__ */ jsx3("ambientLight", { intensity: Math.PI / 2 }),
|
|
17626
|
+
/* @__PURE__ */ jsx3(CubeWithLabeledSides, {})
|
|
17627
|
+
]
|
|
17670
17628
|
}
|
|
17671
17629
|
)
|
|
17672
|
-
|
|
17673
|
-
|
|
17674
|
-
|
|
17675
|
-
|
|
17676
|
-
|
|
17677
|
-
|
|
17678
|
-
|
|
17679
|
-
|
|
17680
|
-
|
|
17681
|
-
|
|
17682
|
-
|
|
17683
|
-
|
|
17684
|
-
|
|
17685
|
-
|
|
17686
|
-
|
|
17687
|
-
|
|
17688
|
-
|
|
17689
|
-
|
|
17690
|
-
|
|
17691
|
-
|
|
17692
|
-
|
|
17693
|
-
|
|
17694
|
-
|
|
17630
|
+
}
|
|
17631
|
+
),
|
|
17632
|
+
/* @__PURE__ */ jsxs3(
|
|
17633
|
+
Canvas,
|
|
17634
|
+
{
|
|
17635
|
+
scene: { up: [0, 0, 1] },
|
|
17636
|
+
camera: { up: [0, 0, 1], position: initialCameraPosition },
|
|
17637
|
+
children: [
|
|
17638
|
+
/* @__PURE__ */ jsx3(RotationTracker, {}),
|
|
17639
|
+
/* @__PURE__ */ jsx3(OrbitControls, { autoRotate: !autoRotateDisabled, autoRotateSpeed: 1 }),
|
|
17640
|
+
/* @__PURE__ */ jsx3("ambientLight", { intensity: Math.PI / 2 }),
|
|
17641
|
+
/* @__PURE__ */ jsx3(
|
|
17642
|
+
"pointLight",
|
|
17643
|
+
{
|
|
17644
|
+
position: [-10, -10, 10],
|
|
17645
|
+
decay: 0,
|
|
17646
|
+
intensity: Math.PI / 4
|
|
17647
|
+
}
|
|
17648
|
+
),
|
|
17649
|
+
/* @__PURE__ */ jsx3(
|
|
17650
|
+
Grid,
|
|
17651
|
+
{
|
|
17652
|
+
rotation: [Math.PI / 2, 0, 0],
|
|
17653
|
+
infiniteGrid: true,
|
|
17654
|
+
cellSize: 1,
|
|
17655
|
+
sectionSize: 10
|
|
17656
|
+
}
|
|
17657
|
+
),
|
|
17658
|
+
/* @__PURE__ */ jsx3("object3D", { ref, children }),
|
|
17659
|
+
hoveredComponent && /* @__PURE__ */ jsx3(
|
|
17660
|
+
Html,
|
|
17661
|
+
{
|
|
17662
|
+
position: hoveredComponent.mousePosition,
|
|
17663
|
+
style: {
|
|
17664
|
+
fontFamily: "sans-serif",
|
|
17665
|
+
transform: "translate3d(50%, 50%, 0)",
|
|
17666
|
+
backgroundColor: "white",
|
|
17667
|
+
padding: "5px",
|
|
17668
|
+
borderRadius: "3px",
|
|
17669
|
+
pointerEvents: "none",
|
|
17670
|
+
userSelect: "none",
|
|
17671
|
+
WebkitUserSelect: "none",
|
|
17672
|
+
MozUserSelect: "none",
|
|
17673
|
+
msUserSelect: "none"
|
|
17674
|
+
},
|
|
17675
|
+
children: hoveredComponent.name
|
|
17676
|
+
}
|
|
17677
|
+
)
|
|
17678
|
+
]
|
|
17679
|
+
}
|
|
17680
|
+
),
|
|
17681
|
+
/* @__PURE__ */ jsxs3(
|
|
17682
|
+
"div",
|
|
17683
|
+
{
|
|
17684
|
+
style: {
|
|
17685
|
+
position: "absolute",
|
|
17686
|
+
right: 24,
|
|
17687
|
+
bottom: 24,
|
|
17688
|
+
fontFamily: "sans-serif",
|
|
17689
|
+
color: "white",
|
|
17690
|
+
WebkitTextStroke: "0.5px rgba(0, 0, 0, 0.5)",
|
|
17691
|
+
fontSize: 11
|
|
17692
|
+
},
|
|
17693
|
+
children: [
|
|
17694
|
+
"@",
|
|
17695
|
+
package_default.version
|
|
17696
|
+
]
|
|
17697
|
+
}
|
|
17698
|
+
)
|
|
17699
|
+
] });
|
|
17700
|
+
}
|
|
17701
|
+
);
|
|
17695
17702
|
|
|
17696
17703
|
// src/ContainerWithTooltip.tsx
|
|
17697
17704
|
import { useRef as useRef4, useCallback } from "react";
|
|
@@ -18076,12 +18083,26 @@ var CadViewer = forwardRef2(({ soup, circuitJson, children, autoRotateDisabled }
|
|
|
18076
18083
|
circuitJson ??= soup;
|
|
18077
18084
|
const [hoveredComponent, setHoveredComponent] = useState3(null);
|
|
18078
18085
|
circuitJson ??= useConvertChildrenToSoup(children, circuitJson);
|
|
18079
|
-
|
|
18086
|
+
const initialCameraPosition = useMemo4(() => {
|
|
18087
|
+
if (!circuitJson) return [5, 5, 5];
|
|
18088
|
+
try {
|
|
18089
|
+
const board = su2(circuitJson).pcb_board.list()[0];
|
|
18090
|
+
if (!board) return [5, 5, 5];
|
|
18091
|
+
const { width, height } = board;
|
|
18092
|
+
const largestDim = Math.max(width, height);
|
|
18093
|
+
return [largestDim / 2, largestDim / 2, largestDim];
|
|
18094
|
+
} catch (e) {
|
|
18095
|
+
console.error(e);
|
|
18096
|
+
return [5, 5, 5];
|
|
18097
|
+
}
|
|
18098
|
+
}, [circuitJson]);
|
|
18080
18099
|
const boardGeom = useMemo4(() => {
|
|
18100
|
+
if (!circuitJson) return null;
|
|
18081
18101
|
if (!circuitJson.some((e) => e.type === "pcb_board")) return null;
|
|
18082
18102
|
return createBoardGeomFromSoup(circuitJson);
|
|
18083
18103
|
}, [circuitJson]);
|
|
18084
18104
|
const { stls: boardStls, loading } = useStlsFromGeom(boardGeom);
|
|
18105
|
+
if (!circuitJson) return null;
|
|
18085
18106
|
const cad_components = su2(circuitJson).cad_component.list();
|
|
18086
18107
|
return /* @__PURE__ */ jsxs6(
|
|
18087
18108
|
CadViewerContainer,
|
|
@@ -18089,6 +18110,7 @@ var CadViewer = forwardRef2(({ soup, circuitJson, children, autoRotateDisabled }
|
|
|
18089
18110
|
ref,
|
|
18090
18111
|
hoveredComponent,
|
|
18091
18112
|
autoRotateDisabled,
|
|
18113
|
+
initialCameraPosition,
|
|
18092
18114
|
children: [
|
|
18093
18115
|
boardStls.map(({ stlUrl, color }, index) => /* @__PURE__ */ jsx10(
|
|
18094
18116
|
STLModel,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/3d-viewer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.130",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@react-three/drei": "^9.121.4",
|
|
33
33
|
"@react-three/fiber": "^8.17.14",
|
|
34
34
|
"@tscircuit/core": "^0.0.302",
|
|
35
|
-
"@tscircuit/props": "^0.0.
|
|
35
|
+
"@tscircuit/props": "^0.0.143",
|
|
36
36
|
"@tscircuit/react-fiber": "^1.2.0",
|
|
37
37
|
"@tscircuit/soup-util": "^0.0.41",
|
|
38
38
|
"jscad-electronics": "^0.0.23",
|