@rulecad/cad 0.6.0 → 0.7.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/AGENTS.md +3 -0
- package/README.md +20 -0
- package/bin/cad.mjs +36 -21
- package/lib/design.mjs +6 -5
- package/lib/optimise.mjs +100 -31
- package/package.json +4 -4
- package/schemas/problem.schema.json +313 -42
package/AGENTS.md
CHANGED
|
@@ -86,6 +86,9 @@ variable says which rule it comes from. Follow these steps; they're what makes a
|
|
|
86
86
|
material's rule set. `npx cad optimise <project>/<problem>` and **look at the picture** in `.preview/`.
|
|
87
87
|
- A design reads the result through a `problem` variable and builds it with `v.shapes.optimisedOutline(...)`. Add an
|
|
88
88
|
`analysis` to the object so `cad check` reports its stiffness; report those numbers with their load and material.
|
|
89
|
+
- Solid parts (brackets, joints) are 3D problems: regions with a z, a named part as the space if it helps. Set
|
|
90
|
+
`"overhang"` to the way up it will print, so the result needs no supports, and give horizontal bosses and holes a
|
|
91
|
+
`teardrop`. Build with `v.shapes.optimisedSolid(...)` and `"engine": "manifold"`; look at the four views.
|
|
89
92
|
- Say plainly that the analysis is coarse and the material values are data-sheet figures: anything that could hurt
|
|
90
93
|
someone if it broke needs testing, not just a check.
|
|
91
94
|
|
package/README.md
CHANGED
|
@@ -378,6 +378,26 @@ export function main (v) {
|
|
|
378
378
|
`optimisedOutline` gives the outline as a 2D shape, its keep regions added and avoid regions cut exactly, so bolt
|
|
379
379
|
holes come out true.
|
|
380
380
|
|
|
381
|
+
### Solid parts (3D)
|
|
382
|
+
|
|
383
|
+
A problem whose regions have a z is solid. It has no thickness, and takes more kinds of region:
|
|
384
|
+
- **A box:** `size`.
|
|
385
|
+
- **A cylinder:** `r`, `length` and `axis`. Along x or y it can be a teardrop: `"teardrop": "-z"` for a boss,
|
|
386
|
+
`"+z"` for a hole. It gets a 45° point, so it prints.
|
|
387
|
+
- **A ball:** `r`.
|
|
388
|
+
- **A named part of another design in the project:** `{ "part": "envelope.body" }`.
|
|
389
|
+
|
|
390
|
+
Supports and loads can be any region; a force has x, y and z. `"overhang": "+z"` keeps only material that prints
|
|
391
|
+
without supports standing that way up (a variable holding `"+z"` or `"none"` works too, so a variant can switch it).
|
|
392
|
+
|
|
393
|
+
`cad optimise` draws the result's four views in `.preview/`. A design builds the result with
|
|
394
|
+
`v.shapes.optimisedSolid(v.problems[v.problem], { ops: v.ops })`, which adds the keep regions and cuts the avoid
|
|
395
|
+
regions exactly. The surface is a big mesh, so set the object's `"engine": "manifold"`. An `analysis` of a solid part
|
|
396
|
+
voxelises it on the problem's grid.
|
|
397
|
+
|
|
398
|
+
Grids in 3D are solved by multigrid. A 16 × 16 × 40 grid (about 10,000 cubes) takes a second or two a step, so a whole
|
|
399
|
+
optimisation takes a few minutes. The result is kept, so it's worked out once.
|
|
400
|
+
|
|
381
401
|
### Analysis
|
|
382
402
|
|
|
383
403
|
Any flat part, optimised or not, can be checked under a problem's supports and loads. An object's `analysis` names
|
package/bin/cad.mjs
CHANGED
|
@@ -110,8 +110,9 @@ function report(findings, about = {}) {
|
|
|
110
110
|
const say = (...a) => { if (!opt('json')) console.log(...a); }; // text output that --json leaves out
|
|
111
111
|
|
|
112
112
|
const sig = (n) => (Number.isFinite(n) ? String(Number(n.toPrecision(3))) : String(n)); // three significant figures
|
|
113
|
-
// cad optimise: run a problem (with a progress line), then report it and draw it
|
|
114
|
-
|
|
113
|
+
// cad optimise: run a problem (with a progress line), then report it and draw it: a 2D layout as an SVG of its
|
|
114
|
+
// densities, a 3D one as the preview's four views of its surface
|
|
115
|
+
async function optimiseProblem(ref) {
|
|
115
116
|
const [project, name] = String(ref).split('/');
|
|
116
117
|
if (!project || !name) throw new Error('usage: cad optimise <project>/<problem>[:variant]');
|
|
117
118
|
const file = problemFile(project, name.split(':')[0]);
|
|
@@ -120,36 +121,49 @@ function optimiseProblem(ref) {
|
|
|
120
121
|
if (bad.length) { report(bad); process.exitCode = 1; return; }
|
|
121
122
|
}
|
|
122
123
|
const live = !opt('json') && process.stderr.isTTY;
|
|
123
|
-
const r = optimised(project, name, { fresh: !!opt('fresh'), onStep: (s) => live && process.stderr.write(`\r\x1b[Kstep ${s.step}/${s.steps} compliance ${s.compliance.toPrecision(5)} N·mm change ${s.change.toFixed(3)} sharpness ${s.beta}`) });
|
|
124
|
+
const r = await optimised(project, name, { fresh: !!opt('fresh'), onStep: (s) => live && process.stderr.write(`\r\x1b[Kstep ${s.step}/${s.steps} compliance ${s.compliance.toPrecision(5)} N·mm change ${s.change.toFixed(3)} sharpness ${s.beta}`) });
|
|
124
125
|
if (live) process.stderr.write('\r\x1b[K');
|
|
125
|
-
const
|
|
126
|
-
const lines = [`${p.material.name}
|
|
127
|
-
`${fmt(r.volume * 100)}% of the space, ${
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
const p = await readProblem(project, name), cells = r.dim === 3 ? `${r.grid.nx} × ${r.grid.ny} × ${r.grid.nz}` : `${r.grid.nx} × ${r.grid.ny}`;
|
|
127
|
+
const lines = [`${p.material.name}${r.dim === 2 ? `, ${fmt(r.thickness)} mm thick` : ''}: ${r.cases.map((c) => `${c.name} ${sig(c.deflection)} mm (${sig(c.stiffness)} N/mm)`).join(', ')}`,
|
|
128
|
+
`${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}` : ''}`];
|
|
129
|
+
let out;
|
|
130
|
+
if (r.dim === 3) {
|
|
131
|
+
out = paths.preview(project, `${name.replace(':', '-')}-optimised.png`);
|
|
132
|
+
const triangles = r.mesh.faces.map((f) => f.map((i) => r.mesh.vertices[i]));
|
|
133
|
+
await preview([{ name: 'body', label: r.title, triangles }], { title: r.title, meta: lines.join(' · '), out });
|
|
134
|
+
} else {
|
|
135
|
+
out = paths.preview(project, `${name.replace(':', '-')}-optimised.svg`);
|
|
136
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
137
|
+
fs.writeFileSync(out, picture(r, { title: r.title, lines }));
|
|
138
|
+
}
|
|
139
|
+
if (opt('json')) return console.log(JSON.stringify((({ density, history, mesh, ...x }) => x)(r), null, 2));
|
|
131
140
|
console.log(`${r.title}${r.cached ? ' (cached)' : ` (${fmt(r.seconds)} s)`}`);
|
|
132
141
|
for (const c of r.cases) console.log(` ${c.name}: moves ${sig(c.deflection)} mm along its load, ${sig(c.stiffness)} N/mm`);
|
|
133
|
-
console.log(` ${fmt(r.volume * 100)}% of the space filled
|
|
134
|
-
console.log(` ${r.
|
|
142
|
+
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}` : ''}`);
|
|
143
|
+
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)`);
|
|
144
|
+
console.log(` ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? ', settled' : ': stopped before it settled (raise steps)'}`);
|
|
135
145
|
console.log(out);
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
// An object's analyses for cad check: each problem's load cases on the part, and its volume against a target
|
|
139
|
-
function analyses(b, d, tag) {
|
|
149
|
+
async function analyses(b, d, tag) {
|
|
140
150
|
const lookup = (n) => { const v = n.split('.').reduce((o, k) => (o == null ? o : o[k]), b.values); if (typeof v !== 'number') throw new Error(`analysis: "${n}" isn't a number`); return v; };
|
|
141
|
-
|
|
151
|
+
const all = [];
|
|
152
|
+
for (const a of b.object.analysis || []) all.push(...await (async () => {
|
|
142
153
|
const part = a.part ? b.parts.find((p) => p.name === a.part) : b.parts.find((p) => p.role !== 'support');
|
|
143
154
|
if (!part) return [{ level: 'fail', text: `analysis: no part "${a.part}"`, code: 'fea.part' }];
|
|
144
|
-
const r = analysePart(part.triangles, d.project, a.problem), m = r.material, limit = a.max_deflection != null ? evaluate(a.max_deflection, lookup) : null;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
155
|
+
const r = await analysePart(part.triangles, d.project, a.problem), m = r.material, limit = a.max_deflection != null ? evaluate(a.max_deflection, lookup) : null;
|
|
156
|
+
let out = null;
|
|
157
|
+
if (r.dim !== 3) { // a flat part's picture: its cells as analysed, with the supports and loads
|
|
158
|
+
out = paths.preview(d.project, `${d.name}${tag}-analysis-${a.problem.replace(':', '-')}.svg`);
|
|
159
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
160
|
+
fs.writeFileSync(out, picture({ ...r, ...(await readProblem(d.project, a.problem)).problem }, { title: `${b.object.title || d.name}: ${a.problem}`, lines: r.cases.map((c) => `${c.name}: ${sig(c.deflection)} mm, ${sig(c.stiffness)} N/mm, peak stress ${sig(c.stress)} MPa`) }));
|
|
161
|
+
}
|
|
148
162
|
const found = r.cases.map((c) => {
|
|
149
163
|
const safety = m.strength ? `, peak stress ${sig(c.stress)} MPa (${sig(m.strength / c.stress)}× under ${m.name}'s strength; coarse)` : '';
|
|
150
164
|
const text = `${a.problem} ${c.name}: moves ${sig(c.deflection)} mm under ${fmt(c.force)} N, ${sig(c.stiffness)} N/mm${safety}`;
|
|
151
165
|
const values = { deflection: c.deflection, force: c.force, stiffness: c.stiffness, stress: c.stress, ...(limit != null ? { limit } : {}) };
|
|
152
|
-
return { level: limit == null ? 'info' : c.deflection <= limit ? 'pass' : 'fail', text: limit == null ? text : `${text} (at most ${fmt(limit)})`, code: 'fea.deflection', values, refs: { problem: a.problem, part: part.name, picture: path.relative(WS, out) } };
|
|
166
|
+
return { level: limit == null ? 'info' : c.deflection <= limit ? 'pass' : 'fail', text: limit == null ? text : `${text} (at most ${fmt(limit)})`, code: 'fea.deflection', values, refs: { problem: a.problem, part: part.name, ...(out ? { picture: path.relative(WS, out) } : {}) } };
|
|
153
167
|
});
|
|
154
168
|
const grams = m.density ? ` (${fmt((r.volume / 1000) * m.density)} g of ${m.name})` : '';
|
|
155
169
|
if (a.volume != null) {
|
|
@@ -157,7 +171,8 @@ function analyses(b, d, tag) {
|
|
|
157
171
|
found.push({ level: Math.abs(off) <= tol ? 'pass' : 'fail', text: `volume ${fmt(r.volume)} mm³${grams}: ${off >= 0 ? '+' : ''}${fmt(off * 100)}% from ${fmt(want)} (within ${fmt(tol * 100)}%)`, code: 'fea.volume', values: { volume: r.volume, target: want, off } });
|
|
158
172
|
} else found.push({ level: 'info', text: `volume ${fmt(r.volume)} mm³${grams}`, code: 'fea.volume', values: { volume: r.volume } });
|
|
159
173
|
return found;
|
|
160
|
-
});
|
|
174
|
+
})());
|
|
175
|
+
return all;
|
|
161
176
|
}
|
|
162
177
|
|
|
163
178
|
async function main() {
|
|
@@ -217,7 +232,7 @@ async function main() {
|
|
|
217
232
|
if (cmd === 'why') return explainValue(ref);
|
|
218
233
|
if (cmd === 'set') return editVariables(ref);
|
|
219
234
|
if (cmd === 'add') return editAssembly(args[1], args[2]);
|
|
220
|
-
if (cmd === 'optimise' || cmd === 'optimize') return optimiseProblem(ref);
|
|
235
|
+
if (cmd === 'optimise' || cmd === 'optimize') return await optimiseProblem(ref);
|
|
221
236
|
if (isAssembly(ref)) return assembly(cmd, ref);
|
|
222
237
|
const [base, at] = ref.split('@');
|
|
223
238
|
const d = at ? materialise(locate(base), at) : locate(ref), set = sets();
|
|
@@ -264,7 +279,7 @@ async function main() {
|
|
|
264
279
|
...(b.object.role === 'reference'
|
|
265
280
|
? [{ level: 'pass', text: `a reference (${(await import('@rulecad/printcheck')).bounds(b.triangles).size.map(fmt).join(' × ')} mm), not printed: no print checks`, code: 'print.reference' }]
|
|
266
281
|
: check(b.triangles, printer(b, d), { parts: b.parts })),
|
|
267
|
-
...analyses(b, d, tag),
|
|
282
|
+
...(await analyses(b, d, tag)),
|
|
268
283
|
], { object: `${d.project}/${d.name}`, title, version, ...(Object.keys(set).length ? { set } : {}), orientation: b.object.orientation, parts: b.parts.map((p) => ({ name: p.name, role: p.role || 'part' })) });
|
|
269
284
|
if (b.object.orientation) say(` orientation: ${b.object.orientation}`);
|
|
270
285
|
if (b.parts.length > 1) say(` parts: ${b.parts.map((p) => `${p.name}${p.role === 'support' ? ' (support)' : ''}`).join(', ')}`);
|
package/lib/design.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import { runSandboxed, sandboxed } from './sandbox.mjs';
|
|
|
21
21
|
export { polygons };
|
|
22
22
|
import fs from 'node:fs';
|
|
23
23
|
import path from 'node:path';
|
|
24
|
-
import { pathToFileURL } from 'node:url';
|
|
24
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
25
25
|
import { createRequire } from 'node:module';
|
|
26
26
|
import crypto from 'node:crypto';
|
|
27
27
|
import { resolve, loadRuleSet } from './rules.mjs';
|
|
@@ -91,12 +91,12 @@ export function layoutsOf(d, object) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// The optimised layouts an object's problem variables pick, by name, for v.problems
|
|
94
|
-
export function problemsOf(d, object, values) {
|
|
94
|
+
export async function problemsOf(d, object, values) {
|
|
95
95
|
const out = {};
|
|
96
96
|
for (const [name, v] of Object.entries(object.variables || {})) if (v.type === 'problem') {
|
|
97
97
|
const ref = values[name];
|
|
98
98
|
if (!out[ref]) {
|
|
99
|
-
const r = optimised(d.project, ref, { onStep: (s) => s.step === 1 && console.error(`optimising ${ref} (once: the result is cached until the problem changes)…`) });
|
|
99
|
+
const r = await optimised(d.project, ref, { onStep: (s) => s.step === 1 && console.error(`optimising ${ref} (once: the result is cached until the problem changes)…`) });
|
|
100
100
|
out[ref] = forDesign(r);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -115,7 +115,8 @@ const CACHE = paths.cache('builds'), CACHE_VERSION = 2;
|
|
|
115
115
|
const source = (f) => fs.readFileSync(new URL(f, import.meta.url), 'utf8');
|
|
116
116
|
// What every build is made with: this code, the shape helpers and JSCAD's version (an upgrade rebuilds everything);
|
|
117
117
|
// boards also with the board engine (engineId: its code and tscircuit's version), loaded only for boards
|
|
118
|
-
const
|
|
118
|
+
const shapesDir = path.dirname(fileURLToPath(import.meta.resolve('@rulecad/shapes')));
|
|
119
|
+
const own = source(import.meta.url) + fs.readdirSync(shapesDir).filter((f) => f.endsWith('.mjs')).sort().map((f) => source(pathToFileURL(path.join(shapesDir, f)).href)).join('') + packageVersion('@jscad/modeling'); // every shapes module, not just its entry
|
|
119
120
|
export const pcbEngine = () => import('@rulecad/pcb').catch((e) => {
|
|
120
121
|
if (e.code === 'ERR_MODULE_NOT_FOUND' && /@rulecad\/pcb/.test(e.message)) throw new Error('boards need the board engine: npm install @rulecad/pcb');
|
|
121
122
|
throw e;
|
|
@@ -150,7 +151,7 @@ export async function build(d, set = {}, { mirror = false } = {}) {
|
|
|
150
151
|
if (Object.keys(files).length) values.layouts = Object.fromEntries(Object.entries(files).map(([n, l]) => [n, { ...l, keys: keys(l), width: width(l), depth: depth(l) }]));
|
|
151
152
|
// Optimised layouts: a "type": "problem" variable picks a problem in the project's problems/; the design gets the
|
|
152
153
|
// one it picked as v.problems[name] (lib/optimise.mjs), optimised the first time and cached after
|
|
153
|
-
const problems = problemsOf(d, object, values);
|
|
154
|
+
const problems = await problemsOf(d, object, values);
|
|
154
155
|
if (Object.keys(problems).length) values.problems = problems;
|
|
155
156
|
|
|
156
157
|
// The cache: everything the build is made from. A hit skips running the design (and its booleans) altogether
|
package/lib/optimise.mjs
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
// Optimisation problems and analysis: problems/<name>.json in a project describes a
|
|
2
|
-
// material may go, what stays solid or empty, supports, loads, material
|
|
3
|
-
// and @rulecad/fea analyses any
|
|
4
|
-
// The problem file is the source: a result is derived from it, cached by everything it's made from, and
|
|
5
|
-
// when one of those changes. A name may pick a variant: lever:both.
|
|
1
|
+
// Optimisation problems and analysis: problems/<name>.json in a project describes a part to optimise, flat (2D) or
|
|
2
|
+
// solid (3D): where material may go, what stays solid or empty, supports, loads, material. @rulecad/topopt finds the
|
|
3
|
+
// stiffest layout, and @rulecad/fea analyses any part under the same problem's loads (an object's "analysis", run by
|
|
4
|
+
// cad check). The problem file is the source: a result is derived from it, cached by everything it's made from, and
|
|
5
|
+
// remade only when one of those changes. A name may pick a variant: lever:both. A 3D region can be a named part of
|
|
6
|
+
// another design in the project ({ "part": "envelope.body" }), as it's built.
|
|
6
7
|
import fs from 'node:fs';
|
|
7
8
|
import path from 'node:path';
|
|
8
9
|
import crypto from 'node:crypto';
|
|
9
10
|
import { host } from './host.mjs';
|
|
10
11
|
import { paths } from './workspace.mjs';
|
|
11
|
-
import { resolve,
|
|
12
|
+
import { resolve, evaluate } from './rules.mjs';
|
|
12
13
|
import { located } from './errors.mjs';
|
|
13
|
-
import { discretise, optimise, outlines, area } from '@rulecad/topopt';
|
|
14
|
+
import { discretise, optimise, outlines, surface, area } from '@rulecad/topopt';
|
|
14
15
|
import { grid as makeGrid, analyse, positions } from '@rulecad/fea';
|
|
15
16
|
|
|
16
|
-
const VERSION =
|
|
17
|
+
const VERSION = 2, source = (m) => fs.readFileSync(new URL(import.meta.resolve(m)), 'utf8'); // the solver's code: a change remakes results
|
|
17
18
|
export const problemFile = (project, name) => path.join(paths.project(project), 'problems', `${name}.json`);
|
|
18
19
|
export const hasProblem = (project, ref) => host.exists(problemFile(project, String(ref).split(':')[0]));
|
|
19
20
|
|
|
@@ -21,7 +22,7 @@ export const hasProblem = (project, ref) => host.exists(problemFile(project, Str
|
|
|
21
22
|
* A problem with every expression worked out: what @rulecad/topopt takes, with its material and settings.
|
|
22
23
|
* @param {string} project @param {string} ref name, or name:variant
|
|
23
24
|
*/
|
|
24
|
-
export function readProblem(project, ref) {
|
|
25
|
+
export async function readProblem(project, ref) {
|
|
25
26
|
const [name, variant] = String(ref).split(':'), file = problemFile(project, name);
|
|
26
27
|
if (!host.exists(file)) throw new Error(`no problem "${name}" (projects/${project}/problems/${name}.json)`);
|
|
27
28
|
const p = JSON.parse(host.readText(file));
|
|
@@ -35,56 +36,108 @@ export function readProblem(project, ref) {
|
|
|
35
36
|
return v;
|
|
36
37
|
};
|
|
37
38
|
const ev = (x) => evaluate(x, lookup), pt = (a) => a.map(ev);
|
|
38
|
-
|
|
39
|
+
// A named part of another design in the project, as triangles (built with its defaults)
|
|
40
|
+
const parts = new Map();
|
|
41
|
+
const part = async (ref) => {
|
|
42
|
+
if (!parts.has(ref)) {
|
|
43
|
+
const [object, partName] = ref.split('.'), { build, locate } = await import('./design.mjs');
|
|
44
|
+
const b = await build(locate(`${project}/${object}`)), found = partName ? b.parts.find((q) => q.name === partName) : b.parts.find((q) => q.role !== 'support');
|
|
45
|
+
if (!found) throw new Error(`${path.basename(file)}: ${object} has no part "${partName}" (parts: ${b.parts.map((q) => q.name).join(', ')})`);
|
|
46
|
+
parts.set(ref, found.triangles);
|
|
47
|
+
}
|
|
48
|
+
return parts.get(ref);
|
|
49
|
+
};
|
|
50
|
+
const region = async (r) => {
|
|
51
|
+
if (r.part) return { triangles: await part(r.part), part: r.part };
|
|
52
|
+
if (r.points) return { points: r.points.map(pt) };
|
|
53
|
+
if (r.size) return { at: pt(r.at), size: r.size.map(ev) };
|
|
54
|
+
if (r.length != null) return { at: pt(r.at), r: ev(r.r), length: ev(r.length), axis: r.axis || 'z', ...(r.teardrop ? { teardrop: r.teardrop } : {}) };
|
|
55
|
+
return { at: pt(r.at), ...(r.r != null ? { r: ev(r.r) } : {}) };
|
|
56
|
+
};
|
|
57
|
+
const regions = (list) => Promise.all([list || []].flat().map(region));
|
|
39
58
|
const m = values[p.material];
|
|
40
59
|
if (typeof m?.modulus !== 'number' || typeof m?.poisson !== 'number') throw new Error(`material ${p.material}: its rule set needs modulus (MPa) and poisson`);
|
|
60
|
+
const space = await regions(p.space), dim = space[0].triangles || space[0].length != null || (space[0].size || space[0].at)?.length === 3 ? 3 : 2;
|
|
61
|
+
// The build direction: a direction ('+z'), or a variable holding one
|
|
62
|
+
const overhang = p.overhang ? (typeof values[p.overhang] === 'string' ? values[p.overhang] : p.overhang) : null;
|
|
41
63
|
const problem = {
|
|
42
|
-
space
|
|
43
|
-
supports: p.supports.map((s) => ({
|
|
44
|
-
loads: p.loads.map((l) => ({
|
|
64
|
+
space, keep: await regions(p.keep), avoid: await regions(p.avoid),
|
|
65
|
+
supports: await Promise.all(p.supports.map(async (s) => ({ ...(await region(s)), fix: s.fix || 'xyz'.slice(0, dim) }))),
|
|
66
|
+
loads: await Promise.all(p.loads.map(async (l) => ({ ...(await region(l)), force: pt(l.force), case: l.case || 'load' }))),
|
|
45
67
|
cases: Object.fromEntries(Object.entries(p.cases || {}).map(([k, w]) => [k, ev(w)])),
|
|
46
|
-
material: { E: m.modulus, nu: m.poisson }, thickness: ev(p.thickness), cell: ev(p.cell), volume: ev(p.volume),
|
|
68
|
+
material: { E: m.modulus, nu: m.poisson }, ...(dim === 2 ? { thickness: ev(p.thickness) } : {}), cell: ev(p.cell), volume: ev(p.volume),
|
|
47
69
|
...(p.filter != null ? { filter: ev(p.filter) } : {}), ...(p.penal != null ? { penal: ev(p.penal) } : {}),
|
|
48
70
|
...(p.projection != null ? { projection: p.projection } : {}), ...(p.steps != null ? { steps: p.steps } : {}),
|
|
71
|
+
...(overhang && overhang !== 'none' ? { overhang } : {}),
|
|
49
72
|
};
|
|
73
|
+
if (dim === 2 && !(problem.thickness > 0)) throw new Error(`${path.basename(file)}: a flat (2D) problem needs a thickness`);
|
|
50
74
|
const outline = { smooth: p.outline?.smooth ?? 4, minArea: p.outline?.min_area != null ? ev(p.outline.min_area) : problem.cell ** 2 * 2 };
|
|
51
|
-
return { ref, name, variant, file, title: p.title || name, material: { name: p.material, ...m }, problem, outline };
|
|
75
|
+
return { ref, name, variant, file, dim, title: p.title || name, material: { name: p.material, ...m }, problem, outline };
|
|
52
76
|
}
|
|
53
77
|
|
|
54
78
|
/**
|
|
55
|
-
* The optimised layout for a problem, from the cache when nothing it depends on has changed.
|
|
79
|
+
* The optimised layout for a problem, from the cache when nothing it depends on has changed. A 2D result has outlines
|
|
80
|
+
* (closed loops in mm); a 3D one has a mesh ({ vertices, faces }, a closed surface in mm).
|
|
56
81
|
* @param {string} project @param {string} ref
|
|
57
82
|
* @param {{ onStep?: Function, fresh?: boolean }} [options] fresh: run it even if it's cached
|
|
58
83
|
*/
|
|
59
|
-
export function optimised(project, ref, { onStep, fresh = false } = {}) {
|
|
60
|
-
const r = readProblem(project, ref);
|
|
61
|
-
const
|
|
62
|
-
|
|
84
|
+
export async function optimised(project, ref, { onStep, fresh = false } = {}) {
|
|
85
|
+
const r = await readProblem(project, ref), topopt = source('@rulecad/topopt'), [solver] = topopt.split('// ---------- shapes from results ----------');
|
|
86
|
+
const digest = (x) => crypto.createHash('sha256').update(JSON.stringify(x)).digest('hex');
|
|
87
|
+
// Two keeps: the densities, by the problem and the code that decides them (the slow part), and the shape drawn from
|
|
88
|
+
// them, by everything: a change to how shapes are drawn redraws them without optimising again
|
|
89
|
+
const hash = digest([VERSION, r.problem, r.outline, topopt, source('@rulecad/fea')]), file = paths.cache('optimise', `${hash}.json`);
|
|
63
90
|
if (!fresh && !process.env.CAD_NO_CACHE && host.exists(file)) return { ...JSON.parse(host.readText(file)), cached: true };
|
|
64
|
-
const spec = discretise(r.problem);
|
|
65
|
-
const o = optimise(spec, { onStep });
|
|
66
|
-
|
|
91
|
+
const spec = discretise(r.problem), densities = paths.cache('densities', `${digest([VERSION, r.problem, solver, source('@rulecad/fea')])}.json`);
|
|
92
|
+
const o = !fresh && !process.env.CAD_NO_CACHE && host.exists(densities) ? (({ density, ...x }) => ({ ...x, density: Float64Array.from(density) }))(JSON.parse(host.readText(densities))) : optimise(spec, { onStep });
|
|
93
|
+
if (!host.exists(densities)) host.writeText(densities, JSON.stringify({ ...o, density: Array.from(o.density) }));
|
|
94
|
+
// Regions as data: a part's triangles are named, not copied
|
|
95
|
+
const named = (list) => list.map(({ triangles, ...x }) => x);
|
|
96
|
+
const shape = r.dim === 2 ? (() => {
|
|
97
|
+
const loops = outlines(spec.grid, o.density, spec.origin, r.outline);
|
|
98
|
+
return { outlines: loops.map((l) => l.map(([x, y]) => [round(x), round(y)])), area: loops.reduce((s, l) => s + area(l), 0) };
|
|
99
|
+
})() : (() => {
|
|
100
|
+
// The surface's level, found so the solid holds as much material as the optimised densities do (drawn at 0.5,
|
|
101
|
+
// thin members come out thinner than they are)
|
|
102
|
+
const want = o.density.reduce((t, d) => t + d, 0) * spec.grid.h ** 3, at = (iso) => surface(spec.grid, o.density, spec.origin, { smooth: r.outline.smooth, iso });
|
|
103
|
+
let lo = 0.2, hi = 0.8, best = at(0.5), iso = 0.5;
|
|
104
|
+
for (let k = 0; k < 10 && Math.abs(meshVolume(best.vertices, best.faces) / want - 1) > 0.003; k++) {
|
|
105
|
+
if (meshVolume(best.vertices, best.faces) < want) hi = iso; else lo = iso; // a lower level encloses more
|
|
106
|
+
iso = (lo + hi) / 2; best = at(iso);
|
|
107
|
+
}
|
|
108
|
+
const { vertices, faces } = best;
|
|
109
|
+
return { mesh: { vertices: vertices.map((v) => v.map((c) => round(c, 3))), faces }, solid: meshVolume(vertices, faces), iso };
|
|
110
|
+
})();
|
|
67
111
|
const result = {
|
|
68
|
-
problem: ref, title: r.title, hash, material: r.material.name, thickness: r.problem.thickness,
|
|
69
|
-
grid: spec.grid, origin: spec.origin, regions: spec.regions,
|
|
70
|
-
|
|
112
|
+
problem: ref, title: r.title, hash, dim: r.dim, material: r.material.name, ...(r.dim === 2 ? { thickness: r.problem.thickness } : {}),
|
|
113
|
+
grid: spec.grid, origin: spec.origin, regions: { keep: named(spec.regions.keep), avoid: named(spec.regions.avoid) }, ...shape,
|
|
114
|
+
volume: o.volume, compliance: o.compliance, cases: o.cases, overhang: r.problem.overhang || null,
|
|
71
115
|
steps: o.steps, converged: o.converged, seconds: o.seconds, history: o.history, density: Array.from(o.density, (d) => round(d, 3)),
|
|
72
|
-
supports: r.problem.supports, loads: r.problem.loads,
|
|
116
|
+
supports: named(r.problem.supports), loads: named(r.problem.loads),
|
|
73
117
|
};
|
|
74
118
|
host.writeText(file, JSON.stringify(result));
|
|
75
119
|
return result;
|
|
76
120
|
}
|
|
77
121
|
|
|
122
|
+
// A closed mesh's volume (mm³), by the divergence theorem
|
|
123
|
+
function meshVolume(vertices, faces) {
|
|
124
|
+
let v = 0;
|
|
125
|
+
for (const [i, j, k] of faces) { const a = vertices[i], b = vertices[j], c = vertices[k]; v += (a[0] * (b[1] * c[2] - b[2] * c[1]) - a[1] * (b[0] * c[2] - b[2] * c[0]) + a[2] * (b[0] * c[1] - b[1] * c[0])) / 6; }
|
|
126
|
+
return v;
|
|
127
|
+
}
|
|
128
|
+
|
|
78
129
|
// What a design gets as v.problems[name]: the outlines and regions to build from, and the numbers to report
|
|
79
130
|
export const forDesign = ({ density, history, ...r }) => r;
|
|
80
131
|
|
|
81
132
|
/**
|
|
82
|
-
* Analyse a
|
|
83
|
-
* each cell is as solid as the share of the problem's thickness the part fills above it.
|
|
133
|
+
* Analyse a part under a problem's supports and loads, on its grid. A flat part (2D problem: triangles, z up, the
|
|
134
|
+
* plate lying on the bed): each cell is as solid as the share of the problem's thickness the part fills above it. A
|
|
135
|
+
* solid part (3D): each cube is solid if its centre is inside the part.
|
|
84
136
|
* @param {number[][][]} triangles @param {string} project @param {string} ref
|
|
85
137
|
*/
|
|
86
|
-
export function analysePart(triangles, project, ref) {
|
|
87
|
-
const r = readProblem(project, ref), { problem } = r, h = problem.cell;
|
|
138
|
+
export async function analysePart(triangles, project, ref) {
|
|
139
|
+
const r = await readProblem(project, ref), { problem } = r, h = problem.cell;
|
|
140
|
+
if (r.dim === 3) return analyseSolid(triangles, r);
|
|
88
141
|
// The grid covers the part and the problem's space
|
|
89
142
|
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
90
143
|
for (const t of triangles) for (const [x, y] of t) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); }
|
|
@@ -119,6 +172,22 @@ export function analysePart(triangles, project, ref) {
|
|
|
119
172
|
return { problem: ref, material: r.material, cases, volume: volume(triangles), grid: { nx, ny, h }, origin: [x0, y0], density };
|
|
120
173
|
}
|
|
121
174
|
|
|
175
|
+
// A solid part on the problem's grid: the part itself is the space (keep and avoid regions don't apply), so the
|
|
176
|
+
// supports and loads land on it as they would on an optimised layout
|
|
177
|
+
function analyseSolid(triangles, r) {
|
|
178
|
+
const { problem } = r, spec = discretise({ ...problem, space: { triangles }, keep: [], avoid: [], volume: 1 });
|
|
179
|
+
const g = makeGrid(spec.grid), density = Float64Array.from(spec.passive, (p) => (p === 0 ? 1 : 0));
|
|
180
|
+
if (!density.some((d) => d)) throw new Error('the part is smaller than one cell of the problem: use a smaller cell');
|
|
181
|
+
const a = analyse({ grid: g, density, material: problem.material, fixed: spec.fixed, loads: spec.loads.map((l) => l.force) });
|
|
182
|
+
const cases = spec.loads.map((l, c) => {
|
|
183
|
+
const deflection = l.size ? a.compliance[c] / l.size : 0;
|
|
184
|
+
let most = 0;
|
|
185
|
+
for (let e = 0; e < density.length; e++) if (density[e]) most = Math.max(most, a.stress[c][e]);
|
|
186
|
+
return { name: l.name, force: l.size, deflection, stiffness: deflection ? l.size / deflection : Infinity, stress: most };
|
|
187
|
+
});
|
|
188
|
+
return { problem: r.ref, dim: 3, material: r.material, cases, volume: volume(triangles), grid: spec.grid, origin: spec.origin, density };
|
|
189
|
+
}
|
|
190
|
+
|
|
122
191
|
// How much of the thickness the part fills over each cell's centre: a ray straight up through the part enters it
|
|
123
192
|
// through faces that face down and leaves through faces that face up, so the filled length is the sum of the up
|
|
124
193
|
// faces' heights there less the down faces'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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": {
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@rulecad/fit": "^0.2.1",
|
|
51
51
|
"@rulecad/model-link": "^0.2.0",
|
|
52
52
|
"@rulecad/versions": "^0.1.0",
|
|
53
|
-
"@rulecad/shapes": "^0.
|
|
53
|
+
"@rulecad/shapes": "^0.4.0",
|
|
54
54
|
"@rulecad/rules": "^0.3.0",
|
|
55
55
|
"@jscad/modeling": "^2.12.0",
|
|
56
56
|
"three": "^0.186.1",
|
|
57
|
-
"@rulecad/fea": "^0.
|
|
58
|
-
"@rulecad/topopt": "^0.
|
|
57
|
+
"@rulecad/fea": "^0.2.0",
|
|
58
|
+
"@rulecad/topopt": "^0.2.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0"
|
|
@@ -2,75 +2,346 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://jonibach.github.io/rulecad/schemas/problem.schema.json",
|
|
4
4
|
"title": "rulecad optimisation problem",
|
|
5
|
-
"description": "A
|
|
5
|
+
"description": "A part to optimise, flat (2D) or solid (3D), in projects/<project>/problems/<name>.json: where material may go, what must stay solid or empty, where it's held and loaded, and what it's made of. Numbers are expressions, as in objects: of its variables and the rule sets it uses. cad optimise runs it; a design reads the result through a variable of type problem.",
|
|
6
6
|
"type": "object",
|
|
7
|
-
"required": [
|
|
7
|
+
"required": [
|
|
8
|
+
"material",
|
|
9
|
+
"cell",
|
|
10
|
+
"volume",
|
|
11
|
+
"space",
|
|
12
|
+
"supports",
|
|
13
|
+
"loads"
|
|
14
|
+
],
|
|
8
15
|
"additionalProperties": false,
|
|
9
16
|
"properties": {
|
|
10
|
-
"$schema": {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
"$schema": {
|
|
18
|
+
"type": "string"
|
|
19
|
+
},
|
|
20
|
+
"title": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
},
|
|
23
|
+
"description": {
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
"uses": {
|
|
27
|
+
"type": "array",
|
|
28
|
+
"items": {
|
|
29
|
+
"type": "string"
|
|
30
|
+
},
|
|
31
|
+
"description": "Rule sets: the material's, the printer's, the part's own"
|
|
32
|
+
},
|
|
33
|
+
"variables": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"description": "As in objects"
|
|
36
|
+
},
|
|
37
|
+
"variants": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"additionalProperties": {
|
|
40
|
+
"type": "object"
|
|
41
|
+
},
|
|
42
|
+
"description": "Named settings of variables with tweak ranges, picked as name:variant"
|
|
43
|
+
},
|
|
44
|
+
"material": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"description": "A rule set with modulus (MPa), poisson and, for safety factors, strength (MPa)"
|
|
47
|
+
},
|
|
48
|
+
"thickness": {
|
|
49
|
+
"$ref": "#/$defs/expr",
|
|
50
|
+
"description": "A flat (2D) problem's thickness, mm"
|
|
51
|
+
},
|
|
52
|
+
"cell": {
|
|
53
|
+
"$ref": "#/$defs/expr",
|
|
54
|
+
"description": "The grid's cell size, mm: smaller is finer and slower"
|
|
55
|
+
},
|
|
56
|
+
"volume": {
|
|
57
|
+
"$ref": "#/$defs/expr",
|
|
58
|
+
"description": "The share of the space to fill, 0 to 1 (keep regions count towards it)"
|
|
59
|
+
},
|
|
60
|
+
"filter": {
|
|
61
|
+
"$ref": "#/$defs/expr",
|
|
62
|
+
"description": "Filter radius, mm: about the thinnest member (default 1.5 cells)"
|
|
63
|
+
},
|
|
64
|
+
"penal": {
|
|
65
|
+
"$ref": "#/$defs/expr",
|
|
66
|
+
"description": "The penalty on part-solid cells (default 3)"
|
|
67
|
+
},
|
|
68
|
+
"projection": {
|
|
69
|
+
"type": "boolean",
|
|
70
|
+
"description": "Sharpen the result to solid and empty (default true)"
|
|
71
|
+
},
|
|
72
|
+
"steps": {
|
|
73
|
+
"type": "integer",
|
|
74
|
+
"description": "At most this many steps (default 300)"
|
|
75
|
+
},
|
|
76
|
+
"space": {
|
|
77
|
+
"oneOf": [
|
|
78
|
+
{
|
|
79
|
+
"$ref": "#/$defs/region"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"type": "array",
|
|
83
|
+
"items": {
|
|
84
|
+
"$ref": "#/$defs/region"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"description": "Where material may go"
|
|
89
|
+
},
|
|
90
|
+
"keep": {
|
|
91
|
+
"type": "array",
|
|
92
|
+
"items": {
|
|
93
|
+
"$ref": "#/$defs/region"
|
|
94
|
+
},
|
|
95
|
+
"description": "Must stay solid: bosses round bolt holes"
|
|
96
|
+
},
|
|
97
|
+
"avoid": {
|
|
98
|
+
"type": "array",
|
|
99
|
+
"items": {
|
|
100
|
+
"$ref": "#/$defs/region"
|
|
101
|
+
},
|
|
102
|
+
"description": "Must stay empty: holes, clearances (avoid wins over keep)"
|
|
103
|
+
},
|
|
104
|
+
"supports": {
|
|
105
|
+
"type": "array",
|
|
106
|
+
"minItems": 1,
|
|
107
|
+
"items": {
|
|
108
|
+
"$ref": "#/$defs/support"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"loads": {
|
|
112
|
+
"type": "array",
|
|
113
|
+
"minItems": 1,
|
|
114
|
+
"items": {
|
|
115
|
+
"$ref": "#/$defs/load"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"cases": {
|
|
119
|
+
"type": "object",
|
|
120
|
+
"additionalProperties": {
|
|
121
|
+
"$ref": "#/$defs/expr"
|
|
122
|
+
},
|
|
123
|
+
"description": "Each load case's weight in the optimisation (default 1); 0 analyses it without optimising for it"
|
|
124
|
+
},
|
|
30
125
|
"outline": {
|
|
31
126
|
"type": "object",
|
|
32
127
|
"additionalProperties": false,
|
|
33
128
|
"properties": {
|
|
34
|
-
"smooth": {
|
|
35
|
-
|
|
129
|
+
"smooth": {
|
|
130
|
+
"type": "integer",
|
|
131
|
+
"description": "Smoothing passes for the outline (2D) or surface (3D), default 4"
|
|
132
|
+
},
|
|
133
|
+
"min_area": {
|
|
134
|
+
"$ref": "#/$defs/expr",
|
|
135
|
+
"description": "Holes and islands smaller than this (mm²) are dropped"
|
|
136
|
+
}
|
|
36
137
|
}
|
|
138
|
+
},
|
|
139
|
+
"overhang": {
|
|
140
|
+
"type": "string",
|
|
141
|
+
"description": "3D: printable this way up ('+z', '-y', …), or a variable holding it, or 'none': only material supported from below at 45° or less"
|
|
37
142
|
}
|
|
38
143
|
},
|
|
39
144
|
"$defs": {
|
|
40
|
-
"expr": {
|
|
41
|
-
|
|
145
|
+
"expr": {
|
|
146
|
+
"type": [
|
|
147
|
+
"number",
|
|
148
|
+
"string"
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
"point": {
|
|
152
|
+
"type": "array",
|
|
153
|
+
"items": {
|
|
154
|
+
"$ref": "#/$defs/expr"
|
|
155
|
+
},
|
|
156
|
+
"minItems": 2,
|
|
157
|
+
"maxItems": 3
|
|
158
|
+
},
|
|
42
159
|
"region": {
|
|
43
160
|
"type": "object",
|
|
44
161
|
"additionalProperties": false,
|
|
45
162
|
"properties": {
|
|
46
|
-
"at": {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
163
|
+
"at": {
|
|
164
|
+
"$ref": "#/$defs/point",
|
|
165
|
+
"description": "The centre, mm: [x, y] in 2D, [x, y, z] in 3D"
|
|
166
|
+
},
|
|
167
|
+
"r": {
|
|
168
|
+
"$ref": "#/$defs/expr",
|
|
169
|
+
"description": "A circle's or ball's radius, or a cylinder's"
|
|
170
|
+
},
|
|
171
|
+
"size": {
|
|
172
|
+
"type": "array",
|
|
173
|
+
"items": {
|
|
174
|
+
"$ref": "#/$defs/expr"
|
|
175
|
+
},
|
|
176
|
+
"minItems": 2,
|
|
177
|
+
"maxItems": 3,
|
|
178
|
+
"description": "A rectangle's or box's sides"
|
|
179
|
+
},
|
|
180
|
+
"length": {
|
|
181
|
+
"$ref": "#/$defs/expr",
|
|
182
|
+
"description": "3D: a cylinder's length (with r)"
|
|
183
|
+
},
|
|
184
|
+
"axis": {
|
|
185
|
+
"enum": [
|
|
186
|
+
"x",
|
|
187
|
+
"y",
|
|
188
|
+
"z"
|
|
189
|
+
],
|
|
190
|
+
"description": "3D: the cylinder's axis (default z)"
|
|
191
|
+
},
|
|
192
|
+
"points": {
|
|
193
|
+
"type": "array",
|
|
194
|
+
"items": {
|
|
195
|
+
"$ref": "#/$defs/point"
|
|
196
|
+
},
|
|
197
|
+
"minItems": 3,
|
|
198
|
+
"description": "2D: a polygon's corners"
|
|
199
|
+
},
|
|
200
|
+
"part": {
|
|
201
|
+
"type": "string",
|
|
202
|
+
"description": "3D: a named part of another design in the project, as it's built: object.part"
|
|
203
|
+
},
|
|
204
|
+
"label": {
|
|
205
|
+
"type": "string"
|
|
206
|
+
},
|
|
207
|
+
"teardrop": {
|
|
208
|
+
"enum": [
|
|
209
|
+
"-z",
|
|
210
|
+
"+z"
|
|
211
|
+
],
|
|
212
|
+
"description": "3D: a cylinder along x or y with a 45° point that way, so it prints without support: '-z' for a boss (its underside), '+z' for a hole (its roof)"
|
|
213
|
+
}
|
|
51
214
|
}
|
|
52
215
|
},
|
|
53
216
|
"support": {
|
|
54
217
|
"type": "object",
|
|
55
|
-
"required": [
|
|
218
|
+
"required": [],
|
|
56
219
|
"additionalProperties": false,
|
|
57
220
|
"properties": {
|
|
58
|
-
"at": {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
221
|
+
"at": {
|
|
222
|
+
"$ref": "#/$defs/point",
|
|
223
|
+
"description": "The centre, mm: [x, y] in 2D, [x, y, z] in 3D"
|
|
224
|
+
},
|
|
225
|
+
"r": {
|
|
226
|
+
"$ref": "#/$defs/expr",
|
|
227
|
+
"description": "A circle's or ball's radius, or a cylinder's"
|
|
228
|
+
},
|
|
229
|
+
"size": {
|
|
230
|
+
"type": "array",
|
|
231
|
+
"items": {
|
|
232
|
+
"$ref": "#/$defs/expr"
|
|
233
|
+
},
|
|
234
|
+
"minItems": 2,
|
|
235
|
+
"maxItems": 3,
|
|
236
|
+
"description": "A rectangle's or box's sides"
|
|
237
|
+
},
|
|
238
|
+
"length": {
|
|
239
|
+
"$ref": "#/$defs/expr",
|
|
240
|
+
"description": "3D: a cylinder's length (with r)"
|
|
241
|
+
},
|
|
242
|
+
"axis": {
|
|
243
|
+
"enum": [
|
|
244
|
+
"x",
|
|
245
|
+
"y",
|
|
246
|
+
"z"
|
|
247
|
+
],
|
|
248
|
+
"description": "3D: the cylinder's axis (default z)"
|
|
249
|
+
},
|
|
250
|
+
"points": {
|
|
251
|
+
"type": "array",
|
|
252
|
+
"items": {
|
|
253
|
+
"$ref": "#/$defs/point"
|
|
254
|
+
},
|
|
255
|
+
"minItems": 3,
|
|
256
|
+
"description": "2D: a polygon's corners"
|
|
257
|
+
},
|
|
258
|
+
"part": {
|
|
259
|
+
"type": "string",
|
|
260
|
+
"description": "3D: a named part of another design in the project, as it's built: object.part"
|
|
261
|
+
},
|
|
262
|
+
"label": {
|
|
263
|
+
"type": "string"
|
|
264
|
+
},
|
|
265
|
+
"fix": {
|
|
266
|
+
"type": "string",
|
|
267
|
+
"pattern": "^[xyz]+$",
|
|
268
|
+
"description": "Which ways it's held: x, y, z (default all)"
|
|
269
|
+
},
|
|
270
|
+
"teardrop": {
|
|
271
|
+
"enum": [
|
|
272
|
+
"-z",
|
|
273
|
+
"+z"
|
|
274
|
+
],
|
|
275
|
+
"description": "3D: a cylinder along x or y with a 45° point that way, so it prints without support: '-z' for a boss (its underside), '+z' for a hole (its roof)"
|
|
276
|
+
}
|
|
62
277
|
}
|
|
63
278
|
},
|
|
64
279
|
"load": {
|
|
65
280
|
"type": "object",
|
|
66
|
-
"required": [
|
|
281
|
+
"required": [
|
|
282
|
+
"force"
|
|
283
|
+
],
|
|
67
284
|
"additionalProperties": false,
|
|
68
285
|
"properties": {
|
|
69
|
-
"at": {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
286
|
+
"at": {
|
|
287
|
+
"$ref": "#/$defs/point",
|
|
288
|
+
"description": "The centre, mm: [x, y] in 2D, [x, y, z] in 3D"
|
|
289
|
+
},
|
|
290
|
+
"r": {
|
|
291
|
+
"$ref": "#/$defs/expr",
|
|
292
|
+
"description": "A circle's or ball's radius, or a cylinder's"
|
|
293
|
+
},
|
|
294
|
+
"size": {
|
|
295
|
+
"type": "array",
|
|
296
|
+
"items": {
|
|
297
|
+
"$ref": "#/$defs/expr"
|
|
298
|
+
},
|
|
299
|
+
"minItems": 2,
|
|
300
|
+
"maxItems": 3,
|
|
301
|
+
"description": "A rectangle's or box's sides"
|
|
302
|
+
},
|
|
303
|
+
"length": {
|
|
304
|
+
"$ref": "#/$defs/expr",
|
|
305
|
+
"description": "3D: a cylinder's length (with r)"
|
|
306
|
+
},
|
|
307
|
+
"axis": {
|
|
308
|
+
"enum": [
|
|
309
|
+
"x",
|
|
310
|
+
"y",
|
|
311
|
+
"z"
|
|
312
|
+
],
|
|
313
|
+
"description": "3D: the cylinder's axis (default z)"
|
|
314
|
+
},
|
|
315
|
+
"points": {
|
|
316
|
+
"type": "array",
|
|
317
|
+
"items": {
|
|
318
|
+
"$ref": "#/$defs/point"
|
|
319
|
+
},
|
|
320
|
+
"minItems": 3,
|
|
321
|
+
"description": "2D: a polygon's corners"
|
|
322
|
+
},
|
|
323
|
+
"part": {
|
|
324
|
+
"type": "string",
|
|
325
|
+
"description": "3D: a named part of another design in the project, as it's built: object.part"
|
|
326
|
+
},
|
|
327
|
+
"label": {
|
|
328
|
+
"type": "string"
|
|
329
|
+
},
|
|
330
|
+
"force": {
|
|
331
|
+
"$ref": "#/$defs/point",
|
|
332
|
+
"description": "x, y (and z), in N"
|
|
333
|
+
},
|
|
334
|
+
"case": {
|
|
335
|
+
"type": "string",
|
|
336
|
+
"description": "Its load case (default load)"
|
|
337
|
+
},
|
|
338
|
+
"teardrop": {
|
|
339
|
+
"enum": [
|
|
340
|
+
"-z",
|
|
341
|
+
"+z"
|
|
342
|
+
],
|
|
343
|
+
"description": "3D: a cylinder along x or y with a 45° point that way, so it prints without support: '-z' for a boss (its underside), '+z' for a hole (its roof)"
|
|
344
|
+
}
|
|
74
345
|
}
|
|
75
346
|
}
|
|
76
347
|
}
|