formacad 0.0.0-stage → 0.1.0
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/LICENSE +200 -0
- package/README.md +87 -2
- package/build/cli/src/forma.d.ts +2 -0
- package/build/cli/src/forma.js +285 -0
- package/build/cli/src/forma.js.map +1 -0
- package/build/cli/src/preview.d.ts +3 -0
- package/build/cli/src/preview.js +268 -0
- package/build/cli/src/preview.js.map +1 -0
- package/build/core/fonts/Roboto-Bold.ttf +0 -0
- package/build/core/fonts/Roboto-Regular.ttf +0 -0
- package/build/core/src/bevel.d.ts +41 -0
- package/build/core/src/bevel.js +548 -0
- package/build/core/src/bevel.js.map +1 -0
- package/build/core/src/difflib.d.ts +3 -0
- package/build/core/src/difflib.js +94 -0
- package/build/core/src/difflib.js.map +1 -0
- package/build/core/src/errors.d.ts +9 -0
- package/build/core/src/errors.js +14 -0
- package/build/core/src/errors.js.map +1 -0
- package/build/core/src/export2d.d.ts +7 -0
- package/build/core/src/export2d.js +79 -0
- package/build/core/src/export2d.js.map +1 -0
- package/build/core/src/geometry.d.ts +92 -0
- package/build/core/src/geometry.js +946 -0
- package/build/core/src/geometry.js.map +1 -0
- package/build/core/src/host.d.ts +28 -0
- package/build/core/src/host.js +113 -0
- package/build/core/src/host.js.map +1 -0
- package/build/core/src/importers.d.ts +11 -0
- package/build/core/src/importers.js +711 -0
- package/build/core/src/importers.js.map +1 -0
- package/build/core/src/index.d.ts +81 -0
- package/build/core/src/index.js +155 -0
- package/build/core/src/index.js.map +1 -0
- package/build/core/src/inflate.d.ts +15 -0
- package/build/core/src/inflate.js +230 -0
- package/build/core/src/inflate.js.map +1 -0
- package/build/core/src/interp.d.ts +142 -0
- package/build/core/src/interp.js +2026 -0
- package/build/core/src/interp.js.map +1 -0
- package/build/core/src/lexer.d.ts +14 -0
- package/build/core/src/lexer.js +217 -0
- package/build/core/src/lexer.js.map +1 -0
- package/build/core/src/manifold.d.ts +26 -0
- package/build/core/src/manifold.js +687 -0
- package/build/core/src/manifold.js.map +1 -0
- package/build/core/src/parser.d.ts +46 -0
- package/build/core/src/parser.js +408 -0
- package/build/core/src/parser.js.map +1 -0
- package/build/core/src/std.d.ts +3 -0
- package/build/core/src/std.js +47 -0
- package/build/core/src/std.js.map +1 -0
- package/build/core/src/threemf.d.ts +4 -0
- package/build/core/src/threemf.js +127 -0
- package/build/core/src/threemf.js.map +1 -0
- package/build/core/src/ttf.d.ts +39 -0
- package/build/core/src/ttf.js +473 -0
- package/build/core/src/ttf.js.map +1 -0
- package/build/core/src/values.d.ts +116 -0
- package/build/core/src/values.js +294 -0
- package/build/core/src/values.js.map +1 -0
- package/build/core/src/xml.d.ts +13 -0
- package/build/core/src/xml.js +152 -0
- package/build/core/src/xml.js.map +1 -0
- package/build/core/std/electronics.forma +120 -0
- package/build/core/std/enclosures.forma +76 -0
- package/build/core/std/fasteners.forma +170 -0
- package/build/core/std/gridfinity.forma +182 -0
- package/build/core/std/joints.forma +120 -0
- package/build/core/std/mechanics.forma +276 -0
- package/build/core/std/patterns.forma +138 -0
- package/build/core/std/threads.forma +152 -0
- package/package.json +58 -4
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// std/mechanics.forma — Involute gears (spur, helical, herringbone, ring), racks, GT2 pulleys, bearings, shafts, and NEMA 17 mounts.
|
|
2
|
+
// Usage: import "std/mechanics.forma" as mech
|
|
3
|
+
|
|
4
|
+
// Pitch radius of a gear
|
|
5
|
+
func pitchRadius(teeth: Number, mod: Length = 2mm) -> Length {
|
|
6
|
+
assert(teeth >= 6, "gear must have at least 6 teeth")
|
|
7
|
+
assert(mod > 0mm, "gear module must be positive")
|
|
8
|
+
return teeth * mod / 2
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Exact center-to-center distance for two meshing external gears
|
|
12
|
+
func centerDistance(z1: Number, z2: Number, mod: Length = 2mm, backlash: Length = 0mm) -> Length {
|
|
13
|
+
(z1 + z2) * mod / 2 + backlash
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Phase rotation for the second meshing gear placed on +X so a tooth lands cleanly in a valley
|
|
17
|
+
func meshAngle(teeth: Number) -> Angle {
|
|
18
|
+
(teeth % 2 == 0) ? 180deg / teeth : 0deg
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Involute function inv(alpha) = tan(alpha) - alpha (in dimensionless radians)
|
|
22
|
+
func invAngle(a: Angle) -> Number {
|
|
23
|
+
tan(a) - (a / 180deg) * pi
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Polar angle delta (in radians) on an involute flank at radius r >= rBase
|
|
27
|
+
func invAtRadius(r: Length, rBase: Length) -> Number {
|
|
28
|
+
let ratio = r / rBase
|
|
29
|
+
let t = ratio <= 1 ? 0 : sqrt(ratio * ratio - 1)
|
|
30
|
+
return t - (atan(t) / 180deg) * pi
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 2D involute gear profile (external when internal: false, internal cutter when internal: true)
|
|
34
|
+
func gearPoints(teeth: Number, mod: Length, pressureAngle: Angle, backlash: Length, profileShift: Number, internal: Bool) -> List {
|
|
35
|
+
let pr = teeth * mod / 2
|
|
36
|
+
let rBase = pr * cos(pressureAngle)
|
|
37
|
+
let shift = profileShift * mod
|
|
38
|
+
let rRoot = max(0.5 * mod, pr - 1.25 * mod + shift)
|
|
39
|
+
let rTip = pr + 1.0 * mod + shift
|
|
40
|
+
let rStart = max(rRoot, rBase)
|
|
41
|
+
let stepRad = (2 * pi) / teeth
|
|
42
|
+
let invA = invAngle(a: pressureAngle)
|
|
43
|
+
// Backlash thins external teeth and widens internal tooth spaces
|
|
44
|
+
let blSign = internal ? -1 : 1
|
|
45
|
+
let halfPitch = (pi / 2 + 2 * profileShift * tan(pressureAngle) - blSign * (backlash / mod)) / teeth
|
|
46
|
+
let phiB = halfPitch + invA
|
|
47
|
+
let rootPad = min(0.04 * stepRad, max(0, stepRad / 2 - phiB - 0.01))
|
|
48
|
+
|
|
49
|
+
return stride(from: 0, to: teeth * 10, by: 1).map { k in
|
|
50
|
+
let i = floor(k / 10)
|
|
51
|
+
let s = k % 10
|
|
52
|
+
let cAngle = i * stepRad
|
|
53
|
+
let frac = (s >= 1 && s <= 4) ? (s - 1) / 3 : (s >= 5 && s <= 8) ? (8 - s) / 3 : 0
|
|
54
|
+
let r = (s == 0 || s == 9) ? rRoot : rStart + frac * (rTip - rStart)
|
|
55
|
+
let dTheta = (s == 0) ? -(phiB + rootPad)
|
|
56
|
+
: (s == 9) ? (phiB + rootPad)
|
|
57
|
+
: (s <= 4) ? -(phiB - invAtRadius(r: r, rBase: rBase))
|
|
58
|
+
: (phiB - invAtRadius(r: r, rBase: rBase))
|
|
59
|
+
let a = (cAngle + dTheta) * (180deg / pi)
|
|
60
|
+
return [r * cos(a), r * sin(a)]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// True involute spur, helical, or herringbone (double-helical) gear with FDM bore & elephant's-foot compensation
|
|
65
|
+
component SpurGear(
|
|
66
|
+
teeth: Number = 16,
|
|
67
|
+
mod: Length = 2mm,
|
|
68
|
+
thickness: Length = 6mm,
|
|
69
|
+
bore: Length = 5mm,
|
|
70
|
+
boreClearance: Length = 0.15mm,
|
|
71
|
+
elephantsFoot: Length = 0.3mm,
|
|
72
|
+
pressureAngle: Angle = 20deg,
|
|
73
|
+
helix: Angle = 0deg,
|
|
74
|
+
herringbone: Bool = false,
|
|
75
|
+
backlash: Length = 0.15mm,
|
|
76
|
+
profileShift: Number = 0,
|
|
77
|
+
hubD: Length = 0mm,
|
|
78
|
+
hubH: Length = 0mm
|
|
79
|
+
) {
|
|
80
|
+
assert(teeth >= 6, "SpurGear requires at least 6 teeth")
|
|
81
|
+
assert(mod > 0mm && thickness > 0mm, "SpurGear mod and thickness must be positive")
|
|
82
|
+
let pr = pitchRadius(teeth: teeth, mod: mod)
|
|
83
|
+
let rRoot = pr - 1.25 * mod + profileShift * mod
|
|
84
|
+
let rTip = pr + 1.0 * mod + profileShift * mod
|
|
85
|
+
assert(bore < rRoot * 1.9, "SpurGear bore is too large for the root diameter")
|
|
86
|
+
|
|
87
|
+
let profile = Polygon(points: gearPoints(
|
|
88
|
+
teeth: teeth, mod: mod, pressureAngle: pressureAngle,
|
|
89
|
+
backlash: backlash, profileShift: profileShift, internal: false
|
|
90
|
+
))
|
|
91
|
+
|
|
92
|
+
let rawGear = Union {
|
|
93
|
+
if herringbone && helix != 0deg {
|
|
94
|
+
let halfH = thickness / 2
|
|
95
|
+
let halfTwist = ((halfH * tan(helix)) / pr) * (180deg / pi)
|
|
96
|
+
let slices = max(6, ceil(abs(halfTwist) / 4deg))
|
|
97
|
+
let lower = profile.extrude(height: halfH, twist: halfTwist, slices: slices)
|
|
98
|
+
lower
|
|
99
|
+
lower.mirror(.z).at(z: thickness)
|
|
100
|
+
} else if helix != 0deg {
|
|
101
|
+
let twist = ((thickness * tan(helix)) / pr) * (180deg / pi)
|
|
102
|
+
let slices = max(8, ceil(abs(twist) / 4deg))
|
|
103
|
+
profile.extrude(height: thickness, twist: twist, slices: slices)
|
|
104
|
+
} else {
|
|
105
|
+
profile.extrude(height: thickness)
|
|
106
|
+
}
|
|
107
|
+
if hubD > bore && hubH > 0mm {
|
|
108
|
+
Cylinder(d: hubD, h: thickness + hubH).chamfer(0.4mm, edges: .top)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Difference {
|
|
113
|
+
if elephantsFoot > 0mm {
|
|
114
|
+
Intersection {
|
|
115
|
+
rawGear
|
|
116
|
+
Union {
|
|
117
|
+
Cone(r1: rTip - elephantsFoot, r2: rTip + 0.5mm, h: elephantsFoot + 0.5mm)
|
|
118
|
+
Cylinder(r: rTip + 0.5mm, h: thickness + hubH + 1mm).at(z: elephantsFoot)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
rawGear
|
|
123
|
+
}
|
|
124
|
+
if bore > 0mm {
|
|
125
|
+
Cylinder(d: bore + boreClearance, h: thickness + hubH + 2mm).at(z: -1mm)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Internal involute ring gear (for planetary gearboxes with matching SpurGear sun & planets)
|
|
131
|
+
component RingGear(
|
|
132
|
+
teeth: Number = 36,
|
|
133
|
+
mod: Length = 2mm,
|
|
134
|
+
thickness: Length = 6mm,
|
|
135
|
+
rim: Length = 4mm,
|
|
136
|
+
elephantsFoot: Length = 0.3mm,
|
|
137
|
+
pressureAngle: Angle = 20deg,
|
|
138
|
+
helix: Angle = 0deg,
|
|
139
|
+
herringbone: Bool = false,
|
|
140
|
+
backlash: Length = 0.2mm
|
|
141
|
+
) {
|
|
142
|
+
assert(teeth >= 14, "RingGear requires at least 14 teeth")
|
|
143
|
+
assert(rim > 0mm && thickness > 0mm, "RingGear rim and thickness must be positive")
|
|
144
|
+
let pr = pitchRadius(teeth: teeth, mod: mod)
|
|
145
|
+
let outerR = pr + 1.25 * mod + rim
|
|
146
|
+
let innerR = pr - 1.0 * mod
|
|
147
|
+
let profile = Polygon(points: gearPoints(
|
|
148
|
+
teeth: teeth, mod: mod, pressureAngle: pressureAngle,
|
|
149
|
+
backlash: backlash, profileShift: 0, internal: true
|
|
150
|
+
))
|
|
151
|
+
|
|
152
|
+
let cutH = thickness + 2mm
|
|
153
|
+
Difference {
|
|
154
|
+
Cylinder(r: outerR, h: thickness).chamfer(0.4mm, edges: .horizontal)
|
|
155
|
+
if herringbone && helix != 0deg {
|
|
156
|
+
let halfH = thickness / 2 + 1mm
|
|
157
|
+
let halfTwist = ((halfH * tan(helix)) / pr) * (180deg / pi)
|
|
158
|
+
let slices = max(6, ceil(abs(halfTwist) / 4deg))
|
|
159
|
+
let lower = profile.extrude(height: halfH, twist: halfTwist, slices: slices).at(z: -1mm)
|
|
160
|
+
Union {
|
|
161
|
+
lower
|
|
162
|
+
lower.mirror(.z).at(z: thickness)
|
|
163
|
+
}
|
|
164
|
+
} else if helix != 0deg {
|
|
165
|
+
let twist = ((cutH * tan(helix)) / pr) * (180deg / pi)
|
|
166
|
+
let slices = max(8, ceil(abs(twist) / 4deg))
|
|
167
|
+
profile.extrude(height: cutH, twist: twist, slices: slices).at(z: -1mm)
|
|
168
|
+
} else {
|
|
169
|
+
profile.extrude(height: cutH).at(z: -1mm)
|
|
170
|
+
}
|
|
171
|
+
if elephantsFoot > 0mm {
|
|
172
|
+
Cone(r1: innerR + elephantsFoot + 0.2mm, r2: innerR, h: elephantsFoot + 0.2mm).at(z: -0.1mm)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Linear involute gear rack matching SpurGear(mod:, pressureAngle:)
|
|
178
|
+
// Pitch line sits at y = 1.25 * mod (back face at y = -back).
|
|
179
|
+
component GearRack(
|
|
180
|
+
teeth: Number = 10,
|
|
181
|
+
mod: Length = 2mm,
|
|
182
|
+
thickness: Length = 6mm,
|
|
183
|
+
back: Length = 5mm,
|
|
184
|
+
pressureAngle: Angle = 20deg,
|
|
185
|
+
backlash: Length = 0.15mm
|
|
186
|
+
) {
|
|
187
|
+
assert(teeth >= 2 && mod > 0mm && back > 0mm, "GearRack parameters must be positive")
|
|
188
|
+
let pitch = pi * mod
|
|
189
|
+
let totalL = teeth * pitch
|
|
190
|
+
let add = 1.0 * mod
|
|
191
|
+
let ded = 1.25 * mod
|
|
192
|
+
let toothH = add + ded
|
|
193
|
+
let halfPitchW = pitch / 4 - backlash / 2
|
|
194
|
+
let halfRootW = halfPitchW + ded * tan(pressureAngle)
|
|
195
|
+
let halfTipW = max(0.2 * mod, halfPitchW - add * tan(pressureAngle))
|
|
196
|
+
Union {
|
|
197
|
+
Box(width: totalL, depth: back, height: thickness).at(y: -back / 2)
|
|
198
|
+
for i in 0..<teeth {
|
|
199
|
+
let x0 = -totalL / 2 + (i + 0.5) * pitch
|
|
200
|
+
Polygon(points: [
|
|
201
|
+
[x0 - halfRootW, -0.05mm],
|
|
202
|
+
[x0 + halfRootW, -0.05mm],
|
|
203
|
+
[x0 + halfTipW, toothH],
|
|
204
|
+
[x0 - halfTipW, toothH]
|
|
205
|
+
]).extrude(height: thickness)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// GT2 2mm-pitch timing belt pulley with support-free 45-degree chamfered top flange and FDM bore clearance
|
|
211
|
+
component PulleyGT2(teeth: Number = 20, beltW: Length = 6.5mm, bore: Length = 5mm, boreClearance: Length = 0.15mm, flangeH: Length = 1.4mm) {
|
|
212
|
+
assert(teeth >= 12, "PulleyGT2 requires at least 12 teeth")
|
|
213
|
+
let pitch = 2mm
|
|
214
|
+
let pr = (teeth * pitch) / (2 * pi)
|
|
215
|
+
let rOut = pr - 0.254mm
|
|
216
|
+
let rIn = rOut - 0.75mm
|
|
217
|
+
let rFlange = rOut + 1.6mm
|
|
218
|
+
let rampH = rFlange - rOut
|
|
219
|
+
let step = 360deg / teeth
|
|
220
|
+
let pts = stride(from: 0, to: teeth * 6, by: 1).map { k in
|
|
221
|
+
let i = floor(k / 6)
|
|
222
|
+
let s = k % 6
|
|
223
|
+
let frac = s == 0 ? 0.00 : s == 1 ? 0.20 : s == 2 ? 0.32 : s == 3 ? 0.50 : s == 4 ? 0.68 : 0.80
|
|
224
|
+
let r = (s == 3) ? rIn : (s == 2 || s == 4) ? (rIn + 0.25mm) : rOut
|
|
225
|
+
let a = (i + frac) * step
|
|
226
|
+
return [r * cos(a), r * sin(a)]
|
|
227
|
+
}
|
|
228
|
+
let totalH = flangeH + beltW + rampH + flangeH
|
|
229
|
+
Difference {
|
|
230
|
+
Union {
|
|
231
|
+
Cylinder(r: rFlange, h: flangeH).chamfer(0.3mm, edges: .bottom)
|
|
232
|
+
Polygon(points: pts).extrude(height: beltW + 0.2mm).at(z: flangeH - 0.1mm)
|
|
233
|
+
// 45-degree overhang-free transition into upper flange
|
|
234
|
+
Cone(r1: rOut, r2: rFlange, h: rampH).at(z: flangeH + beltW)
|
|
235
|
+
Cylinder(r: rFlange, h: flangeH).chamfer(0.3mm, edges: .top).at(z: flangeH + beltW + rampH)
|
|
236
|
+
}
|
|
237
|
+
if bore > 0mm {
|
|
238
|
+
Cylinder(d: bore + boreClearance, h: totalH + 2mm).at(z: -1mm)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Ball bearing reference model (default 608: 22mm OD x 8mm ID x 7mm W; also 625: 16x5x5, 6800: 19x10x5)
|
|
244
|
+
component Bearing(od: Length = 22mm, id: Length = 8mm, width: Length = 7mm) {
|
|
245
|
+
assert(od > id && width > 0mm, "Bearing od must exceed id")
|
|
246
|
+
Difference {
|
|
247
|
+
Cylinder(d: od, h: width).chamfer(0.4mm, edges: .horizontal)
|
|
248
|
+
Cylinder(d: id, h: width + 2mm).at(z: -1mm)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Bearing press-fit seat cutter (use inside Difference)
|
|
253
|
+
component BearingSeat(od: Length = 22mm, width: Length = 7mm, clearance: Length = 0.15mm) {
|
|
254
|
+
Cylinder(d: od + 2 * clearance, h: width + 0.3mm).at(z: -0.1mm)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// D-shaft hole cutter (flat cut on +X side; use inside Difference)
|
|
258
|
+
component DShaftHole(d: Length = 5mm, flat: Length = 0.5mm, depth: Length = 10mm, clearance: Length = 0.2mm) {
|
|
259
|
+
assert(flat < d / 2, "DShaftHole flat must be less than radius")
|
|
260
|
+
let r = d / 2 + clearance
|
|
261
|
+
Difference {
|
|
262
|
+
Cylinder(r: r, h: depth + 2mm).at(z: -1mm)
|
|
263
|
+
Box(width: d, depth: d + 2mm, height: depth + 4mm).at(x: r - flat + d / 2, z: -2mm)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// NEMA 17 stepper motor faceplate cutout (31mm M3 bolt pattern + 22.6mm pilot boss)
|
|
268
|
+
component Nema17Mount(wall: Length = 5mm) {
|
|
269
|
+
Cylinder(d: 22.6mm, h: wall + 2mm, center: true)
|
|
270
|
+
for ix in 0..<2 {
|
|
271
|
+
for iy in 0..<2 {
|
|
272
|
+
Cylinder(d: 3.4mm, h: wall + 2mm, center: true)
|
|
273
|
+
.at(x: (ix == 0 ? -1 : 1) * 15.5mm, y: (iy == 0 ? -1 : 1) * 15.5mm)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// std/patterns.forma — Parametric arrays, centered honeycomb grids, knurled knobs, and cable management.
|
|
2
|
+
// Usage: import "std/patterns.forma" as pat
|
|
3
|
+
|
|
4
|
+
// Repeat children in a straight line along X
|
|
5
|
+
component LinearArray(count: Number = 4, step: Length = 10mm, center: Bool = true) {
|
|
6
|
+
assert(count >= 1, "LinearArray count must be at least 1")
|
|
7
|
+
let x0 = center ? -((count - 1) * step) / 2 : 0mm
|
|
8
|
+
for i in 0..<count {
|
|
9
|
+
Union { children }.at(x: x0 + i * step)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Repeat children in a 2D rectangular grid (cols along X, rows along Y)
|
|
14
|
+
component GridArray(cols: Number = 3, rows: Number = 2, stepX: Length = 10mm, stepY: Length = 10mm, center: Bool = true) {
|
|
15
|
+
assert(cols >= 1 && rows >= 1, "GridArray cols and rows must be at least 1")
|
|
16
|
+
let x0 = center ? -((cols - 1) * stepX) / 2 : 0mm
|
|
17
|
+
let y0 = center ? -((rows - 1) * stepY) / 2 : 0mm
|
|
18
|
+
for ix in 0..<cols {
|
|
19
|
+
for iy in 0..<rows {
|
|
20
|
+
Union { children }.at(x: x0 + ix * stepX, y: y0 + iy * stepY)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Repeat children around a circle or arc of radius r
|
|
26
|
+
component CircularArray(
|
|
27
|
+
count: Number = 6,
|
|
28
|
+
r: Length = 15mm,
|
|
29
|
+
startAngle: Angle = 0deg,
|
|
30
|
+
sweepAngle: Angle = 360deg,
|
|
31
|
+
rotateItems: Bool = true
|
|
32
|
+
) {
|
|
33
|
+
assert(count >= 1, "CircularArray count must be at least 1")
|
|
34
|
+
let step = (sweepAngle == 360deg || count == 1) ? sweepAngle / count : sweepAngle / (count - 1)
|
|
35
|
+
for i in 0..<count {
|
|
36
|
+
let a = startAngle + i * step
|
|
37
|
+
if rotateItems {
|
|
38
|
+
Union { children }.at(x: r).rotate(z: a)
|
|
39
|
+
} else {
|
|
40
|
+
Union { children }.at(x: r * cos(a), y: r * sin(a))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Centered hexagonal honeycomb cutout grid (use inside Difference for lightweight panels or vents)
|
|
46
|
+
component HexGrid(cols: Number = 4, rows: Number = 3, cell: Length = 8mm, wall: Length = 1.6mm, depth: Length = 6mm) {
|
|
47
|
+
assert(cols >= 1 && rows >= 1 && cell > 0mm, "HexGrid requires cols >= 1, rows >= 1, cell > 0")
|
|
48
|
+
let dx = (cell + wall) * 0.866025
|
|
49
|
+
let dy = cell + wall
|
|
50
|
+
let wTotal = (cols - 1) * dx
|
|
51
|
+
let hTotal = (rows - 1) * dy + (cols > 1 ? dy / 2 : 0mm)
|
|
52
|
+
for c in 0..<cols {
|
|
53
|
+
for r in 0..<rows {
|
|
54
|
+
let ox = -wTotal / 2 + c * dx
|
|
55
|
+
let oy = -hTotal / 2 + r * dy + (c % 2 == 1 ? dy / 2 : 0mm)
|
|
56
|
+
Polygon(sides: 6, d: cell).extrude(height: depth, center: true).at(x: ox, y: oy)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Grippy diamond-knurled rotary knob with .round/.dshaft bore, bottom chamfer, top pointer, and optional M3 set-screw
|
|
62
|
+
component KnurledKnob(
|
|
63
|
+
d: Length = 24mm,
|
|
64
|
+
h: Length = 14mm,
|
|
65
|
+
teeth: Number = 24,
|
|
66
|
+
bore: Length = 6mm,
|
|
67
|
+
shaft: Enum = .dshaft,
|
|
68
|
+
flat: Length = 1.5mm,
|
|
69
|
+
setScrew: Bool = false
|
|
70
|
+
) {
|
|
71
|
+
assert(d > bore + 4mm && h >= 6mm && teeth >= 8, "KnurledKnob dimensions invalid")
|
|
72
|
+
let rOut = d / 2
|
|
73
|
+
let rIn = rOut - 0.7mm
|
|
74
|
+
let step = 360deg / teeth
|
|
75
|
+
let pts = stride(from: 0, to: teeth * 2, by: 1).map { k in
|
|
76
|
+
let a = k * (step / 2)
|
|
77
|
+
let r = (k % 2 == 0) ? rIn : rOut
|
|
78
|
+
return [r * cos(a), r * sin(a)]
|
|
79
|
+
}
|
|
80
|
+
let boreH = h - 3mm
|
|
81
|
+
Difference {
|
|
82
|
+
Intersection {
|
|
83
|
+
Polygon(points: pts).extrude(height: h, twist: 25deg, slices: 8)
|
|
84
|
+
Polygon(points: pts).extrude(height: h, twist: -25deg, slices: 8)
|
|
85
|
+
Cylinder(d: d, h: h).chamfer(1.2mm, edges: .top).chamfer(0.4mm, edges: .bottom)
|
|
86
|
+
}
|
|
87
|
+
// Top pointer indicator groove along +X
|
|
88
|
+
Box(width: rOut * 0.55, depth: 1.4mm, height: 1.2mm).at(x: rOut * 0.52, z: h - 0.8mm)
|
|
89
|
+
// Shaft bore (round or D-shaft)
|
|
90
|
+
if bore > 0mm {
|
|
91
|
+
if shaft == .dshaft {
|
|
92
|
+
let r = bore / 2 + 0.15mm
|
|
93
|
+
Difference {
|
|
94
|
+
Cylinder(r: r, h: boreH + 0.5mm).at(z: -0.5mm)
|
|
95
|
+
Box(width: bore, depth: bore + 2mm, height: boreH + 2mm).at(x: r - flat + bore / 2, z: -1mm)
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
Cylinder(d: bore + 0.3mm, h: boreH + 0.5mm).at(z: -0.5mm)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Optional radial M3 set-screw hole on +X side
|
|
102
|
+
if setScrew {
|
|
103
|
+
Cylinder(d: 2.8mm, h: rOut + 2mm).rotate(y: 90deg).at(z: boreH * 0.5)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Desk/wall snap-in cable organizer clip with 45-degree V-funnel lead-ins
|
|
109
|
+
component CableClip(cableD: Length = 5mm, count: Number = 3, wall: Length = 2.4mm) {
|
|
110
|
+
assert(cableD >= 2mm && count >= 1, "CableClip cableD >= 2mm and count >= 1")
|
|
111
|
+
let pitch = cableD + wall + 2.5mm
|
|
112
|
+
let totalW = count * pitch + wall
|
|
113
|
+
let h = cableD + wall + 2.4mm
|
|
114
|
+
let slotW = cableD * 0.72
|
|
115
|
+
Difference {
|
|
116
|
+
Box(width: totalW, depth: 12mm, height: h)
|
|
117
|
+
.fillet(r: 2.5mm, edges: .vertical)
|
|
118
|
+
.chamfer(0.4mm, edges: .bottom)
|
|
119
|
+
for i in 0..<count {
|
|
120
|
+
let cx = -((count - 1) * pitch) / 2 + i * pitch
|
|
121
|
+
Cylinder(d: cableD + 0.4mm, h: 16mm, center: true).rotate(x: 90deg).at(x: cx, z: wall + cableD / 2)
|
|
122
|
+
Box(width: slotW, depth: 16mm, height: h).at(x: cx, z: wall + cableD / 2)
|
|
123
|
+
// 45-degree V-funnel lead-in at the top of each slot for one-finger snap-in
|
|
124
|
+
Polygon(points: [
|
|
125
|
+
[-slotW / 2, h - 1.8mm],
|
|
126
|
+
[slotW / 2, h - 1.8mm],
|
|
127
|
+
[slotW / 2 + 2.2mm, h + 0.4mm],
|
|
128
|
+
[-slotW / 2 - 2.2mm, h + 0.4mm]
|
|
129
|
+
]).extrude(height: 16mm, center: true).rotate(x: 90deg).at(x: cx)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Zip-tie pass-through slot cutter (use inside Difference)
|
|
135
|
+
component ZipTieSlot(width: Length = 4.5mm, thick: Length = 2mm, depth: Length = 6mm) {
|
|
136
|
+
assert(width > 0mm && thick > 0mm && depth > 0mm, "ZipTieSlot dimensions must be positive")
|
|
137
|
+
Box(width: width, depth: thick, height: depth, center: true)
|
|
138
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// std/threads.forma — True coaxial 3D-printable helical threads (ISO metric, nuts, PET bottle neck/cap, tripod mounts).
|
|
2
|
+
// Usage: import "std/threads.forma" as threads
|
|
3
|
+
|
|
4
|
+
// Standard ISO coarse metric thread pitch (M3..M20)
|
|
5
|
+
func isoPitch(d: Length) -> Length {
|
|
6
|
+
d <= 3.2mm ? 0.5mm
|
|
7
|
+
: d <= 4.2mm ? 0.7mm
|
|
8
|
+
: d <= 5.2mm ? 0.8mm
|
|
9
|
+
: d <= 6.2mm ? 1.0mm
|
|
10
|
+
: d <= 8.2mm ? 1.25mm
|
|
11
|
+
: d <= 10.2mm ? 1.5mm
|
|
12
|
+
: d <= 12.2mm ? 1.75mm
|
|
13
|
+
: d <= 16.2mm ? 2.0mm
|
|
14
|
+
: 2.5mm
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Thread radial profile r(u) for helical phase u in [0, 1): flat root, straight flanks, flat crest
|
|
18
|
+
func threadProfileRadius(u: Number, rMinor: Length, rMajor: Length) -> Length {
|
|
19
|
+
u < 0.125 ? rMinor
|
|
20
|
+
: u < 0.4375 ? rMinor + ((u - 0.125) / 0.3125) * (rMajor - rMinor)
|
|
21
|
+
: u < 0.5625 ? rMajor
|
|
22
|
+
: u < 0.875 ? rMajor - ((u - 0.5625) / 0.3125) * (rMajor - rMinor)
|
|
23
|
+
: rMinor
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// True coaxial helical trapezoidal/ISO V-thread rod (or internal tap cutter when internal: true).
|
|
27
|
+
// Built directly as a closed, watertight Polyhedron with flat crest/root and lead-in chamfers.
|
|
28
|
+
// Use flankAngle: 90deg for 45-degree overhang-free FDM threads, or flatSide: true for horizontal bed printing.
|
|
29
|
+
component MetricThread(
|
|
30
|
+
d: Length = 12mm,
|
|
31
|
+
pitch: Length = 2mm,
|
|
32
|
+
h: Length = 16mm,
|
|
33
|
+
internal: Bool = false,
|
|
34
|
+
clearance: Length = 0.25mm,
|
|
35
|
+
flankAngle: Angle = 60deg,
|
|
36
|
+
flatSide: Bool = false
|
|
37
|
+
) {
|
|
38
|
+
assert(d > 2 * pitch, "MetricThread diameter must exceed 2 * pitch")
|
|
39
|
+
assert(pitch > 0mm && h > 0mm, "MetricThread pitch and height must be positive")
|
|
40
|
+
|
|
41
|
+
let rMajor = d / 2 + (internal ? clearance : 0mm)
|
|
42
|
+
// ISO thread depth H1 = 5/8 * H where H = pitch / (2 * tan(flankAngle / 2))
|
|
43
|
+
let threadH = (0.3125 * pitch) / tan(flankAngle / 2)
|
|
44
|
+
let rMinor = max(0.5mm, rMajor - threadH)
|
|
45
|
+
|
|
46
|
+
let segs = 24
|
|
47
|
+
let ringsPerTurn = 8
|
|
48
|
+
let rings = max(6, round((h / pitch) * ringsPerTurn))
|
|
49
|
+
let nVerts = (rings + 1) * segs
|
|
50
|
+
let botCenter = nVerts
|
|
51
|
+
let topCenter = nVerts + 1
|
|
52
|
+
|
|
53
|
+
let ringPts = stride(from: 0, to: nVerts, by: 1).map { k in
|
|
54
|
+
let ir = floor(k / segs)
|
|
55
|
+
let ia = k % segs
|
|
56
|
+
let z = (ir / rings) * h
|
|
57
|
+
let a = (ia / segs) * 360deg
|
|
58
|
+
let rawPhase = z / pitch - ia / segs
|
|
59
|
+
let u = rawPhase - floor(rawPhase)
|
|
60
|
+
let r = threadProfileRadius(u: u, rMinor: rMinor, rMajor: rMajor)
|
|
61
|
+
return [r * cos(a), r * sin(a), z]
|
|
62
|
+
}
|
|
63
|
+
let points = concat(ringPts, [[0mm, 0mm, 0mm], [0mm, 0mm, h]])
|
|
64
|
+
|
|
65
|
+
let sideFaces = stride(from: 0, to: rings * segs * 2, by: 1).map { k in
|
|
66
|
+
let quad = floor(k / 2)
|
|
67
|
+
let tri = k % 2
|
|
68
|
+
let ir = floor(quad / segs)
|
|
69
|
+
let ia = quad % segs
|
|
70
|
+
let iaNext = (ia + 1) % segs
|
|
71
|
+
let v00 = ir * segs + ia
|
|
72
|
+
let v01 = ir * segs + iaNext
|
|
73
|
+
let v10 = (ir + 1) * segs + ia
|
|
74
|
+
let v11 = (ir + 1) * segs + iaNext
|
|
75
|
+
return tri == 0 ? [v00, v01, v11] : [v00, v11, v10]
|
|
76
|
+
}
|
|
77
|
+
let botFaces = stride(from: 0, to: segs, by: 1).map { ia in
|
|
78
|
+
[botCenter, (ia + 1) % segs, ia]
|
|
79
|
+
}
|
|
80
|
+
let topBase = rings * segs
|
|
81
|
+
let topFaces = stride(from: 0, to: segs, by: 1).map { ia in
|
|
82
|
+
[topCenter, topBase + ia, topBase + (ia + 1) % segs]
|
|
83
|
+
}
|
|
84
|
+
let core = Polyhedron(points: points, faces: concat(sideFaces, concat(botFaces, topFaces)))
|
|
85
|
+
|
|
86
|
+
if internal {
|
|
87
|
+
core
|
|
88
|
+
} else {
|
|
89
|
+
let lead = min(pitch * 0.65, h * 0.2)
|
|
90
|
+
let chamfered = Intersection {
|
|
91
|
+
core
|
|
92
|
+
Union {
|
|
93
|
+
Cone(r1: rMinor, r2: rMajor + 0.1mm, h: lead)
|
|
94
|
+
Cylinder(r: rMajor + 0.1mm, h: h - 2 * lead).at(z: lead)
|
|
95
|
+
Cone(r1: rMajor + 0.1mm, r2: rMinor, h: lead).at(z: h - lead)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if flatSide {
|
|
99
|
+
Difference {
|
|
100
|
+
chamfered
|
|
101
|
+
Box(width: d + 4mm, depth: d, height: h + 2mm).at(y: -rMajor * 0.85 - d / 2, z: -1mm)
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
chamfered
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Printable hex nut matching MetricThread(d:, pitch:) (phase-aligned to z = 0)
|
|
110
|
+
component IsoNut(d: Length = 12mm, pitch: Length = 2mm, h: Length = 8mm, clearance: Length = 0.25mm) {
|
|
111
|
+
let flatW = d * 1.55
|
|
112
|
+
Difference {
|
|
113
|
+
Polygon(sides: 6, d: flatW / cos(30deg)).extrude(height: h).chamfer(0.5mm, edges: .horizontal)
|
|
114
|
+
MetricThread(d: d, pitch: pitch, h: h + 2 * pitch, internal: true, clearance: clearance).at(z: -pitch)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Standard 28mm PET bottle neck (PCO-1881 style, 2.7mm pitch)
|
|
119
|
+
component BottleNeck(h: Length = 14mm, wall: Length = 2.4mm) {
|
|
120
|
+
let pitch = 2.7mm
|
|
121
|
+
let threadDepth = (0.3125 * pitch) / tan(30deg)
|
|
122
|
+
let innerD = 27.4mm - 2 * threadDepth - 2 * wall
|
|
123
|
+
Difference {
|
|
124
|
+
Union {
|
|
125
|
+
MetricThread(d: 27.4mm, pitch: pitch, h: h)
|
|
126
|
+
Cylinder(d: 33mm, h: 2.5mm).chamfer(0.6mm, edges: .horizontal)
|
|
127
|
+
}
|
|
128
|
+
Cylinder(d: innerD, h: h + 2mm).at(z: -1mm)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Matching screw-on cap for BottleNeck() with bed-flush chamfered vertical grip flutes
|
|
133
|
+
component BottleCap(h: Length = 13mm, wall: Length = 2.2mm, clearance: Length = 0.3mm) {
|
|
134
|
+
let outerD = 27.4mm + 2 * clearance + 2 * wall
|
|
135
|
+
Difference {
|
|
136
|
+
Union {
|
|
137
|
+
Cylinder(d: outerD, h: h).chamfer(0.8mm, edges: .top)
|
|
138
|
+
for i in 0..<24 {
|
|
139
|
+
Cylinder(d: 1.4mm, h: h - 1.2mm)
|
|
140
|
+
.chamfer(0.3mm, edges: .horizontal)
|
|
141
|
+
.at(x: outerD / 2 - 0.15mm)
|
|
142
|
+
.rotate(z: i * 15deg)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
MetricThread(d: 27.4mm, pitch: 2.7mm, h: h - 1.5mm, internal: true, clearance: clearance).at(z: -0.5mm)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 1/4"-20 camera tripod mounting hole cutter (use inside Difference)
|
|
150
|
+
component TripodHole(depth: Length = 8mm, clearance: Length = 0.18mm) {
|
|
151
|
+
MetricThread(d: 6.35mm, pitch: 1.27mm, h: depth + 1mm, internal: true, clearance: clearance).at(z: -0.5mm)
|
|
152
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formacad",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Forma — a Swift-style language for 3D-printable models (TypeScript + Manifold WASM)",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"cad",
|
|
9
|
+
"3d-printing",
|
|
10
|
+
"stl",
|
|
11
|
+
"3mf",
|
|
12
|
+
"openscad",
|
|
13
|
+
"parametric",
|
|
14
|
+
"manifold",
|
|
15
|
+
"geometry",
|
|
16
|
+
"forma"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://ivanmakhnyk.github.io/formacad/",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/ivanmakhnyk/formacad.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/ivanmakhnyk/formacad/issues"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=22.3.0"
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"forma": "./build/cli/src/forma.js",
|
|
31
|
+
"formacad": "./build/cli/src/forma.js"
|
|
32
|
+
},
|
|
33
|
+
"main": "./build/core/src/index.js",
|
|
34
|
+
"types": "./build/core/src/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./build/core/src/index.d.ts",
|
|
38
|
+
"import": "./build/core/src/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"build/core/",
|
|
43
|
+
"build/cli/",
|
|
44
|
+
"LICENSE",
|
|
45
|
+
"README.md"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p . && node scripts/copy-assets.mjs",
|
|
49
|
+
"test": "npm run build && node tests/js/memory_host.test.mjs && node tests/run_tests.mjs",
|
|
50
|
+
"prepublishOnly": "npm test",
|
|
51
|
+
"build:site": "npm run build && node scripts/build-site.mjs",
|
|
52
|
+
"serve": "node scripts/serve.mjs 8080"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"typescript": "^5.6.0"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"manifold-3d": "^3.5.5"
|
|
59
|
+
}
|
|
60
|
+
}
|