@rulecad/cad 0.7.25 → 0.7.26
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/EXAMPLES.md +386 -0
- package/README.md +2 -1
- package/TUTORIAL.md +2 -1
- package/lib/optimise.mjs +3 -1
- package/package.json +3 -2
- package/schemas/problem.schema.json +8 -0
package/EXAMPLES.md
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
# Worked examples: from parts to a mechanism
|
|
2
|
+
|
|
3
|
+
[The tutorial](TUTORIAL.md) ends with a wall hook checked against its screw. These examples carry on from there, one
|
|
4
|
+
for each thing the [README](README.md) describes after that: parts, variants and releases, joints and poses, a model
|
|
5
|
+
from elsewhere, an optimised part, a board, and a mechanism printed flat. Each is a few files and the commands to run
|
|
6
|
+
them. The tests write every file here and run every command, so what you read is what works.
|
|
7
|
+
|
|
8
|
+
They start from a workspace `npm create rulecad my-designs` makes, as the tutorial does, and run in order: later
|
|
9
|
+
examples use earlier files where it saves repeating them.
|
|
10
|
+
|
|
11
|
+
## 1. Parts: a support that breaks away, and a second filament
|
|
12
|
+
|
|
13
|
+
A tag with a raised legend on top, printed as one object in two filaments, standing on a breakaway brim. `main`
|
|
14
|
+
returns named parts; the `.json` says what each is for.
|
|
15
|
+
|
|
16
|
+
```json projects/home/objects/tag.json
|
|
17
|
+
{
|
|
18
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
19
|
+
"name": "tag",
|
|
20
|
+
"title": "Name tag",
|
|
21
|
+
"version": "0.1.0",
|
|
22
|
+
"uses": ["x1c"],
|
|
23
|
+
"material": "PLA",
|
|
24
|
+
"orientation": "Flat, legend up, on a brim that snaps off",
|
|
25
|
+
"parts": {
|
|
26
|
+
"base": { "label": "Tag" },
|
|
27
|
+
"legend": { "label": "Raised legend", "filament": "legend" },
|
|
28
|
+
"brim": { "role": "support", "label": "Breakaway brim" }
|
|
29
|
+
},
|
|
30
|
+
"variables": {
|
|
31
|
+
"length": { "value": 50, "unit": "mm", "rule": "Room for a short name", "label": "Length", "show": true, "tweak": { "min": 30, "max": 90 } },
|
|
32
|
+
"width": { "value": 20, "unit": "mm", "rule": "Two lines of text", "label": "Width", "show": true },
|
|
33
|
+
"thick": { "value": "x1c.layer * 8", "unit": "mm", "rule": "Eight layers: stiff enough to pin to a coat" },
|
|
34
|
+
"raise": { "value": "x1c.layer * 3", "unit": "mm", "rule": "The legend stands three layers proud, so the second filament has layers of its own" },
|
|
35
|
+
"inset": { "value": "x1c.line * 4", "unit": "mm", "rule": "The legend's border, in from the edge" },
|
|
36
|
+
"brim": { "value": 4, "unit": "mm", "rule": "A brim this wide holds a thin tag flat while it prints" },
|
|
37
|
+
"brim_gap": { "value": "x1c.support_gap", "unit": "mm", "rule": "The gap a breakaway support leaves, so it snaps off" }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The brim is a frame round the tag one layer tall, a support gap below the tag's edge; the check knows a `support`
|
|
43
|
+
part is printed and removed, so the tag resting on it is not an overhang.
|
|
44
|
+
|
|
45
|
+
```js projects/home/objects/tag.js
|
|
46
|
+
// A name tag: a slab, a raised legend in a second filament, on a breakaway brim.
|
|
47
|
+
import jscad from '@jscad/modeling'
|
|
48
|
+
const { cuboid } = jscad.primitives
|
|
49
|
+
const { subtract } = jscad.booleans
|
|
50
|
+
|
|
51
|
+
export function main (v) {
|
|
52
|
+
const base = cuboid({ size: [v.length, v.width, v.thick], center: [0, 0, v.thick / 2] })
|
|
53
|
+
const legend = cuboid({ size: [v.length - 2 * v.inset, v.width - 2 * v.inset, v.raise], center: [0, 0, v.thick + v.raise / 2] })
|
|
54
|
+
const ring = subtract(cuboid({ size: [v.length + 2 * v.brim, v.width + 2 * v.brim, v.thick], center: [0, 0, v.thick / 2] }), cuboid({ size: [v.length - 2 * v.brim, v.width - 2 * v.brim, v.thick], center: [0, 0, v.thick / 2] }))
|
|
55
|
+
const brim = subtract(ring, cuboid({ size: [v.length + 2 * v.brim, v.width + 2 * v.brim, v.thick], center: [0, 0, v.thick / 2 + v.brim_gap + v.x1c.layer] }))
|
|
56
|
+
return { base, legend, brim }
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The second filament is named in the project: a slot in the AMS.
|
|
61
|
+
|
|
62
|
+
```json projects/home/project.json
|
|
63
|
+
{
|
|
64
|
+
"name": "home",
|
|
65
|
+
"title": "Things for the house",
|
|
66
|
+
"printer": "x1c",
|
|
67
|
+
"filaments": { "base": { "slot": 1 }, "legend": { "slot": 2 } }
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
npx cad check home/tag
|
|
73
|
+
npx cad export home/tag
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The print file groups the three parts as one object, the legend on its own slot, the brim marked as support.
|
|
77
|
+
|
|
78
|
+
## 2. Variants, then a release
|
|
79
|
+
|
|
80
|
+
A variant is a named set of inputs, kept beside the design rather than as a copy: a long tag next to the standard
|
|
81
|
+
one, a short one beside it. They are `variants` entries in the `.json` (values a variable's `tweak` range allows),
|
|
82
|
+
built as `home/tag:long`.
|
|
83
|
+
|
|
84
|
+
```json projects/home/objects/tag.json
|
|
85
|
+
{
|
|
86
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
87
|
+
"name": "tag",
|
|
88
|
+
"title": "Name tag",
|
|
89
|
+
"version": "0.1.0",
|
|
90
|
+
"uses": ["x1c"],
|
|
91
|
+
"material": "PLA",
|
|
92
|
+
"orientation": "Flat, legend up, on a brim that snaps off",
|
|
93
|
+
"parts": {
|
|
94
|
+
"base": { "label": "Tag" },
|
|
95
|
+
"legend": { "label": "Raised legend", "filament": "legend" },
|
|
96
|
+
"brim": { "role": "support", "label": "Breakaway brim" }
|
|
97
|
+
},
|
|
98
|
+
"variants": { "long": { "length": 80 }, "short": { "length": 35 } },
|
|
99
|
+
"variables": {
|
|
100
|
+
"length": { "value": 50, "unit": "mm", "rule": "Room for a short name", "label": "Length", "show": true, "tweak": { "min": 30, "max": 90 } },
|
|
101
|
+
"width": { "value": 20, "unit": "mm", "rule": "Two lines of text", "label": "Width", "show": true },
|
|
102
|
+
"thick": { "value": "x1c.layer * 8", "unit": "mm", "rule": "Eight layers: stiff enough to pin to a coat" },
|
|
103
|
+
"raise": { "value": "x1c.layer * 3", "unit": "mm", "rule": "The legend stands three layers proud, so the second filament has layers of its own" },
|
|
104
|
+
"inset": { "value": "x1c.line * 4", "unit": "mm", "rule": "The legend's border, in from the edge" },
|
|
105
|
+
"brim": { "value": 4, "unit": "mm", "rule": "A brim this wide holds a thin tag flat while it prints" },
|
|
106
|
+
"brim_gap": { "value": "x1c.support_gap", "unit": "mm", "rule": "The gap a breakaway support leaves, so it snaps off" }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
npx cad variants home/tag
|
|
113
|
+
npx cad check home/tag:long
|
|
114
|
+
npx cad compare home/tag short long
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`compare` puts two variants (or two releases) side by side: what differs in their values and their sizes.
|
|
118
|
+
|
|
119
|
+
Versions are git tags, so a release needs the workspace in git. `--dry-run` shows the bump a change would need
|
|
120
|
+
without making it: here the first release of a new object is `0.1.0` as written.
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
npx cad release home/tag -m "First tag" --dry-run
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 3. Joints and poses: a lid on a hinge
|
|
127
|
+
|
|
128
|
+
A box with a lid is one assembly, with the lid on a revolute joint between two anchors. The base and the lid name
|
|
129
|
+
their anchors in their `.json`; the poses say where the joint stands.
|
|
130
|
+
|
|
131
|
+
```json projects/home/objects/base.json
|
|
132
|
+
{
|
|
133
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
134
|
+
"name": "base",
|
|
135
|
+
"title": "Box base",
|
|
136
|
+
"version": "0.1.0",
|
|
137
|
+
"uses": ["x1c"],
|
|
138
|
+
"anchors": { "hinge": { "at": [0, "depth / 2", "height"], "axis": [1, 0, 0] } },
|
|
139
|
+
"variables": {
|
|
140
|
+
"width": { "value": 40, "unit": "mm", "rule": "The box's width", "label": "Width", "show": true },
|
|
141
|
+
"depth": { "value": 30, "unit": "mm", "rule": "Its depth", "label": "Depth", "show": true },
|
|
142
|
+
"height": { "value": 16, "unit": "mm", "rule": "Its height", "label": "Height", "show": true },
|
|
143
|
+
"wall": { "value": "x1c.line * 3", "unit": "mm", "rule": "Three lines" }
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```js projects/home/objects/base.js
|
|
149
|
+
// An open box: a tray with walls, the hinge along the middle of its back edge.
|
|
150
|
+
import jscad from '@jscad/modeling'
|
|
151
|
+
const { cuboid } = jscad.primitives
|
|
152
|
+
const { subtract } = jscad.booleans
|
|
153
|
+
|
|
154
|
+
export function main (v) {
|
|
155
|
+
const outer = cuboid({ size: [v.width, v.depth, v.height], center: [0, 0, v.height / 2] })
|
|
156
|
+
const inner = cuboid({ size: [v.width - 2 * v.wall, v.depth - 2 * v.wall, v.height], center: [0, 0, v.height / 2 + v.wall] })
|
|
157
|
+
return subtract(outer, inner)
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```json projects/home/objects/lid.json
|
|
162
|
+
{
|
|
163
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
164
|
+
"name": "lid",
|
|
165
|
+
"title": "Box lid",
|
|
166
|
+
"version": "0.1.0",
|
|
167
|
+
"uses": ["x1c"],
|
|
168
|
+
"anchors": { "hinge": { "at": [0, "depth / 2", 0], "axis": [1, 0, 0] } },
|
|
169
|
+
"variables": {
|
|
170
|
+
"width": { "value": 40, "unit": "mm", "rule": "The box's width", "label": "Width", "show": true },
|
|
171
|
+
"depth": { "value": 30, "unit": "mm", "rule": "Its depth", "label": "Depth", "show": true },
|
|
172
|
+
"thick": { "value": "x1c.layer * 10", "unit": "mm", "rule": "Ten layers" }
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```js projects/home/objects/lid.js
|
|
178
|
+
// A flat lid, hinged along its back edge.
|
|
179
|
+
import jscad from '@jscad/modeling'
|
|
180
|
+
|
|
181
|
+
export function main (v) {
|
|
182
|
+
return jscad.primitives.cuboid({ size: [v.width, v.depth, v.thick], center: [0, 0, v.thick / 2] })
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The assembly: the lid's hinge anchor sits on the base's, and the joint turns it from there. Angle 0 is shut; the lid
|
|
187
|
+
opens by turning back over the hinge, so the open pose is negative.
|
|
188
|
+
|
|
189
|
+
```json projects/home/assemblies/box.json
|
|
190
|
+
{
|
|
191
|
+
"title": "Box with its lid",
|
|
192
|
+
"kind": "fit",
|
|
193
|
+
"items": [
|
|
194
|
+
{ "id": "base", "object": "base" },
|
|
195
|
+
{ "id": "lid", "object": "lid" }
|
|
196
|
+
],
|
|
197
|
+
"joints": [
|
|
198
|
+
{ "id": "hinge", "type": "revolute", "parent": "base.hinge", "child": "lid.hinge", "min": -120, "max": 0, "label": "Lid" }
|
|
199
|
+
],
|
|
200
|
+
"poses": { "shut": { "hinge": 0 }, "open": { "hinge": -110 } }
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```sh
|
|
205
|
+
npx cad check home/box
|
|
206
|
+
npx cad check home/box --pose open
|
|
207
|
+
npx cad check home/box --sweep --steps 12
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Every pose is checked for parts overlapping; the sweep turns the hinge through its range and names where anything
|
|
211
|
+
collides on the way. The link carries the joint as a slider: `npx cad link home/box --md`.
|
|
212
|
+
|
|
213
|
+
## 4. A model from elsewhere: measured into rules, and matched
|
|
214
|
+
|
|
215
|
+
Something you must fit (a socket, a maker's part) is best measured from its model, not guessed. Here the model is the
|
|
216
|
+
box base exported as a 3MF, standing in for a file from a model site: `cad measure` reads its sections into a draft
|
|
217
|
+
rule set, and `cad match` lays the model over a design and reports how far apart their surfaces are.
|
|
218
|
+
|
|
219
|
+
```sh
|
|
220
|
+
npx cad export home/base
|
|
221
|
+
npx cad measure exports/home/base@0.1.0.3mf --rules basemodel --source "exports/home/base@0.1.0.3mf" --licence "CC0" --no-pictures
|
|
222
|
+
npx cad match home/base exports/home/base@0.1.0.3mf --no-pictures --samples 3000
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The rule set `rules/basemodel.json` has every value as `kind: derived` with the file it came from: rename its
|
|
226
|
+
placeholder names (`size_x`, `sectionA_w`) for what they are before a design uses them. The match of the design
|
|
227
|
+
against its own export is exact; against someone else's model, a deliberate clearance shows as an even offset.
|
|
228
|
+
|
|
229
|
+
## 5. An optimised part, analysed
|
|
230
|
+
|
|
231
|
+
A lever arm: where to put material so it bends least under a load, with bosses kept round the bolt and the pin. The
|
|
232
|
+
problem is a file in the project's `problems/`.
|
|
233
|
+
|
|
234
|
+
```json projects/home/problems/arm.json
|
|
235
|
+
{
|
|
236
|
+
"title": "Lever arm",
|
|
237
|
+
"uses": ["m4", "x1c"],
|
|
238
|
+
"material": "pla",
|
|
239
|
+
"thickness": 4,
|
|
240
|
+
"cell": 1.5,
|
|
241
|
+
"volume": 0.4,
|
|
242
|
+
"filter": 3,
|
|
243
|
+
"space": { "at": [25, 0], "size": [62, 24] },
|
|
244
|
+
"keep": [{ "at": [0, 0], "r": 5 }, { "at": [50, 0], "r": 4 }],
|
|
245
|
+
"avoid": [{ "at": [0, 0], "r": "m4.clearance / 2" }, { "at": [50, 0], "r": 1.6 }],
|
|
246
|
+
"supports": [{ "at": [0, 0], "r": "m4.clearance / 2" }],
|
|
247
|
+
"loads": [{ "at": [50, 0], "r": 1.6, "force": [0, -10], "case": "down" }]
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
The design reads the result through a `problem` variable and draws it; `analysis` has `cad check` report its
|
|
252
|
+
stiffness and peak stress on finer cells.
|
|
253
|
+
|
|
254
|
+
```json projects/home/objects/arm.json
|
|
255
|
+
{
|
|
256
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
257
|
+
"name": "arm",
|
|
258
|
+
"title": "Lever arm",
|
|
259
|
+
"version": "0.1.0",
|
|
260
|
+
"uses": ["x1c"],
|
|
261
|
+
"material": "PLA",
|
|
262
|
+
"orientation": "Flat on the bed",
|
|
263
|
+
"variables": {
|
|
264
|
+
"problem": { "type": "problem", "value": "arm", "choice": ["arm"] },
|
|
265
|
+
"thick": { "value": 4, "unit": "mm", "rule": "As the problem's thickness" }
|
|
266
|
+
},
|
|
267
|
+
"analysis": [{ "problem": "arm", "cell": 0.5, "max_deflection": 1 }]
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
```js projects/home/objects/arm.js
|
|
272
|
+
// The optimised arm, extruded to its thickness: the holes come out true, cut from the outline.
|
|
273
|
+
import jscad from '@jscad/modeling'
|
|
274
|
+
|
|
275
|
+
export function main (v) {
|
|
276
|
+
return jscad.extrusions.extrudeLinear({ height: v.thick }, v.shapes.optimisedOutline(v.problems[v.problem]))
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
```sh
|
|
281
|
+
npx cad optimise home/arm
|
|
282
|
+
npx cad check home/arm
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`optimise` draws the layout in `.preview/` and reports how far the load moves; the result is kept until the problem
|
|
286
|
+
or the solver changes. `check` analyses the part as drawn, on cells half the size and again a quarter bigger, and says
|
|
287
|
+
whether the stiffness has settled.
|
|
288
|
+
|
|
289
|
+
## 6. A board, and a case that reads it
|
|
290
|
+
|
|
291
|
+
A four-key pad: keys in a matrix, one diode each, and a Pico beside them. Every track is drawn by rule; the
|
|
292
|
+
checks run the fab's design rules.
|
|
293
|
+
|
|
294
|
+
```json projects/home/objects/pad.json
|
|
295
|
+
{
|
|
296
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
297
|
+
"name": "pad",
|
|
298
|
+
"title": "Four-key pad",
|
|
299
|
+
"version": "0.1.0",
|
|
300
|
+
"engine": "pcb",
|
|
301
|
+
"uses": ["mx", "pico", "sod123", "m2", "jlcpcb"],
|
|
302
|
+
"variables": {
|
|
303
|
+
"rows": { "value": 2, "rule": "Two rows" },
|
|
304
|
+
"cols": { "value": 2, "rule": "Two columns" },
|
|
305
|
+
"track": { "value": "jlcpcb.track_min * 2.5", "unit": "mm", "rule": "Tracks well over the fab's least" },
|
|
306
|
+
"clear": { "value": "jlcpcb.gap_min * 2.5", "unit": "mm", "rule": "Clearance well over the fab's least" },
|
|
307
|
+
"thickness": { "value": "jlcpcb.thickness", "unit": "mm", "rule": "The usual board" },
|
|
308
|
+
"margin": { "value": 5, "unit": "mm", "rule": "Board edge beyond the keys" },
|
|
309
|
+
"mcu_gap": { "value": 2, "unit": "mm", "rule": "Between the keys and the Pico" },
|
|
310
|
+
"mcu_side": { "value": "left", "choice": ["left", "right"], "rule": "Which way the Pico's USB faces" },
|
|
311
|
+
"mcu_row": { "value": 0, "rule": "Which key row the Pico sits beside" },
|
|
312
|
+
"mount_holes": { "value": 1, "rule": "M2 holes in the corners" },
|
|
313
|
+
"controller": { "value": "beside", "choice": ["beside", "under"], "rule": "The Pico beside the keys" }
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
```js projects/home/objects/pad.js
|
|
319
|
+
// A key matrix on the keyboard recipe: the board and its matrix (rows, columns, GPIO) for the firmware.
|
|
320
|
+
export function main (v) {
|
|
321
|
+
const keys = v.pcb.grid(v.rows, v.cols, v.mx.pitch)
|
|
322
|
+
return v.pcb.keyboard(v, keys)
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
```sh
|
|
327
|
+
npx cad check home/pad
|
|
328
|
+
npx cad export home/pad
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
A case reads the board rather than copying its numbers: `"uses": ["home/pad"]`, then `v.pad.board_w` and
|
|
332
|
+
`v.pad.board_holes` are the board's own.
|
|
333
|
+
|
|
334
|
+
## 7. A mechanism printed flat
|
|
335
|
+
|
|
336
|
+
A leaf spring and a block that flicks, drawn in one plane and printed on its side. The lamina's checks come out with
|
|
337
|
+
the print checks: it prints free, its sequence is clear, and a hard stop catches the leaf before its strain limit.
|
|
338
|
+
|
|
339
|
+
```json projects/home/objects/flick.json
|
|
340
|
+
{
|
|
341
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
342
|
+
"name": "flick",
|
|
343
|
+
"title": "Flicker",
|
|
344
|
+
"version": "0.1.0",
|
|
345
|
+
"uses": ["x1c", "pla"],
|
|
346
|
+
"material": "PLA",
|
|
347
|
+
"orientation": "On its side: the plane of the drawing is the bed",
|
|
348
|
+
"variables": {
|
|
349
|
+
"len": { "value": 20, "unit": "mm", "rule": "The leaf's length", "label": "Leaf", "show": true },
|
|
350
|
+
"t": { "value": "x1c.line * 2", "unit": "mm", "rule": "Two lines thick: it bends within its layers" },
|
|
351
|
+
"fillet": { "value": "x1c.line * 2", "unit": "mm", "rule": "Rounded where it meets its blocks: a square corner is where a print yields" },
|
|
352
|
+
"h": { "value": 10, "unit": "mm", "rule": "The print's height, the leaf's width: tall, so the tip can't flex out of the plane" },
|
|
353
|
+
"gap": { "value": "x1c.print_gap", "unit": "mm", "rule": "The gap that prints apart" },
|
|
354
|
+
"post": { "value": "x1c.print_gap + x1c.line", "unit": "mm", "rule": "How far the stop's lip stands over the tip block" },
|
|
355
|
+
"bend": { "value": 0.3, "unit": "mm", "rule": "How far the state bends it" },
|
|
356
|
+
"block": { "value": 4, "unit": "mm", "rule": "The tip block, the root, the frame's bars" }
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
```js projects/home/objects/flick.js
|
|
362
|
+
// A leaf from a root block to a tip block, bent by a state. The frame is one piece: the root, a floor under
|
|
363
|
+
// everything, and a post past the tip with a lip over it, the hard stop.
|
|
364
|
+
import jscad from '@jscad/modeling'
|
|
365
|
+
const rect = (x0, y0, x1, y1) => jscad.primitives.polygon({ points: [[x0, y0], [x1, y0], [x1, y1], [x0, y1]] })
|
|
366
|
+
|
|
367
|
+
export function main (v) {
|
|
368
|
+
const f = v.flexures, b = v.block, tipTop = b / 2, floor = 0 - b - b, postX = v.len + b + v.gap
|
|
369
|
+
return f.lamina({
|
|
370
|
+
height: v.h, gap: v.gap, material: f.flexureMaterial({ modulus: v.pla.modulus, strength: v.pla.strength }),
|
|
371
|
+
ground: [rect(0 - b, floor, 0, b), rect(0 - b, floor, postX + b, floor + b), rect(postX, floor, postX + b, tipTop + v.post + b), rect(v.len, tipTop + v.post, postX + b, tipTop + v.post + b)],
|
|
372
|
+
bodies: { tip: rect(v.len - b / 2, 0 - b / 2, v.len + b, tipTop) },
|
|
373
|
+
joints: { leaf: { kind: 'leaf', params: { length: v.len, thickness: v.t, fillet: v.fillet }, at: [0 - 1, 0], from: 'ground', to: 'tip' } },
|
|
374
|
+
states: { bent: { leaf: v.bend } }, sequence: ['rest', 'bent', 'rest']
|
|
375
|
+
})
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
```sh
|
|
380
|
+
npx cad check home/flick
|
|
381
|
+
npx cad animate home/flick
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
`animate` writes the sequence as an animated SVG in `.preview/`, the leaf drawn bent, and a page that plays it with
|
|
385
|
+
the force on each step. The launcher in `examples/bench/projects/launcher` is the same idea at full size: a flooded
|
|
386
|
+
frame, catches, a trigger, and a shot.
|
package/README.md
CHANGED
|
@@ -18,7 +18,8 @@ npx cad link bathroom/soap-tray # a link that opens the model in a browser
|
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
**New here?** [The tutorial](TUTORIAL.md) walks from an empty folder to a part of your own, checked against the thing
|
|
21
|
-
it fits, in about twenty minutes. This page is the reference.
|
|
21
|
+
it fits, in about twenty minutes. This page is the reference. [The worked examples](EXAMPLES.md) go on from there: parts, variants and a release, a lid on a hinge, a model
|
|
22
|
+
measured into rules, an optimised arm, a board, and a mechanism printed flat, each tested as written.
|
|
22
23
|
|
|
23
24
|
```
|
|
24
25
|
rules/ shared facts, one file per set: x1c.json (printer), mx.json (Cherry MX). A set from
|
package/TUTORIAL.md
CHANGED
|
@@ -213,7 +213,8 @@ itself: nothing is uploaded.
|
|
|
213
213
|
|
|
214
214
|
## Where next
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
[The worked examples](EXAMPLES.md) carry on from here, one for each of these, with the files to write and the
|
|
217
|
+
commands to run, tested the same way as this page. Each is also a section of [the README](README.md):
|
|
217
218
|
|
|
218
219
|
- **Parts**: a design that returns several named parts, supports that break away, a second colour.
|
|
219
220
|
- **Variants**: named sets of inputs, side by side (`home/hook:long`).
|
package/lib/optimise.mjs
CHANGED
|
@@ -84,7 +84,9 @@ export async function readProblem(project, ref) {
|
|
|
84
84
|
if (dim === 2 && !(problem.thickness > 0)) throw new Error(`${path.basename(file)}: a flat (2D) problem needs a thickness`);
|
|
85
85
|
const outline = { smooth: p.outline?.smooth ?? 4, minArea: p.outline?.min_area != null ? ev(p.outline.min_area) : problem.cell ** 2 * 2, fine: p.outline?.fine != null ? ev(p.outline.fine) : 1.25 }; // fine: the cells a printable solid is cleaned and drawn on, mm (its own cells if smaller)
|
|
86
86
|
// A printable solid's surface is kept within the printer's overhang limit too (smoothing can tip faces past it)
|
|
87
|
-
|
|
87
|
+
// (outline.tip: faces the smoothing left steeper than the limit are tipped back to it too; off unless asked, since
|
|
88
|
+
// tipped corners leave dips that slice as islands, and the layers step out no further for it)
|
|
89
|
+
if (dim === 3 && problem.overhang) { const n = printerOf(project), pr = resolve({ uses: [n] }).values[n]; outline.overhang = { up: problem.overhang, angle: pr?.overhang ?? 45, bridge: pr?.bridge ?? 5, layer: pr?.layer ?? 0.2, line: pr?.line ?? 0.42, ...(p.outline?.tip ? { tip: true } : {}) }; problem.bridge = outline.overhang.bridge; } // (the optimiser bridges half that)
|
|
88
90
|
return { ref, name, variant, file, dim, title: p.title || name, material: { name: p.material, ...m }, problem, outline, critical: !!p.critical };
|
|
89
91
|
}
|
|
90
92
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.26",
|
|
4
4
|
"description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"templates",
|
|
32
32
|
"README.md",
|
|
33
33
|
"TUTORIAL.md",
|
|
34
|
+
"EXAMPLES.md",
|
|
34
35
|
"LICENSE",
|
|
35
36
|
"AGENTS.md"
|
|
36
37
|
],
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"@rulecad/flexures": "^0.3.0"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
|
-
"@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0"
|
|
71
|
+
"@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0"
|
|
71
72
|
},
|
|
72
73
|
"peerDependenciesMeta": {
|
|
73
74
|
"@rulecad/pcb": {
|
|
@@ -136,6 +136,14 @@
|
|
|
136
136
|
"min_area": {
|
|
137
137
|
"$ref": "#/$defs/expr",
|
|
138
138
|
"description": "Holes and islands smaller than this (mm²) are dropped"
|
|
139
|
+
},
|
|
140
|
+
"fine": {
|
|
141
|
+
"$ref": "#/$defs/expr",
|
|
142
|
+
"description": "3D: the surface drawn on cells this many times finer than the problem's (default 1.25)"
|
|
143
|
+
},
|
|
144
|
+
"tip": {
|
|
145
|
+
"type": "boolean",
|
|
146
|
+
"description": "3D with an overhang direction: faces the smoothing left steeper than the printer's limit are tipped back to it as well (off by default: tipped corners can leave dips that slice as islands, and the sliced overhang is no smaller for it; the bracket example's 160 mm² of lean is the same either way)"
|
|
139
147
|
}
|
|
140
148
|
}
|
|
141
149
|
},
|