formacad 0.0.0-stage → 0.2.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 +98 -2
- package/build/cli/src/forma.d.ts +2 -0
- package/build/cli/src/forma.js +546 -0
- package/build/cli/src/forma.js.map +1 -0
- package/build/cli/src/mcp.d.ts +1 -0
- package/build/cli/src/mcp.js +495 -0
- package/build/cli/src/mcp.js.map +1 -0
- package/build/cli/src/preview.d.ts +31 -0
- package/build/cli/src/preview.js +427 -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 +10 -0
- package/build/core/src/export2d.js +127 -0
- package/build/core/src/export2d.js.map +1 -0
- package/build/core/src/geometry.d.ts +93 -0
- package/build/core/src/geometry.js +946 -0
- package/build/core/src/geometry.js.map +1 -0
- package/build/core/src/gltf.d.ts +6 -0
- package/build/core/src/gltf.js +154 -0
- package/build/core/src/gltf.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 +12 -0
- package/build/core/src/importers.js +1025 -0
- package/build/core/src/importers.js.map +1 -0
- package/build/core/src/index.d.ts +92 -0
- package/build/core/src/index.js +227 -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 +178 -0
- package/build/core/src/interp.js +3012 -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/modeling.d.ts +18 -0
- package/build/core/src/modeling.js +483 -0
- package/build/core/src/modeling.js.map +1 -0
- package/build/core/src/parser.d.ts +46 -0
- package/build/core/src/parser.js +478 -0
- package/build/core/src/parser.js.map +1 -0
- package/build/core/src/scad/colors.d.ts +1 -0
- package/build/core/src/scad/colors.js +37 -0
- package/build/core/src/scad/colors.js.map +1 -0
- package/build/core/src/scad/convert.d.ts +33 -0
- package/build/core/src/scad/convert.js +2842 -0
- package/build/core/src/scad/convert.js.map +1 -0
- package/build/core/src/scad/parser.d.ts +239 -0
- package/build/core/src/scad/parser.js +578 -0
- package/build/core/src/scad/parser.js.map +1 -0
- package/build/core/src/scad/sources.d.ts +39 -0
- package/build/core/src/scad/sources.js +171 -0
- package/build/core/src/scad/sources.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/surface.d.ts +21 -0
- package/build/core/src/surface.js +253 -0
- package/build/core/src/surface.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 +146 -0
- package/build/core/src/values.js +365 -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 +59 -4
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// A small, dependency-free XML parser — enough for SVG and 3MF files.
|
|
2
|
+
// Comments, processing instructions, DOCTYPE and text content are skipped, like ElementTree does
|
|
3
|
+
// for the parts Forma reads.
|
|
4
|
+
export class XmlError extends Error {
|
|
5
|
+
}
|
|
6
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
|
|
7
|
+
function decodeEntities(s) {
|
|
8
|
+
return s.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[A-Za-z]+);/g, (m, e) => {
|
|
9
|
+
if (e[0] === '#') {
|
|
10
|
+
const code = e[1] === 'x' || e[1] === 'X' ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
|
|
11
|
+
return String.fromCodePoint(code);
|
|
12
|
+
}
|
|
13
|
+
return e in ENTITIES ? ENTITIES[e] : m;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function localName(name) {
|
|
17
|
+
const i = name.indexOf(':');
|
|
18
|
+
return i >= 0 ? name.slice(i + 1) : name;
|
|
19
|
+
}
|
|
20
|
+
/** The value of an attribute whose local name is `name` (any namespace prefix). */
|
|
21
|
+
export function attrLocal(el, name) {
|
|
22
|
+
for (const [k, v] of el.attrs)
|
|
23
|
+
if (k === name || k.endsWith(':' + name))
|
|
24
|
+
return v;
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
export function* iterElements(el) {
|
|
28
|
+
yield el;
|
|
29
|
+
for (const c of el.children)
|
|
30
|
+
yield* iterElements(c);
|
|
31
|
+
}
|
|
32
|
+
export function parseXml(text) {
|
|
33
|
+
let i = 0;
|
|
34
|
+
const n = text.length;
|
|
35
|
+
let line = 1;
|
|
36
|
+
const fail = (msg) => {
|
|
37
|
+
line = text.slice(0, i).split('\n').length;
|
|
38
|
+
throw new XmlError(`${msg}: line ${line}`);
|
|
39
|
+
};
|
|
40
|
+
if (text.charCodeAt(0) === 0xfeff)
|
|
41
|
+
i = 1;
|
|
42
|
+
const stack = [];
|
|
43
|
+
let root = null;
|
|
44
|
+
const nameRe = /[^\s/>=]+/y;
|
|
45
|
+
const attrRe = /\s*([^\s/>=]+)\s*=\s*("([^"]*)"|'([^']*)')/y;
|
|
46
|
+
while (i < n) {
|
|
47
|
+
const lt = text.indexOf('<', i);
|
|
48
|
+
if (lt < 0) {
|
|
49
|
+
if (text.slice(i).trim())
|
|
50
|
+
fail('text outside the root element');
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
if (!stack.length && text.slice(i, lt).trim())
|
|
54
|
+
fail('syntax error');
|
|
55
|
+
i = lt;
|
|
56
|
+
if (text.startsWith('<!--', i)) {
|
|
57
|
+
const e = text.indexOf('-->', i + 4);
|
|
58
|
+
if (e < 0)
|
|
59
|
+
fail('unclosed comment');
|
|
60
|
+
i = e + 3;
|
|
61
|
+
}
|
|
62
|
+
else if (text.startsWith('<?', i)) {
|
|
63
|
+
const e = text.indexOf('?>', i + 2);
|
|
64
|
+
if (e < 0)
|
|
65
|
+
fail('unclosed processing instruction');
|
|
66
|
+
i = e + 2;
|
|
67
|
+
}
|
|
68
|
+
else if (text.startsWith('<![CDATA[', i)) {
|
|
69
|
+
const e = text.indexOf(']]>', i + 9);
|
|
70
|
+
if (e < 0)
|
|
71
|
+
fail('unclosed CDATA');
|
|
72
|
+
i = e + 3;
|
|
73
|
+
}
|
|
74
|
+
else if (text.startsWith('<!', i)) {
|
|
75
|
+
// DOCTYPE, possibly with an internal subset in [ ... ]
|
|
76
|
+
let depth = 0;
|
|
77
|
+
let j = i + 2;
|
|
78
|
+
for (; j < n; j++) {
|
|
79
|
+
const c = text[j];
|
|
80
|
+
if (c === '[')
|
|
81
|
+
depth++;
|
|
82
|
+
else if (c === ']')
|
|
83
|
+
depth--;
|
|
84
|
+
else if (c === '>' && depth <= 0)
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (j >= n)
|
|
88
|
+
fail('unclosed declaration');
|
|
89
|
+
i = j + 1;
|
|
90
|
+
}
|
|
91
|
+
else if (text.startsWith('</', i)) {
|
|
92
|
+
nameRe.lastIndex = i + 2;
|
|
93
|
+
const m = nameRe.exec(text);
|
|
94
|
+
if (!m)
|
|
95
|
+
fail('bad closing tag');
|
|
96
|
+
const close = m[0];
|
|
97
|
+
const top = stack.pop();
|
|
98
|
+
if (!top || top.qname !== close)
|
|
99
|
+
fail(`mismatched tag </${close}>`);
|
|
100
|
+
const gt = text.indexOf('>', nameRe.lastIndex);
|
|
101
|
+
if (gt < 0)
|
|
102
|
+
fail('unclosed tag');
|
|
103
|
+
i = gt + 1;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
nameRe.lastIndex = i + 1;
|
|
107
|
+
const m = nameRe.exec(text);
|
|
108
|
+
if (!m)
|
|
109
|
+
fail('syntax error');
|
|
110
|
+
const qname = m[0];
|
|
111
|
+
let j = nameRe.lastIndex;
|
|
112
|
+
const attrs = new Map();
|
|
113
|
+
for (;;) {
|
|
114
|
+
attrRe.lastIndex = j;
|
|
115
|
+
const a = attrRe.exec(text);
|
|
116
|
+
if (!a)
|
|
117
|
+
break;
|
|
118
|
+
attrs.set(a[1], decodeEntities(a[3] ?? a[4] ?? ''));
|
|
119
|
+
j = attrRe.lastIndex;
|
|
120
|
+
}
|
|
121
|
+
while (j < n && /\s/.test(text[j]))
|
|
122
|
+
j++;
|
|
123
|
+
let selfClosing = false;
|
|
124
|
+
if (text[j] === '/' && text[j + 1] === '>') {
|
|
125
|
+
selfClosing = true;
|
|
126
|
+
j += 2;
|
|
127
|
+
}
|
|
128
|
+
else if (text[j] === '>')
|
|
129
|
+
j += 1;
|
|
130
|
+
else
|
|
131
|
+
fail('not well-formed (invalid token)');
|
|
132
|
+
const el = { tag: localName(qname), qname, attrs, children: [] };
|
|
133
|
+
if (stack.length)
|
|
134
|
+
stack[stack.length - 1].children.push(el);
|
|
135
|
+
else if (root)
|
|
136
|
+
fail('junk after document element');
|
|
137
|
+
else
|
|
138
|
+
root = el;
|
|
139
|
+
if (!selfClosing)
|
|
140
|
+
stack.push(el);
|
|
141
|
+
i = j;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (stack.length)
|
|
145
|
+
fail(`unclosed element <${stack[stack.length - 1].qname}>`);
|
|
146
|
+
if (!root) {
|
|
147
|
+
i = n;
|
|
148
|
+
fail('no element found');
|
|
149
|
+
}
|
|
150
|
+
return root;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=xml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml.js","sourceRoot":"","sources":["../../../packages/core/src/xml.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,iGAAiG;AACjG,6BAA6B;AAS7B,MAAM,OAAO,QAAS,SAAQ,KAAK;CAAG;AAEtC,MAAM,QAAQ,GAA2B,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAE9F,SAAS,cAAc,CAAC,CAAS;IAC/B,OAAO,CAAC,CAAC,OAAO,CAAC,uCAAuC,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE;QACzE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CA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"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// std/electronics.forma — Reference PCBs/batteries (.reference) and port/fan cutouts for enclosures.
|
|
2
|
+
// Usage: import "std/electronics.forma" as elec
|
|
3
|
+
|
|
4
|
+
// Standard Raspberry Pi 4/5 M2.5 mounting hole coordinates (58mm x 49mm pattern relative to board center)
|
|
5
|
+
let rpiMountPoints = [
|
|
6
|
+
[-23.5mm, -24.5mm],
|
|
7
|
+
[34.5mm, -24.5mm],
|
|
8
|
+
[-23.5mm, 24.5mm],
|
|
9
|
+
[34.5mm, 24.5mm]
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
// Standard cooling fan mounting hole spacing for common sizes (30..120mm)
|
|
13
|
+
func fanHoleSpacing(size: Length) -> Length {
|
|
14
|
+
size == 30mm ? 24mm
|
|
15
|
+
: size == 40mm ? 32mm
|
|
16
|
+
: size == 50mm ? 40mm
|
|
17
|
+
: size == 60mm ? 50mm
|
|
18
|
+
: size == 80mm ? 71.5mm
|
|
19
|
+
: size == 120mm ? 105mm
|
|
20
|
+
: size * 0.8
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Raspberry Pi 4/5 reference model (85 x 56 mm, with M2.5 mounting holes & ports; use with .layer(.reference))
|
|
24
|
+
component RaspberryPiBoard() {
|
|
25
|
+
Difference {
|
|
26
|
+
Box(width: 85mm, depth: 56mm, height: 1.6mm)
|
|
27
|
+
for p in rpiMountPoints {
|
|
28
|
+
Cylinder(d: 2.75mm, h: 3mm).at(x: p[0], y: p[1], z: -0.5mm)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// SoC + 40-pin GPIO header
|
|
32
|
+
Box(width: 15mm, depth: 15mm, height: 3mm).at(x: -10mm, y: 2mm, z: 1.6mm)
|
|
33
|
+
Box(width: 51mm, depth: 5mm, height: 8.5mm).at(x: -10mm, y: 24.5mm, z: 1.6mm)
|
|
34
|
+
// Ethernet + dual USB stacks (+X edge)
|
|
35
|
+
Box(width: 21mm, depth: 16mm, height: 13.5mm).at(x: 33.5mm, y: -17mm, z: 1.6mm)
|
|
36
|
+
Box(width: 17mm, depth: 13mm, height: 15mm).at(x: 35.5mm, y: 1mm, z: 1.6mm)
|
|
37
|
+
Box(width: 17mm, depth: 13mm, height: 15mm).at(x: 35.5mm, y: 18mm, z: 1.6mm)
|
|
38
|
+
// USB-C power + dual micro-HDMI (-Y edge)
|
|
39
|
+
Box(width: 9mm, depth: 7mm, height: 3.2mm).at(x: -31.3mm, y: -25.5mm, z: 1.6mm)
|
|
40
|
+
Box(width: 6.5mm, depth: 7mm, height: 3.0mm).at(x: -16.5mm, y: -25.5mm, z: 1.6mm)
|
|
41
|
+
Box(width: 6.5mm, depth: 7mm, height: 3.0mm).at(x: -3.0mm, y: -25.5mm, z: 1.6mm)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ESP32 DevKit reference model (51.5 x 28 mm)
|
|
45
|
+
component ESP32Board() {
|
|
46
|
+
Box(width: 51.5mm, depth: 28mm, height: 1.6mm)
|
|
47
|
+
Box(width: 18mm, depth: 16mm, height: 3.2mm).at(x: 14mm, z: 1.6mm)
|
|
48
|
+
Box(width: 7mm, depth: 9mm, height: 3.2mm).at(x: -23mm, z: 1.6mm)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// USB-C port cutout along Y through a wall, with optional outer plug overmold relief for thick walls
|
|
52
|
+
component USBC_Cutout(wall: Length = 4mm, clearance: Length = 0.4mm, plugRelief: Bool = true) {
|
|
53
|
+
assert(wall > 0mm, "USBC_Cutout wall must be positive")
|
|
54
|
+
let w = 9.0mm + 2 * clearance
|
|
55
|
+
let h = 3.2mm + 2 * clearance
|
|
56
|
+
Rect(width: w, height: h)
|
|
57
|
+
.fillet(r: h * 0.48)
|
|
58
|
+
.extrude(height: wall + 2mm, center: true)
|
|
59
|
+
.rotate(x: 90deg)
|
|
60
|
+
if plugRelief && wall > 1.8mm {
|
|
61
|
+
Rect(width: 12.6mm + 2 * clearance, height: 6.8mm + 2 * clearance)
|
|
62
|
+
.fillet(r: 2.2mm)
|
|
63
|
+
.extrude(height: wall, center: true)
|
|
64
|
+
.rotate(x: 90deg)
|
|
65
|
+
.at(y: wall / 2 + 1.2mm)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Cooling fan cutout with circular airway and 4 corner mounting holes (30, 40, 50, 60, 80, 120 mm)
|
|
70
|
+
component FanCutout(size: Length = 40mm, wall: Length = 5mm, hole: Length = 3.4mm) {
|
|
71
|
+
assert(size >= 20mm && wall > 0mm, "FanCutout size >= 20mm and wall > 0")
|
|
72
|
+
let spacing = fanHoleSpacing(size: size)
|
|
73
|
+
Cylinder(d: size - 3mm, h: wall + 2mm, center: true)
|
|
74
|
+
for ix in 0..<2 {
|
|
75
|
+
for iy in 0..<2 {
|
|
76
|
+
Cylinder(d: hole, h: wall + 2mm, center: true)
|
|
77
|
+
.at(x: (ix == 0 ? -1 : 1) * spacing / 2, y: (iy == 0 ? -1 : 1) * spacing / 2)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 0.96" I2C OLED display cutout (active window + 4 M2 mounting holes)
|
|
83
|
+
component OLED_Cutout(wall: Length = 4mm) {
|
|
84
|
+
assert(wall > 0mm, "OLED_Cutout wall must be positive")
|
|
85
|
+
Box(width: 24.5mm, depth: 13.5mm, height: wall + 2mm, center: true)
|
|
86
|
+
for ix in 0..<2 {
|
|
87
|
+
for iy in 0..<2 {
|
|
88
|
+
Cylinder(d: 2.3mm, h: wall + 2mm, center: true)
|
|
89
|
+
.at(x: (ix == 0 ? -1 : 1) * 11.5mm, y: (iy == 0 ? -1 : 1) * 11.5mm)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 18650 lithium-ion cell reference model (18.2 x 65 mm, horizontal along X)
|
|
95
|
+
component Battery18650() {
|
|
96
|
+
Cylinder(d: 18.2mm, h: 65mm, center: true).rotate(y: 90deg)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Printable 18650 snap-in cradle with flex-relief side slots, end contact slots, and bottom push-out opening
|
|
100
|
+
component BatteryHolder18650(wall: Length = 2.2mm) {
|
|
101
|
+
assert(wall >= 1.5mm, "BatteryHolder18650 wall should be at least 1.5mm")
|
|
102
|
+
let len = 65.6mm
|
|
103
|
+
let d = 18.6mm
|
|
104
|
+
Difference {
|
|
105
|
+
Box(width: len + 2 * wall, depth: d + 2 * wall, height: d * 0.65)
|
|
106
|
+
.fillet(r: 2mm, edges: .vertical)
|
|
107
|
+
.chamfer(0.4mm, edges: .horizontal)
|
|
108
|
+
// Cylindrical cell cradle + top snap opening
|
|
109
|
+
Cylinder(d: d, h: len, center: true).rotate(y: 90deg).at(z: d / 2 + 1.5mm)
|
|
110
|
+
Box(width: len, depth: d * 0.88, height: d).at(z: d * 0.55)
|
|
111
|
+
// Longitudinal flex-relief slots so PLA walls flex smoothly without cracking
|
|
112
|
+
for sy in [-1, 1] {
|
|
113
|
+
Box(width: len - 14mm, depth: 2.2mm, height: 3.5mm).at(y: sy * (d / 2 + wall * 0.4), z: -0.5mm)
|
|
114
|
+
}
|
|
115
|
+
// End contact strip / leaf-spring slots at both ends
|
|
116
|
+
Box(width: len + 2 * wall + 2mm, depth: 8mm, height: 8mm).at(z: d * 0.28)
|
|
117
|
+
// Bottom finger push-out window for easy cell removal
|
|
118
|
+
Rect(width: 26mm, height: 10mm).fillet(r: 4.5mm).extrude(height: 6mm).at(z: -1mm)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// std/enclosures.forma — Building blocks for 3D-printable enclosures: standoffs, vents, lips, ears, and corner posts.
|
|
2
|
+
// Usage: import "std/enclosures.forma" as enclosures
|
|
3
|
+
|
|
4
|
+
// PCB mounting standoff with 45-degree overhang-free reinforcing gussets and screw pilot hole
|
|
5
|
+
component Standoff(h: Length = 6mm, od: Length = 6.5mm, hole: Length = 2.6mm, gussets: Number = 4) {
|
|
6
|
+
assert(h > 0mm && od > hole, "Standoff od must exceed hole diameter")
|
|
7
|
+
let ribH = h * 0.6
|
|
8
|
+
let ribReach = min(od * 0.65, ribH)
|
|
9
|
+
Difference {
|
|
10
|
+
Union {
|
|
11
|
+
Cylinder(d: od, h: h)
|
|
12
|
+
if gussets > 0 {
|
|
13
|
+
for i in 0..<gussets {
|
|
14
|
+
let a = i * (360deg / gussets)
|
|
15
|
+
Polygon(points: [
|
|
16
|
+
[0mm, 0mm],
|
|
17
|
+
[od / 2 + ribReach, 0mm],
|
|
18
|
+
[od / 2 - 0.3mm, ribH],
|
|
19
|
+
[0mm, ribH]
|
|
20
|
+
]).extrude(height: 1.2mm, center: true)
|
|
21
|
+
.rotate(x: 90deg)
|
|
22
|
+
.rotate(z: a)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
Cylinder(d: hole, h: h + 2mm).at(z: -0.5mm)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Parametric ventilation slot array cutter (use inside Difference)
|
|
31
|
+
component VentSlots(count: Number = 6, slotW: Length = 2.8mm, slotL: Length = 20mm, pitch: Length = 5.5mm, depth: Length = 6mm) {
|
|
32
|
+
assert(count >= 1 && slotW > 0mm && slotL > slotW, "VentSlots requires count >= 1 and slotL > slotW")
|
|
33
|
+
let total = (count - 1) * pitch
|
|
34
|
+
for i in 0..<count {
|
|
35
|
+
Rect(width: slotW, height: slotL)
|
|
36
|
+
.fillet(r: slotW * 0.45)
|
|
37
|
+
.extrude(height: depth)
|
|
38
|
+
.at(x: -total / 2 + i * pitch)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Centering lip for an enclosure lid with top lead-in chamfer (fits inside an inner cavity of width x depth)
|
|
43
|
+
component LidLip(width: Length = 60mm, depth: Length = 40mm, height: Length = 2.5mm, wall: Length = 1.6mm, r: Length = 2.5mm, clearance: Length = 0.25mm) {
|
|
44
|
+
assert(width > 2 * wall && depth > 2 * wall && height > 0.6mm, "LidLip dimensions too small")
|
|
45
|
+
let w = width - 2 * clearance
|
|
46
|
+
let d = depth - 2 * clearance
|
|
47
|
+
Difference {
|
|
48
|
+
Box(width: w, depth: d, height: height)
|
|
49
|
+
.fillet(r: r, edges: .vertical)
|
|
50
|
+
.chamfer(min(0.5mm, wall * 0.35), edges: .top)
|
|
51
|
+
Box(width: w - 2 * wall, depth: d - 2 * wall, height: height + 2mm)
|
|
52
|
+
.fillet(r: max(0.5mm, r - wall), edges: .vertical)
|
|
53
|
+
.at(z: -1mm)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// External mounting ear / flange with screw hole
|
|
58
|
+
component MountingEar(width: Length = 14mm, length: Length = 14mm, thick: Length = 3.5mm, hole: Length = 4.4mm) {
|
|
59
|
+
assert(width > hole && length >= width / 2, "MountingEar width must exceed hole")
|
|
60
|
+
Difference {
|
|
61
|
+
Hull {
|
|
62
|
+
Box(width: width, depth: 2mm, height: thick).at(y: 1mm)
|
|
63
|
+
Cylinder(d: width, h: thick).at(y: length - width / 2)
|
|
64
|
+
}
|
|
65
|
+
Cylinder(d: hole, h: thick + 2mm).at(y: length - width / 2, z: -1mm)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Corner screw boss inside an enclosure (blind by default, or through-hole with through: true)
|
|
70
|
+
component CornerPost(h: Length = 15mm, od: Length = 7mm, hole: Length = 2.8mm, through: Bool = false) {
|
|
71
|
+
assert(h > 2mm && od > hole, "CornerPost od must exceed hole")
|
|
72
|
+
Difference {
|
|
73
|
+
Cylinder(d: od, h: h)
|
|
74
|
+
Cylinder(d: hole, h: h + 2mm).at(z: through ? -1mm : 1.5mm)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// std/fasteners.forma — Metric fasteners, heat-set inserts, nut traps, and magnet pockets for 3D printing.
|
|
2
|
+
// Usage: import "std/fasteners.forma" as fasteners
|
|
3
|
+
|
|
4
|
+
let defaultClearance = 0.2mm
|
|
5
|
+
|
|
6
|
+
// Recommended FDM wall thickness for an exact integer number of perimeters (avoids weak gap-fill)
|
|
7
|
+
func perimeters(count: Number = 4, nozzle: Length = 0.4mm) -> Length {
|
|
8
|
+
assert(count >= 1 && nozzle > 0mm, "perimeters requires count >= 1 and nozzle > 0")
|
|
9
|
+
return count * nozzle * 1.05
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Clearance hole diameter for metric screws (M2..M8)
|
|
13
|
+
func holeDiameter(size: Number, clearance: Length = 0.2mm) -> Length {
|
|
14
|
+
assert(size >= 1.6, "screw size must be at least M1.6")
|
|
15
|
+
return size * 1mm + 2 * clearance
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ISO hex nut width across flats
|
|
19
|
+
func nutWidth(size: Number) -> Length {
|
|
20
|
+
size == 2 ? 4.0mm
|
|
21
|
+
: size == 2.5 ? 5.0mm
|
|
22
|
+
: size == 3 ? 5.5mm
|
|
23
|
+
: size == 4 ? 7.0mm
|
|
24
|
+
: size == 5 ? 8.0mm
|
|
25
|
+
: size == 6 ? 10.0mm
|
|
26
|
+
: size == 8 ? 13.0mm
|
|
27
|
+
: size * 1.65mm
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ISO 4762 socket-head cap diameter
|
|
31
|
+
func headDiameter(size: Number) -> Length {
|
|
32
|
+
size == 2 ? 3.8mm
|
|
33
|
+
: size == 2.5 ? 4.5mm
|
|
34
|
+
: size == 3 ? 5.5mm
|
|
35
|
+
: size == 4 ? 7.0mm
|
|
36
|
+
: size == 5 ? 8.5mm
|
|
37
|
+
: size == 6 ? 10.0mm
|
|
38
|
+
: size == 8 ? 13.0mm
|
|
39
|
+
: size * 1.8mm
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ISO 10642 90-degree countersunk flat-head diameter
|
|
43
|
+
func countersunkDiameter(size: Number) -> Length {
|
|
44
|
+
size == 2 ? 4.0mm
|
|
45
|
+
: size == 2.5 ? 5.0mm
|
|
46
|
+
: size == 3 ? 6.0mm
|
|
47
|
+
: size == 4 ? 8.0mm
|
|
48
|
+
: size == 5 ? 10.0mm
|
|
49
|
+
: size == 6 ? 12.0mm
|
|
50
|
+
: size == 8 ? 16.0mm
|
|
51
|
+
: size * 2.0mm
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Through-hole with optional .socket counterbore, .countersunk 90-deg bevel, .hex recess, or .none.
|
|
55
|
+
// Set sacrificialLayer: true for upside-down FDM counterbores (adds a 0.2mm bridge layer).
|
|
56
|
+
component ScrewHole(
|
|
57
|
+
size: Number = 3,
|
|
58
|
+
depth: Length = 10mm,
|
|
59
|
+
head: Enum = .socket,
|
|
60
|
+
clearance: Length = 0.2mm,
|
|
61
|
+
sacrificialLayer: Bool = false
|
|
62
|
+
) {
|
|
63
|
+
assert(depth > 0mm, "ScrewHole depth must be positive")
|
|
64
|
+
let d = holeDiameter(size: size, clearance: clearance)
|
|
65
|
+
let hd = headDiameter(size: size) + 2 * clearance
|
|
66
|
+
let hh = size * 1mm + 0.4mm
|
|
67
|
+
if sacrificialLayer && (head == .socket || head == .hex) {
|
|
68
|
+
Cylinder(d: d, h: max(0.5mm, depth - hh - 0.2mm) + 1mm).at(z: -1mm)
|
|
69
|
+
} else {
|
|
70
|
+
Cylinder(d: d, h: depth + 2mm).at(z: -1mm)
|
|
71
|
+
}
|
|
72
|
+
if head == .socket {
|
|
73
|
+
Cylinder(d: hd, h: hh + 1mm).at(z: depth - hh)
|
|
74
|
+
} else if head == .hex {
|
|
75
|
+
let hw = nutWidth(size: size) + 2 * clearance
|
|
76
|
+
Polygon(sides: 6, d: hw / cos(30deg)).extrude(height: hh + 1mm).at(z: depth - hh)
|
|
77
|
+
} else if head == .countersunk {
|
|
78
|
+
let csd = countersunkDiameter(size: size) + 2 * clearance
|
|
79
|
+
let ch = (csd - d) / 2
|
|
80
|
+
Cone(d1: d, d2: csd + 0.4mm, h: ch + 0.2mm).at(z: depth - ch)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Heat-set threaded brass insert pocket (Ruthex / CNC Kitchen style) with lead-in chamfer and melt-zone relief
|
|
85
|
+
component HeatInsert(size: Number = 3, depth: Length = 6mm, meltZone: Length = 1.5mm) {
|
|
86
|
+
assert(depth > 1mm, "HeatInsert depth must exceed 1mm")
|
|
87
|
+
let od = size == 2 ? 3.2mm
|
|
88
|
+
: size == 2.5 ? 4.0mm
|
|
89
|
+
: size == 3 ? 4.6mm
|
|
90
|
+
: size == 4 ? 5.6mm
|
|
91
|
+
: size == 5 ? 6.4mm
|
|
92
|
+
: size == 6 ? 8.0mm
|
|
93
|
+
: size == 8 ? 9.6mm
|
|
94
|
+
: size * 1.45mm
|
|
95
|
+
Cylinder(d: od, h: depth + 0.5mm).at(z: -0.5mm)
|
|
96
|
+
if meltZone > 0mm {
|
|
97
|
+
Cylinder(d: size * 1mm + 0.4mm, h: meltZone + 0.5mm).at(z: -meltZone)
|
|
98
|
+
}
|
|
99
|
+
Cone(d1: od, d2: od + 0.8mm, h: 0.8mm).at(z: depth - 0.8mm)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Hexagonal nut trap pocket with optional side insertion slot along +X and sequential-bridge step on top
|
|
103
|
+
component NutTrap(size: Number = 3, depth: Length = 3.2mm, clearance: Length = 0.2mm, slot: Length = 0mm, bridgeStep: Bool = false) {
|
|
104
|
+
assert(depth > 0mm, "NutTrap depth must be positive")
|
|
105
|
+
let w = nutWidth(size: size) + 2 * clearance
|
|
106
|
+
let dHole = holeDiameter(size: size, clearance: clearance)
|
|
107
|
+
Polygon(sides: 6, d: w / cos(30deg)).extrude(height: depth)
|
|
108
|
+
if slot > 0mm {
|
|
109
|
+
Box(width: slot, depth: w, height: depth).at(x: slot / 2)
|
|
110
|
+
}
|
|
111
|
+
if bridgeStep {
|
|
112
|
+
// 1-layer rectangular bridge step so a circular screw hole above the hex pocket prints cleanly
|
|
113
|
+
Box(width: dHole, depth: w, height: 0.25mm).at(z: depth)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Horizontal-axis teardrop hole cutter (axis along Y, 45-degree peaked roof prevents FDM crown sagging)
|
|
118
|
+
component TeardropHole(d: Length = 4mm, depth: Length = 10mm, clearance: Length = 0.2mm) {
|
|
119
|
+
assert(d > 0mm && depth > 0mm, "TeardropHole d and depth must be positive")
|
|
120
|
+
let r = d / 2 + clearance
|
|
121
|
+
Hull {
|
|
122
|
+
Circle(r: r)
|
|
123
|
+
Polygon(points: [[-r * 0.707, r * 0.707], [r * 0.707, r * 0.707], [0mm, r * 1.414]])
|
|
124
|
+
}.extrude(height: depth + 2mm, center: true).rotate(x: 90deg)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Neodymium magnet pocket with press-fit clearance and optional 2mm air-escape / punch-out pinhole
|
|
128
|
+
component MagnetPocket(d: Length = 6mm, h: Length = 2mm, clearance: Length = 0.15mm, knockout: Bool = false) {
|
|
129
|
+
assert(d > 0mm && h > 0mm, "MagnetPocket d and h must be positive")
|
|
130
|
+
Cylinder(d: d + 2 * clearance, h: h + 0.3mm).at(z: -0.1mm)
|
|
131
|
+
if knockout {
|
|
132
|
+
Cylinder(d: 2mm, h: h + 6mm).at(z: -5.5mm)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Quick 3D-printer FDM clearance calibration gauge (pegs with 0.15, 0.20, 0.25, 0.30, 0.40 mm radial gaps)
|
|
137
|
+
component ToleranceTest(thick: Length = 6mm) {
|
|
138
|
+
let gaps = [0.15mm, 0.20mm, 0.25mm, 0.30mm, 0.40mm]
|
|
139
|
+
let pitch = 14mm
|
|
140
|
+
let totalW = gaps.count * pitch + 6mm
|
|
141
|
+
let pegD = 6mm
|
|
142
|
+
Union {
|
|
143
|
+
Difference {
|
|
144
|
+
Box(width: totalW, depth: 18mm, height: thick)
|
|
145
|
+
.fillet(r: 3mm, edges: .vertical)
|
|
146
|
+
.chamfer(0.4mm, edges: .horizontal)
|
|
147
|
+
for i in 0..<gaps.count {
|
|
148
|
+
let cx = -((gaps.count - 1) * pitch) / 2 + i * pitch
|
|
149
|
+
Cylinder(d: pegD + 2 * gaps[i], h: thick + 2mm).at(x: cx, z: -1mm)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Captive test pins inside each hole (print-in-place: test which pins break free cleanly)
|
|
153
|
+
for i in 0..<gaps.count {
|
|
154
|
+
let cx = -((gaps.count - 1) * pitch) / 2 + i * pitch
|
|
155
|
+
Cylinder(d: pegD, h: thick + 2mm).chamfer(0.4mm, edges: .horizontal).at(x: cx)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Visual reference socket-head bolt (use with .layer(.reference) for fit checks)
|
|
161
|
+
component Bolt(size: Number = 3, length: Length = 12mm) {
|
|
162
|
+
assert(length > 0mm, "Bolt length must be positive")
|
|
163
|
+
let hd = headDiameter(size: size)
|
|
164
|
+
let hh = size * 1mm
|
|
165
|
+
Cylinder(d: size * 1mm, h: length).at(z: -length)
|
|
166
|
+
Difference {
|
|
167
|
+
Cylinder(d: hd, h: hh).chamfer(0.3mm, edges: .top)
|
|
168
|
+
Polygon(sides: 6, d: hd * 0.55).extrude(height: hh * 0.65).at(z: hh * 0.4)
|
|
169
|
+
}
|
|
170
|
+
}
|