jscad-electronics 0.0.183 → 0.0.184

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/vanilla.js CHANGED
@@ -218,7 +218,7 @@ var createHexSocketBoltMesh = (input) => {
218
218
  } = hexSocketBoltDimensions[props.metricSize];
219
219
  const { length, showThreads } = props;
220
220
  const segments = 96;
221
- const steps = Math.max(2, Math.ceil(length / pitch * 24));
221
+ const steps = showThreads ? Math.max(2, Math.ceil(length / pitch * 24)) : 2;
222
222
  if (steps > 24e3)
223
223
  throw new Error(
224
224
  "Bolt length exceeds mesh resolution limit (1000 thread turns)"
@@ -254,8 +254,11 @@ var createHexSocketBoltMesh = (input) => {
254
254
  }
255
255
  };
256
256
  let previous = -1;
257
- for (let step = 0; step <= steps; step++) {
258
- const z = -length + length * step / steps;
257
+ const shaftLevels = showThreads ? Array.from(
258
+ { length: steps + 1 },
259
+ (_, step) => -length + length * step / steps
260
+ ) : [-length, -length + tipBevel, 0];
261
+ for (const z of shaftLevels) {
259
262
  const current = ring(z, (angle) => {
260
263
  const phase = ((z / pitch - angle / (2 * Math.PI)) % 1 + 1) % 1;
261
264
  const distance2 = Math.min(phase, 1 - phase);
@@ -472,7 +475,11 @@ function SheetMetal({ color = "#737e8f", ...props }) {
472
475
  }
473
476
 
474
477
  // lib/NemaMotor.tsx
478
+ import jscad3 from "@jscad/modeling";
479
+
480
+ // lib/utils/nemaMotorWireGeometry.ts
475
481
  import jscad2 from "@jscad/modeling";
482
+ import { getNemaMotorReferencePoints } from "@tscircuit/modelprinter";
476
483
 
477
484
  // lib/utils/nemaMotorParameters.ts
478
485
  import { mp as mp2, nemaMotorModelPropsSchema } from "@tscircuit/modelprinter";
@@ -480,6 +487,66 @@ var resolveNemaMotorProps = nemaMotorModelPropsSchema.parse.bind(
480
487
  nemaMotorModelPropsSchema
481
488
  );
482
489
 
490
+ // lib/utils/nemaMotorWireGeometry.ts
491
+ function createNemaMotorWireGeometry(input) {
492
+ const p = resolveNemaMotorProps(input);
493
+ if (p.wireConnection === "none") return [];
494
+ const { position } = getNemaMotorReferencePoints(p).wireside;
495
+ const angle = p.wireSideAngle * Math.PI / 180;
496
+ const place = (geometry) => jscad2.transforms.translate(
497
+ [position.x, position.y, position.z],
498
+ jscad2.transforms.rotateZ(angle, geometry)
499
+ );
500
+ if (p.wireConnection === "stubs") {
501
+ const colors = [
502
+ "#d53f3f",
503
+ "#2463af",
504
+ "#3b934b",
505
+ "#252830",
506
+ "#e5d049",
507
+ "#eeeeee",
508
+ "#ce7432",
509
+ "#803e91"
510
+ ];
511
+ return Array.from({ length: p.wireCount }, (_, i) => ({
512
+ color: colors[i],
513
+ geometry: place(
514
+ jscad2.transforms.translate(
515
+ [
516
+ (p.wireLength - 0.15) / 2,
517
+ (i - (p.wireCount - 1) / 2) * p.wireDiameter * 1.5,
518
+ 0
519
+ ],
520
+ jscad2.transforms.rotateY(
521
+ Math.PI / 2,
522
+ jscad2.primitives.cylinder({
523
+ height: p.wireLength + 0.15,
524
+ radius: p.wireDiameter / 2,
525
+ segments: 24
526
+ })
527
+ )
528
+ )
529
+ )
530
+ }));
531
+ }
532
+ const shell = jscad2.booleans.subtract(
533
+ jscad2.primitives.cuboid({ size: [6.1, 13.9, 4.5], center: [2.95, 0, 0] }),
534
+ jscad2.primitives.cuboid({ size: [5.5, 12.7, 3.3], center: [3.55, 0, 0] })
535
+ );
536
+ return [
537
+ { color: "#eeeeea", geometry: place(shell) },
538
+ ...Array.from({ length: 6 }, (_, i) => ({
539
+ color: "#b8bec6",
540
+ geometry: place(
541
+ jscad2.primitives.cuboid({
542
+ size: [3.4, 0.5, 0.5],
543
+ center: [1.7, (i - 2.5) * 2, 0]
544
+ })
545
+ )
546
+ }))
547
+ ];
548
+ }
549
+
483
550
  // lib/utils/nemaMotorGeometry.ts
484
551
  var circle = (radius, x = 0, y = 0) => Array.from({ length: 96 }, (_, i) => [
485
552
  x + radius * Math.cos(i * Math.PI / 48),
@@ -579,6 +646,7 @@ function createNemaMotorSections(input) {
579
646
  }
580
647
 
581
648
  // lib/NemaMotor.tsx
649
+ var generalize = jscad3.modifiers.generalize;
582
650
  function NemaMotor({
583
651
  bodyColor = "#242830",
584
652
  capColor = "#aeb5bd",
@@ -587,7 +655,7 @@ function NemaMotor({
587
655
  ...props
588
656
  }) {
589
657
  const p = resolveNemaMotorProps(props);
590
- const screw = p.backFace === "screws" ? jscad2.transforms.rotateX(
658
+ const screw = p.backFace === "screws" ? jscad3.transforms.rotateX(
591
659
  Math.PI,
592
660
  createHexSocketBoltGeom({
593
661
  metricSize: p.backFaceScrewSize,
@@ -598,14 +666,14 @@ function NemaMotor({
598
666
  const halfPitch = p.backFaceHoleSpacing / 2;
599
667
  return /* @__PURE__ */ jsxs(Fragment2, { children: [
600
668
  createNemaMotorSections(p).map((section, index) => {
601
- const outline = jscad2.geometries.geom2.fromPoints(section.outline);
602
- const profile = section.holes.length ? jscad2.booleans.subtract(
669
+ const outline = jscad3.geometries.geom2.fromPoints(section.outline);
670
+ const profile = section.holes.length ? jscad3.booleans.subtract(
603
671
  outline,
604
- ...section.holes.map((h2) => jscad2.geometries.geom2.fromPoints(h2))
672
+ ...section.holes.map((h2) => jscad3.geometries.geom2.fromPoints(h2))
605
673
  ) : outline;
606
- const geometry = jscad2.transforms.translate(
674
+ const geometry = jscad3.transforms.translate(
607
675
  [0, 0, section.zMin],
608
- jscad2.extrusions.extrudeLinear(
676
+ jscad3.extrusions.extrudeLinear(
609
677
  { height: section.zMax - section.zMin },
610
678
  profile
611
679
  )
@@ -614,18 +682,19 @@ function NemaMotor({
614
682
  Colorize,
615
683
  {
616
684
  color: section.name === "body" ? bodyColor : section.name === "shaft" ? shaftColor : capColor,
617
- children: /* @__PURE__ */ jsx(Custom, { geometry })
685
+ children: /* @__PURE__ */ jsx(Custom, { geometry: generalize({ simplify: true }, geometry) })
618
686
  },
619
687
  `${section.name}-${index}`
620
688
  );
621
689
  }),
690
+ createNemaMotorWireGeometry(p).map(({ geometry, color }, index) => /* @__PURE__ */ jsx(Colorize, { color, children: /* @__PURE__ */ jsx(Custom, { geometry: generalize({ simplify: true }, geometry) }) }, `wire-${index}`)),
622
691
  screw && [-halfPitch, halfPitch].flatMap(
623
692
  (x) => [-halfPitch, halfPitch].map((y) => /* @__PURE__ */ jsx(Colorize, { color: screwColor, children: /* @__PURE__ */ jsx(
624
693
  Custom,
625
694
  {
626
- geometry: jscad2.transforms.translate(
695
+ geometry: jscad3.transforms.translate(
627
696
  [x, y, -p.bodyLength],
628
- screw
697
+ generalize({ simplify: true }, screw)
629
698
  )
630
699
  }
631
700
  ) }, `rear-screw-${x}-${y}`))
@@ -9460,8 +9529,8 @@ function renderNode(node, colorCtx, renderCtx) {
9460
9529
  }
9461
9530
  return (children ?? []).flatMap((c) => renderNode(c, colorCtx, renderCtx));
9462
9531
  }
9463
- function render(root, jscad3) {
9464
- const geometries = renderNode(root, void 0, { jscad: jscad3 });
9532
+ function render(root, jscad4) {
9533
+ const geometries = renderNode(root, void 0, { jscad: jscad4 });
9465
9534
  return { geometries };
9466
9535
  }
9467
9536
 
@@ -9549,24 +9618,24 @@ function convertCSGToThreeGeom(csg) {
9549
9618
  }
9550
9619
 
9551
9620
  // lib/vanilla/index.ts
9552
- function getJscadModelForFootprint(footprint, jscad3) {
9621
+ function getJscadModelForFootprint(footprint, jscad4) {
9553
9622
  const vnode = h(Footprinter3d, { footprint });
9554
- return render(vnode, jscad3);
9623
+ return render(vnode, jscad4);
9555
9624
  }
9556
- function getJscadModelForFootprintWithPads(footprint, jscad3) {
9625
+ function getJscadModelForFootprintWithPads(footprint, jscad4) {
9557
9626
  const vnode = h(
9558
9627
  Fragment,
9559
9628
  {},
9560
9629
  h(Footprinter3d, { footprint }),
9561
9630
  h(ExtrudedPads, { footprint })
9562
9631
  );
9563
- return render(vnode, jscad3);
9632
+ return render(vnode, jscad4);
9564
9633
  }
9565
- function createJSCADRenderer(jscad3) {
9634
+ function createJSCADRenderer(jscad4) {
9566
9635
  function createJSCADRoot(container) {
9567
9636
  return {
9568
9637
  render(element) {
9569
- const { geometries } = render(element, jscad3);
9638
+ const { geometries } = render(element, jscad4);
9570
9639
  container.splice(0, container.length, ...geometries);
9571
9640
  }
9572
9641
  };