@rulecad/cad 0.9.0 → 0.11.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 +29 -10
- package/CHANGELOG.md +604 -0
- package/EXAMPLES.md +122 -105
- package/README.md +292 -63
- package/bin/cad.mjs +500 -87
- package/lib/assembly.mjs +486 -134
- package/lib/bays.mjs +124 -0
- package/lib/cache-file.mjs +148 -0
- package/lib/clone.mjs +93 -11
- package/lib/code-text.mjs +28 -0
- package/lib/design-imports.mjs +127 -0
- package/lib/design.mjs +291 -59
- package/lib/designshapes.mjs +142 -0
- package/lib/edit.mjs +29 -5
- package/lib/estimates.mjs +51 -0
- package/lib/fasten.mjs +11 -5
- package/lib/fe-key.mjs +29 -0
- package/lib/fittings.mjs +20 -15
- package/lib/fixings.mjs +17 -4
- package/lib/framebuild.mjs +73 -92
- package/lib/framecheck.mjs +154 -77
- package/lib/framegen.mjs +9 -1
- package/lib/frames.mjs +6 -2
- package/lib/framesize.mjs +45 -82
- package/lib/gait.mjs +17 -7
- package/lib/guides.mjs +84 -50
- package/lib/host.mjs +7 -3
- package/lib/kit.mjs +5 -5
- package/lib/list.mjs +29 -21
- package/lib/live-guard.mjs +18 -8
- package/lib/loads.mjs +35 -23
- package/lib/measured.mjs +740 -99
- package/lib/mesh.mjs +156 -56
- package/lib/motors.mjs +26 -33
- package/lib/names.mjs +15 -0
- package/lib/node-version.mjs +52 -0
- package/lib/optimise.mjs +34 -25
- package/lib/order.mjs +5 -12
- package/lib/parts.mjs +3 -0
- package/lib/picture-servers.mjs +66 -0
- package/lib/power.mjs +14 -7
- package/lib/preview.mjs +12 -25
- package/lib/programs.mjs +113 -0
- package/lib/rules.mjs +2 -1
- package/lib/sandbox-guard.mjs +43 -0
- package/lib/sandbox-hooks.mjs +109 -15
- package/lib/sandbox-lock.mjs +225 -0
- package/lib/sandbox-preload.mjs +2 -2
- package/lib/sandbox-run.mjs +22 -24
- package/lib/sandbox.mjs +345 -42
- package/lib/sheet.mjs +114 -3
- package/lib/targets/gist.mjs +9 -6
- package/lib/versions.mjs +294 -35
- package/lib/workspace.mjs +6 -3
- package/package.json +14 -14
- package/schemas/assembly.schema.json +6 -5
- package/schemas/object.schema.json +1 -1
- package/schemas/project.schema.json +6 -0
- package/templates/coupons/MEASURE.md +109 -0
- package/templates/coupons/assemblies/fixings-test.json +20 -0
- package/templates/coupons/assemblies/slot-test.json +11 -0
- package/templates/coupons/objects/fixings-coupon.js +88 -0
- package/templates/coupons/objects/fixings-coupon.json +26 -0
- package/templates/coupons/objects/holds-coupon.js +130 -0
- package/templates/coupons/objects/holds-coupon.json +42 -0
- package/templates/coupons/objects/slot-coupon.js +89 -0
- package/templates/coupons/objects/slot-coupon.json +29 -0
- package/templates/coupons/project.json +10 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
3
|
+
"name": "holds-coupon",
|
|
4
|
+
"title": "Holds coupon",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"uses": [
|
|
7
|
+
"x1c"
|
|
8
|
+
],
|
|
9
|
+
"engine": "manifold",
|
|
10
|
+
"orientation": "Flat on the bed as drawn: the plate on its base with every hole opening upward, the bolts standing on their heads, the snap pins on their feet",
|
|
11
|
+
"description": "The fixings coupon's second plate: snap pin sockets for 3 and 4 mm pins at three clearances, holes for a 3 mm steel dowel and 1.75 mm filament at three press and three slip fits, 6x3 and 8x3 disc magnet pockets at three press fits and an 8x3 with crush ribs at three, and printed nuts, a hex nut's height, for M8 and M10 printed bolts at three thread gaps. Loose beside it: the six printed bolts, a pull bolt to break, and six snap pins at three barb depths. Each figure is the one to write back with cad measured (MEASURE.md, rows 40 to 47). Print it with the fixings coupon, once per printer and plastic.",
|
|
12
|
+
"variables": {
|
|
13
|
+
"base": { "value": "x1c.layer * 6", "unit": "mm", "rule": "The plate every feature stands on: six layers, the floor under every blind hole and pocket, and a first layer that is one plain rectangle but for the socket and push-out holes" },
|
|
14
|
+
"wall": { "value": "x1c.wall_min * 2", "unit": "mm", "rule": "Plastic round every hole and pocket: four print lines, as a design gives a boss" },
|
|
15
|
+
"gap": { "value": "x1c.wall_min", "unit": "mm", "rule": "Between features, between a feature and its figure, between loose pieces, and round the edge" },
|
|
16
|
+
"root": { "value": "x1c.chamfer", "unit": "mm", "rule": "The 45° flare where each boss meets the plate, so no inside corner is square" },
|
|
17
|
+
"step": { "value": "x1c.hole_comp", "unit": "mm", "rule": "Sockets, slip fits, magnet pockets and printed nuts step by the printer's hole compensation either side of what the kit draws: the amount a printed hole comes out wrong by" },
|
|
18
|
+
"press_step": { "value": "x1c.hole_comp / 2", "unit": "mm", "rule": "A pin's press fit steps by half that: a pin grips or splits its boss over a few hundredths of a millimetre" },
|
|
19
|
+
"shaft": { "value": 6, "unit": "mm", "rule": "A snap pin's shaft, and the thickness of its socket's boss from the bed, so the barb clicks out just past the plate's underside" },
|
|
20
|
+
"barb": { "value": 0.4, "unit": "mm", "rule": "The middle snap pin's barb depth, the kit's default; the others are a barb_step either side" },
|
|
21
|
+
"barb_step": { "value": 0.1, "unit": "mm", "rule": "The snap pins' barbs step by a tenth of a millimetre: about a quarter of the barb, enough to feel between a pin that clicks and one that will not go" },
|
|
22
|
+
"pin_depth": { "value": 6, "unit": "mm", "rule": "How deep a dowel or a filament pin goes into its hole: twice a 3 mm dowel's diameter, so it is held straight, and the rest of a 12 mm pin stands out to pull on" },
|
|
23
|
+
"push": { "value": 2, "unit": "mm", "rule": "The hole under each magnet pocket, to push a pressed magnet out with a 1.75 mm filament or a small screwdriver" },
|
|
24
|
+
"engaged": { "value": 2, "rule": "A printed bolt's length as a multiple of its nut's height: it goes right through the nut, with as much again to hold it by" },
|
|
25
|
+
"tiny": { "value": 1e-6, "rule": "What a height may be over a whole number of layers and still count as that number" },
|
|
26
|
+
"pull_length": { "value": 45, "unit": "mm", "rule": "The pull bolt's length under its head: the waist, then 36 mm of full thread, room for blocks up to 20 mm thick (MEASURE.md row 47: an 18 mm plywood offcut), an M8 washer (1.6 mm), a bought M8 nut (6.8 mm at most) and a pitch to start the nut on" },
|
|
27
|
+
"waist": { "value": 3.5, "unit": "mm", "rule": "The pull bolt's waist, across: 9.62 mm², which breaks at about 38 kg if the plastic holds 39 MPa across its layers (less across them in practice), within a 50 kg luggage scale's reach. Thick enough that the bolt prints standing: a sideways push of 1 N at its tip, as the nozzle passes, stresses the waist about 9.9 MPa (16 at 3 mm) and sways the tip about 0.46 mm (1 mm at 3 mm by 6), by beam bending at pla.modulus 2680 MPa: an estimate" },
|
|
28
|
+
"waist_length": { "value": 3.5, "unit": "mm", "rule": "The waist's straight length, one diameter, so it breaks in the waist and not where the cones meet the shank, and short so the bolt sways little as it prints standing" },
|
|
29
|
+
"small_pin": { "value": 3, "unit": "mm", "rule": "The smaller snap pin: the thinnest the kit draws a sampler's pins, above fixings.pin_least (2 mm) by half again" },
|
|
30
|
+
"large_pin": { "value": 4, "unit": "mm", "rule": "The larger snap pin: the size the kit's examples hold a lid with (snap pin 4x6)" },
|
|
31
|
+
"places": { "value": 3, "rule": "Figures in a row are worked to a thousandth of a millimetre, so a step's sum does not leave 0.30000000000000004" },
|
|
32
|
+
"fits": { "value": 3, "rule": "Three of every feature: the kit's figure and a step either side" },
|
|
33
|
+
"notch_turn": { "value": 60, "unit": "°", "rule": "The notches are a sixth of a turn apart, so on a hex head they fall on its flats" },
|
|
34
|
+
"half_turn": { "value": 180, "unit": "°", "rule": "Half a turn, to turn degrees into radians" },
|
|
35
|
+
"notch": { "value": 0.5, "unit": "mm", "rule": "The notches down the side of a loose bolt's head or a snap pin's foot that say which figure it is: one, two or three, for the first, second and third figure in its row" },
|
|
36
|
+
"label": { "value": 2.5, "unit": "mm", "rule": "Figure height: six print lines tall, readable close up, and small enough that a figure is no wider than its feature" },
|
|
37
|
+
"stroke": { "value": "x1c.line", "unit": "mm", "rule": "One print line, for the figures" },
|
|
38
|
+
"emboss": { "value": "x1c.layer * 2", "unit": "mm", "rule": "Two layers proud" },
|
|
39
|
+
"corner": { "value": 3, "unit": "mm", "rule": "The plate's corners, rounded so they stay down" },
|
|
40
|
+
"segments": { "value": 48, "rule": "Facets on round holes, bosses and the pull bolt's waist" }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The slot coupon: what a printed part needs to slide in a bought beam's slot, for the two slot families most hobby
|
|
2
|
+
// beams have (slot 6 on 20 mm beams, slot 8 on 30 and 40 mm beams). For each: five tongues, the part of a printed
|
|
3
|
+
// fitting that keys into the slot's opening; five printed carriers (@rulecad/frames' carrier, a block holding a hex nut
|
|
4
|
+
// that slides along the slot like a slide-in nut); and three short printed slots, standing on end, that a bought slot
|
|
5
|
+
// nut slides into. Every piece lies loose on the bed with its figure, the clearance a side, on top. Each is drawn from
|
|
6
|
+
// the slot's rule set (v.frames.slotModel): print it again once the slot is measured, and it is drawn from yours.
|
|
7
|
+
// Each piece is a part of its own. Everything stands on a plain first layer and nothing needs a support (MEASURE.md, rows 29 to 33).
|
|
8
|
+
import jscad from '@jscad/modeling'
|
|
9
|
+
const { cuboid, polygon } = jscad.primitives
|
|
10
|
+
const { extrudeLinear } = jscad.extrusions
|
|
11
|
+
const { translate, rotateZ } = jscad.transforms
|
|
12
|
+
const { offset } = jscad.expansions
|
|
13
|
+
const { measureBoundingBox } = jscad.measurements
|
|
14
|
+
|
|
15
|
+
// The families, each with the thread its carriers hold: the largest hex nut a carrier takes in that slot at every
|
|
16
|
+
// clearance tried (an M3 nut leaves too little plastic under it in slot 6 at 0.3 mm a side)
|
|
17
|
+
const FAMILIES = [['slot-6', 'M2.5'], ['slot-8', 'M5']]
|
|
18
|
+
|
|
19
|
+
export function main (v) {
|
|
20
|
+
const fig = (x) => String(Number(x.toFixed(2))) // a figure as it is labelled and written back
|
|
21
|
+
const around = (centre, n, step) => Array.from({ length: n }, (_, i) => centre + (i - (n - 1) / 2) * step)
|
|
22
|
+
const width = (text) => { const [lo, hi] = measureBoundingBox(v.shapes.text({ text, height: v.label, stroke: v.stroke })); return hi[0] - lo[0] }
|
|
23
|
+
const say = (text, x, y, z) => translate([x, y, z], extrudeLinear({ height: v.emboss }, v.shapes.text({ text, height: v.label, stroke: v.stroke })))
|
|
24
|
+
const box = (lo, hi) => translate(lo.map((a, i) => (a + hi[i]) / 2), cuboid({ size: lo.map((a, i) => hi[i] - a) }))
|
|
25
|
+
const wordy = Math.max(...around(v.fit, v.fits, v.step).map((c) => width(fig(c))))
|
|
26
|
+
|
|
27
|
+
// ---------- the pieces, each drawn with its length along x from 0 and centred on y = 0, on the bed ----------
|
|
28
|
+
// A tongue: a head that lies on the beam's face, and under it (printed on top) a tongue as deep as the slot's lips,
|
|
29
|
+
// narrower than the opening by the clearance each side. A V-groove at each side of its root, so no inside corner is
|
|
30
|
+
// square; the head runs on past the tongue to carry its figure
|
|
31
|
+
const tongue = (slot, c) => {
|
|
32
|
+
const w = slot.opening - 2 * c, head = slot.opening + 2 * v.wall, long = v.key + v.gap * 2 + wordy, top = v.base + slot.lip
|
|
33
|
+
const solid = v.ops.union(box([0, -head / 2, 0], [long, head / 2, v.base]), box([0, -w / 2, v.base - v.root], [v.key, w / 2, top]))
|
|
34
|
+
const cut = [1, -1].map((s) => groove(s, w / 2, v.base, v.root, v.key))
|
|
35
|
+
return { long, across: head, solid: v.ops.subtract(solid, ...cut), label: say(fig(c), v.key + v.gap + wordy / 2, 0, v.base) }
|
|
36
|
+
}
|
|
37
|
+
// A carrier for a hex nut, as frames draws it with the clearance as the printer's slot fit, long enough that its
|
|
38
|
+
// figure fits beside the screw's hole
|
|
39
|
+
const carrier = (slot, thread, c) => {
|
|
40
|
+
const printer = { ...v.x1c, slot_fit: c }, m0 = v.frames.carrierModel(slot, { thread, printer })
|
|
41
|
+
const length = Math.ceil(Math.max(m0.length, m0.screwHole + 2 * (wordy + v.gap * 2)))
|
|
42
|
+
const m = v.frames.carrierModel(slot, { thread, printer, length }), high = m.levels.bottom - m.levels.top
|
|
43
|
+
return { long: m.total, across: Math.max(...m.section.map(([y]) => Math.abs(y))) * 2, solid: v.frames.carrier(m, { pose: 'print', printer }), label: say(fig(c), (m.total + m.screwHole) / 2 + v.gap + wordy / 2, 0, high), model: m }
|
|
44
|
+
}
|
|
45
|
+
// A short printed slot standing on end: the slot's outline, opened by the clearance each side (its inside corners
|
|
46
|
+
// round by as much), cut down into a block from the top to a floor, the slot's face on the block's side (y = 0)
|
|
47
|
+
const printed = (slot, c) => {
|
|
48
|
+
const path = v.frames.slotPath(slot).map(([u, d]) => [u, -d]), void2 = polygon({ points: [[path[0][0], v.wall], ...path, [path[path.length - 1][0], v.wall]] })
|
|
49
|
+
const open = offset({ delta: c, corners: 'round', segments: v.segments }, void2), across = slot.cavityWidth + 2 * c + 2 * v.wall, deep = slot.cavityDepth + c + v.wall + v.label + v.gap * 2
|
|
50
|
+
const block = box([-across / 2, -deep, 0], [across / 2, 0, v.tall]), cut = translate([0, 0, v.base], extrudeLinear({ height: v.tall }, open))
|
|
51
|
+
return { long: across, across: deep, centre: -deep / 2, solid: v.ops.subtract(block, cut), label: say(fig(c), 0, -deep + v.gap + v.label / 2, v.tall) }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ---------- the rows, front to back: tongues, carriers, printed slots; slot 6 on the left, slot 8 on the right ----------
|
|
55
|
+
const groups = FAMILIES.map(([name, thread]) => {
|
|
56
|
+
const slot = v.frames.slotModel(name)
|
|
57
|
+
return {
|
|
58
|
+
name,
|
|
59
|
+
tongues: around(v.fit, v.fits, v.step).map((c) => ({ c, ...tongue(slot, c) })),
|
|
60
|
+
carriers: around(v.fit, v.fits, v.step).map((c) => ({ c, ...carrier(slot, thread, c) })),
|
|
61
|
+
slots: around(v.fit, v.slots, v.slot_step).map((c) => ({ c, ...printed(slot, c) }))
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
const out = {} // each piece a part of its own, named for its family, what it is and its clearance: slot-6-tongue-0.15
|
|
65
|
+
let y = v.gap
|
|
66
|
+
for (const row of ['tongues', 'carriers', 'slots']) {
|
|
67
|
+
let x = v.gap, deep = 0
|
|
68
|
+
for (const g of groups) {
|
|
69
|
+
for (const p of g[row]) {
|
|
70
|
+
// tongues and carriers turned to run along y, side by side in x; a printed slot stands as it is
|
|
71
|
+
const turned = row !== 'slots', span = turned ? p.across : p.long, reach = turned ? p.long : p.across
|
|
72
|
+
const place = (s) => turned ? translate([x + span / 2, y, 0], rotateZ(Math.PI / 2, s)) : translate([x + span / 2, y + reach, 0], s)
|
|
73
|
+
out[`${g.name}-${row.slice(0, -1)}-${fig(p.c)}`] = v.ops.union(place(p.solid), place(p.label))
|
|
74
|
+
x += span + v.gap * 2; deep = Math.max(deep, reach)
|
|
75
|
+
}
|
|
76
|
+
x += v.gap * 2
|
|
77
|
+
}
|
|
78
|
+
y += deep + v.gap * 2
|
|
79
|
+
}
|
|
80
|
+
return out
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The V-groove beside a tongue's root, along x: a triangle in y, z with its point down, cut into the head's top beside
|
|
84
|
+
// the tongue's side at y = s × edge
|
|
85
|
+
function groove (s, edge, base, root, key) {
|
|
86
|
+
const tri = s > 0 ? [[edge, base - root], [edge + root, base], [edge, base]] : [[-edge, base - root], [-edge, base], [-edge - root, base]]
|
|
87
|
+
// drawn in x, y as (y, z), extruded along z for the tongue's length, then turned so the extrusion runs along x
|
|
88
|
+
return jscad.transforms.transform([0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1], extrudeLinear({ height: key }, polygon({ points: tri })))
|
|
89
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
3
|
+
"name": "slot-coupon",
|
|
4
|
+
"title": "Slot coupon",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"uses": [
|
|
7
|
+
"x1c"
|
|
8
|
+
],
|
|
9
|
+
"engine": "manifold",
|
|
10
|
+
"orientation": "Loose pieces flat on the bed as drawn: tongues head down, carriers floor down, printed slots standing on end with their floor down",
|
|
11
|
+
"description": "For slot 6 (20 mm beams) and slot 8 (30 and 40 mm beams): five tongues and five printed nut carriers (M2.5 in slot 6, M5 in slot 8) at clearances either side of the printer's fit, and three short printed slots for a bought slot nut. Each piece carries its clearance a side, the figure to write back with cad measured (MEASURE.md, rows 29 to 33). Drawn from the slot's rule set: print it again once the slot is measured.",
|
|
12
|
+
"variables": {
|
|
13
|
+
"base": { "value": "x1c.layer * 6", "unit": "mm", "rule": "A tongue's head and a printed slot's floor: six layers, and a first layer that is one plain piece" },
|
|
14
|
+
"wall": { "value": "x1c.wall_min * 2", "unit": "mm", "rule": "Plastic round a printed slot, and a tongue's head beyond the opening each side: four print lines" },
|
|
15
|
+
"gap": { "value": "x1c.wall_min", "unit": "mm", "rule": "Between pieces, between a feature and its figure, and round the edge" },
|
|
16
|
+
"root": { "value": "x1c.chamfer", "unit": "mm", "rule": "The V-groove each side of a tongue's root, so the tongue meets its head with no square inside corner and the head still lies flat on the beam's face" },
|
|
17
|
+
"fit": { "value": "x1c.fit", "unit": "mm", "rule": "The middle clearance a side: what the kit draws a printed part in a slot with until the slot fit is measured" },
|
|
18
|
+
"step": { "value": "x1c.hole_comp / 2", "unit": "mm", "rule": "Tongues and carriers step by half the printer's hole compensation: a printed width comes out about that far either way, and a slot's opening is held to a tenth or two" },
|
|
19
|
+
"slot_step": { "value": "x1c.hole_comp", "unit": "mm", "rule": "Printed slots step by the printer's hole compensation, the amount a printed hole comes out wrong by" },
|
|
20
|
+
"fits": { "value": 5, "rule": "Five tongues and five carriers: the printer's fit and two steps either side" },
|
|
21
|
+
"slots": { "value": 3, "rule": "Three printed slots: the printer's fit and a step either side" },
|
|
22
|
+
"key": { "value": 12, "unit": "mm", "rule": "A tongue's length along the slot: longer than the opening is wide, so it slides straight and cannot twist" },
|
|
23
|
+
"tall": { "value": 15, "unit": "mm", "rule": "A printed slot's height: longer than a bought slide-in nut, so it slides its whole length" },
|
|
24
|
+
"label": { "value": 2.5, "unit": "mm", "rule": "Figure height: six print lines tall, readable close up, and narrow enough to sit across a carrier's top" },
|
|
25
|
+
"stroke": { "value": "x1c.line", "unit": "mm", "rule": "One print line, for the figures" },
|
|
26
|
+
"emboss": { "value": "x1c.layer * 2", "unit": "mm", "rule": "Two layers proud" },
|
|
27
|
+
"segments": { "value": 48, "rule": "Facets on the rounds of a printed slot's corners" }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "coupons",
|
|
3
|
+
"description": "Test prints that settle the kit's figures on your printer and plastic: the fixings, holds and slot coupons. MEASURE.md says how to read each and the cad measured command that writes the figure back.",
|
|
4
|
+
"material": "PLA",
|
|
5
|
+
"objects": [
|
|
6
|
+
"fixings-coupon",
|
|
7
|
+
"holds-coupon",
|
|
8
|
+
"slot-coupon"
|
|
9
|
+
]
|
|
10
|
+
}
|