jscad-electronics 0.0.190 → 0.0.192

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/cables.d.ts CHANGED
@@ -16,6 +16,12 @@ type CableConnectorSpec = ConnectorBody & ({
16
16
  pitch: number;
17
17
  } | {
18
18
  kind: "nema_5_15p" | "iec_c13";
19
+ } | {
20
+ kind: "bullet_male" | "bullet_female";
21
+ diameter: number;
22
+ contactDepth: number;
23
+ pinCount: number;
24
+ pitch: number;
19
25
  });
20
26
  /** Structural subset of a cableprinter definition; no runtime spec dependency. */
21
27
  type CableGeometryDefinition = {
package/dist/cables.js CHANGED
@@ -1,3 +1,6 @@
1
+ // lib/cables/bullet-meshes.ts
2
+ import jscad2 from "@jscad/modeling";
3
+
1
4
  // lib/materials.ts
2
5
  var componentMaterials = {
3
6
  moldedPlastic: { metalness: 0, roughness: 0.7 },
@@ -10,9 +13,6 @@ var componentMaterials = {
10
13
  steel: { metalness: 1, roughness: 0.25 }
11
14
  };
12
15
 
13
- // lib/cables/connector-meshes.ts
14
- import jscad2 from "@jscad/modeling";
15
-
16
16
  // lib/cables/geometry-to-mesh.ts
17
17
  import jscad from "@jscad/modeling";
18
18
 
@@ -141,11 +141,97 @@ function placeConnectorMesh({
141
141
  return { ...mesh, positions };
142
142
  }
143
143
 
144
+ // lib/cables/bullet-meshes.ts
145
+ function createBulletMeshes(connector) {
146
+ const { cylinder: cylinder2, sphere: sphere2, cuboid: cuboid2 } = jscad2.primitives;
147
+ const { subtract: subtract3, union: union2 } = jscad2.booleans;
148
+ const { diameter, contactDepth, bodyDepth, kind } = connector;
149
+ const bodyWidth = connector.bodyHeight;
150
+ const radius = diameter / 2;
151
+ let contact = kind === "bullet_male" ? union2(
152
+ sphere2({ radius, center: [0, 0, radius], segments: 32 }),
153
+ cylinder2({
154
+ radius,
155
+ height: contactDepth - radius,
156
+ center: [0, 0, (contactDepth + radius) / 2],
157
+ segments: 32
158
+ })
159
+ ) : subtract3(
160
+ cylinder2({
161
+ radius: bodyWidth / 2,
162
+ height: contactDepth,
163
+ center: [0, 0, contactDepth / 2],
164
+ segments: 32
165
+ }),
166
+ cylinder2({
167
+ radius,
168
+ height: contactDepth - diameter / 4 + 0.1,
169
+ center: [0, 0, (contactDepth - diameter / 4 - 0.1) / 2],
170
+ segments: 32
171
+ })
172
+ );
173
+ if (kind === "bullet_male") {
174
+ contact = subtract3(
175
+ contact,
176
+ cuboid2({
177
+ size: [diameter + 0.2, diameter * 0.08, contactDepth * 0.65],
178
+ center: [0, 0, contactDepth * 0.45]
179
+ }),
180
+ cuboid2({
181
+ size: [diameter * 0.08, diameter + 0.2, contactDepth * 0.65],
182
+ center: [0, 0, contactDepth * 0.45]
183
+ })
184
+ );
185
+ }
186
+ const cupDepth = bodyDepth - contactDepth;
187
+ const solderCup = subtract3(
188
+ cylinder2({
189
+ radius: bodyWidth / 2,
190
+ height: cupDepth,
191
+ center: [0, 0, contactDepth + cupDepth / 2],
192
+ segments: 32
193
+ }),
194
+ cylinder2({
195
+ radius: radius * 0.75,
196
+ height: cupDepth * 0.8 + 0.1,
197
+ center: [0, 0, bodyDepth - cupDepth * 0.4 + 0.05],
198
+ segments: 32
199
+ })
200
+ );
201
+ const contactMeshes = [
202
+ geometryToCableMesh({
203
+ geometry: contact,
204
+ material: componentMaterials.goldContact,
205
+ color: [0.83, 0.64, 0.22, 1],
206
+ name: kind === "bullet_male" ? "bullet-pin" : "bullet-socket"
207
+ }),
208
+ geometryToCableMesh({
209
+ geometry: solderCup,
210
+ material: componentMaterials.goldContact,
211
+ color: [0.83, 0.64, 0.22, 1],
212
+ name: "solder-cup"
213
+ })
214
+ ];
215
+ const pinCount = connector.pinCount ?? 1;
216
+ return Array.from({ length: pinCount }, (_, index) => {
217
+ const offset = (index - (pinCount - 1) / 2) * (connector.pitch ?? bodyWidth);
218
+ return contactMeshes.map((mesh) => ({
219
+ ...mesh,
220
+ name: pinCount === 1 ? mesh.name : `${mesh.name}-${index + 1}`,
221
+ // Local +X is the cable frame's normal, paired with sweepRoundCable.offset.
222
+ positions: mesh.positions.map(
223
+ (coordinate, coordinateIndex) => coordinateIndex % 3 === 0 ? coordinate + offset : coordinate
224
+ )
225
+ }));
226
+ }).flat();
227
+ }
228
+
144
229
  // lib/cables/connector-meshes.ts
145
- var { cuboid, roundedCuboid, cylinder, roundedRectangle, polygon, sphere } = jscad2.primitives;
146
- var { extrudeLinear } = jscad2.extrusions;
147
- var { translate, rotateY } = jscad2.transforms;
148
- var { subtract: subtract2, union } = jscad2.booleans;
230
+ import jscad3 from "@jscad/modeling";
231
+ var { cuboid, roundedCuboid, cylinder, roundedRectangle, polygon, sphere } = jscad3.primitives;
232
+ var { extrudeLinear } = jscad3.extrusions;
233
+ var { translate, rotateY } = jscad3.transforms;
234
+ var { subtract: subtract2, union } = jscad3.booleans;
149
235
  var plastic = [0.055, 0.07, 0.09, 1];
150
236
  var housing = [0.86, 0.84, 0.75, 1];
151
237
  var metal = [0.6, 0.64, 0.7, 1];
@@ -418,8 +504,8 @@ function createConnectorMeshes({
418
504
  connector,
419
505
  jacketDiameter
420
506
  }) {
421
- const meshes = connector.kind === "usb_c_plug" ? createUsbMeshes(connector) : "pinCount" in connector ? createJstMeshes(connector) : createMainsMeshes(connector);
422
- if (jacketDiameter !== void 0) {
507
+ const meshes = connector.kind === "usb_c_plug" ? createUsbMeshes(connector) : connector.kind === "bullet_male" || connector.kind === "bullet_female" ? createBulletMeshes(connector) : connector.kind === "jst_sh_housing" || connector.kind === "jst_ph_housing" ? createJstMeshes(connector) : createMainsMeshes(connector);
508
+ if (jacketDiameter !== void 0 && connector.kind !== "bullet_male" && connector.kind !== "bullet_female") {
423
509
  const exit = connectorWireExitDepth(connector);
424
510
  const boot = union(
425
511
  cylinder({
@@ -529,11 +615,26 @@ function validateCableDefinition(definition) {
529
615
  connector.shellHeight,
530
616
  connector.shellDepth
531
617
  );
618
+ if (connector.kind === "bullet_male" || connector.kind === "bullet_female") {
619
+ const pinCount = connector.pinCount ?? 1;
620
+ const pitch = connector.pitch ?? connector.bodyHeight;
621
+ dimensions.push(connector.diameter, connector.contactDepth, pitch);
622
+ if (!Number.isInteger(pinCount) || pinCount < 1 || pinCount > 16 || connector.bodyHeight <= connector.diameter || pitch < connector.bodyHeight || Math.abs(
623
+ connector.bodyWidth - (connector.bodyHeight + (pinCount - 1) * pitch)
624
+ ) > 1e-6 || connector.contactDepth >= connector.bodyDepth || connector.contactDepth <= connector.diameter / 2)
625
+ throw new Error("Bullet contact must fit inside its cylindrical body");
626
+ if (pinCount === 1 && (definition.crossSection.kind !== "round_jacket" || definition.crossSection.diameter > connector.bodyHeight) || pinCount > 1 && (definition.crossSection.kind !== "wire_bundle" || definition.crossSection.wires.length !== pinCount || definition.crossSection.wirePitch !== pitch || definition.crossSection.wires.some(
627
+ (wire) => wire.diameter > connector.bodyHeight
628
+ )))
629
+ throw new Error(
630
+ "Bullet cables require one insulated wire per contact that fits its solder cup"
631
+ );
632
+ }
532
633
  if (dimensions.some(
533
634
  (dimension) => !Number.isFinite(dimension) || dimension <= 0
534
635
  ))
535
636
  throw new Error("Connector dimensions must be finite and positive");
536
- if ("pinCount" in connector && (!Number.isInteger(connector.pinCount) || connector.pinCount < 2 || !Number.isFinite(connector.pitch) || connector.pitch <= 0))
637
+ if ((connector.kind === "jst_sh_housing" || connector.kind === "jst_ph_housing") && (!Number.isInteger(connector.pinCount) || connector.pinCount < 2 || !Number.isFinite(connector.pitch) || connector.pitch <= 0))
537
638
  throw new Error(
538
639
  "JST connectors need a positive pitch and at least two contacts"
539
640
  );
@@ -546,7 +647,7 @@ function validateCableDefinition(definition) {
546
647
  if (!Number.isFinite(crossSection.wirePitch) || crossSection.wires.some((wire) => wire.diameter > crossSection.wirePitch))
547
648
  throw new Error("Insulated bundle wires must not overlap");
548
649
  for (const connector of [definition.connectorA, definition.connectorB]) {
549
- if (!("pinCount" in connector) || connector.pinCount !== crossSection.wires.length)
650
+ if (!("pinCount" in connector) || (connector.pinCount ?? 1) !== crossSection.wires.length)
550
651
  throw new Error("Bundle wire count must match connector contact count");
551
652
  }
552
653
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/materials.ts","../lib/cables/connector-meshes.ts","../lib/cables/geometry-to-mesh.ts","../lib/cables/path-frames.ts","../lib/cables/sweep-round-cable.ts","../lib/cables/create-cable-meshes.ts"],"sourcesContent":["/** Approximate visual finishes, not measured optical properties. */\nexport const componentMaterials = {\n moldedPlastic: { metalness: 0, roughness: 0.7 },\n rubber: { metalness: 0, roughness: 0.9 },\n sleeve: { metalness: 0, roughness: 0.45 },\n tinnedLead: { metalness: 0.8, roughness: 0.55 },\n goldContact: { metalness: 1, roughness: 0.25 },\n copper: { metalness: 1, roughness: 0.35 },\n brushedMetal: { metalness: 1, roughness: 0.4 },\n steel: { metalness: 1, roughness: 0.25 },\n} as const\n","import { componentMaterials } from \"../materials\"\nimport jscad from \"@jscad/modeling\"\nimport { geometryToCableMesh } from \"./geometry-to-mesh\"\nimport type {\n CableColor,\n CableConnectorSpec,\n CableMesh,\n CablePoint,\n} from \"./types\"\n\nconst { cuboid, roundedCuboid, cylinder, roundedRectangle, polygon, sphere } =\n jscad.primitives\nconst { extrudeLinear } = jscad.extrusions\nconst { translate, rotateY } = jscad.transforms\nconst { subtract, union } = jscad.booleans\nconst plastic: CableColor = [0.055, 0.07, 0.09, 1]\nconst housing: CableColor = [0.86, 0.84, 0.75, 1]\nconst metal: CableColor = [0.6, 0.64, 0.7, 1]\nconst brass: CableColor = [0.66, 0.46, 0.18, 1]\n\nexport function connectorWireExitDepth(connector: CableConnectorSpec): number {\n if (connector.kind === \"usb_c_plug\")\n return connector.shellDepth + connector.bodyDepth\n if (connector.kind === \"nema_5_15p\") return 19.05 + connector.bodyDepth\n return connector.bodyDepth\n}\n\nfunction createJstMeshes(\n connector: Extract<\n CableConnectorSpec,\n { kind: \"jst_sh_housing\" | \"jst_ph_housing\" }\n >,\n): CableMesh[] {\n const {\n bodyWidth: width,\n bodyHeight: height,\n bodyDepth: depth,\n pinCount,\n pitch,\n } = connector\n const opening = pitch === 1 ? 0.55 : 1.05\n const holes = Array.from({ length: pinCount }, (_, index) => {\n const x = (index - (pinCount - 1) / 2) * pitch\n return cuboid({\n size: [opening, opening * 1.35, depth - 0.6],\n center: [x, 0, (depth - 0.6) / 2 - 0.02],\n })\n })\n const backHoles = Array.from({ length: pinCount }, (_, index) =>\n cylinder({\n radius: pitch * 0.34,\n height: 1.3,\n segments: 16,\n center: [(index - (pinCount - 1) / 2) * pitch, 0, depth - 0.5],\n }),\n )\n const latchCut = cuboid({\n size: [width * 0.45, 0.5, depth * 0.5],\n center: [0, height / 2, depth * 0.65],\n })\n const body = subtract(\n roundedCuboid({\n size: [width, height, depth],\n center: [0, 0, depth / 2],\n roundRadius: 0.1,\n segments: 8,\n }),\n ...holes,\n ...backHoles,\n latchCut,\n ...Array.from({ length: pinCount }, (_, index) =>\n cuboid({\n size: [opening * 0.8, height * 0.7, depth * 0.24],\n center: [(index - (pinCount - 1) / 2) * pitch, height / 2, depth * 0.7],\n }),\n ),\n )\n const contacts = Array.from({ length: pinCount }, (_, index) => {\n const x = (index - (pinCount - 1) / 2) * pitch\n return geometryToCableMesh({\n material: componentMaterials.goldContact,\n name: `contact-${index + 1}`,\n color: metal,\n geometry: subtract(\n cuboid({\n size: [opening * 0.92, opening * 1.25, depth * 0.65],\n center: [x, 0, depth * 0.45],\n }),\n cuboid({\n size: [\n opening * 0.92 - 0.12,\n opening * 1.25 - 0.12,\n depth * 0.65 + 0.2,\n ],\n center: [x, 0, depth * 0.45],\n }),\n ),\n })\n })\n return [\n geometryToCableMesh({ geometry: body, color: housing, name: \"housing\" }),\n ...contacts,\n ]\n}\n\nfunction createUsbMeshes(\n connector: Extract<CableConnectorSpec, { kind: \"usb_c_plug\" }>,\n): CableMesh[] {\n const {\n shellWidth,\n shellHeight,\n shellDepth,\n bodyWidth,\n bodyHeight,\n bodyDepth,\n } = connector\n const shell = subtract(\n extrudeLinear(\n { height: shellDepth },\n roundedRectangle({\n size: [shellWidth, shellHeight],\n roundRadius: shellHeight / 2 - 0.02,\n segments: 32,\n }),\n ),\n translate(\n [0, 0, -0.1],\n extrudeLinear(\n { height: shellDepth + 0.2 },\n roundedRectangle({\n size: [shellWidth - 0.4, shellHeight - 0.4],\n roundRadius: (shellHeight - 0.4) / 2 - 0.02,\n segments: 32,\n }),\n ),\n ),\n )\n const liner = subtract(\n extrudeLinear(\n { height: shellDepth },\n roundedRectangle({\n size: [shellWidth - 0.41, shellHeight - 0.41],\n roundRadius: 0.85,\n segments: 32,\n }),\n ),\n translate(\n [0, 0, -0.1],\n extrudeLinear(\n { height: shellDepth - 0.3 },\n roundedRectangle({\n size: [shellWidth - 0.8, shellHeight - 0.8],\n roundRadius: 0.65,\n segments: 32,\n }),\n ),\n ),\n )\n const body = roundedCuboid({\n size: [bodyWidth, bodyHeight, bodyDepth],\n center: [0, 0, shellDepth + bodyDepth / 2],\n roundRadius: Math.min(1.3, bodyHeight / 4),\n segments: 16,\n })\n const contacts = Array.from({ length: 24 }, (_, index) =>\n cuboid({\n size: [0.22, 0.08, 3.5],\n center: [((index % 12) - 5.5) * 0.5, index < 12 ? 0.77 : -0.77, 2.6],\n }),\n )\n return [\n geometryToCableMesh({ geometry: body, color: plastic, name: \"overmold\" }),\n geometryToCableMesh({\n geometry: shell,\n color: metal,\n material: componentMaterials.brushedMetal,\n name: \"shell\",\n }),\n geometryToCableMesh({\n geometry: liner,\n color: [0.025, 0.026, 0.03, 1],\n name: \"liner\",\n }),\n ...contacts.map((geometry, index) =>\n geometryToCableMesh({\n geometry,\n color: brass,\n material: componentMaterials.goldContact,\n name: `contact-${index + 1}`,\n }),\n ),\n ]\n}\n\nfunction createMainsMeshes(connector: CableConnectorSpec): CableMesh[] {\n const { bodyWidth, bodyHeight, bodyDepth, kind } = connector\n const faceDepth = kind === \"nema_5_15p\" ? 19.05 : 0\n let body = roundedCuboid({\n size: [bodyWidth, bodyHeight, bodyDepth],\n center: [0, 0, faceDepth + bodyDepth / 2],\n roundRadius: 2,\n segments: 16,\n })\n if (kind === \"nema_5_15p\") {\n const blades = [-6.35, 6.35].map((x) => {\n const blade = cuboid({\n size: [1.524, 6.35, 15.875],\n center: [x, 2.7, 19.05 - 15.875 / 2],\n })\n const hole = translate(\n [x, 2.7, 7.3],\n rotateY(\n Math.PI / 2,\n cylinder({ radius: 1.1, height: 3, segments: 20 }),\n ),\n )\n return subtract(blade, hole)\n })\n const ground = union(\n cylinder({\n radius: 2.38125,\n height: 19.05 - 2.38125,\n center: [0, -9.20625, (19.05 + 2.38125) / 2],\n segments: 32,\n }),\n sphere({ radius: 2.38125, center: [0, -9.20625, 2.38125], segments: 32 }),\n )\n return [\n geometryToCableMesh({\n geometry: body,\n color: plastic,\n name: \"plug-body\",\n }),\n ...blades.map((geometry, index) =>\n geometryToCableMesh({\n geometry,\n color: brass,\n material: componentMaterials.goldContact,\n name: `blade-${index + 1}`,\n }),\n ),\n geometryToCableMesh({\n geometry: ground,\n color: brass,\n material: componentMaterials.goldContact,\n name: \"ground-pin\",\n }),\n ]\n }\n const recess = translate(\n [0, 0, -0.1],\n extrudeLinear(\n { height: 3.2 },\n polygon({\n points: [\n [-9, -6],\n [9, -6],\n [9, 2],\n [5, 6],\n [-5, 6],\n [-9, 2],\n ],\n }),\n ),\n )\n const sockets: CablePoint[] = [\n [-4.4, -1.8, 8],\n [4.4, -1.8, 8],\n [0, 3.1, 8],\n ]\n body = subtract(\n body,\n recess,\n ...sockets.map((center) => cuboid({ size: [2.3, 3.4, 16.2], center })),\n )\n return [\n geometryToCableMesh({\n geometry: body,\n color: plastic,\n name: \"appliance-body\",\n }),\n ...sockets.map(([x, y], index) =>\n geometryToCableMesh({\n geometry: cuboid({ size: [0.15, 2.8, 6], center: [x - 1.05, y, 7.8] }),\n color: brass,\n material: componentMaterials.goldContact,\n name: `socket-contact-${index + 1}`,\n }),\n ),\n ]\n}\n\nexport function createConnectorMeshes({\n connector,\n jacketDiameter,\n}: { connector: CableConnectorSpec; jacketDiameter?: number }): CableMesh[] {\n const meshes =\n connector.kind === \"usb_c_plug\"\n ? createUsbMeshes(connector)\n : \"pinCount\" in connector\n ? createJstMeshes(connector)\n : createMainsMeshes(connector)\n if (jacketDiameter !== undefined) {\n const exit = connectorWireExitDepth(connector)\n const boot = union(\n cylinder({\n radius: jacketDiameter / 2 + 0.15,\n height: 5,\n center: [0, 0, exit + 2.5],\n segments: 32,\n }),\n ...Array.from({ length: 7 }, (_, index) =>\n cylinder({\n radius: jacketDiameter / 2 + 0.8 - index * 0.06,\n height: 0.28,\n center: [0, 0, exit + 0.4 + index * 0.7],\n segments: 32,\n }),\n ),\n )\n meshes.push(\n geometryToCableMesh({\n geometry: boot,\n color: plastic,\n name: \"strain-relief\",\n }),\n )\n }\n return meshes\n}\n","import jscad from \"@jscad/modeling\"\nimport type { Geom3 } from \"@jscad/modeling/src/geometries/geom3\"\nimport type { CableMesh, CableColor, CableFrame, CablePoint } from \"./types\"\nimport { add, scale } from \"./path-frames\"\n\ntype VertexKey = string\n\nexport function geometryToCableMesh({\n geometry,\n color,\n name,\n material,\n}: {\n geometry: Geom3\n color: CableColor\n name: string\n material?: CableMesh[\"material\"]\n}): CableMesh {\n const triangles = jscad.geometries.geom3.toPolygons(geometry)\n const positions: number[] = []\n const indices: number[] = []\n const vertices = new Map<VertexKey, number>()\n for (const triangle of triangles) {\n const polygonIndices: number[] = []\n for (const point of triangle.vertices) {\n const key = point.map((coordinate) => coordinate.toFixed(8)).join(\",\")\n let index = vertices.get(key)\n if (index === undefined) {\n index = positions.length / 3\n positions.push(...point)\n vertices.set(key, index)\n }\n polygonIndices.push(index)\n }\n // JSCAD CSG polygons are convex, so a fan preserves their outward winding.\n for (let side = 1; side < polygonIndices.length - 1; side++) {\n indices.push(\n polygonIndices[0]!,\n polygonIndices[side]!,\n polygonIndices[side + 1]!,\n )\n }\n }\n return { name, positions, indices, color, material, smooth: false }\n}\n\nexport function placeConnectorMesh({\n mesh,\n frame,\n wireExitDepth,\n isEnd,\n}: {\n mesh: CableMesh\n frame: CableFrame\n wireExitDepth: number\n isEnd: boolean\n}): CableMesh {\n const tangent = scale(frame.tangent, isEnd ? -1 : 1)\n const binormal: CablePoint = isEnd\n ? scale(frame.binormal, -1)\n : frame.binormal\n const origin = add(frame.point, scale(tangent, -wireExitDepth))\n const positions: number[] = []\n for (let index = 0; index < mesh.positions.length; index += 3) {\n positions.push(\n ...add(\n origin,\n add(\n add(\n scale(frame.normal, mesh.positions[index]!),\n scale(binormal, mesh.positions[index + 1]!),\n ),\n scale(tangent, mesh.positions[index + 2]!),\n ),\n ),\n )\n }\n return { ...mesh, positions }\n}\n","import type { CableFrame, CablePoint } from \"./types\"\n\nexport const add = (a: CablePoint, b: CablePoint): CablePoint => [\n a[0] + b[0],\n a[1] + b[1],\n a[2] + b[2],\n]\nexport const subtract = (a: CablePoint, b: CablePoint): CablePoint => [\n a[0] - b[0],\n a[1] - b[1],\n a[2] - b[2],\n]\nexport const scale = (point: CablePoint, factor: number): CablePoint => [\n point[0] * factor,\n point[1] * factor,\n point[2] * factor,\n]\nexport const dot = (a: CablePoint, b: CablePoint) =>\n a[0] * b[0] + a[1] * b[1] + a[2] * b[2]\nexport const cross = (a: CablePoint, b: CablePoint): CablePoint => [\n a[1] * b[2] - a[2] * b[1],\n a[2] * b[0] - a[0] * b[2],\n a[0] * b[1] - a[1] * b[0],\n]\nexport function normalize(point: CablePoint): CablePoint {\n const length = Math.hypot(...point)\n if (length < 1e-10)\n throw new Error(\n \"Cable path must not contain coincident points or a reversing tangent\",\n )\n return scale(point, 1 / length)\n}\n\n/** Parallel transport avoids a wire bundle flipping when its tangent crosses an axis. */\nexport function createCablePathFrames(path: CablePoint[]): CableFrame[] {\n if (\n path.length < 2 ||\n path.some((point) => point.length !== 3 || !point.every(Number.isFinite))\n ) {\n throw new Error(\"Cable path needs at least two finite 3D points\")\n }\n const segments = path\n .slice(1)\n .map((point, index) => normalize(subtract(point, path[index]!)))\n const tangents = path.map((_, index) =>\n index === 0\n ? segments[0]!\n : index === path.length - 1\n ? segments.at(-1)!\n : normalize(add(segments[index - 1]!, segments[index]!)),\n )\n const initialUp: CablePoint =\n Math.abs(tangents[0]![2]) > 0.95 ? [0, 1, 0] : [0, 0, 1]\n let normal = normalize(cross(initialUp, tangents[0]!))\n return tangents.map((tangent, index) => {\n if (index > 0) {\n const previousTangent = tangents[index - 1]!\n const axis = cross(previousTangent, tangent)\n const sine = Math.hypot(...axis)\n const cosine = Math.max(-1, Math.min(1, dot(previousTangent, tangent)))\n if (sine > 1e-10) {\n const unitAxis = scale(axis, 1 / sine)\n normal = normalize(\n add(\n add(scale(normal, cosine), scale(cross(unitAxis, normal), sine)),\n scale(unitAxis, dot(unitAxis, normal) * (1 - cosine)),\n ),\n )\n }\n }\n return {\n point: path[index]!,\n tangent,\n normal,\n binormal: normalize(cross(tangent, normal)),\n }\n })\n}\n","import { add, scale } from \"./path-frames\"\nimport type { CableFrame, CableMesh, CableColor } from \"./types\"\n\n/** Closed indexed sweep around a supplied centerline; this does not choose a route. */\nexport function sweepRoundCable({\n frames,\n diameter,\n offset = 0,\n radialSegments,\n color,\n name,\n}: {\n frames: CableFrame[]\n diameter: number\n offset?: number\n radialSegments: number\n color: CableColor\n name: string\n}): CableMesh {\n const positions: number[] = []\n const indices: number[] = []\n for (const frame of frames) {\n const center = add(frame.point, scale(frame.normal, offset))\n for (let side = 0; side < radialSegments; side++) {\n const angle = (side * Math.PI * 2) / radialSegments\n positions.push(\n ...add(\n center,\n add(\n scale(frame.normal, (diameter * Math.cos(angle)) / 2),\n scale(frame.binormal, (diameter * Math.sin(angle)) / 2),\n ),\n ),\n )\n }\n }\n for (let ring = 0; ring < frames.length - 1; ring++) {\n for (let side = 0; side < radialSegments; side++) {\n const a = ring * radialSegments + side\n const b = ring * radialSegments + ((side + 1) % radialSegments)\n const c = a + radialSegments\n const d = b + radialSegments\n indices.push(a, b, c, b, d, c)\n }\n }\n const startCenter = positions.length / 3\n positions.push(...add(frames[0]!.point, scale(frames[0]!.normal, offset)))\n const endCenter = positions.length / 3\n positions.push(\n ...add(frames.at(-1)!.point, scale(frames.at(-1)!.normal, offset)),\n )\n const lastRing = (frames.length - 1) * radialSegments\n for (let side = 0; side < radialSegments; side++) {\n const next = (side + 1) % radialSegments\n indices.push(\n startCenter,\n next,\n side,\n endCenter,\n lastRing + side,\n lastRing + next,\n )\n }\n return { name, positions, indices, color, smooth: true }\n}\n","import {\n createConnectorMeshes,\n connectorWireExitDepth,\n} from \"./connector-meshes\"\nimport { placeConnectorMesh } from \"./geometry-to-mesh\"\nimport { createCablePathFrames } from \"./path-frames\"\nimport { sweepRoundCable } from \"./sweep-round-cable\"\nimport type {\n CableColor,\n CableGeometryDefinition,\n CableMesh,\n CablePoint,\n} from \"./types\"\n\nfunction parseCableColor(color: string): CableColor {\n if (!/^#[a-f\\d]{6}$/i.test(color))\n throw new Error(\"Cable colors must be six-digit hex strings\")\n return [\n parseInt(color.slice(1, 3), 16) / 255,\n parseInt(color.slice(3, 5), 16) / 255,\n parseInt(color.slice(5, 7), 16) / 255,\n 1,\n ]\n}\n\nfunction validateCableDefinition(definition: CableGeometryDefinition) {\n for (const connector of [definition.connectorA, definition.connectorB]) {\n const dimensions = [\n connector.bodyWidth,\n connector.bodyHeight,\n connector.bodyDepth,\n ]\n if (connector.kind === \"usb_c_plug\")\n dimensions.push(\n connector.shellWidth,\n connector.shellHeight,\n connector.shellDepth,\n )\n if (\n dimensions.some(\n (dimension) => !Number.isFinite(dimension) || dimension <= 0,\n )\n )\n throw new Error(\"Connector dimensions must be finite and positive\")\n if (\n \"pinCount\" in connector &&\n (!Number.isInteger(connector.pinCount) ||\n connector.pinCount < 2 ||\n !Number.isFinite(connector.pitch) ||\n connector.pitch <= 0)\n )\n throw new Error(\n \"JST connectors need a positive pitch and at least two contacts\",\n )\n }\n const crossSection = definition.crossSection\n const diameters =\n crossSection.kind === \"round_jacket\"\n ? [crossSection.diameter]\n : crossSection.wires.map((wire) => wire.diameter)\n if (\n diameters.length === 0 ||\n diameters.some((diameter) => !Number.isFinite(diameter) || diameter <= 0)\n )\n throw new Error(\"Cable diameters must be finite and positive\")\n if (crossSection.kind === \"wire_bundle\") {\n if (\n !Number.isFinite(crossSection.wirePitch) ||\n crossSection.wires.some((wire) => wire.diameter > crossSection.wirePitch)\n )\n throw new Error(\"Insulated bundle wires must not overlap\")\n for (const connector of [definition.connectorA, definition.connectorB]) {\n if (\n !(\"pinCount\" in connector) ||\n connector.pinCount !== crossSection.wires.length\n )\n throw new Error(\"Bundle wire count must match connector contact count\")\n }\n }\n}\n\n/** Mesh generation only. Path samples are already resolved in world millimeters, +Z up. */\nexport function createCableMeshes({\n definition,\n path,\n radialSegments = 24,\n}: {\n definition: CableGeometryDefinition\n path: CablePoint[]\n radialSegments?: number\n}): CableMesh[] {\n validateCableDefinition(definition)\n if (\n !Number.isInteger(radialSegments) ||\n radialSegments < 8 ||\n radialSegments > 128\n )\n throw new Error(\"radialSegments must be an integer from 8 to 128\")\n const frames = createCablePathFrames(path)\n const crossSection = definition.crossSection\n const jacketDiameter =\n crossSection.kind === \"round_jacket\" ? crossSection.diameter : undefined\n const meshes =\n crossSection.kind === \"round_jacket\"\n ? [\n sweepRoundCable({\n frames,\n diameter: crossSection.diameter,\n radialSegments,\n color: parseCableColor(crossSection.color),\n name: \"jacket\",\n }),\n ]\n : crossSection.wires.map((wire, index) =>\n sweepRoundCable({\n frames,\n diameter: wire.diameter,\n offset:\n (index - (crossSection.wires.length - 1) / 2) *\n crossSection.wirePitch,\n radialSegments,\n color: parseCableColor(wire.color),\n name: `wire-${index + 1}`,\n }),\n )\n for (const [index, connector] of [\n definition.connectorA,\n definition.connectorB,\n ].entries()) {\n const frame = index === 0 ? frames[0]! : frames.at(-1)!\n const parts = createConnectorMeshes({ connector, jacketDiameter })\n meshes.push(\n ...parts.map((mesh) =>\n placeConnectorMesh({\n mesh: { ...mesh, name: `${index === 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AAK,KAC3C,aAAa;AAAA,MACf;AAAA,MACA,OAAO,gBAAgB,KAAK,KAAK;AAAA,MACjC,MAAM,QAAQ,QAAQ,CAAC;AAAA,IACzB,CAAC;AAAA,EACH;AACN,aAAW,CAAC,OAAO,SAAS,KAAK;AAAA,IAC/B,WAAW;AAAA,IACX,WAAW;AAAA,EACb,EAAE,QAAQ,GAAG;AACX,UAAM,QAAQ,UAAU,IAAI,OAAO,CAAC,IAAK,OAAO,GAAG,EAAE;AACrD,UAAM,QAAQ,sBAAsB,EAAE,WAAW,eAAe,CAAC;AACjE,WAAO;AAAA,MACL,GAAG,MAAM;AAAA,QAAI,CAAC,SACZ,mBAAmB;AAAA,UACjB,MAAM,EAAE,GAAG,MAAM,MAAM,GAAG,UAAU,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG;AAAA,UACjE;AAAA,UACA,OAAO,UAAU;AAAA,UACjB,eAAe,uBAAuB,SAAS;AAAA,QACjD,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["jscad","jscad","subtract"]}
1
+ {"version":3,"sources":["../lib/cables/bullet-meshes.ts","../lib/materials.ts","../lib/cables/geometry-to-mesh.ts","../lib/cables/path-frames.ts","../lib/cables/connector-meshes.ts","../lib/cables/sweep-round-cable.ts","../lib/cables/create-cable-meshes.ts"],"sourcesContent":["import jscad from \"@jscad/modeling\"\nimport { componentMaterials } from \"../materials\"\nimport { geometryToCableMesh } from \"./geometry-to-mesh\"\nimport type { CableConnectorSpec, CableMesh } from \"./types\"\n\n/** Right-handed connector-local mm: mating tip/mouth at z=0, +Z to wire exit.\n * Female socket is hollow; male contact has a rounded tip and spring slots.\n */\nexport function createBulletMeshes(\n connector: Extract<\n CableConnectorSpec,\n { kind: \"bullet_male\" | \"bullet_female\" }\n >,\n): CableMesh[] {\n const { cylinder, sphere, cuboid } = jscad.primitives\n const { subtract, union } = jscad.booleans\n const { diameter, contactDepth, bodyDepth, kind } = connector\n const bodyWidth = connector.bodyHeight\n const radius = diameter / 2\n let contact =\n kind === \"bullet_male\"\n ? union(\n sphere({ radius, center: [0, 0, radius], segments: 32 }),\n cylinder({\n radius,\n height: contactDepth - radius,\n center: [0, 0, (contactDepth + radius) / 2],\n segments: 32,\n }),\n )\n : subtract(\n cylinder({\n radius: bodyWidth / 2,\n height: contactDepth,\n center: [0, 0, contactDepth / 2],\n segments: 32,\n }),\n cylinder({\n radius,\n height: contactDepth - diameter / 4 + 0.1,\n center: [0, 0, (contactDepth - diameter / 4 - 0.1) / 2],\n segments: 32,\n }),\n )\n if (kind === \"bullet_male\") {\n contact = subtract(\n contact,\n cuboid({\n size: [diameter + 0.2, diameter * 0.08, contactDepth * 0.65],\n center: [0, 0, contactDepth * 0.45],\n }),\n cuboid({\n size: [diameter * 0.08, diameter + 0.2, contactDepth * 0.65],\n center: [0, 0, contactDepth * 0.45],\n }),\n )\n }\n const cupDepth = bodyDepth - contactDepth\n const solderCup = subtract(\n cylinder({\n radius: bodyWidth / 2,\n height: cupDepth,\n center: [0, 0, contactDepth + cupDepth / 2],\n segments: 32,\n }),\n cylinder({\n radius: radius * 0.75,\n height: cupDepth * 0.8 + 0.1,\n center: [0, 0, bodyDepth - cupDepth * 0.4 + 0.05],\n segments: 32,\n }),\n )\n const contactMeshes = [\n geometryToCableMesh({\n geometry: contact,\n material: componentMaterials.goldContact,\n color: [0.83, 0.64, 0.22, 1],\n name: kind === \"bullet_male\" ? \"bullet-pin\" : \"bullet-socket\",\n }),\n geometryToCableMesh({\n geometry: solderCup,\n material: componentMaterials.goldContact,\n color: [0.83, 0.64, 0.22, 1],\n name: \"solder-cup\",\n }),\n ]\n const pinCount = connector.pinCount ?? 1\n return Array.from({ length: pinCount }, (_, index) => {\n const offset = (index - (pinCount - 1) / 2) * (connector.pitch ?? bodyWidth)\n return contactMeshes.map((mesh) => ({\n ...mesh,\n name: pinCount === 1 ? mesh.name : `${mesh.name}-${index + 1}`,\n // Local +X is the cable frame's normal, paired with sweepRoundCable.offset.\n positions: mesh.positions.map((coordinate, coordinateIndex) =>\n coordinateIndex % 3 === 0 ? coordinate + offset : coordinate,\n ),\n }))\n }).flat()\n}\n","/** Approximate visual finishes, not measured optical properties. */\nexport const componentMaterials = {\n moldedPlastic: { metalness: 0, roughness: 0.7 },\n rubber: { metalness: 0, roughness: 0.9 },\n sleeve: { metalness: 0, roughness: 0.45 },\n tinnedLead: { metalness: 0.8, roughness: 0.55 },\n goldContact: { metalness: 1, roughness: 0.25 },\n copper: { metalness: 1, roughness: 0.35 },\n brushedMetal: { metalness: 1, roughness: 0.4 },\n steel: { metalness: 1, roughness: 0.25 },\n} as const\n","import jscad from \"@jscad/modeling\"\nimport type { Geom3 } from \"@jscad/modeling/src/geometries/geom3\"\nimport type { CableMesh, CableColor, CableFrame, CablePoint } from \"./types\"\nimport { add, scale } from \"./path-frames\"\n\ntype VertexKey = string\n\nexport function geometryToCableMesh({\n geometry,\n color,\n name,\n material,\n}: {\n geometry: Geom3\n color: CableColor\n name: string\n material?: CableMesh[\"material\"]\n}): CableMesh {\n const triangles = jscad.geometries.geom3.toPolygons(geometry)\n const positions: number[] = []\n const indices: number[] = []\n const vertices = new Map<VertexKey, number>()\n for (const triangle of triangles) {\n const polygonIndices: number[] = []\n for (const point of triangle.vertices) {\n const key = point.map((coordinate) => coordinate.toFixed(8)).join(\",\")\n let index = vertices.get(key)\n if (index === undefined) {\n index = positions.length / 3\n positions.push(...point)\n vertices.set(key, index)\n }\n polygonIndices.push(index)\n }\n // JSCAD CSG polygons are convex, so a fan preserves their outward winding.\n for (let side = 1; side < polygonIndices.length - 1; side++) {\n indices.push(\n polygonIndices[0]!,\n polygonIndices[side]!,\n polygonIndices[side + 1]!,\n )\n }\n }\n return { name, positions, indices, color, material, smooth: false }\n}\n\nexport function placeConnectorMesh({\n mesh,\n frame,\n wireExitDepth,\n isEnd,\n}: {\n mesh: CableMesh\n frame: CableFrame\n wireExitDepth: number\n isEnd: boolean\n}): CableMesh {\n const tangent = scale(frame.tangent, isEnd ? -1 : 1)\n const binormal: CablePoint = isEnd\n ? scale(frame.binormal, -1)\n : frame.binormal\n const origin = add(frame.point, scale(tangent, -wireExitDepth))\n const positions: number[] = []\n for (let index = 0; index < mesh.positions.length; index += 3) {\n positions.push(\n ...add(\n origin,\n add(\n add(\n scale(frame.normal, mesh.positions[index]!),\n scale(binormal, mesh.positions[index + 1]!),\n ),\n scale(tangent, mesh.positions[index + 2]!),\n ),\n ),\n )\n }\n return { ...mesh, positions }\n}\n","import type { CableFrame, CablePoint } from \"./types\"\n\nexport const add = (a: CablePoint, b: CablePoint): CablePoint => [\n a[0] + b[0],\n a[1] + b[1],\n a[2] + b[2],\n]\nexport const subtract = (a: CablePoint, b: CablePoint): CablePoint => [\n a[0] - b[0],\n a[1] - b[1],\n a[2] - b[2],\n]\nexport const scale = (point: CablePoint, factor: number): CablePoint => [\n point[0] * factor,\n point[1] * factor,\n point[2] * factor,\n]\nexport const dot = (a: CablePoint, b: CablePoint) =>\n a[0] * b[0] + a[1] * b[1] + a[2] * b[2]\nexport const cross = (a: CablePoint, b: CablePoint): CablePoint => [\n a[1] * b[2] - a[2] * b[1],\n a[2] * b[0] - a[0] * b[2],\n a[0] * b[1] - a[1] * b[0],\n]\nexport function normalize(point: CablePoint): CablePoint {\n const length = Math.hypot(...point)\n if (length < 1e-10)\n throw new Error(\n \"Cable path must not contain coincident points or a reversing tangent\",\n )\n return scale(point, 1 / length)\n}\n\n/** Parallel transport avoids a wire bundle flipping when its tangent crosses an axis. */\nexport function createCablePathFrames(path: CablePoint[]): CableFrame[] {\n if (\n path.length < 2 ||\n path.some((point) => point.length !== 3 || !point.every(Number.isFinite))\n ) {\n throw new Error(\"Cable path needs at least two finite 3D points\")\n }\n const segments = path\n .slice(1)\n .map((point, index) => normalize(subtract(point, path[index]!)))\n const tangents = path.map((_, index) =>\n index === 0\n ? segments[0]!\n : index === path.length - 1\n ? segments.at(-1)!\n : normalize(add(segments[index - 1]!, segments[index]!)),\n )\n const initialUp: CablePoint =\n Math.abs(tangents[0]![2]) > 0.95 ? [0, 1, 0] : [0, 0, 1]\n let normal = normalize(cross(initialUp, tangents[0]!))\n return tangents.map((tangent, index) => {\n if (index > 0) {\n const previousTangent = tangents[index - 1]!\n const axis = cross(previousTangent, tangent)\n const sine = Math.hypot(...axis)\n const cosine = Math.max(-1, Math.min(1, dot(previousTangent, tangent)))\n if (sine > 1e-10) {\n const unitAxis = scale(axis, 1 / sine)\n normal = normalize(\n add(\n add(scale(normal, cosine), scale(cross(unitAxis, normal), sine)),\n scale(unitAxis, dot(unitAxis, normal) * (1 - cosine)),\n ),\n )\n }\n }\n return {\n point: path[index]!,\n tangent,\n normal,\n binormal: normalize(cross(tangent, normal)),\n }\n })\n}\n","import { createBulletMeshes } from \"./bullet-meshes\"\nimport { componentMaterials } from \"../materials\"\nimport jscad from \"@jscad/modeling\"\nimport { geometryToCableMesh } from \"./geometry-to-mesh\"\nimport type {\n CableColor,\n CableConnectorSpec,\n CableMesh,\n CablePoint,\n} from \"./types\"\n\nconst { cuboid, roundedCuboid, cylinder, roundedRectangle, polygon, sphere } =\n jscad.primitives\nconst { extrudeLinear } = jscad.extrusions\nconst { translate, rotateY } = jscad.transforms\nconst { subtract, union } = jscad.booleans\nconst plastic: CableColor = [0.055, 0.07, 0.09, 1]\nconst housing: CableColor = [0.86, 0.84, 0.75, 1]\nconst metal: CableColor = [0.6, 0.64, 0.7, 1]\nconst brass: CableColor = [0.66, 0.46, 0.18, 1]\n\nexport function connectorWireExitDepth(connector: CableConnectorSpec): number {\n if (connector.kind === \"usb_c_plug\")\n return connector.shellDepth + connector.bodyDepth\n if (connector.kind === \"nema_5_15p\") return 19.05 + connector.bodyDepth\n return connector.bodyDepth\n}\n\nfunction createJstMeshes(\n connector: Extract<\n CableConnectorSpec,\n { kind: \"jst_sh_housing\" | \"jst_ph_housing\" }\n >,\n): CableMesh[] {\n const {\n bodyWidth: width,\n bodyHeight: height,\n bodyDepth: depth,\n pinCount,\n pitch,\n } = connector\n const opening = pitch === 1 ? 0.55 : 1.05\n const holes = Array.from({ length: pinCount }, (_, index) => {\n const x = (index - (pinCount - 1) / 2) * pitch\n return cuboid({\n size: [opening, opening * 1.35, depth - 0.6],\n center: [x, 0, (depth - 0.6) / 2 - 0.02],\n })\n })\n const backHoles = Array.from({ length: pinCount }, (_, index) =>\n cylinder({\n radius: pitch * 0.34,\n height: 1.3,\n segments: 16,\n center: [(index - (pinCount - 1) / 2) * pitch, 0, depth - 0.5],\n }),\n )\n const latchCut = cuboid({\n size: [width * 0.45, 0.5, depth * 0.5],\n center: [0, height / 2, depth * 0.65],\n })\n const body = subtract(\n roundedCuboid({\n size: [width, height, depth],\n center: [0, 0, depth / 2],\n roundRadius: 0.1,\n segments: 8,\n }),\n ...holes,\n ...backHoles,\n latchCut,\n ...Array.from({ length: pinCount }, (_, index) =>\n cuboid({\n size: [opening * 0.8, height * 0.7, depth * 0.24],\n center: [(index - (pinCount - 1) / 2) * pitch, height / 2, depth * 0.7],\n }),\n ),\n )\n const contacts = Array.from({ length: pinCount }, (_, index) => {\n const x = (index - (pinCount - 1) / 2) * pitch\n return geometryToCableMesh({\n material: componentMaterials.goldContact,\n name: `contact-${index + 1}`,\n color: metal,\n geometry: subtract(\n cuboid({\n size: [opening * 0.92, opening * 1.25, depth * 0.65],\n center: [x, 0, depth * 0.45],\n }),\n cuboid({\n size: [\n opening * 0.92 - 0.12,\n opening * 1.25 - 0.12,\n depth * 0.65 + 0.2,\n ],\n center: [x, 0, depth * 0.45],\n }),\n ),\n })\n })\n return [\n geometryToCableMesh({ geometry: body, color: housing, name: \"housing\" }),\n ...contacts,\n ]\n}\n\nfunction createUsbMeshes(\n connector: Extract<CableConnectorSpec, { kind: \"usb_c_plug\" }>,\n): CableMesh[] {\n const {\n shellWidth,\n shellHeight,\n shellDepth,\n bodyWidth,\n bodyHeight,\n bodyDepth,\n } = connector\n const shell = subtract(\n extrudeLinear(\n { height: shellDepth },\n roundedRectangle({\n size: [shellWidth, shellHeight],\n roundRadius: shellHeight / 2 - 0.02,\n segments: 32,\n }),\n ),\n translate(\n [0, 0, -0.1],\n extrudeLinear(\n { height: shellDepth + 0.2 },\n roundedRectangle({\n size: [shellWidth - 0.4, shellHeight - 0.4],\n roundRadius: (shellHeight - 0.4) / 2 - 0.02,\n segments: 32,\n }),\n ),\n ),\n )\n const liner = subtract(\n extrudeLinear(\n { height: shellDepth },\n roundedRectangle({\n size: [shellWidth - 0.41, shellHeight - 0.41],\n roundRadius: 0.85,\n segments: 32,\n }),\n ),\n translate(\n [0, 0, -0.1],\n extrudeLinear(\n { height: shellDepth - 0.3 },\n roundedRectangle({\n size: [shellWidth - 0.8, shellHeight - 0.8],\n roundRadius: 0.65,\n segments: 32,\n }),\n ),\n ),\n )\n const body = roundedCuboid({\n size: [bodyWidth, bodyHeight, bodyDepth],\n center: [0, 0, shellDepth + bodyDepth / 2],\n roundRadius: Math.min(1.3, bodyHeight / 4),\n segments: 16,\n })\n const contacts = Array.from({ length: 24 }, (_, index) =>\n cuboid({\n size: [0.22, 0.08, 3.5],\n center: [((index % 12) - 5.5) * 0.5, index < 12 ? 0.77 : -0.77, 2.6],\n }),\n )\n return [\n geometryToCableMesh({ geometry: body, color: plastic, name: \"overmold\" }),\n geometryToCableMesh({\n geometry: shell,\n color: metal,\n material: componentMaterials.brushedMetal,\n name: \"shell\",\n }),\n geometryToCableMesh({\n geometry: liner,\n color: [0.025, 0.026, 0.03, 1],\n name: \"liner\",\n }),\n ...contacts.map((geometry, index) =>\n geometryToCableMesh({\n geometry,\n color: brass,\n material: componentMaterials.goldContact,\n name: `contact-${index + 1}`,\n }),\n ),\n ]\n}\n\nfunction createMainsMeshes(connector: CableConnectorSpec): CableMesh[] {\n const { bodyWidth, bodyHeight, bodyDepth, kind } = connector\n const faceDepth = kind === \"nema_5_15p\" ? 19.05 : 0\n let body = roundedCuboid({\n size: [bodyWidth, bodyHeight, bodyDepth],\n center: [0, 0, faceDepth + bodyDepth / 2],\n roundRadius: 2,\n segments: 16,\n })\n if (kind === \"nema_5_15p\") {\n const blades = [-6.35, 6.35].map((x) => {\n const blade = cuboid({\n size: [1.524, 6.35, 15.875],\n center: [x, 2.7, 19.05 - 15.875 / 2],\n })\n const hole = translate(\n [x, 2.7, 7.3],\n rotateY(\n Math.PI / 2,\n cylinder({ radius: 1.1, height: 3, segments: 20 }),\n ),\n )\n return subtract(blade, hole)\n })\n const ground = union(\n cylinder({\n radius: 2.38125,\n height: 19.05 - 2.38125,\n center: [0, -9.20625, (19.05 + 2.38125) / 2],\n segments: 32,\n }),\n sphere({ radius: 2.38125, center: [0, -9.20625, 2.38125], segments: 32 }),\n )\n return [\n geometryToCableMesh({\n geometry: body,\n color: plastic,\n name: \"plug-body\",\n }),\n ...blades.map((geometry, index) =>\n geometryToCableMesh({\n geometry,\n color: brass,\n material: componentMaterials.goldContact,\n name: `blade-${index + 1}`,\n }),\n ),\n geometryToCableMesh({\n geometry: ground,\n color: brass,\n material: componentMaterials.goldContact,\n name: \"ground-pin\",\n }),\n ]\n }\n const recess = translate(\n [0, 0, -0.1],\n extrudeLinear(\n { height: 3.2 },\n polygon({\n points: [\n [-9, -6],\n [9, -6],\n [9, 2],\n [5, 6],\n [-5, 6],\n [-9, 2],\n ],\n }),\n ),\n )\n const sockets: CablePoint[] = [\n [-4.4, -1.8, 8],\n [4.4, -1.8, 8],\n [0, 3.1, 8],\n ]\n body = subtract(\n body,\n recess,\n ...sockets.map((center) => cuboid({ size: [2.3, 3.4, 16.2], center })),\n )\n return [\n geometryToCableMesh({\n geometry: body,\n color: plastic,\n name: \"appliance-body\",\n }),\n ...sockets.map(([x, y], index) =>\n geometryToCableMesh({\n geometry: cuboid({ size: [0.15, 2.8, 6], center: [x - 1.05, y, 7.8] }),\n color: brass,\n material: componentMaterials.goldContact,\n name: `socket-contact-${index + 1}`,\n }),\n ),\n ]\n}\n\nexport function createConnectorMeshes({\n connector,\n jacketDiameter,\n}: { connector: CableConnectorSpec; jacketDiameter?: number }): CableMesh[] {\n const meshes =\n connector.kind === \"usb_c_plug\"\n ? createUsbMeshes(connector)\n : connector.kind === \"bullet_male\" || connector.kind === \"bullet_female\"\n ? createBulletMeshes(connector)\n : connector.kind === \"jst_sh_housing\" ||\n connector.kind === \"jst_ph_housing\"\n ? createJstMeshes(connector)\n : createMainsMeshes(connector)\n if (\n jacketDiameter !== undefined &&\n connector.kind !== \"bullet_male\" &&\n connector.kind !== \"bullet_female\"\n ) {\n const exit = connectorWireExitDepth(connector)\n const boot = union(\n cylinder({\n radius: jacketDiameter / 2 + 0.15,\n height: 5,\n center: [0, 0, exit + 2.5],\n segments: 32,\n }),\n ...Array.from({ length: 7 }, (_, index) =>\n cylinder({\n radius: jacketDiameter / 2 + 0.8 - index * 0.06,\n height: 0.28,\n center: [0, 0, exit + 0.4 + index * 0.7],\n segments: 32,\n }),\n ),\n )\n meshes.push(\n geometryToCableMesh({\n geometry: boot,\n color: plastic,\n name: \"strain-relief\",\n }),\n )\n }\n return meshes\n}\n","import { add, scale } from \"./path-frames\"\nimport type { CableFrame, CableMesh, CableColor } from \"./types\"\n\n/** Closed indexed sweep around a supplied centerline; this does not choose a route. */\nexport function sweepRoundCable({\n frames,\n diameter,\n offset = 0,\n radialSegments,\n color,\n name,\n}: {\n frames: CableFrame[]\n diameter: number\n offset?: number\n radialSegments: number\n color: CableColor\n name: string\n}): CableMesh {\n const positions: number[] = []\n const indices: number[] = []\n for (const frame of frames) {\n const center = add(frame.point, scale(frame.normal, offset))\n for (let side = 0; side < radialSegments; side++) {\n const angle = (side * Math.PI * 2) / radialSegments\n positions.push(\n ...add(\n center,\n add(\n scale(frame.normal, (diameter * Math.cos(angle)) / 2),\n scale(frame.binormal, (diameter * Math.sin(angle)) / 2),\n ),\n ),\n )\n }\n }\n for (let ring = 0; ring < frames.length - 1; ring++) {\n for (let side = 0; side < radialSegments; side++) {\n const a = ring * radialSegments + side\n const b = ring * radialSegments + ((side + 1) % radialSegments)\n const c = a + radialSegments\n const d = b + radialSegments\n indices.push(a, b, c, b, d, c)\n }\n }\n const startCenter = positions.length / 3\n positions.push(...add(frames[0]!.point, scale(frames[0]!.normal, offset)))\n const endCenter = positions.length / 3\n positions.push(\n ...add(frames.at(-1)!.point, scale(frames.at(-1)!.normal, offset)),\n )\n const lastRing = (frames.length - 1) * radialSegments\n for (let side = 0; side < radialSegments; side++) {\n const next = (side + 1) % radialSegments\n indices.push(\n startCenter,\n next,\n side,\n endCenter,\n lastRing + side,\n lastRing + next,\n )\n }\n return { name, positions, indices, color, smooth: true }\n}\n","import {\n createConnectorMeshes,\n connectorWireExitDepth,\n} from \"./connector-meshes\"\nimport { placeConnectorMesh } from \"./geometry-to-mesh\"\nimport { createCablePathFrames } from \"./path-frames\"\nimport { sweepRoundCable } from \"./sweep-round-cable\"\nimport type {\n CableColor,\n CableGeometryDefinition,\n CableMesh,\n CablePoint,\n} from \"./types\"\n\nfunction parseCableColor(color: string): CableColor {\n if (!/^#[a-f\\d]{6}$/i.test(color))\n throw new Error(\"Cable colors must be six-digit hex strings\")\n return [\n parseInt(color.slice(1, 3), 16) / 255,\n parseInt(color.slice(3, 5), 16) / 255,\n parseInt(color.slice(5, 7), 16) / 255,\n 1,\n ]\n}\n\nfunction validateCableDefinition(definition: CableGeometryDefinition) {\n for (const connector of [definition.connectorA, definition.connectorB]) {\n const dimensions = [\n connector.bodyWidth,\n connector.bodyHeight,\n connector.bodyDepth,\n ]\n if (connector.kind === \"usb_c_plug\")\n dimensions.push(\n connector.shellWidth,\n connector.shellHeight,\n connector.shellDepth,\n )\n if (\n connector.kind === \"bullet_male\" ||\n connector.kind === \"bullet_female\"\n ) {\n const pinCount = connector.pinCount ?? 1\n const pitch = connector.pitch ?? connector.bodyHeight\n dimensions.push(connector.diameter, connector.contactDepth, pitch)\n if (\n !Number.isInteger(pinCount) ||\n pinCount < 1 ||\n pinCount > 16 ||\n connector.bodyHeight <= connector.diameter ||\n pitch < connector.bodyHeight ||\n Math.abs(\n connector.bodyWidth - (connector.bodyHeight + (pinCount - 1) * pitch),\n ) > 1e-6 ||\n connector.contactDepth >= connector.bodyDepth ||\n connector.contactDepth <= connector.diameter / 2\n )\n throw new Error(\"Bullet contact must fit inside its cylindrical body\")\n if (\n (pinCount === 1 &&\n (definition.crossSection.kind !== \"round_jacket\" ||\n definition.crossSection.diameter > connector.bodyHeight)) ||\n (pinCount > 1 &&\n (definition.crossSection.kind !== \"wire_bundle\" ||\n definition.crossSection.wires.length !== pinCount ||\n definition.crossSection.wirePitch !== pitch ||\n definition.crossSection.wires.some(\n (wire) => wire.diameter > connector.bodyHeight,\n )))\n )\n throw new Error(\n \"Bullet cables require one insulated wire per contact that fits its solder cup\",\n )\n }\n if (\n dimensions.some(\n (dimension) => !Number.isFinite(dimension) || dimension <= 0,\n )\n )\n throw new Error(\"Connector dimensions must be finite and positive\")\n if (\n (connector.kind === \"jst_sh_housing\" ||\n connector.kind === \"jst_ph_housing\") &&\n (!Number.isInteger(connector.pinCount) ||\n connector.pinCount < 2 ||\n !Number.isFinite(connector.pitch) ||\n connector.pitch <= 0)\n )\n throw new Error(\n \"JST connectors need a positive pitch and at least two contacts\",\n )\n }\n const crossSection = definition.crossSection\n const diameters =\n crossSection.kind === \"round_jacket\"\n ? [crossSection.diameter]\n : crossSection.wires.map((wire) => wire.diameter)\n if (\n diameters.length === 0 ||\n diameters.some((diameter) => !Number.isFinite(diameter) || diameter <= 0)\n )\n throw new Error(\"Cable diameters must be finite and positive\")\n if (crossSection.kind === \"wire_bundle\") {\n if (\n !Number.isFinite(crossSection.wirePitch) ||\n crossSection.wires.some((wire) => wire.diameter > crossSection.wirePitch)\n )\n throw new Error(\"Insulated bundle wires must not overlap\")\n for (const connector of [definition.connectorA, definition.connectorB]) {\n if (\n !(\"pinCount\" in connector) ||\n (connector.pinCount ?? 1) !== crossSection.wires.length\n )\n throw new Error(\"Bundle wire count must match connector contact count\")\n }\n }\n}\n\n/** Mesh generation only. Path samples are already resolved in world millimeters, +Z up. */\nexport function createCableMeshes({\n definition,\n path,\n radialSegments = 24,\n}: {\n definition: CableGeometryDefinition\n path: CablePoint[]\n radialSegments?: number\n}): CableMesh[] {\n validateCableDefinition(definition)\n if (\n !Number.isInteger(radialSegments) ||\n radialSegments < 8 ||\n radialSegments > 128\n )\n throw new Error(\"radialSegments must be an integer from 8 to 128\")\n const frames = createCablePathFrames(path)\n const crossSection = definition.crossSection\n const jacketDiameter =\n crossSection.kind === \"round_jacket\" ? crossSection.diameter : undefined\n const meshes =\n crossSection.kind === \"round_jacket\"\n ? [\n sweepRoundCable({\n frames,\n diameter: crossSection.diameter,\n radialSegments,\n color: parseCableColor(crossSection.color),\n name: \"jacket\",\n }),\n ]\n : crossSection.wires.map((wire, index) =>\n sweepRoundCable({\n frames,\n diameter: wire.diameter,\n offset:\n (index - (crossSection.wires.length - 1) / 2) *\n crossSection.wirePitch,\n radialSegments,\n color: parseCableColor(wire.color),\n name: `wire-${index + 1}`,\n }),\n )\n for (const [index, connector] of [\n definition.connectorA,\n definition.connectorB,\n ].entries()) {\n const frame = index === 0 ? frames[0]! : frames.at(-1)!\n const parts = createConnectorMeshes({ connector, jacketDiameter })\n meshes.push(\n ...parts.map((mesh) =>\n placeConnectorMesh({\n mesh: { ...mesh, name: `${index === 0 ? \"A\" : \"B\"}-${mesh.name}` },\n frame,\n isEnd: index === 1,\n wireExitDepth: connectorWireExitDepth(connector),\n }),\n ),\n )\n }\n return meshes\n}\n"],"mappings":";AAAA,OAAOA,YAAW;;;ACCX,IAAM,qBAAqB;AAAA,EAChC,eAAe,EAAE,WAAW,GAAG,WAAW,IAAI;AAAA,EAC9C,QAAQ,EAAE,WAAW,GAAG,WAAW,IAAI;AAAA,EACvC,QAAQ,EAAE,WAAW,GAAG,WAAW,KAAK;AAAA,EACxC,YAAY,EAAE,WAAW,KAAK,WAAW,KAAK;AAAA,EAC9C,aAAa,EAAE,WAAW,GAAG,WAAW,KAAK;AAAA,EAC7C,QAAQ,EAAE,WAAW,GAAG,W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AAI;AACzC,QAAM,eAAe,WAAW;AAChC,QAAM,iBACJ,aAAa,SAAS,iBAAiB,aAAa,WAAW;AACjE,QAAM,SACJ,aAAa,SAAS,iBAClB;AAAA,IACE,gBAAgB;AAAA,MACd;AAAA,MACA,UAAU,aAAa;AAAA,MACvB;AAAA,MACA,OAAO,gBAAgB,aAAa,KAAK;AAAA,MACzC,MAAM;AAAA,IACR,CAAC;AAAA,EACH,IACA,aAAa,MAAM;AAAA,IAAI,CAAC,MAAM,UAC5B,gBAAgB;AAAA,MACd;AAAA,MACA,UAAU,KAAK;AAAA,MACf,SACG,SAAS,aAAa,MAAM,SAAS,KAAK,KAC3C,aAAa;AAAA,MACf;AAAA,MACA,OAAO,gBAAgB,KAAK,KAAK;AAAA,MACjC,MAAM,QAAQ,QAAQ,CAAC;AAAA,IACzB,CAAC;AAAA,EACH;AACN,aAAW,CAAC,OAAO,SAAS,KAAK;AAAA,IAC/B,WAAW;AAAA,IACX,WAAW;AAAA,EACb,EAAE,QAAQ,GAAG;AACX,UAAM,QAAQ,UAAU,IAAI,OAAO,CAAC,IAAK,OAAO,GAAG,EAAE;AACrD,UAAM,QAAQ,sBAAsB,EAAE,WAAW,eAAe,CAAC;AACjE,WAAO;AAAA,MACL,GAAG,MAAM;AAAA,QAAI,CAAC,SACZ,mBAAmB;AAAA,UACjB,MAAM,EAAE,GAAG,MAAM,MAAM,GAAG,UAAU,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG;AAAA,UACjE;AAAA,UACA,OAAO,UAAU;AAAA,UACjB,eAAe,uBAAuB,SAAS;AAAA,QACjD,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["jscad","cylinder","sphere","cuboid","jscad","subtract","union","jscad","jscad","subtract"]}
package/dist/index.js CHANGED
@@ -2151,7 +2151,10 @@ import jscad3 from "@jscad/modeling";
2151
2151
 
2152
2152
  // lib/utils/nemaMotorWireGeometry.ts
2153
2153
  import jscad2 from "@jscad/modeling";
2154
- import { getNemaMotorReferencePoints } from "@tscircuit/modelprinter";
2154
+ import {
2155
+ getJstMotorConnector,
2156
+ getNemaMotorReferencePoints
2157
+ } from "@tscircuit/modelprinter";
2155
2158
 
2156
2159
  // lib/utils/nemaMotorParameters.ts
2157
2160
  import { mp, nemaMotorModelPropsSchema } from "@tscircuit/modelprinter";
@@ -2201,18 +2204,29 @@ function createNemaMotorWireGeometry(input) {
2201
2204
  )
2202
2205
  }));
2203
2206
  }
2207
+ const connector = getJstMotorConnector(p.wireConnection);
2208
+ const { pinCount, pitch, bodyWidth, bodyHeight, matingDepth } = connector;
2209
+ const wall = pitch === 2 ? 0.6 : 0.3;
2210
+ const contactLength = pitch === 2 ? 3.4 : 2.4;
2211
+ const contactSize = pitch === 2 ? 0.5 : 0.3;
2204
2212
  const shell = jscad2.booleans.subtract(
2205
- jscad2.primitives.cuboid({ size: [6.1, 13.9, 4.5], center: [2.95, 0, 0] }),
2206
- jscad2.primitives.cuboid({ size: [5.5, 12.7, 3.3], center: [3.55, 0, 0] })
2213
+ jscad2.primitives.cuboid({
2214
+ size: [matingDepth + 0.1, bodyWidth, bodyHeight],
2215
+ center: [(matingDepth - 0.1) / 2, 0, 0]
2216
+ }),
2217
+ jscad2.primitives.cuboid({
2218
+ size: [matingDepth - 0.5, bodyWidth - 2 * wall, bodyHeight - 2 * wall],
2219
+ center: [matingDepth / 2 + 0.55, 0, 0]
2220
+ })
2207
2221
  );
2208
2222
  return [
2209
2223
  { color: "#eeeeea", geometry: place(shell) },
2210
- ...Array.from({ length: 6 }, (_, i) => ({
2224
+ ...Array.from({ length: pinCount }, (_, i) => ({
2211
2225
  color: "#b8bec6",
2212
2226
  geometry: place(
2213
2227
  jscad2.primitives.cuboid({
2214
- size: [3.4, 0.5, 0.5],
2215
- center: [1.7, (i - 2.5) * 2, 0]
2228
+ size: [contactLength, contactSize, contactSize],
2229
+ center: [contactLength / 2, (i - (pinCount - 1) / 2) * pitch, 0]
2216
2230
  })
2217
2231
  )
2218
2232
  }))