@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.
Files changed (2) hide show
  1. package/dist/index.js +99 -53
  2. 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 geom of geometries2) {
25367
- const threeGeom = convertCSGToThreeGeom(geom);
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.343",
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.1.1";
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 loadManifoldFromCDN = async () => {
28881
+ const initManifold = async (ManifoldModule) => {
28872
28882
  try {
28873
- const manifoldURL = `${MANIFOLD_CDN_BASE_URL}/manifold.js`;
28874
- const { default: ManifoldModule } = await import(
28875
- /* @vite-ignore */
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 load Manifold from CDN:", error);
28887
+ console.error("Failed to initialize Manifold:", error);
28891
28888
  setManifoldLoadingError(
28892
- `Failed to load Manifold module: ${error instanceof Error ? error.message : "Unknown error"}`
28889
+ `Failed to initialize Manifold: ${error instanceof Error ? error.message : "Unknown error"}`
28893
28890
  );
28894
28891
  }
28895
28892
  };
28896
- loadManifoldFromCDN();
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
- const threeGeom = convertCSGToThreeGeom(jscadObject);
29411
- const material2 = new THREE24.MeshStandardMaterial({
29412
- color: 8947848,
29413
- metalness: 0.5,
29414
- roughness: 0.5,
29415
- side: THREE24.DoubleSide
29416
- });
29417
- const mesh2 = new THREE24.Mesh(threeGeom, material2);
29418
- if (component.position) {
29419
- mesh2.position.set(
29420
- component.position.x ?? 0,
29421
- component.position.y ?? 0,
29422
- (component.position.z ?? 0) + 0.5
29423
- );
29424
- }
29425
- if (component.rotation) {
29426
- mesh2.rotation.set(
29427
- THREE24.MathUtils.degToRad(component.rotation.x ?? 0),
29428
- THREE24.MathUtils.degToRad(component.rotation.y ?? 0),
29429
- THREE24.MathUtils.degToRad(component.rotation.z ?? 0)
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 geom of geometries2) {
29440
- const threeGeom = convertCSGToThreeGeom(geom);
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
- color: 4473924,
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 geometry = createGeometryFromPolygons(geom.polygons);
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
- geom.color?.[0] ?? 0,
29529
- geom.color?.[1] ?? 0,
29530
- geom.color?.[2] ?? 0
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/3d-viewer",
3
- "version": "0.0.344",
3
+ "version": "0.0.346",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",