@rulecad/shapes 0.4.3 → 0.4.4
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/README.md +2 -0
- package/package.json +1 -1
- package/seats.d.mts +72 -0
- package/seats.mjs +63 -10
- package/shapes.d.mts +1 -1
- package/shapes.mjs +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,8 @@ clipGroove(8, { width: 1, depth: 0.5, at: [0, 0, 30] })
|
|
|
72
72
|
| Ledge (`lip`) | a quarter of the races' radial depth by default, so it carries the outer race only; at most half |
|
|
73
73
|
| Plain bore, as drawn | shaft + 2 × clearance + `hole_comp`, the clearance being the printer's `fit` each side by default |
|
|
74
74
|
|
|
75
|
+
`lm8uuPocket`, `nutTrap`, `pulleyBore` and `beltClamp` are the same idea for a linear bearing, a lead-screw nut's flange and body, a pulley on its shaft and a GT2 belt's grip.
|
|
76
|
+
|
|
75
77
|
`press` and `slip` are estimates until they are measured with the seats coupon in the bench project: print it once per
|
|
76
78
|
filament, press a bearing into each pocket, and write the one that holds without cracking into the printer's rules.
|
|
77
79
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/shapes",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Shape helpers for printed JSCAD designs: text that prints cleanly, anchors on a face, clean local cuts, and enclosure pieces (shells, lids, rails, print-safe holes).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
package/seats.d.mts
CHANGED
|
@@ -94,3 +94,75 @@ export function clipGroove(shaft: number, { width, depth, at }?: {
|
|
|
94
94
|
depth: number;
|
|
95
95
|
at?: number[];
|
|
96
96
|
}): object;
|
|
97
|
+
/**
|
|
98
|
+
* A pocket for a linear bearing's outside (an LM8UU), to subtract: a straight press or slip for its whole length, and on
|
|
99
|
+
* through for the rod. Stood up (±z) or across (±x, ±y), with a teardrop's roof when across.
|
|
100
|
+
* @param {{ outer_diameter: number, length: number, bore: number }} bearing
|
|
101
|
+
* @param {{ fit?: 'press' | 'slip' | number, clearance?: number, through?: boolean, printer: object, at?: number[], into?: string }} o clearance: round the rod, each side
|
|
102
|
+
* @returns {object} a JSCAD geom3 to subtract, with .pocket the diameter as drawn
|
|
103
|
+
*/
|
|
104
|
+
export function lm8uuPocket(bearing: {
|
|
105
|
+
outer_diameter: number;
|
|
106
|
+
length: number;
|
|
107
|
+
bore: number;
|
|
108
|
+
}, { fit, clearance, through, printer, at, into }?: {
|
|
109
|
+
fit?: "press" | "slip" | number;
|
|
110
|
+
clearance?: number;
|
|
111
|
+
through?: boolean;
|
|
112
|
+
printer: object;
|
|
113
|
+
at?: number[];
|
|
114
|
+
into?: string;
|
|
115
|
+
}): object;
|
|
116
|
+
/**
|
|
117
|
+
* A pocket for a lead-screw nut, to subtract: its flange let in from a face, its body on through, and its bolts' holes on
|
|
118
|
+
* their circle. Goes down from a top face; the flange sits flush.
|
|
119
|
+
* @param {{ flange_diameter: number, flange_thickness?: number, body_diameter: number, length: number, hole_circle: number, hole_count: number, hole_diameter?: number }} nut
|
|
120
|
+
* @param {{ fit?: number, printer: object, at?: number[], depth?: number }} o fit: clearance across the flange (default the printer's fit, each side)
|
|
121
|
+
*/
|
|
122
|
+
export function nutTrap(nut: {
|
|
123
|
+
flange_diameter: number;
|
|
124
|
+
flange_thickness?: number;
|
|
125
|
+
body_diameter: number;
|
|
126
|
+
length: number;
|
|
127
|
+
hole_circle: number;
|
|
128
|
+
hole_count: number;
|
|
129
|
+
hole_diameter?: number;
|
|
130
|
+
}, { fit, printer, at, depth }?: {
|
|
131
|
+
fit?: number;
|
|
132
|
+
printer: object;
|
|
133
|
+
at?: number[];
|
|
134
|
+
depth?: number;
|
|
135
|
+
}): jscad.geometries.geom3.Geom3 & {
|
|
136
|
+
flange: number;
|
|
137
|
+
body: number;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* A bore for a pulley on a stepper's round shaft (no flat: a pulley's grub screw bears on the shaft), or a plain idler's
|
|
141
|
+
* axle, to subtract. A pass-through with a chamfered mouth.
|
|
142
|
+
* @param {{ bore: number }} pulley @param {{ length: number, printer: object, at?: number[], into?: string, through?: boolean }} o
|
|
143
|
+
*/
|
|
144
|
+
export function pulleyBore(pulley: {
|
|
145
|
+
bore: number;
|
|
146
|
+
}, { length, printer, at, into, through }?: {
|
|
147
|
+
length: number;
|
|
148
|
+
printer: object;
|
|
149
|
+
at?: number[];
|
|
150
|
+
into?: string;
|
|
151
|
+
through?: boolean;
|
|
152
|
+
}): any;
|
|
153
|
+
/**
|
|
154
|
+
* A comb that grips a GT2 belt, to add: teeth of the belt's pitch on a block, the belt pressed in face first and held by
|
|
155
|
+
* a plain cover. Printed teeth up, so nothing overhangs.
|
|
156
|
+
* @param {{ pitch: number, width: number }} belt @param {{ length: number, height: number, wall: number, at?: number[] }} o
|
|
157
|
+
* @returns {object} a JSCAD geom3 to add, x along the belt, z up
|
|
158
|
+
*/
|
|
159
|
+
export function beltClamp(belt: {
|
|
160
|
+
pitch: number;
|
|
161
|
+
width: number;
|
|
162
|
+
}, { length, height, wall, at }?: {
|
|
163
|
+
length: number;
|
|
164
|
+
height: number;
|
|
165
|
+
wall: number;
|
|
166
|
+
at?: number[];
|
|
167
|
+
}): object;
|
|
168
|
+
import jscad from '@jscad/modeling';
|
package/seats.mjs
CHANGED
|
@@ -76,16 +76,18 @@ export function seatSize(bearing, { fit = 'press', lip, printer } = {}) {
|
|
|
76
76
|
export function bearingSeat(bearing, { fit = 'press', lip, relief = 1, through = false, into = '-z', lead = UP[into] ? 0 : 0.4, printer, at = [0, 0, 0] } = {}) {
|
|
77
77
|
const what = 'bearingSeat', s = seatSize(bearing, { fit, lip, printer });
|
|
78
78
|
size(what, 'relief', relief); size(what, 'lead', lead, { zero: true });
|
|
79
|
-
const R = s.pocket / 2, r = s.relief / 2, up = UP[into] ?? null, D = s.depth, past = D + relief + (through ? OUT : 0)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
79
|
+
const R = s.pocket / 2, r = s.relief / 2, up = UP[into] ?? null, D = s.depth, past = D + relief + (through ? OUT : 0);
|
|
80
|
+
if (up) { // across a part, a teardrop's roof on each step
|
|
81
|
+
const cuts = [tear(R, R, lead ? 0 : OUT, -D, up), tear(r, r, -D + EDGE, -past, up)];
|
|
82
|
+
if (lead) cuts.push(tear(R + lead, R, 0, -lead, up), tear(R + lead, R + lead, OUT, 0, up));
|
|
83
|
+
return Object.assign(along(union(cuts), into, at), { seat: s });
|
|
84
|
+
}
|
|
85
|
+
// Going up or down, one profile turned about the axis: no seams between the steps for a boolean to leak at
|
|
86
|
+
const mouth = lead ? [[R + lead, OUT], [R + lead, 0], [R, -lead]] : [[R, OUT]], z0 = -D, floor = through ? Math.min(-past, -D - R) - OUT : -past;
|
|
87
|
+
const inner = into === '+z' ? (through ? [[R, z0], [r, z0 - (R - r)], [r, floor]] : [[R, z0], [TINY, z0 - (R - TINY)]]) : [[R, z0], [r, z0], [r, -past]];
|
|
88
|
+
const pts = [[0, OUT], ...mouth, ...inner, [0, inner.at(-1)[1]]].reverse();
|
|
89
|
+
const turned = extrudeRotate({ segments: SEGMENTS }, polygon({ points: pts }));
|
|
90
|
+
const g = along(turned, into, at);
|
|
89
91
|
return Object.assign(g, { seat: s });
|
|
90
92
|
}
|
|
91
93
|
|
|
@@ -143,3 +145,54 @@ export function clipGroove(shaft, { width, depth, at = [0, 0, 0] } = {}) {
|
|
|
143
145
|
const g = extrudeRotate({ segments: SEGMENTS }, polygon({ points: [[r, 0], [over, 0], [over, width + rise], [r, width]] }));
|
|
144
146
|
return Object.assign(translate(at, g), { root: 2 * r });
|
|
145
147
|
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* A pocket for a linear bearing's outside (an LM8UU), to subtract: a straight press or slip for its whole length, and on
|
|
151
|
+
* through for the rod. Stood up (±z) or across (±x, ±y), with a teardrop's roof when across.
|
|
152
|
+
* @param {{ outer_diameter: number, length: number, bore: number }} bearing
|
|
153
|
+
* @param {{ fit?: 'press' | 'slip' | number, clearance?: number, through?: boolean, printer: object, at?: number[], into?: string }} o clearance: round the rod, each side
|
|
154
|
+
* @returns {object} a JSCAD geom3 to subtract, with .pocket the diameter as drawn
|
|
155
|
+
*/
|
|
156
|
+
export function lm8uuPocket(bearing, { fit = 'press', clearance = 1, through = false, printer, at = [0, 0, 0], into = '-z' } = {}) {
|
|
157
|
+
const what = 'lm8uuPocket', p = printerOf(what, printer), L = size(what, 'length', bearing?.length), s = seatSize({ bore: bearing?.bore, outer_diameter: bearing?.outer_diameter, width: L }, { fit, printer: p, lip: 0.01 }), up = UP[into] ?? null, R = s.pocket / 2, rod = bearing.bore / 2 + clearance;
|
|
158
|
+
const cuts = [tear(R, R, OUT, -L, up)];
|
|
159
|
+
if (into === '+z') { const rise = R - rod; cuts.push(tear(R, rod, -L, -L - rise)); cuts.push(tear(rod, rod, -L - rise / 2, -(L + rise + (through ? OUT : 2)))); } else cuts.push(tear(rod, rod, -L + EDGE, -(L + 2 + (through ? OUT : 0)), up));
|
|
160
|
+
return Object.assign(along(union(cuts), into, at), { pocket: s.pocket, clearance: s.clearance });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A pocket for a lead-screw nut, to subtract: its flange let in from a face, its body on through, and its bolts' holes on
|
|
165
|
+
* their circle. Goes down from a top face; the flange sits flush.
|
|
166
|
+
* @param {{ flange_diameter: number, flange_thickness?: number, body_diameter: number, length: number, hole_circle: number, hole_count: number, hole_diameter?: number }} nut
|
|
167
|
+
* @param {{ fit?: number, printer: object, at?: number[], depth?: number }} o fit: clearance across the flange (default the printer's fit, each side)
|
|
168
|
+
*/
|
|
169
|
+
export function nutTrap(nut, { fit, printer, at = [0, 0, 0], depth } = {}) {
|
|
170
|
+
const what = 'nutTrap', p = printerOf(what, printer), comp = size(what, 'printer.hole_comp', p.hole_comp, { zero: true }), gap = fit ?? 2 * size(what, 'printer.fit', p.fit), flange = size(what, 'flange_diameter', nut?.flange_diameter), body = size(what, 'body_diameter', nut.body_diameter), length = size(what, 'length', nut.length), circle = size(what, 'hole_circle', nut.hole_circle), n = size(what, 'hole_count', nut.hole_count), hole = nut.hole_diameter ?? 3.5;
|
|
171
|
+
const t = nut.flange_thickness ?? 3.5, D = depth ?? length, r = (body + comp + gap) / 2, R = (flange + comp + gap) / 2;
|
|
172
|
+
if (circle / 2 + hole / 2 > R + 0.01 || circle / 2 - hole / 2 < r) throw new Error(`nutTrap: holes on a ${circle} mm circle don't fall between the ${body} mm body and the ${flange} mm flange`);
|
|
173
|
+
const cuts = [tear(R, R, OUT, -t), tear(r, r, -t + EDGE, -D - OUT)], holes = Array.from({ length: n }, (_, i) => { const a = (i * 2 * Math.PI) / n; return translate([(circle / 2) * Math.cos(a), (circle / 2) * Math.sin(a), 0], tear((hole + comp) / 2, (hole + comp) / 2, 0, -D - OUT)); });
|
|
174
|
+
return Object.assign(translate(at, union(...cuts, ...holes)), { flange: 2 * R, body: 2 * r });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* A bore for a pulley on a stepper's round shaft (no flat: a pulley's grub screw bears on the shaft), or a plain idler's
|
|
179
|
+
* axle, to subtract. A pass-through with a chamfered mouth.
|
|
180
|
+
* @param {{ bore: number }} pulley @param {{ length: number, printer: object, at?: number[], into?: string, through?: boolean }} o
|
|
181
|
+
*/
|
|
182
|
+
export function pulleyBore(pulley, { length, printer, at = [0, 0, 0], into = '-z', through = false } = {}) {
|
|
183
|
+
return plainBearing(size('pulleyBore', 'bore', pulley?.bore), { length, printer, at, into, through, clearance: printerOf('pulleyBore', printer).slip ?? printer.fit / 2 });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A comb that grips a GT2 belt, to add: teeth of the belt's pitch on a block, the belt pressed in face first and held by
|
|
188
|
+
* a plain cover. Printed teeth up, so nothing overhangs.
|
|
189
|
+
* @param {{ pitch: number, width: number }} belt @param {{ length: number, height: number, wall: number, at?: number[] }} o
|
|
190
|
+
* @returns {object} a JSCAD geom3 to add, x along the belt, z up
|
|
191
|
+
*/
|
|
192
|
+
export function beltClamp(belt, { length, height, wall, at = [0, 0, 0] } = {}) {
|
|
193
|
+
const what = 'beltClamp', pitch = size(what, 'pitch', belt?.pitch), width = size(what, 'width', belt.width);
|
|
194
|
+
size(what, 'length', length); size(what, 'height', height); size(what, 'wall', wall);
|
|
195
|
+
const count = Math.floor(length / pitch), base = translate([0, 0, height / 2], cuboid({ size: [length, width + 2 * wall, height] })), teeth = [], tooth = pitch * 0.45;
|
|
196
|
+
for (let i = 0; i < count; i++) teeth.push(translate([-length / 2 + pitch * (i + 0.5), 0, height + 0.375], cuboid({ size: [tooth, width + 2 * wall, 0.75] })));
|
|
197
|
+
return translate(at, union(base, ...teeth));
|
|
198
|
+
}
|
package/shapes.d.mts
CHANGED
|
@@ -27,5 +27,5 @@ export const scale: typeof jscad.transforms.scale;
|
|
|
27
27
|
import jscad from '@jscad/modeling';
|
|
28
28
|
export { outline, slab, shell, lid, dovetail, gabled, diamond, vents } from "./enclosure.mjs";
|
|
29
29
|
export { countersink, teardropHole, nutPocket, crushRibs, wallOpening } from "./features.mjs";
|
|
30
|
-
export { seatSize, bearingSeat, plainBearing, shaftShoulder, clipGroove } from "./seats.mjs";
|
|
30
|
+
export { seatSize, bearingSeat, plainBearing, shaftShoulder, clipGroove, lm8uuPocket, nutTrap, pulleyBore, beltClamp } from "./seats.mjs";
|
|
31
31
|
export { fromOutlines, regionShape, optimisedOutline, solidRegion, optimisedSolid } from "./optimised.mjs";
|
package/shapes.mjs
CHANGED
|
@@ -106,6 +106,6 @@ export const size = (g) => { const [lo, hi] = measureBoundingBox(g); return [hi[
|
|
|
106
106
|
export { scale };
|
|
107
107
|
export { outline, slab, shell, lid, dovetail, gabled, diamond, vents } from './enclosure.mjs';
|
|
108
108
|
export { countersink, teardropHole, nutPocket, crushRibs, wallOpening } from './features.mjs';
|
|
109
|
-
export { seatSize, bearingSeat, plainBearing, shaftShoulder, clipGroove } from './seats.mjs';
|
|
109
|
+
export { seatSize, bearingSeat, plainBearing, shaftShoulder, clipGroove, lm8uuPocket, nutTrap, pulleyBore, beltClamp } from './seats.mjs';
|
|
110
110
|
export { ops } from './ops.mjs';
|
|
111
111
|
export { fromOutlines, regionShape, optimisedOutline, solidRegion, optimisedSolid } from './optimised.mjs';
|