@tscircuit/3d-viewer 0.0.450 → 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 +62 -17
- 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",
|