@tscircuit/3d-viewer 0.0.344 → 0.0.346
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 +99 -53
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25291,6 +25291,9 @@ var JscadModel = ({
|
|
|
25291
25291
|
const { rootObject } = useThree();
|
|
25292
25292
|
const { threeGeom, material } = useMemo3(() => {
|
|
25293
25293
|
const jscadObject = (0, import_jscad_planner.executeJscadOperations)(import_modeling2.default, jscadPlan);
|
|
25294
|
+
if (!jscadObject || !jscadObject.polygons && !jscadObject.sides) {
|
|
25295
|
+
return { threeGeom: null, material: null };
|
|
25296
|
+
}
|
|
25294
25297
|
const threeGeom2 = convertCSGToThreeGeom(jscadObject);
|
|
25295
25298
|
const material2 = new THREE3.MeshStandardMaterial({
|
|
25296
25299
|
vertexColors: true,
|
|
@@ -25363,8 +25366,15 @@ var FootprinterModel = ({
|
|
|
25363
25366
|
if (!footprint) return null;
|
|
25364
25367
|
const { geometries: geometries2 } = getJscadModelForFootprint(footprint);
|
|
25365
25368
|
const group2 = new THREE4.Group();
|
|
25366
|
-
for (const
|
|
25367
|
-
const
|
|
25369
|
+
for (const geomInfo of geometries2.flat(Infinity)) {
|
|
25370
|
+
const geom = geomInfo.geom;
|
|
25371
|
+
if (!geom || !geom.polygons && !geom.sides) {
|
|
25372
|
+
continue;
|
|
25373
|
+
}
|
|
25374
|
+
const color = new THREE4.Color(geomInfo.color);
|
|
25375
|
+
color.convertLinearToSRGB();
|
|
25376
|
+
const geomWithColor = { ...geom, color: [color.r, color.g, color.b] };
|
|
25377
|
+
const threeGeom = convertCSGToThreeGeom(geomWithColor);
|
|
25368
25378
|
const material = new THREE4.MeshStandardMaterial({
|
|
25369
25379
|
vertexColors: true,
|
|
25370
25380
|
side: THREE4.DoubleSide
|
|
@@ -25572,7 +25582,7 @@ import * as THREE10 from "three";
|
|
|
25572
25582
|
// package.json
|
|
25573
25583
|
var package_default = {
|
|
25574
25584
|
name: "@tscircuit/3d-viewer",
|
|
25575
|
-
version: "0.0.
|
|
25585
|
+
version: "0.0.345",
|
|
25576
25586
|
main: "./dist/index.js",
|
|
25577
25587
|
module: "./dist/index.js",
|
|
25578
25588
|
type: "module",
|
|
@@ -28853,7 +28863,7 @@ var BoardMeshes = ({
|
|
|
28853
28863
|
}, [rootObject, geometryMeshes, textureMeshes]);
|
|
28854
28864
|
return null;
|
|
28855
28865
|
};
|
|
28856
|
-
var MANIFOLD_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/manifold-3d@3.
|
|
28866
|
+
var MANIFOLD_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1";
|
|
28857
28867
|
var CadViewerManifold = ({
|
|
28858
28868
|
circuitJson: circuitJsonProp,
|
|
28859
28869
|
autoRotateDisabled,
|
|
@@ -28868,32 +28878,57 @@ var CadViewerManifold = ({
|
|
|
28868
28878
|
const [manifoldJSModule, setManifoldJSModule] = useState13(null);
|
|
28869
28879
|
const [manifoldLoadingError, setManifoldLoadingError] = useState13(null);
|
|
28870
28880
|
useEffect20(() => {
|
|
28871
|
-
const
|
|
28881
|
+
const initManifold = async (ManifoldModule) => {
|
|
28872
28882
|
try {
|
|
28873
|
-
const
|
|
28874
|
-
|
|
28875
|
-
|
|
28876
|
-
manifoldURL
|
|
28877
|
-
);
|
|
28878
|
-
if (ManifoldModule) {
|
|
28879
|
-
const loadedModule = await ManifoldModule({
|
|
28880
|
-
locateFile: () => `${MANIFOLD_CDN_BASE_URL}/manifold.wasm`
|
|
28881
|
-
});
|
|
28882
|
-
loadedModule.setup();
|
|
28883
|
-
setManifoldJSModule(loadedModule);
|
|
28884
|
-
} else {
|
|
28885
|
-
throw new Error(
|
|
28886
|
-
"ManifoldModule not found in dynamically imported module"
|
|
28887
|
-
);
|
|
28888
|
-
}
|
|
28883
|
+
const loadedModule = await ManifoldModule();
|
|
28884
|
+
loadedModule.setup();
|
|
28885
|
+
setManifoldJSModule(loadedModule);
|
|
28889
28886
|
} catch (error) {
|
|
28890
|
-
console.error("Failed to
|
|
28887
|
+
console.error("Failed to initialize Manifold:", error);
|
|
28891
28888
|
setManifoldLoadingError(
|
|
28892
|
-
`Failed to
|
|
28889
|
+
`Failed to initialize Manifold: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
28893
28890
|
);
|
|
28894
28891
|
}
|
|
28895
28892
|
};
|
|
28896
|
-
|
|
28893
|
+
if (window.ManifoldModule) {
|
|
28894
|
+
initManifold(window.ManifoldModule);
|
|
28895
|
+
return;
|
|
28896
|
+
}
|
|
28897
|
+
const eventName = "manifoldLoaded";
|
|
28898
|
+
const handleLoad = () => {
|
|
28899
|
+
if (window.ManifoldModule) {
|
|
28900
|
+
initManifold(window.ManifoldModule);
|
|
28901
|
+
} else {
|
|
28902
|
+
const errText = "ManifoldModule not found on window after script load.";
|
|
28903
|
+
console.error(errText);
|
|
28904
|
+
setManifoldLoadingError(errText);
|
|
28905
|
+
}
|
|
28906
|
+
};
|
|
28907
|
+
window.addEventListener(eventName, handleLoad, { once: true });
|
|
28908
|
+
const script = document.createElement("script");
|
|
28909
|
+
script.type = "module";
|
|
28910
|
+
script.innerHTML = `
|
|
28911
|
+
try {
|
|
28912
|
+
const { default: ManifoldModule } = await import('${MANIFOLD_CDN_BASE_URL}/manifold.js');
|
|
28913
|
+
window.ManifoldModule = ManifoldModule;
|
|
28914
|
+
} catch (e) {
|
|
28915
|
+
console.error('Error importing manifold in dynamic script:', e);
|
|
28916
|
+
} finally {
|
|
28917
|
+
window.dispatchEvent(new CustomEvent('${eventName}'));
|
|
28918
|
+
}
|
|
28919
|
+
`.trim();
|
|
28920
|
+
const scriptError = (err) => {
|
|
28921
|
+
const errText = "Failed to load Manifold loader script.";
|
|
28922
|
+
console.error(errText, err);
|
|
28923
|
+
setManifoldLoadingError(errText);
|
|
28924
|
+
window.removeEventListener(eventName, handleLoad);
|
|
28925
|
+
};
|
|
28926
|
+
script.addEventListener("error", scriptError);
|
|
28927
|
+
document.body.appendChild(script);
|
|
28928
|
+
return () => {
|
|
28929
|
+
window.removeEventListener(eventName, handleLoad);
|
|
28930
|
+
script.removeEventListener("error", scriptError);
|
|
28931
|
+
};
|
|
28897
28932
|
}, []);
|
|
28898
28933
|
const {
|
|
28899
28934
|
geoms,
|
|
@@ -29407,39 +29442,48 @@ async function renderComponent(component, scene) {
|
|
|
29407
29442
|
import_modeling3.default,
|
|
29408
29443
|
component.model_jscad
|
|
29409
29444
|
);
|
|
29410
|
-
|
|
29411
|
-
|
|
29412
|
-
|
|
29413
|
-
|
|
29414
|
-
|
|
29415
|
-
|
|
29416
|
-
|
|
29417
|
-
|
|
29418
|
-
|
|
29419
|
-
|
|
29420
|
-
|
|
29421
|
-
|
|
29422
|
-
|
|
29423
|
-
|
|
29424
|
-
|
|
29425
|
-
|
|
29426
|
-
|
|
29427
|
-
|
|
29428
|
-
|
|
29429
|
-
|
|
29430
|
-
|
|
29445
|
+
if (jscadObject && (jscadObject.polygons || jscadObject.sides)) {
|
|
29446
|
+
const threeGeom = convertCSGToThreeGeom(jscadObject);
|
|
29447
|
+
const material2 = new THREE24.MeshStandardMaterial({
|
|
29448
|
+
color: 8947848,
|
|
29449
|
+
metalness: 0.5,
|
|
29450
|
+
roughness: 0.5,
|
|
29451
|
+
side: THREE24.DoubleSide
|
|
29452
|
+
});
|
|
29453
|
+
const mesh2 = new THREE24.Mesh(threeGeom, material2);
|
|
29454
|
+
if (component.position) {
|
|
29455
|
+
mesh2.position.set(
|
|
29456
|
+
component.position.x ?? 0,
|
|
29457
|
+
component.position.y ?? 0,
|
|
29458
|
+
(component.position.z ?? 0) + 0.5
|
|
29459
|
+
);
|
|
29460
|
+
}
|
|
29461
|
+
if (component.rotation) {
|
|
29462
|
+
mesh2.rotation.set(
|
|
29463
|
+
THREE24.MathUtils.degToRad(component.rotation.x ?? 0),
|
|
29464
|
+
THREE24.MathUtils.degToRad(component.rotation.y ?? 0),
|
|
29465
|
+
THREE24.MathUtils.degToRad(component.rotation.z ?? 0)
|
|
29466
|
+
);
|
|
29467
|
+
}
|
|
29468
|
+
scene.add(mesh2);
|
|
29431
29469
|
}
|
|
29432
|
-
scene.add(mesh2);
|
|
29433
29470
|
return;
|
|
29434
29471
|
}
|
|
29435
29472
|
if (component.footprinter_string) {
|
|
29436
29473
|
const { geometries: geometries2 } = getJscadModelForFootprint(
|
|
29437
29474
|
component.footprinter_string
|
|
29438
29475
|
);
|
|
29439
|
-
for (const
|
|
29440
|
-
const
|
|
29476
|
+
for (const geomInfo of geometries2.flat(Infinity)) {
|
|
29477
|
+
const geom = geomInfo.geom;
|
|
29478
|
+
if (!geom || !geom.polygons && !geom.sides) {
|
|
29479
|
+
continue;
|
|
29480
|
+
}
|
|
29481
|
+
const color = new THREE24.Color(geomInfo.color);
|
|
29482
|
+
color.convertLinearToSRGB();
|
|
29483
|
+
const geomWithColor = { ...geom, color: [color.r, color.g, color.b] };
|
|
29484
|
+
const threeGeom = convertCSGToThreeGeom(geomWithColor);
|
|
29441
29485
|
const material2 = new THREE24.MeshStandardMaterial({
|
|
29442
|
-
|
|
29486
|
+
vertexColors: true,
|
|
29443
29487
|
metalness: 0.2,
|
|
29444
29488
|
roughness: 0.8,
|
|
29445
29489
|
side: THREE24.DoubleSide
|
|
@@ -29522,12 +29566,14 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
|
|
|
29522
29566
|
const boardGeom = createBoardGeomFromCircuitJson(circuitJson);
|
|
29523
29567
|
if (boardGeom) {
|
|
29524
29568
|
for (const geom of boardGeom) {
|
|
29525
|
-
const
|
|
29569
|
+
const g = geom;
|
|
29570
|
+
if (!g.polygons || g.polygons.length === 0) continue;
|
|
29571
|
+
const geometry = createGeometryFromPolygons(g.polygons);
|
|
29526
29572
|
const material = new THREE25.MeshStandardMaterial({
|
|
29527
29573
|
color: new THREE25.Color(
|
|
29528
|
-
|
|
29529
|
-
|
|
29530
|
-
|
|
29574
|
+
g.color?.[0] ?? 0,
|
|
29575
|
+
g.color?.[1] ?? 0,
|
|
29576
|
+
g.color?.[2] ?? 0
|
|
29531
29577
|
),
|
|
29532
29578
|
metalness: 0.1,
|
|
29533
29579
|
roughness: 0.8,
|