@tscircuit/3d-viewer 0.0.449 → 0.0.451
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 +93 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14530,12 +14530,28 @@ function MixedStlModel({
|
|
|
14530
14530
|
onHover,
|
|
14531
14531
|
onUnhover,
|
|
14532
14532
|
isHovered,
|
|
14533
|
-
scale: scale3
|
|
14533
|
+
scale: scale3,
|
|
14534
|
+
isTranslucent = false
|
|
14534
14535
|
}) {
|
|
14535
14536
|
const obj = useGlobalObjLoader(url);
|
|
14536
14537
|
const { rootObject } = useThree();
|
|
14537
14538
|
const model = useMemo2(() => {
|
|
14538
14539
|
if (obj && !(obj instanceof Error)) {
|
|
14540
|
+
obj.traverse((child) => {
|
|
14541
|
+
if (child instanceof THREE2.Mesh && child.material) {
|
|
14542
|
+
const setMaterialTransparency = (mat) => {
|
|
14543
|
+
mat.transparent = isTranslucent;
|
|
14544
|
+
mat.opacity = isTranslucent ? 0.5 : 1;
|
|
14545
|
+
mat.depthWrite = !isTranslucent;
|
|
14546
|
+
mat.needsUpdate = true;
|
|
14547
|
+
};
|
|
14548
|
+
if (Array.isArray(child.material)) {
|
|
14549
|
+
child.material.forEach(setMaterialTransparency);
|
|
14550
|
+
} else {
|
|
14551
|
+
setMaterialTransparency(child.material);
|
|
14552
|
+
}
|
|
14553
|
+
}
|
|
14554
|
+
});
|
|
14539
14555
|
return obj;
|
|
14540
14556
|
}
|
|
14541
14557
|
return new THREE2.Mesh(
|
|
@@ -14546,7 +14562,7 @@ function MixedStlModel({
|
|
|
14546
14562
|
opacity: 0.25
|
|
14547
14563
|
})
|
|
14548
14564
|
);
|
|
14549
|
-
}, [obj]);
|
|
14565
|
+
}, [obj, isTranslucent]);
|
|
14550
14566
|
useEffect4(() => {
|
|
14551
14567
|
if (!rootObject || !model) return;
|
|
14552
14568
|
rootObject.add(model);
|
|
@@ -14639,7 +14655,8 @@ function GltfModel({
|
|
|
14639
14655
|
onHover,
|
|
14640
14656
|
onUnhover,
|
|
14641
14657
|
isHovered,
|
|
14642
|
-
scale: scale3
|
|
14658
|
+
scale: scale3,
|
|
14659
|
+
isTranslucent = false
|
|
14643
14660
|
}) {
|
|
14644
14661
|
const { renderer, rootObject } = useThree();
|
|
14645
14662
|
const [model, setModel] = useState3(null);
|
|
@@ -14651,7 +14668,24 @@ function GltfModel({
|
|
|
14651
14668
|
loader.load(
|
|
14652
14669
|
gltfUrl,
|
|
14653
14670
|
(gltf) => {
|
|
14654
|
-
if (isMounted)
|
|
14671
|
+
if (!isMounted) return;
|
|
14672
|
+
const scene = gltf.scene;
|
|
14673
|
+
scene.traverse((child) => {
|
|
14674
|
+
if (child instanceof THREE4.Mesh && child.material) {
|
|
14675
|
+
const setMaterialTransparency = (mat) => {
|
|
14676
|
+
mat.transparent = isTranslucent;
|
|
14677
|
+
mat.opacity = isTranslucent ? 0.5 : 1;
|
|
14678
|
+
mat.depthWrite = !isTranslucent;
|
|
14679
|
+
mat.needsUpdate = true;
|
|
14680
|
+
};
|
|
14681
|
+
if (Array.isArray(child.material)) {
|
|
14682
|
+
child.material.forEach(setMaterialTransparency);
|
|
14683
|
+
} else {
|
|
14684
|
+
setMaterialTransparency(child.material);
|
|
14685
|
+
}
|
|
14686
|
+
}
|
|
14687
|
+
});
|
|
14688
|
+
setModel(scene);
|
|
14655
14689
|
},
|
|
14656
14690
|
void 0,
|
|
14657
14691
|
(error) => {
|
|
@@ -14664,7 +14698,7 @@ function GltfModel({
|
|
|
14664
14698
|
return () => {
|
|
14665
14699
|
isMounted = false;
|
|
14666
14700
|
};
|
|
14667
|
-
}, [gltfUrl]);
|
|
14701
|
+
}, [gltfUrl, isTranslucent]);
|
|
14668
14702
|
useEffect5(() => {
|
|
14669
14703
|
if (!model) return;
|
|
14670
14704
|
if (position) model.position.fromArray(position);
|
|
@@ -28045,7 +28079,8 @@ var JscadModel = ({
|
|
|
28045
28079
|
onHover,
|
|
28046
28080
|
onUnhover,
|
|
28047
28081
|
isHovered,
|
|
28048
|
-
scale: scale3
|
|
28082
|
+
scale: scale3,
|
|
28083
|
+
isTranslucent = false
|
|
28049
28084
|
}) => {
|
|
28050
28085
|
const { rootObject } = useThree();
|
|
28051
28086
|
const { threeGeom, material } = useMemo4(() => {
|
|
@@ -28056,11 +28091,13 @@ var JscadModel = ({
|
|
|
28056
28091
|
const threeGeom2 = convertCSGToThreeGeom(jscadObject);
|
|
28057
28092
|
const material2 = new THREE5.MeshStandardMaterial({
|
|
28058
28093
|
vertexColors: true,
|
|
28059
|
-
side: THREE5.DoubleSide
|
|
28060
|
-
|
|
28094
|
+
side: THREE5.DoubleSide,
|
|
28095
|
+
transparent: isTranslucent,
|
|
28096
|
+
opacity: isTranslucent ? 0.5 : 1,
|
|
28097
|
+
depthWrite: !isTranslucent
|
|
28061
28098
|
});
|
|
28062
28099
|
return { threeGeom: threeGeom2, material: material2 };
|
|
28063
|
-
}, [jscadPlan]);
|
|
28100
|
+
}, [jscadPlan, isTranslucent]);
|
|
28064
28101
|
const mesh = useMemo4(() => {
|
|
28065
28102
|
if (!threeGeom) return null;
|
|
28066
28103
|
return new THREE5.Mesh(threeGeom, material);
|
|
@@ -28122,7 +28159,8 @@ var FootprinterModel = ({
|
|
|
28122
28159
|
onHover,
|
|
28123
28160
|
onUnhover,
|
|
28124
28161
|
isHovered,
|
|
28125
|
-
scale: scale3
|
|
28162
|
+
scale: scale3,
|
|
28163
|
+
isTranslucent = false
|
|
28126
28164
|
}) => {
|
|
28127
28165
|
const { rootObject } = useThree();
|
|
28128
28166
|
const group = useMemo5(() => {
|
|
@@ -28140,13 +28178,16 @@ var FootprinterModel = ({
|
|
|
28140
28178
|
const threeGeom = convertCSGToThreeGeom(geomWithColor);
|
|
28141
28179
|
const material = new THREE6.MeshStandardMaterial({
|
|
28142
28180
|
vertexColors: true,
|
|
28143
|
-
side: THREE6.DoubleSide
|
|
28181
|
+
side: THREE6.DoubleSide,
|
|
28182
|
+
transparent: isTranslucent,
|
|
28183
|
+
opacity: isTranslucent ? 0.5 : 1,
|
|
28184
|
+
depthWrite: !isTranslucent
|
|
28144
28185
|
});
|
|
28145
28186
|
const mesh = new THREE6.Mesh(threeGeom, material);
|
|
28146
28187
|
group2.add(mesh);
|
|
28147
28188
|
}
|
|
28148
28189
|
return group2;
|
|
28149
|
-
}, [footprint]);
|
|
28190
|
+
}, [footprint, isTranslucent]);
|
|
28150
28191
|
useEffect7(() => {
|
|
28151
28192
|
if (!group || !rootObject) return;
|
|
28152
28193
|
rootObject.add(group);
|
|
@@ -28368,7 +28409,8 @@ var AnyCadComponent = ({
|
|
|
28368
28409
|
scale: cad_component2.model_unit_to_mm_scale_factor,
|
|
28369
28410
|
onHover: handleHover,
|
|
28370
28411
|
onUnhover: handleUnhover,
|
|
28371
|
-
isHovered
|
|
28412
|
+
isHovered,
|
|
28413
|
+
isTranslucent: cad_component2.show_as_translucent_model
|
|
28372
28414
|
},
|
|
28373
28415
|
cad_component2.cad_component_id
|
|
28374
28416
|
);
|
|
@@ -28386,7 +28428,8 @@ var AnyCadComponent = ({
|
|
|
28386
28428
|
scale: cad_component2.model_unit_to_mm_scale_factor,
|
|
28387
28429
|
onHover: handleHover,
|
|
28388
28430
|
onUnhover: handleUnhover,
|
|
28389
|
-
isHovered
|
|
28431
|
+
isHovered,
|
|
28432
|
+
isTranslucent: cad_component2.show_as_translucent_model
|
|
28390
28433
|
},
|
|
28391
28434
|
cad_component2.cad_component_id
|
|
28392
28435
|
);
|
|
@@ -28399,7 +28442,8 @@ var AnyCadComponent = ({
|
|
|
28399
28442
|
scale: cad_component2.model_unit_to_mm_scale_factor,
|
|
28400
28443
|
onHover: handleHover,
|
|
28401
28444
|
onUnhover: handleUnhover,
|
|
28402
|
-
isHovered
|
|
28445
|
+
isHovered,
|
|
28446
|
+
isTranslucent: cad_component2.show_as_translucent_model
|
|
28403
28447
|
},
|
|
28404
28448
|
cad_component2.cad_component_id
|
|
28405
28449
|
);
|
|
@@ -28417,7 +28461,8 @@ var AnyCadComponent = ({
|
|
|
28417
28461
|
scale: cad_component2.model_unit_to_mm_scale_factor,
|
|
28418
28462
|
onHover: handleHover,
|
|
28419
28463
|
onUnhover: handleUnhover,
|
|
28420
|
-
isHovered
|
|
28464
|
+
isHovered,
|
|
28465
|
+
isTranslucent: cad_component2.show_as_translucent_model
|
|
28421
28466
|
}
|
|
28422
28467
|
);
|
|
28423
28468
|
}
|
|
@@ -28464,7 +28509,7 @@ import * as THREE15 from "three";
|
|
|
28464
28509
|
// package.json
|
|
28465
28510
|
var package_default = {
|
|
28466
28511
|
name: "@tscircuit/3d-viewer",
|
|
28467
|
-
version: "0.0.
|
|
28512
|
+
version: "0.0.450",
|
|
28468
28513
|
main: "./dist/index.js",
|
|
28469
28514
|
module: "./dist/index.js",
|
|
28470
28515
|
type: "module",
|
|
@@ -32727,12 +32772,12 @@ function createPlatedHoleDrill({
|
|
|
32727
32772
|
Manifold,
|
|
32728
32773
|
x,
|
|
32729
32774
|
y,
|
|
32730
|
-
|
|
32775
|
+
holeDiameter,
|
|
32731
32776
|
thickness,
|
|
32732
32777
|
zOffset = 1e-3,
|
|
32733
32778
|
segments = 32
|
|
32734
32779
|
}) {
|
|
32735
|
-
const boardHoleRadius =
|
|
32780
|
+
const boardHoleRadius = holeDiameter / 2 + zOffset;
|
|
32736
32781
|
const drill = Manifold.cylinder(
|
|
32737
32782
|
thickness * 1.2,
|
|
32738
32783
|
boardHoleRadius,
|
|
@@ -33005,7 +33050,7 @@ function processPlatedHolesForManifold(Manifold, CrossSection, circuitJson, pcbT
|
|
|
33005
33050
|
Manifold,
|
|
33006
33051
|
x: ph.x,
|
|
33007
33052
|
y: ph.y,
|
|
33008
|
-
|
|
33053
|
+
holeDiameter: ph.hole_diameter * 1.02,
|
|
33009
33054
|
thickness: pcbThickness,
|
|
33010
33055
|
zOffset: MANIFOLD_Z_OFFSET,
|
|
33011
33056
|
segments: SMOOTH_CIRCLE_SEGMENTS
|
|
@@ -33488,22 +33533,42 @@ function createViaCopper({
|
|
|
33488
33533
|
zOffset = 1e-3,
|
|
33489
33534
|
segments = 32
|
|
33490
33535
|
}) {
|
|
33491
|
-
const
|
|
33492
|
-
|
|
33493
|
-
|
|
33536
|
+
const padThickness = zOffset;
|
|
33537
|
+
const platingThickness = zOffset;
|
|
33538
|
+
if (outerDiameter < holeDiameter) {
|
|
33539
|
+
throw new Error(
|
|
33540
|
+
`Invalid via geometry: outerDiameter (${outerDiameter}) must be >= holeDiameter (${holeDiameter})`
|
|
33541
|
+
);
|
|
33542
|
+
}
|
|
33543
|
+
const barrelRadius = Math.min(
|
|
33544
|
+
outerDiameter / 2,
|
|
33545
|
+
holeDiameter / 2 + platingThickness
|
|
33546
|
+
);
|
|
33547
|
+
const barrel = Manifold.cylinder(thickness, barrelRadius, -1, segments, true);
|
|
33548
|
+
const topPad = Manifold.cylinder(
|
|
33549
|
+
padThickness,
|
|
33494
33550
|
outerDiameter / 2,
|
|
33495
33551
|
-1,
|
|
33496
33552
|
segments,
|
|
33497
33553
|
true
|
|
33498
|
-
);
|
|
33554
|
+
).translate([0, 0, thickness / 2]);
|
|
33555
|
+
const bottomPad = Manifold.cylinder(
|
|
33556
|
+
padThickness,
|
|
33557
|
+
outerDiameter / 2,
|
|
33558
|
+
-1,
|
|
33559
|
+
segments,
|
|
33560
|
+
true
|
|
33561
|
+
).translate([0, 0, -thickness / 2]);
|
|
33562
|
+
const viaSolid = Manifold.union([barrel, topPad, bottomPad]);
|
|
33563
|
+
const drillHeight = thickness + padThickness * 2;
|
|
33499
33564
|
const drill = Manifold.cylinder(
|
|
33500
|
-
|
|
33565
|
+
drillHeight,
|
|
33501
33566
|
holeDiameter / 2,
|
|
33502
33567
|
-1,
|
|
33503
33568
|
segments,
|
|
33504
33569
|
true
|
|
33505
33570
|
);
|
|
33506
|
-
const finalViaCopperOp =
|
|
33571
|
+
const finalViaCopperOp = viaSolid.subtract(drill);
|
|
33507
33572
|
return finalViaCopperOp.translate([x, y, 0]);
|
|
33508
33573
|
}
|
|
33509
33574
|
|
|
@@ -33514,12 +33579,12 @@ function processViasForManifold(Manifold, circuitJson, pcbThickness, manifoldIns
|
|
|
33514
33579
|
const pcbVias = su11(circuitJson).pcb_via.list();
|
|
33515
33580
|
const viaCopperGeoms = [];
|
|
33516
33581
|
pcbVias.forEach((via, index2) => {
|
|
33517
|
-
if (typeof via.
|
|
33582
|
+
if (typeof via.hole_diameter === "number") {
|
|
33518
33583
|
const translatedDrill = createPlatedHoleDrill({
|
|
33519
33584
|
Manifold,
|
|
33520
33585
|
x: via.x,
|
|
33521
33586
|
y: via.y,
|
|
33522
|
-
|
|
33587
|
+
holeDiameter: via.hole_diameter,
|
|
33523
33588
|
thickness: pcbThickness,
|
|
33524
33589
|
zOffset: MANIFOLD_Z_OFFSET,
|
|
33525
33590
|
segments: SMOOTH_CIRCLE_SEGMENTS
|