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/index.js +81 -12
- package/dist/index.js.map +1 -1
- package/dist/vanilla.js +89 -20
- package/dist/vanilla.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -896,7 +896,7 @@ var createHexSocketBoltMesh = (input) => {
|
|
|
896
896
|
} = hexSocketBoltDimensions[props.metricSize];
|
|
897
897
|
const { length, showThreads } = props;
|
|
898
898
|
const segments = 96;
|
|
899
|
-
const steps = Math.max(2, Math.ceil(length / pitch * 24));
|
|
899
|
+
const steps = showThreads ? Math.max(2, Math.ceil(length / pitch * 24)) : 2;
|
|
900
900
|
if (steps > 24e3)
|
|
901
901
|
throw new Error(
|
|
902
902
|
"Bolt length exceeds mesh resolution limit (1000 thread turns)"
|
|
@@ -932,8 +932,11 @@ var createHexSocketBoltMesh = (input) => {
|
|
|
932
932
|
}
|
|
933
933
|
};
|
|
934
934
|
let previous = -1;
|
|
935
|
-
|
|
936
|
-
|
|
935
|
+
const shaftLevels = showThreads ? Array.from(
|
|
936
|
+
{ length: steps + 1 },
|
|
937
|
+
(_, step) => -length + length * step / steps
|
|
938
|
+
) : [-length, -length + tipBevel, 0];
|
|
939
|
+
for (const z of shaftLevels) {
|
|
937
940
|
const current = ring(z, (angle) => {
|
|
938
941
|
const phase = ((z / pitch - angle / (2 * Math.PI)) % 1 + 1) % 1;
|
|
939
942
|
const distance2 = Math.min(phase, 1 - phase);
|
|
@@ -1155,7 +1158,11 @@ function SheetMetal({ color = "#737e8f", ...props }) {
|
|
|
1155
1158
|
}
|
|
1156
1159
|
|
|
1157
1160
|
// lib/NemaMotor.tsx
|
|
1161
|
+
import jscad3 from "@jscad/modeling";
|
|
1162
|
+
|
|
1163
|
+
// lib/utils/nemaMotorWireGeometry.ts
|
|
1158
1164
|
import jscad2 from "@jscad/modeling";
|
|
1165
|
+
import { getNemaMotorReferencePoints } from "@tscircuit/modelprinter";
|
|
1159
1166
|
|
|
1160
1167
|
// lib/utils/nemaMotorParameters.ts
|
|
1161
1168
|
import { mp as mp2, nemaMotorModelPropsSchema } from "@tscircuit/modelprinter";
|
|
@@ -1163,6 +1170,66 @@ var resolveNemaMotorProps = nemaMotorModelPropsSchema.parse.bind(
|
|
|
1163
1170
|
nemaMotorModelPropsSchema
|
|
1164
1171
|
);
|
|
1165
1172
|
|
|
1173
|
+
// lib/utils/nemaMotorWireGeometry.ts
|
|
1174
|
+
function createNemaMotorWireGeometry(input) {
|
|
1175
|
+
const p = resolveNemaMotorProps(input);
|
|
1176
|
+
if (p.wireConnection === "none") return [];
|
|
1177
|
+
const { position } = getNemaMotorReferencePoints(p).wireside;
|
|
1178
|
+
const angle = p.wireSideAngle * Math.PI / 180;
|
|
1179
|
+
const place = (geometry) => jscad2.transforms.translate(
|
|
1180
|
+
[position.x, position.y, position.z],
|
|
1181
|
+
jscad2.transforms.rotateZ(angle, geometry)
|
|
1182
|
+
);
|
|
1183
|
+
if (p.wireConnection === "stubs") {
|
|
1184
|
+
const colors = [
|
|
1185
|
+
"#d53f3f",
|
|
1186
|
+
"#2463af",
|
|
1187
|
+
"#3b934b",
|
|
1188
|
+
"#252830",
|
|
1189
|
+
"#e5d049",
|
|
1190
|
+
"#eeeeee",
|
|
1191
|
+
"#ce7432",
|
|
1192
|
+
"#803e91"
|
|
1193
|
+
];
|
|
1194
|
+
return Array.from({ length: p.wireCount }, (_, i) => ({
|
|
1195
|
+
color: colors[i],
|
|
1196
|
+
geometry: place(
|
|
1197
|
+
jscad2.transforms.translate(
|
|
1198
|
+
[
|
|
1199
|
+
(p.wireLength - 0.15) / 2,
|
|
1200
|
+
(i - (p.wireCount - 1) / 2) * p.wireDiameter * 1.5,
|
|
1201
|
+
0
|
|
1202
|
+
],
|
|
1203
|
+
jscad2.transforms.rotateY(
|
|
1204
|
+
Math.PI / 2,
|
|
1205
|
+
jscad2.primitives.cylinder({
|
|
1206
|
+
height: p.wireLength + 0.15,
|
|
1207
|
+
radius: p.wireDiameter / 2,
|
|
1208
|
+
segments: 24
|
|
1209
|
+
})
|
|
1210
|
+
)
|
|
1211
|
+
)
|
|
1212
|
+
)
|
|
1213
|
+
}));
|
|
1214
|
+
}
|
|
1215
|
+
const shell = jscad2.booleans.subtract(
|
|
1216
|
+
jscad2.primitives.cuboid({ size: [6.1, 13.9, 4.5], center: [2.95, 0, 0] }),
|
|
1217
|
+
jscad2.primitives.cuboid({ size: [5.5, 12.7, 3.3], center: [3.55, 0, 0] })
|
|
1218
|
+
);
|
|
1219
|
+
return [
|
|
1220
|
+
{ color: "#eeeeea", geometry: place(shell) },
|
|
1221
|
+
...Array.from({ length: 6 }, (_, i) => ({
|
|
1222
|
+
color: "#b8bec6",
|
|
1223
|
+
geometry: place(
|
|
1224
|
+
jscad2.primitives.cuboid({
|
|
1225
|
+
size: [3.4, 0.5, 0.5],
|
|
1226
|
+
center: [1.7, (i - 2.5) * 2, 0]
|
|
1227
|
+
})
|
|
1228
|
+
)
|
|
1229
|
+
}))
|
|
1230
|
+
];
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1166
1233
|
// lib/utils/nemaMotorGeometry.ts
|
|
1167
1234
|
var circle = (radius, x = 0, y = 0) => Array.from({ length: 96 }, (_, i) => [
|
|
1168
1235
|
x + radius * Math.cos(i * Math.PI / 48),
|
|
@@ -1264,6 +1331,7 @@ function createNemaMotorSections(input) {
|
|
|
1264
1331
|
// lib/NemaMotor.tsx
|
|
1265
1332
|
import { Colorize as Colorize9, Custom as Custom3 } from "jscad-fiber";
|
|
1266
1333
|
import { Fragment as Fragment14, jsx as jsx19, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
1334
|
+
var generalize = jscad3.modifiers.generalize;
|
|
1267
1335
|
function NemaMotor({
|
|
1268
1336
|
bodyColor = "#242830",
|
|
1269
1337
|
capColor = "#aeb5bd",
|
|
@@ -1272,7 +1340,7 @@ function NemaMotor({
|
|
|
1272
1340
|
...props
|
|
1273
1341
|
}) {
|
|
1274
1342
|
const p = resolveNemaMotorProps(props);
|
|
1275
|
-
const screw = p.backFace === "screws" ?
|
|
1343
|
+
const screw = p.backFace === "screws" ? jscad3.transforms.rotateX(
|
|
1276
1344
|
Math.PI,
|
|
1277
1345
|
createHexSocketBoltGeom({
|
|
1278
1346
|
metricSize: p.backFaceScrewSize,
|
|
@@ -1283,14 +1351,14 @@ function NemaMotor({
|
|
|
1283
1351
|
const halfPitch = p.backFaceHoleSpacing / 2;
|
|
1284
1352
|
return /* @__PURE__ */ jsxs16(Fragment14, { children: [
|
|
1285
1353
|
createNemaMotorSections(p).map((section, index) => {
|
|
1286
|
-
const outline =
|
|
1287
|
-
const profile = section.holes.length ?
|
|
1354
|
+
const outline = jscad3.geometries.geom2.fromPoints(section.outline);
|
|
1355
|
+
const profile = section.holes.length ? jscad3.booleans.subtract(
|
|
1288
1356
|
outline,
|
|
1289
|
-
...section.holes.map((h) =>
|
|
1357
|
+
...section.holes.map((h) => jscad3.geometries.geom2.fromPoints(h))
|
|
1290
1358
|
) : outline;
|
|
1291
|
-
const geometry =
|
|
1359
|
+
const geometry = jscad3.transforms.translate(
|
|
1292
1360
|
[0, 0, section.zMin],
|
|
1293
|
-
|
|
1361
|
+
jscad3.extrusions.extrudeLinear(
|
|
1294
1362
|
{ height: section.zMax - section.zMin },
|
|
1295
1363
|
profile
|
|
1296
1364
|
)
|
|
@@ -1299,18 +1367,19 @@ function NemaMotor({
|
|
|
1299
1367
|
Colorize9,
|
|
1300
1368
|
{
|
|
1301
1369
|
color: section.name === "body" ? bodyColor : section.name === "shaft" ? shaftColor : capColor,
|
|
1302
|
-
children: /* @__PURE__ */ jsx19(Custom3, { geometry })
|
|
1370
|
+
children: /* @__PURE__ */ jsx19(Custom3, { geometry: generalize({ simplify: true }, geometry) })
|
|
1303
1371
|
},
|
|
1304
1372
|
`${section.name}-${index}`
|
|
1305
1373
|
);
|
|
1306
1374
|
}),
|
|
1375
|
+
createNemaMotorWireGeometry(p).map(({ geometry, color }, index) => /* @__PURE__ */ jsx19(Colorize9, { color, children: /* @__PURE__ */ jsx19(Custom3, { geometry: generalize({ simplify: true }, geometry) }) }, `wire-${index}`)),
|
|
1307
1376
|
screw && [-halfPitch, halfPitch].flatMap(
|
|
1308
1377
|
(x) => [-halfPitch, halfPitch].map((y) => /* @__PURE__ */ jsx19(Colorize9, { color: screwColor, children: /* @__PURE__ */ jsx19(
|
|
1309
1378
|
Custom3,
|
|
1310
1379
|
{
|
|
1311
|
-
geometry:
|
|
1380
|
+
geometry: jscad3.transforms.translate(
|
|
1312
1381
|
[x, y, -p.bodyLength],
|
|
1313
|
-
screw
|
|
1382
|
+
generalize({ simplify: true }, screw)
|
|
1314
1383
|
)
|
|
1315
1384
|
}
|
|
1316
1385
|
) }, `rear-screw-${x}-${y}`))
|