@rulecad/cad 0.7.92 → 0.7.97
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/AGENTS.md +2 -0
- package/CHANGELOG.md +39 -0
- package/README.md +23 -2
- package/bin/cad.mjs +19 -5
- package/lib/fittings.mjs +8 -3
- package/lib/optimise.mjs +33 -7
- package/package.json +4 -4
- package/schemas/problem.schema.json +25 -7
package/AGENTS.md
CHANGED
|
@@ -256,6 +256,8 @@ variable says which rule it comes from. Follow these steps; they're what makes a
|
|
|
256
256
|
factor, and where the peak stress is.
|
|
257
257
|
- For a part that must not break (a lever, a pedal), give its problem a `"stress"` limit (the material's strength
|
|
258
258
|
over a safety factor) instead of a `"volume"`: the lightest layout under it. Then verify it on finer cells.
|
|
259
|
+
Add `"robust": true` so it holds made a little thin and a little thick too (`cad optimise` prints both copies'
|
|
260
|
+
peaks); a mechanism with `"robust": true` and a `"strain"` limit is optimised under the limit.
|
|
259
261
|
- Mark a problem `"critical": true` if the part could hurt someone if it broke. Say plainly that the analysis is a
|
|
260
262
|
design aid and the material values are data-sheet figures: such a part needs testing, recorded under
|
|
261
263
|
`"verification"`, not just a check.
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,45 @@ print (a hole's diameter, a seat's depth, a part's outline). Each release lists
|
|
|
5
5
|
its reason. A **fasten** is an entry in an assembly's `"fasten"` list: one screwed joint, naming the screw by thread
|
|
6
6
|
and head, the parts it passes through and the part it ends in.
|
|
7
7
|
|
|
8
|
+
## 0.7.97: robust: true
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- A problem's `robust: true` (schema first): optimised as made, a little thin and a little thick (topopt's robust
|
|
12
|
+
formulation). With a stress or strain limit, the lightest layout that keeps it on all three; a mechanism, the layout
|
|
13
|
+
whose worst copy moves furthest, and with a limit, optimised under it. `cad optimise` prints the copies: "made a
|
|
14
|
+
little thin, peak stress X MPa; a little thick, Y MPa" (with a note where either is over the limit) and, for a
|
|
15
|
+
mechanism, "made a little thin, its output moves X mm; a little thick, Y mm". Refused by name with a volume alone.
|
|
16
|
+
|
|
17
|
+
### Printed sizes that moved
|
|
18
|
+
|
|
19
|
+
- None.
|
|
20
|
+
|
|
21
|
+
## 0.7.95: a rubber is refused as a printed fitting
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- A project whose material is a rubber (a rule set whose strength over its modulus is past 0.5, such as the kit's new
|
|
25
|
+
`tpu`) is refused by name for printed fittings, whose sums are for a stiff plastic, and a rubber is left out of the
|
|
26
|
+
plastics another refusal lists. No printed size moved.
|
|
27
|
+
|
|
28
|
+
## 0.7.93: milled by a tool, cast with draft, a minimum feature, voids prevented
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- A problem milled from several sides (`"mill": ["+z", "-z"]`), by a tool of a size (`"tool"`, mm), or cast with a
|
|
32
|
+
draft (`"draft"`, degrees): the schema first. `cad optimise` says how it is made, the draft as made at the grid
|
|
33
|
+
("a step out every 3 layers: 18.43°"), and any cells too narrow for the tool, in the design or in avoid regions
|
|
34
|
+
(drill those holes). A tool or draft with no milling or casting is refused by name.
|
|
35
|
+
- `"mill"` and `"cast"` can name a variable holding the side or sides (`"+z"`, `"+z -z"`) or `"none"`, so a variant
|
|
36
|
+
switches the process; a tool or draft goes off with it.
|
|
37
|
+
- `"voids": "prevented"`: the optimiser keeps every empty pocket open to the outside; cad optimise says so, and any
|
|
38
|
+
void a keep region walls in is still an error, said to be left though prevented.
|
|
39
|
+
- `"feature"` (mm): the thinnest member, from the printer's line (`x1c.wall_min`, two lines). `cad optimise` says the
|
|
40
|
+
grid holds it where a cell is as wide, or that it was held to three cells, with any cells left narrower; past three
|
|
41
|
+
cells it is refused with the cell size that would hold it.
|
|
42
|
+
- The bench's lever E (`bench/lever:milled`): the lever's profile milled through a 6 mm plate by a 4 mm end mill,
|
|
43
|
+
98.9 N/mm against the printed C's 100. No existing printed size moves.
|
|
44
|
+
- A refusal of a feature past three cells asks for cells of at least a third of it, rounded up (it asked for cells of
|
|
45
|
+
1.33 mm or less for 4 mm, which it refused again), or a smaller feature.
|
|
46
|
+
|
|
8
47
|
|
|
9
48
|
## 0.7.92: eight axes on a Mega 2560 (#199)
|
|
10
49
|
- The wiring sheet names a Mega slot's pins as step, dir and enable (D38, every slot's): the wire to a driver breakout carries EN, STEP, DIR and GND, and the axis's home switch is a wire of its own. A CNC shield's axis still names its limit pin.
|
package/README.md
CHANGED
|
@@ -1546,6 +1546,11 @@ with numbers as expressions like an object's (schema: `schemas/problem.schema.js
|
|
|
1546
1546
|
area (a hole's edge, a pad), as stress where a load meets a point has no limit. `cad optimise` reports the peak
|
|
1547
1547
|
stress against the limit. Check the final part with an `analysis` on a finer `cell`: a sharp corner that's
|
|
1548
1548
|
within the limit on the optimiser's cells can still be over it on finer ones.
|
|
1549
|
+
- **Robust:** `"robust": true` optimises the design as made, a little thin and a little thick (eroded and dilated
|
|
1550
|
+
copies) together. With a stress or strain limit, the lightest layout that keeps it on all three; a mechanism, the
|
|
1551
|
+
layout whose worst copy moves its output furthest, and with a limit, optimised under it. `cad optimise` prints
|
|
1552
|
+
the copies' peaks (and a mechanism's copies' travels). About three times the solves. A sharp inside corner of the
|
|
1553
|
+
space still stays sharp; topopt's README has the figures.
|
|
1549
1554
|
- **Variants**, picked as `name:variant`, set variables that have a tweak range, as an object's do.
|
|
1550
1555
|
|
|
1551
1556
|
`cad optimise <project>/<problem>` runs it, reports how far each load case moves its load and the stiffness that
|
|
@@ -1612,12 +1617,28 @@ A part made another way says so in place of `overhang` (one process to a problem
|
|
|
1612
1617
|
- **Milled:** `"mill": "+z"` (the tool cuts down from above). No undercuts: a cell is as solid as every cell
|
|
1613
1618
|
between it and the tool. `cad optimise` says `milled from +z: no undercuts`, or counts the cells an avoid region
|
|
1614
1619
|
or the space's own edge hides behind material. The `mill-3axis` rule set holds the walls, corners and pockets a 3-axis machine manages.
|
|
1620
|
+
`"tool": 2` is the end mill's radius (mm, at least a cell): no pocket narrower, every inside corner rounded to it,
|
|
1621
|
+
and `cad optimise` counts any cells still too narrow, in the design or in avoid regions (drill those holes). A flat
|
|
1622
|
+
(2D) problem milled from `+z` with a tool is a plate's profile cut through by an end mill. `"mill": ["+z", "-z"]`
|
|
1623
|
+
mills from several sides, a setup each: a cell stays only where no side's tool reaches it. `"mill"` can also name a
|
|
1624
|
+
variable holding `"+z"`, `"+z -z"` or `"none"`, so a variant switches it: the bench's `bench/lever:milled` is the
|
|
1625
|
+
lever cut from a 6 mm plate by a 4 mm end mill.
|
|
1615
1626
|
- **Cast or moulded:** `"cast": "+z"` for a mould drawn off one way, or `"cast": { "draw": "z", "parting": 6 }` for
|
|
1616
|
-
two halves drawn off both ways from a parting plane (mm along the axis; the space's middle when left out).
|
|
1617
|
-
(
|
|
1627
|
+
two halves drawn off both ways from a parting plane (mm along the axis; the space's middle when left out). `"draft": 15`
|
|
1628
|
+
(degrees) narrows the part towards the side it is drawn off: a wall steps a cell out every whole number of layers
|
|
1629
|
+
in 1 / tan(draft), so at least the draft, and `cad optimise` says the angle made (15° is a step every 3
|
|
1630
|
+
layers, 18.43°). A draft too shallow for the grid (3° needs 19 layers) is refused by name: draw it on the finished
|
|
1631
|
+
part instead (`mould-injection`: a degree or so).
|
|
1618
1632
|
- **Printed in a metal powder bed:** `"overhang": "+z"` with `"voids": "refused"`. Powder left in an enclosed void
|
|
1619
1633
|
can't be got out, so `cad optimise` fails with each void's volume and centre: open it with an avoid region (an
|
|
1620
1634
|
escape hole, `dmls.escape_hole` wide) or allow voids. The `dmls` rule set holds the process's limits.
|
|
1635
|
+
`"voids": "prevented"` keeps every pocket open as the part is optimised (a virtual temperature, kept under a cap:
|
|
1636
|
+
an enclosed void runs hot); any a keep region walls in are still errors.
|
|
1637
|
+
|
|
1638
|
+
Any problem can give `"feature"`, the thinnest member it makes, mm: for a printed part `"x1c.wall_min"`, the
|
|
1639
|
+
printer's two lines (0.84 mm). Where a cell is as wide, every member already is, and `cad optimise` says the grid
|
|
1640
|
+
holds it; up to three cells across, members narrower go as it optimises; wider is refused with the cells that would
|
|
1641
|
+
hold it.
|
|
1621
1642
|
|
|
1622
1643
|
Any of them can also be `"symmetry": { "mirror": "y" }` (mirrored across the grid's middle planes; `"turns": 2` or
|
|
1623
1644
|
`4` about `"axis"` for half or quarter turns) or `"extrude": "x"` (one section all along x, a part cut from a bar).
|
package/bin/cad.mjs
CHANGED
|
@@ -263,7 +263,7 @@ async function optimiseProblem(ref, { preview: previewing = false } = {}) {
|
|
|
263
263
|
const lines = [`${p.material.name}${r.dim === 2 ? `, ${fmt(r.thickness)} mm thick` : ''}: ${r.cases.map((c) => c.moment ? `${c.name} ${sig(c.angle * 180 / Math.PI)}° (${sig(c.torsion / 1000 * Math.PI / 180)} N·m/°)` : `${c.name} ${sig(c.deflection)} mm (${sig(c.stiffness)} N/mm)`).join(', ')}`,
|
|
264
264
|
`${fmt(r.volume * 100)}% of the space, ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? '' : ' (stopped: not settled)'}${r.overhang ? `, printable built ${r.overhang}` : ''}${r.stress ? `, peak stress ${sig(r.stress.peak)} MPa (limit ${sig(r.stress.limit)})` : ''}${r.dropped ? `; ${r.dropped.length} loose ${r.dropped.length === 1 ? 'piece' : 'pieces'} dropped (${sig(r.dropped.reduce((t, v) => t + v, 0))} mm³)` : ''}${r.emptied ? `; ${r.emptied} ${r.emptied === 1 ? 'cell' : 'cells'} that wouldn't print emptied` : ''}${r.cleared ? `; sliced as the printer will, ${r.cleared} ${r.cleared === 1 ? 'cell' : 'cells'} under islands emptied` : ''}`,
|
|
265
265
|
...(r.unsupported > 0.01 ? [`${fmt(r.unsupported * 100)}% of the kept regions has nothing holding it up (at ${r.overhang ? 'the printer\'s overhang limit' : '45°'} or less): give the part more material to stand them on, or keep less`] : []),
|
|
266
|
-
...(r.process ? [processLine(r)] : []), ...(r.voids?.length ? [voidsLine(r)] : [])];
|
|
266
|
+
...(r.process ? [processLine(r)] : []), ...(r.feature ? [featureLine(r)] : []), ...(r.voids?.length ? [voidsLine(r)] : [])];
|
|
267
267
|
let out;
|
|
268
268
|
if (r.dim === 3) {
|
|
269
269
|
out = paths.preview(project, `${name.replace(':', '-')}-optimised.png`);
|
|
@@ -286,22 +286,36 @@ async function optimiseProblem(ref, { preview: previewing = false } = {}) {
|
|
|
286
286
|
if (r.mechanism) console.log(` the output moves ${sig(r.mechanism.travel)} mm its way for ${sig(r.mechanism.input)} mm of push: an advantage of ${sig(r.mechanism.advantage)}`);
|
|
287
287
|
if (r.stress && r.mechanism) console.log(` peak stress ${sig(r.stress.peak)} MPa at its input force${r.stress.strain != null ? ` (strain ${sig(r.stress.strain * 100)}%)` : ''}, the limit ${sig(r.stress.limit)} MPa${r.stress.strainLimit != null ? ` (${sig(r.stress.strainLimit * 100)}%)` : ''}: it reaches the limit at ${sig(r.stress.force)} N of push, its output then ${sig(r.stress.travel)} mm along`);
|
|
288
288
|
else if (r.stress) console.log(` peak stress ${sig(r.stress.peak)} MPa, the limit ${sig(r.stress.limit)} MPa${r.stress.peak > r.stress.limit * 1.02 ? ': over it (raise the volume, ease the limit, or use a smaller cell)' : ''}`);
|
|
289
|
+
if (r.stress?.copies) console.log(` made a little thin, peak stress ${sig(r.stress.copies.eroded)} MPa; a little thick, ${sig(r.stress.copies.dilated)} MPa${Math.max(r.stress.copies.eroded, r.stress.copies.dilated) > r.stress.limit * 1.02 ? ` (over the limit: ${p.problem?.robust ? 'a smaller cell or a looser limit' : 'give the problem robust: true'})` : ''}`);
|
|
290
|
+
if (r.mechanism?.copies) console.log(` made a little thin, its output moves ${sig(r.mechanism.copies.eroded)} mm; a little thick, ${sig(r.mechanism.copies.dilated)} mm`);
|
|
289
291
|
if (r.dim === 3) console.log(` ${fmt(r.volume * 100)}% of the space filled: ${fmt(r.solid / 1000)} cm³ (${fmt(r.solid / 1000 * (p.material.density || 0))} g of ${p.material.name})${r.overhang ? `, printable built ${r.overhang}` : ''}`);
|
|
290
292
|
else console.log(` ${fmt(r.volume * 100)}% of the space filled, outline ${fmt(r.area)} mm² (${fmt(r.area * r.thickness / 1000)} cm³ before bosses and holes are made exact)`);
|
|
291
293
|
if (r.reduced) console.log(` ${r.reduced.before} triangles reduced to ${r.reduced.after} (${fmt(r.reduced.after / r.reduced.before * 100)}%), the surface kept within ${fmt(r.reduced.tolerance)} mm`);
|
|
292
294
|
console.log(` ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? ', settled' : ': stopped before it settled (raise steps)'}`);
|
|
293
295
|
if (r.process) console.log(` ${processLine(r)}`);
|
|
294
296
|
if (r.symmetry || r.extrude) console.log(` ${[r.symmetry?.mirror ? `mirrored across ${[...r.symmetry.mirror].join(' and ')}` : '', r.symmetry?.turns ? `the same each ${r.symmetry.turns === 4 ? 'quarter' : 'half'} turn about ${r.symmetry.axis || 'z'}` : '', r.extrude ? `one section along ${r.extrude}` : ''].filter(Boolean).join(', ')}`);
|
|
297
|
+
if (r.feature) console.log(` ${r.feature.thin ? 'warning: ' : ''}${featureLine(r)}`);
|
|
295
298
|
if (r.grey > 0.1) console.log(` warning: ${greyLine(r)}`);
|
|
296
|
-
if (r.voids?.length) { console.log(` error: ${voidsLine(r)}`); process.exitCode = 1; }
|
|
299
|
+
if (r.voids?.length) { console.log(` error: ${voidsLine(r)}`); process.exitCode = 1; } else if (r.vented) console.log(' voids prevented: none enclosed, every empty pocket open to the outside');
|
|
297
300
|
console.log(out);
|
|
298
301
|
if (previewing) console.log(`${run}\n ${recorded ? `the run, step by step: open it to watch it again (${r.steps} steps)` : 'the run\'s end only: its steps weren\'t recorded (cad preview --fresh runs it again and records them)'}`);
|
|
299
302
|
}
|
|
300
303
|
// How a milled or cast result is made, and its undercuts (none, unless an avoid region or the space's own shape sits
|
|
301
304
|
// behind material: the optimiser keeps every cell as solid as those on its way out, but can't fill a cell it mustn't)
|
|
302
305
|
function processLine(r) {
|
|
303
|
-
const
|
|
304
|
-
|
|
306
|
+
const p = r.process, sides = [p.mill].flat(), tool = p.tool ? ` by a tool of ${fmt(p.tool)} mm radius` : '';
|
|
307
|
+
const draft = p.draft ? ` with a ${fmt(p.draft)}° draft (a step out every ${p.every} layers: ${fmt(p.made)}°)` : '';
|
|
308
|
+
const how = p.mill ? `milled from ${sides.length > 1 ? `${sides.slice(0, -1).join(', ')} and ${sides.at(-1)}` : sides[0]}${tool}` : typeof p.cast === 'string' ? `cast, drawn off ${p.cast}${draft}` : `cast in two halves drawn off along ${p.cast.draw} from ${fmt(p.cast.parting)} mm${draft}`;
|
|
309
|
+
const n = r.narrow, narrow = !n ? '' : [n.design ? `${n.design} ${n.design === 1 ? 'cell' : 'cells'} of the design too narrow for the tool` : '', n.avoided ? `${n.avoided} ${n.avoided === 1 ? 'cell' : 'cells'} of avoid regions narrower than the tool: drill those holes, or give a smaller tool` : ''].filter(Boolean).join('; ');
|
|
310
|
+
const tail = narrow ? `; ${narrow}` : n ? ', and nothing narrower than the tool' : '';
|
|
311
|
+
return r.undercuts ? `${how}: ${r.undercuts} ${r.undercuts === 1 ? 'cell is' : 'cells are'} undercut (an avoid region, or the edge of the space, with material between it and the ${p.mill ? 'tool' : 'draw'}: move it, or make it from that side)${tail}` : `${how}: no undercuts${tail}`;
|
|
312
|
+
}
|
|
313
|
+
// The thinnest member asked (a printer's two lines): met by the grid itself, or held to three cells, with any cells left
|
|
314
|
+
// in members narrower
|
|
315
|
+
function featureLine(r) {
|
|
316
|
+
const f = r.feature, h = f.holds / (2 * f.cells + 1);
|
|
317
|
+
if (!f.cells) return `thinnest member ${fmt(f.asked)} mm: every member is at least a cell (${fmt(h)} mm), so the grid holds it`;
|
|
318
|
+
return `thinnest member ${fmt(f.asked)} mm: held to three cells (${fmt(f.holds)} mm)${f.thin ? `, and ${f.thin} solid ${f.thin === 1 ? 'cell is' : 'cells are'} still in a narrower member or a square outside corner: give a bigger filter radius` : ', none narrower'}`;
|
|
305
319
|
}
|
|
306
320
|
// A grey result (warned of above a tenth): its design cells between a tenth and nine tenths solid. A clear design has
|
|
307
321
|
// a few per cent, on its surfaces (the 3D cantilever milled from above 5.3%, free 2D cantilevers 1 to 3%): a tenth
|
|
@@ -311,7 +325,7 @@ function greyLine(r) {
|
|
|
311
325
|
}
|
|
312
326
|
// Enclosed voids, refused by the problem (powder that can't get out, a trapped core)
|
|
313
327
|
function voidsLine(r) {
|
|
314
|
-
return `${r.voids.length} enclosed ${r.voids.length === 1 ? 'void' : 'voids'} (${r.voids.map((v) => `${sig(v.volume)} ${r.dim === 3 ? 'mm³' : 'mm²'} at ${v.at.map(fmt).join(', ')}`).join('; ')}): powder or a core can't get out: open ${r.voids.length === 1 ? 'it' : 'each'} to the outside with an avoid region (an escape hole), or allow voids`;
|
|
328
|
+
return `${r.voids.length} enclosed ${r.voids.length === 1 ? 'void' : 'voids'} (${r.voids.map((v) => `${sig(v.volume)} ${r.dim === 3 ? 'mm³' : 'mm²'} at ${v.at.map(fmt).join(', ')}`).join('; ')})${r.vented ? ', left though voids were prevented (a keep region or the space walls it in)' : ''}: powder or a core can't get out: open ${r.voids.length === 1 ? 'it' : 'each'} to the outside with an avoid region (an escape hole), or allow voids`;
|
|
315
329
|
}
|
|
316
330
|
|
|
317
331
|
// An object's analyses for cad check: each problem's load cases on the part, and its volume against a target
|
package/lib/fittings.mjs
CHANGED
|
@@ -76,14 +76,19 @@ export function plasticNamed(raw, where = 'the project') {
|
|
|
76
76
|
if (['pla', 'petg'].includes(m)) return m;
|
|
77
77
|
let set = null; try { set = peekRuleSet(m); } catch {}
|
|
78
78
|
const lacks = ['strength', 'modulus', 'density'].filter((k) => !(typeof set?.rules?.[k]?.value === 'number'));
|
|
79
|
-
if (set && !lacks.length) return set;
|
|
80
79
|
const have = plastics().join(', ');
|
|
80
|
+
if (set && !lacks.length && rubber(set.rules)) throw new Error(`${where}: its material is ${JSON.stringify(raw)}, a rubber (its strength over its modulus is ${(set.rules.strength.value / set.rules.modulus.value).toFixed(2)}, a strain far past where its stiffness holds), and printed fittings are sized with sums for a stiff plastic that do not hold for it. Set the material to one of ${have}`);
|
|
81
|
+
if (set && !lacks.length) return set;
|
|
81
82
|
throw new Error(`${where}: its material is ${JSON.stringify(raw)}, and printed fittings are sized from their plastic's strength, modulus and density: ${set ? `rules/${m}.json gives no ${lacks.join(', ')}` : `the kit and this workspace have rule sets for ${have}, and there is no rules/${m}.json`}. Give rules/${m}.json with all three, or set the material to one of ${have}`);
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
// A rubber (TPU): its strength over its modulus, the strain where a stiff plastic yields, is past 0.5. Its stiffness
|
|
86
|
+
// holds only at small strains and it never yields as a plastic does, so the fittings' sums are not for it
|
|
87
|
+
const rubber = (r) => r.strength.value / r.modulus.value > 0.5;
|
|
88
|
+
|
|
84
89
|
/**
|
|
85
90
|
* The plastics a project can name: the rule sets (the workspace's rules/, then the kit's) that give strength, modulus,
|
|
86
|
-
* density and modulus_z, the modulus across a print's layers, which only a printed plastic's set gives.
|
|
91
|
+
* density and modulus_z, the modulus across a print's layers, which only a printed plastic's set gives; a rubber's is left out.
|
|
87
92
|
* @returns {string[]} their names, sorted
|
|
88
93
|
*/
|
|
89
94
|
export function plastics() {
|
|
@@ -92,7 +97,7 @@ export function plastics() {
|
|
|
92
97
|
let files = []; try { files = fs.readdirSync(d).filter((f) => f.endsWith('.json')); } catch { continue; }
|
|
93
98
|
for (const f of files) {
|
|
94
99
|
let r; try { r = JSON.parse(fs.readFileSync(path.join(d, f), 'utf8')).rules; } catch { continue; }
|
|
95
|
-
if (['strength', 'modulus', 'density', 'modulus_z'].every((k) => typeof r?.[k]?.value === 'number')) out.add(f.slice(0, -5));
|
|
100
|
+
if (['strength', 'modulus', 'density', 'modulus_z'].every((k) => typeof r?.[k]?.value === 'number') && !rubber(r)) out.add(f.slice(0, -5));
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
return [...out].sort();
|
package/lib/optimise.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { host, readJson } from './host.mjs';
|
|
|
12
12
|
import { paths, printerOf } from './workspace.mjs';
|
|
13
13
|
import { resolve, evaluate } from './rules.mjs';
|
|
14
14
|
import { located } from './errors.mjs';
|
|
15
|
-
import { discretise, optimise, outlines, surface, area, bounds, resultant, printable, refine, despike, reduce, undercuts, voids, grey } from '@rulecad/topopt';
|
|
15
|
+
import { discretise, optimise, outlines, surface, area, bounds, resultant, printable, refine, despike, reduce, undercuts, voids, grey, featureCells, thin } from '@rulecad/topopt';
|
|
16
16
|
import { islands } from '@rulecad/printcheck';
|
|
17
17
|
import { turn, mul, inv, placeItems, jointValues } from '@rulecad/model-link';
|
|
18
18
|
import { section, loops, slabLevels } from './mesh.mjs';
|
|
@@ -212,6 +212,11 @@ async function readOne(project, ref, link) {
|
|
|
212
212
|
};
|
|
213
213
|
// The build direction: a direction ('+z'), or a variable holding one
|
|
214
214
|
const overhang = p.overhang ? (typeof values[p.overhang] === 'string' ? values[p.overhang] : p.overhang) : null;
|
|
215
|
+
// The sides it is milled from, and a one-way mould's draw, likewise: or a variable holding them ('+z', '+z +x', or
|
|
216
|
+
// 'none': not milled, not cast), so a variant can switch the process
|
|
217
|
+
const named = (v) => (typeof v === 'string' && typeof values[v] === 'string' ? values[v] : v);
|
|
218
|
+
const millSides = (() => { const v = named(p.mill); if (typeof v !== 'string') return v; const list = v.trim().split(/[\s,]+/).filter(Boolean); return v === 'none' ? null : list.length > 1 ? list : v; })();
|
|
219
|
+
const castWay = (() => { const v = named(p.cast); return v === 'none' ? null : v; })();
|
|
215
220
|
// A teardrop's point: a direction, or up or down the build direction (+z, as drawn, when it's free)
|
|
216
221
|
const point = (t) => { const up = overhang && overhang !== 'none' ? overhang : '+z'; return t === 'up' ? up : t === 'down' ? (up[0] === '-' ? '+' : '-') + up[1] : t; };
|
|
217
222
|
const region = async (r) => {
|
|
@@ -247,12 +252,16 @@ async function readOne(project, ref, link) {
|
|
|
247
252
|
supports: await Promise.all(p.supports.map(async (s) => ({ ...(await region(s)), fix: s.fix || 'xyz'.slice(0, dim) }))),
|
|
248
253
|
loads: await Promise.all(p.loads.map(async (l) => ({ ...(await region(l)), force: pt(l.force), case: l.case || 'load' }))),
|
|
249
254
|
cases: Object.fromEntries(Object.entries(p.cases || {}).map(([k, w]) => [k, ev(w)])),
|
|
250
|
-
material: { E: m.modulus, nu: m.poisson }, ...(dim === 2 ? { thickness: ev(p.thickness) } : {}), cell: ev(p.cell), ...(p.volume != null ? { volume: ev(p.volume) } : {}), ...(p.stress != null ? { stress: ev(p.stress) } : {}), ...(p.strain != null ? { strain: ev(p.strain) } : {}),
|
|
255
|
+
material: { E: m.modulus, nu: m.poisson }, ...(dim === 2 ? { thickness: ev(p.thickness) } : {}), cell: ev(p.cell), ...(p.volume != null ? { volume: ev(p.volume) } : {}), ...(p.stress != null ? { stress: ev(p.stress) } : {}), ...(p.strain != null ? { strain: ev(p.strain) } : {}), ...(p.robust ? { robust: true } : {}),
|
|
251
256
|
...(p.filter != null ? { filter: ev(p.filter) } : lines > ev(p.cell) * 1.5 ? { filter: lines } : {}), ...(p.penal != null ? { penal: ev(p.penal) } : {}),
|
|
252
257
|
...(p.projection != null ? { projection: p.projection } : {}), ...(p.steps != null ? { steps: p.steps } : {}),
|
|
253
258
|
...(overhang && overhang !== 'none' ? { overhang } : {}),
|
|
254
259
|
// How it's made other than printed: milled from a side, cast in a mould; symmetric, extruded (topopt's filters)
|
|
255
|
-
...(
|
|
260
|
+
...(millSides ? { mill: millSides } : {}), ...(castWay ? { cast: typeof castWay === 'string' ? castWay : { draw: castWay.draw, ...(castWay.parting != null ? { parting: ev(castWay.parting) } : {}) } } : {}),
|
|
261
|
+
// (a tool or draft with the process switched off by its variable is left out with it; one with no such process
|
|
262
|
+
// at all goes on, for topopt to refuse by name)
|
|
263
|
+
...(p.tool != null && (millSides || !p.mill) ? { tool: ev(p.tool) } : {}), ...(p.draft != null && (castWay || !p.cast) ? { draft: ev(p.draft) } : {}), ...(p.voids === 'prevented' ? { voids: 'prevented' } : {}),
|
|
264
|
+
...(p.feature != null ? { feature: ev(p.feature) } : {}),
|
|
256
265
|
...(p.symmetry ? { symmetry: p.symmetry } : {}), ...(p.extrude ? { extrude: p.extrude } : {}),
|
|
257
266
|
// A mechanism: where the output should move, along one axis, against a spring; a spring the input pushes against
|
|
258
267
|
...(p.output ? { output: { ...(await region(p.output)), direction: pt(p.output.direction), ...(p.output.spring != null ? { spring: ev(p.output.spring) } : {}) } } : {}),
|
|
@@ -289,19 +298,36 @@ function holdEmpty(spec) {
|
|
|
289
298
|
}
|
|
290
299
|
// How a result is made, and what that process can't make in it: for a milled or cast part, the cells a tool or mould
|
|
291
300
|
// half could not reach (undercuts, none by construction unless an avoid region or the space's own shape leaves material between a cell and its side), how grey it is; where enclosed voids are
|
|
292
|
-
// refused (a powder bed print, a trapped core), each void with its volume (mm³, or mm² in 2D) and
|
|
301
|
+
// refused or prevented (a powder bed print, a trapped core), each void left with its volume (mm³, or mm² in 2D) and
|
|
302
|
+
// where it is, and with prevented that they were
|
|
293
303
|
function made(r, spec, density) {
|
|
294
304
|
const p = r.problem, out = {};
|
|
295
305
|
if (p.mill || p.cast) {
|
|
296
|
-
const c = spec.cast, from = p.mill || (typeof c === 'string' ? c : c.draw),
|
|
297
|
-
|
|
306
|
+
const c = spec.cast, from = p.mill || (typeof c === 'string' ? c : c.draw), tool = p.tool ? p.tool / spec.grid.h : undefined;
|
|
307
|
+
const u = undercuts(spec.grid, density, { from, ...(c && typeof c === 'object' ? { parting: c.parting } : {}), ...(p.draft ? { draft: p.draft } : {}) });
|
|
308
|
+
// With a tool's size: the cells it can't get its end into besides, in the design (none, by construction) and in
|
|
309
|
+
// avoid regions (a hole narrower than the tool: drilled, or a smaller tool)
|
|
310
|
+
if (tool) {
|
|
311
|
+
const hidden = new Set(u.cells), narrow = undercuts(spec.grid, density, { from, tool }).cells.filter((e) => !hidden.has(e));
|
|
312
|
+
out.narrow = { design: narrow.filter((e) => spec.passive[e] === 0).length, avoided: narrow.filter((e) => spec.passive[e] === -1).length };
|
|
313
|
+
}
|
|
314
|
+
// (a draft at the grid: a step out every whole number of layers in 1 / tan, so the angle made is atan of one over it)
|
|
315
|
+
const every = p.draft ? Math.max(1, Math.floor(1 / Math.tan((p.draft * Math.PI) / 180) + 1e-9)) : 0;
|
|
316
|
+
out.process = p.mill ? { mill: p.mill, ...(p.tool ? { tool: p.tool } : {}) } : { cast: typeof c === 'string' ? c : { draw: c.draw, parting: round(c.at, 3) }, ...(every ? { draft: p.draft, every, made: round((Math.atan(1 / every) * 180) / Math.PI, 2) } : {}) };
|
|
298
317
|
out.undercuts = u.count;
|
|
299
318
|
}
|
|
300
319
|
if (p.symmetry) out.symmetry = p.symmetry;
|
|
301
320
|
if (p.extrude) out.extrude = p.extrude;
|
|
302
321
|
// How grey it came out: a process or a tie can leave no clear part (a 2D section milled from its side)
|
|
303
322
|
if (p.mill || p.cast || p.symmetry || p.extrude) out.grey = round(grey(density, spec.passive), 3);
|
|
304
|
-
if (r.voids === 'refused') out.voids = voids(spec.grid, density, { origin: spec.origin }).map((v) => ({ volume: round(v.volume, 3), at: v.at.map((x) => round(x, 3)) }));
|
|
323
|
+
if (r.voids === 'refused' || r.voids === 'prevented') out.voids = voids(spec.grid, density, { origin: spec.origin }).map((v) => ({ volume: round(v.volume, 3), at: v.at.map((x) => round(x, 3)) }));
|
|
324
|
+
if (r.voids === 'prevented') out.vented = true;
|
|
325
|
+
// The thinnest member asked: the ball's radius on the grid, the width it holds members to (a cell, where the grid
|
|
326
|
+
// already does), and the solid cells left in members narrower (or on a square outside corner)
|
|
327
|
+
if (p.feature != null) {
|
|
328
|
+
const h = spec.grid.h, cells = featureCells(p.feature, h);
|
|
329
|
+
out.feature = { asked: p.feature, cells, holds: round((2 * cells + 1) * h, 3), thin: cells ? thin(spec.grid, density, { radius: cells }).count : 0 };
|
|
330
|
+
}
|
|
305
331
|
return out;
|
|
306
332
|
}
|
|
307
333
|
const digest = (x) => crypto.createHash('sha256').update(JSON.stringify(x)).digest('hex');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.97",
|
|
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": {
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"@rulecad/model-link": "^0.3.2",
|
|
66
66
|
"@rulecad/versions": "^0.1.6",
|
|
67
67
|
"@rulecad/shapes": "^0.4.9",
|
|
68
|
-
"@rulecad/rules": "^0.3.
|
|
68
|
+
"@rulecad/rules": "^0.3.30",
|
|
69
69
|
"@jscad/modeling": "^2.12.0",
|
|
70
70
|
"three": "^0.186.1",
|
|
71
71
|
"@rulecad/fea": "^0.2.14",
|
|
72
|
-
"@rulecad/topopt": "^0.3.
|
|
73
|
-
"@rulecad/flexures": "^0.5.
|
|
72
|
+
"@rulecad/topopt": "^0.3.8",
|
|
73
|
+
"@rulecad/flexures": "^0.5.17",
|
|
74
74
|
"@rulecad/gears": "^0.3.4",
|
|
75
75
|
"@rulecad/motors": "^0.1.6",
|
|
76
76
|
"@rulecad/fixings": "^0.1.8",
|
|
@@ -64,6 +64,10 @@
|
|
|
64
64
|
"$ref": "#/$defs/expr",
|
|
65
65
|
"description": "A strain limit in place of stress, a share of the length (0.02 is 2%), such as \"pla.strength / pla.modulus / 2\": the stress limit is it times the material's modulus. Most use for a mechanism, whose hinges bend"
|
|
66
66
|
},
|
|
67
|
+
"robust": {
|
|
68
|
+
"type": "boolean",
|
|
69
|
+
"description": "Optimise the design as made a little thin and a little thick too (its eroded and dilated copies, Wang, Lazarov and Sigmund 2011). With a stress or strain limit: the lightest layout that keeps the limit on all three. A mechanism: the one whose worst copy moves its output furthest, and with a limit, kept to it on all three (da Silva, Beck and Sigmund 2019); its supports, input and output stay solid. About three times the solves. Refused with a volume alone"
|
|
70
|
+
},
|
|
67
71
|
"filter": {
|
|
68
72
|
"$ref": "#/$defs/expr",
|
|
69
73
|
"description": "Filter radius, mm: about the thinnest member (default a cell and a half, and never under two of the printer's lines)"
|
|
@@ -190,14 +194,28 @@
|
|
|
190
194
|
"description": "One section all along this axis: a part cut from a bar, an extrusion or a plate of the profile"
|
|
191
195
|
},
|
|
192
196
|
"mill": {
|
|
193
|
-
"
|
|
194
|
-
"
|
|
195
|
-
|
|
197
|
+
"description": "Milled from this side ('+z': the tool cuts down from above): no undercuts, so a cell is as solid as every cell between it and the tool. Or from several sides, a setup each (['+z', '-z']: turned over for the second): a cell is left where no side's tool reaches it. Or a variable holding the side or sides ('+z', '+z -z') or 'none' (not milled), so a variant can switch it. Not with overhang or cast. Rules: mill-3axis",
|
|
198
|
+
"oneOf": [
|
|
199
|
+
{ "type": "string", "pattern": "^([+-][xyz]|[A-Za-z_][A-Za-z0-9_]*)$" },
|
|
200
|
+
{ "type": "array", "items": { "type": "string", "pattern": "^[+-][xyz]$" }, "minItems": 1, "uniqueItems": true }
|
|
201
|
+
]
|
|
202
|
+
},
|
|
203
|
+
"tool": {
|
|
204
|
+
"$ref": "#/$defs/expr",
|
|
205
|
+
"description": "With mill: the tool's radius, mm (a flat end mill). No pocket narrower than the tool, and every inside corner seen from the tool rounded to at least its radius. At the grid's resolution: the tool's end is the cells whose centres are within its radius, so give at least a cell. Rules: mill-3axis (an inside corner's radius)"
|
|
206
|
+
},
|
|
207
|
+
"feature": {
|
|
208
|
+
"$ref": "#/$defs/expr",
|
|
209
|
+
"description": "The thinnest member made, mm: for a printer, its two lines (x1c.wall_min). Members narrower go as the part is optimised, and cad optimise reports any left. Where a cell is as wide or wider, every member already is and nothing changes; up to three cells across it is held by an opening filter; wider is refused by name with the cell size that would hold it. Rules: x1c (wall_min, line)"
|
|
210
|
+
},
|
|
211
|
+
"draft": {
|
|
212
|
+
"$ref": "#/$defs/expr",
|
|
213
|
+
"description": "With cast: the draft, degrees. The part narrows towards the side it is drawn off: a wall steps out a cell every whole number of layers in 1 / tan(draft), so at least this draft; refused by name when the grid is too shallow for one step. Rules: mould-injection"
|
|
196
214
|
},
|
|
197
215
|
"cast": {
|
|
198
|
-
"description": "Cast or moulded: in a mould drawn off one way ('+z'), or in two halves drawn off both ways along an axis from a parting plane. No undercuts from the draw
|
|
216
|
+
"description": "Cast or moulded: in a mould drawn off one way ('+z'), or in two halves drawn off both ways along an axis from a parting plane. No undercuts from the draw, and with draft the walls taper. Not with overhang or mill. Rules: mould-injection",
|
|
199
217
|
"oneOf": [
|
|
200
|
-
{ "type": "string", "pattern": "^[+-][xyz]$" },
|
|
218
|
+
{ "type": "string", "pattern": "^([+-][xyz]|[A-Za-z_][A-Za-z0-9_]*)$", "description": "The way it is drawn off, or a variable holding it (or 'none': not cast)" },
|
|
201
219
|
{
|
|
202
220
|
"type": "object",
|
|
203
221
|
"additionalProperties": false,
|
|
@@ -210,8 +228,8 @@
|
|
|
210
228
|
]
|
|
211
229
|
},
|
|
212
230
|
"voids": {
|
|
213
|
-
"enum": ["allowed", "refused"],
|
|
214
|
-
"description": "Enclosed voids in the result: allowed (the default)
|
|
231
|
+
"enum": ["allowed", "refused", "prevented"],
|
|
232
|
+
"description": "Enclosed voids in the result: allowed (the default); refused, for metal powder bed printing (powder left inside can't be got out) or a casting's trapped core: cad optimise then reports each as an error with its volume and where it is; or prevented: the optimiser keeps every void open to the outside as it goes (a virtual temperature, kept under a cap: an enclosed void runs hot), and any left are still reported as errors. Prevented is for the stiffest part that fills a volume, not a mechanism or a stress limit. Rules: dmls"
|
|
215
233
|
},
|
|
216
234
|
"output": {
|
|
217
235
|
"type": "object",
|