bambu-printer-mcp 1.1.89 → 1.1.91

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.
Files changed (70) hide show
  1. package/README.md +49 -1
  2. package/dist/cad/contracts.d.ts +84 -0
  3. package/dist/cad/contracts.js +50 -5
  4. package/dist/cad/examples.d.ts +22 -0
  5. package/dist/cad/examples.js +81 -0
  6. package/dist/cad/process.js +3 -0
  7. package/dist/cad-engine.d.ts +25 -0
  8. package/dist/cad-engine.js +197 -27
  9. package/dist/counterpart/flight-record.d.ts +155 -0
  10. package/dist/counterpart/flight-record.js +831 -0
  11. package/dist/counterpart/flight-tools.d.ts +213 -0
  12. package/dist/counterpart/flight-tools.js +232 -0
  13. package/dist/counterpart/fresh-frame.d.ts +16 -0
  14. package/dist/counterpart/fresh-frame.js +26 -0
  15. package/dist/counterpart/make-3mf.js +1 -4
  16. package/dist/counterpart/physical-evidence.d.ts +70 -0
  17. package/dist/counterpart/physical-evidence.js +103 -0
  18. package/dist/counterpart/print-geometry.d.ts +13 -0
  19. package/dist/counterpart/print-geometry.js +181 -0
  20. package/dist/counterpart/remote.js +4 -0
  21. package/dist/counterpart/schemas.d.ts +32 -0
  22. package/dist/counterpart/schemas.js +2 -0
  23. package/dist/counterpart/visual-evidence.d.ts +38 -0
  24. package/dist/counterpart/visual-evidence.js +155 -0
  25. package/dist/design-guidance.d.ts +22 -1
  26. package/dist/design-guidance.js +35 -2
  27. package/dist/index.js +35 -3
  28. package/dist/printers/bambu.d.ts +9 -2
  29. package/dist/printers/bambu.js +32 -6
  30. package/dist/safety/print-preview.d.ts +2 -0
  31. package/dist/safety/print-preview.js +1 -1
  32. package/dist/slicer/3mf-xml.d.ts +7 -0
  33. package/dist/slicer/3mf-xml.js +61 -0
  34. package/dist/stl/stl-manipulator.js +5 -2
  35. package/dist/tool-annotations.js +4 -0
  36. package/package.json +2 -1
  37. package/src/cad/contracts.ts +54 -5
  38. package/src/cad/examples/bag_clip.py +86 -0
  39. package/src/cad/examples/bistable_clicker.py +81 -0
  40. package/src/cad/examples/cable_clip.py +55 -0
  41. package/src/cad/examples/chainmail.py +45 -0
  42. package/src/cad/examples/hinged_box.py +101 -0
  43. package/src/cad/examples/knurled_knob.py +50 -0
  44. package/src/cad/examples/loft_handle.py +52 -0
  45. package/src/cad/examples/phone_stand.py +92 -0
  46. package/src/cad/examples/swept_hook.py +69 -0
  47. package/src/cad/examples/threaded_jar.py +62 -0
  48. package/src/cad/examples/trigger_capo.py +95 -0
  49. package/src/cad/examples/wall_hook.py +65 -0
  50. package/src/cad/examples.ts +77 -0
  51. package/src/cad/geometry.py +122 -4
  52. package/src/cad/process.ts +3 -0
  53. package/src/cad/worker.py +4 -0
  54. package/src/cad-engine.ts +221 -52
  55. package/src/counterpart/flight-record.ts +984 -0
  56. package/src/counterpart/flight-tools.ts +282 -0
  57. package/src/counterpart/fresh-frame.ts +45 -0
  58. package/src/counterpart/make-3mf.ts +1 -5
  59. package/src/counterpart/physical-evidence.ts +185 -0
  60. package/src/counterpart/print-geometry.ts +192 -0
  61. package/src/counterpart/remote.ts +4 -0
  62. package/src/counterpart/schemas.ts +3 -0
  63. package/src/counterpart/visual-evidence.ts +212 -0
  64. package/src/design-guidance.ts +35 -2
  65. package/src/index.ts +38 -4
  66. package/src/printers/bambu.ts +34 -5
  67. package/src/safety/print-preview.ts +1 -1
  68. package/src/slicer/3mf-xml.ts +52 -0
  69. package/src/stl/stl-manipulator.ts +4 -1
  70. package/src/tool-annotations.ts +4 -0
@@ -0,0 +1,69 @@
1
+ """Under-desk headphone hook (swept arm with a broad saddle, tape or two screws)
2
+ Pattern: sweep a rounded section along a filleted Polyline path; sweep a second, wider section along part of the same path
3
+ Modelled on: ElevationLab AnchorPro under-desk headphone mount (https://www.elevationlab.com/products/the-anchor-pro); screw is SPAX 4.0 mm flat countersunk (https://www.ahlsell.se/en/products/mounting/wood-screw/wood-screw-spax/71333788---traskruv-tft-spax-svart-4.0x25h-200fp-eta-120114)
4
+ Published sizes used: 4.0 mm = screw thread diameter, 8.0 mm = head diameter, 2.4 mm = head height (retailer listing for SPAX, URL above); the maker publishes no hook dimensions, so every hook size is a design choice
5
+ Concept: Hangs a headset under the desk, out of the way. Frame: the flat top face of the plate goes against the underside of the desk (tape, or two screws driven up from below), the arm drops, runs towards -y and turns up into a tip that stops the headband sliding off; the headband enters through the 42 mm gap between tip and plate. The headband lies across the saddle, a leaf 34 mm wide with fully rounded edges so the padding is not creased the way it is on a thin wire hook. The weight bends the arm at the two bends and pulls on the plate; the bends are large-radius and the stem is filleted into the plate. Print it on its side (X up) so every layer holds the whole J and the bends are not layer joints; the plate and saddle are wider than the arm, so on its side it needs supports under the arm and saddle. PETG or PLA, 4 walls.
6
+ What makes this good: one path drives both the slim arm and the broad saddle, so the saddle follows the bends like a moulded part.
7
+ """
8
+ from build123d import *
9
+
10
+ P = {
11
+ "plate_w": 72.0, # plate across the desk edge (X); screws sit either side of the arm
12
+ "plate_d": 36.0, # plate front to back (Y); the tape area
13
+ "plate_t": 5.0, # plate thickness; leaves 2.6 mm under the screw head
14
+ "screw_d": 4.0, # screw thread diameter (published)
15
+ "screw_head_d": 8.0, # screw head diameter (published)
16
+ "screw_head_h": 2.4, # screw head height (published); sets the countersink depth
17
+ "screw_clear": 0.5, # added to thread and head diameters so the screw drops in
18
+ "screw_pitch": 50.0, # distance between the screws; clear of the saddle for the driver
19
+ "arm_w": 16.0, # arm section width (X)
20
+ "arm_t": 11.0, # arm section thickness, in the bending direction
21
+ "drop": 62.0, # plate underside down to the arm centreline
22
+ "reach": 62.0, # stem to tip, along the desk
23
+ "tip_h": 20.0, # tip rise above the arm centreline
24
+ "bend_r": 14.0, # radius of both bends
25
+ "saddle_w": 34.0, # saddle width: broad, so the headband padding is not dented
26
+ "saddle_t": 8.0, # saddle thickness; its edges are full rounds
27
+ "saddle_lift": 3.5, # saddle centre above the arm centreline, so its crown stands proud
28
+ "saddle_from": 0.38, # where the saddle starts along the path (0 = plate, 1 = tip)
29
+ "saddle_to": 0.88, # where it ends
30
+ "root_fillet": 4.0, # blend of the stem into the plate
31
+ }
32
+
33
+
34
+ def build():
35
+ z_arm = P["arm_t"] / 2 # arm centreline height; the arm's underside sits on z = 0
36
+ z_plate = z_arm + P["drop"] # plate underside
37
+ # path as 3D points: inside the plate, down the stem, along the desk, up the tip
38
+ path = Polyline((0, 0, z_plate + P["plate_t"] / 2), (0, 0, z_arm),
39
+ (0, -P["reach"], z_arm), (0, -P["reach"], z_arm + P["tip_h"]))
40
+ path = fillet(path.vertices(), P["bend_r"])
41
+
42
+ # the arm: an ellipse held square to the path at its start, swept to the tip
43
+ arm = sweep(Plane(path @ 0, x_dir=(1, 0, 0), z_dir=path % 0) * Ellipse(P["arm_w"] / 2, P["arm_t"] / 2), path=path)
44
+ tip = arm.faces().filter_by(GeomType.PLANE).sort_by(Axis.Z)[0] # the lower flat end is the tip
45
+ arm = fillet(tip.edges(), P["arm_t"] * 0.3) # rounded tip
46
+
47
+ # the saddle: a wide round-edged slot swept along the middle of the same path, lifted to the
48
+ # inside of the J (local +y of the section plane) so its top is what the headband touches
49
+ run = path.trim(P["saddle_from"], P["saddle_to"])
50
+ leaf = Plane(run @ 0, x_dir=(1, 0, 0), z_dir=run % 0) * Pos(0, P["saddle_lift"]) * SlotOverall(P["saddle_w"], P["saddle_t"])
51
+ saddle = sweep(leaf, path=run)
52
+ ends = saddle.faces().filter_by(GeomType.PLANE).edges()
53
+ saddle = fillet(ends, P["saddle_t"] * 0.35) # soft ends
54
+
55
+ # plate: flat on top for the desk, lower edge softened; stem blended in
56
+ plate = Pos(0, 0, z_plate) * extrude(RectangleRounded(P["plate_w"], P["plate_d"], P["plate_d"] * 0.4), P["plate_t"])
57
+ plate = fillet(plate.edges().group_by(Axis.Z)[0], P["plate_t"] * 0.4)
58
+ body = plate + arm
59
+ # the seam where the stem leaves the plate is the only spline edge on the plate's underside
60
+ seam = body.edges().filter_by_position(Axis.Z, z_plate - 0.01, z_plate + 0.01).filter_by(GeomType.BSPLINE)
61
+ body = fillet(seam, P["root_fillet"]) + saddle
62
+
63
+ # two countersunk holes, heads on the underside, either side of the arm
64
+ hole_r = (P["screw_d"] + P["screw_clear"]) / 2
65
+ head_r = (P["screw_head_d"] + P["screw_clear"]) / 2
66
+ screw = Cylinder(hole_r, 3 * P["plate_t"]) + Cone(head_r, hole_r, P["screw_head_h"], align=(Align.CENTER, Align.CENTER, Align.MIN))
67
+ for x in (P["screw_pitch"] / 2, -P["screw_pitch"] / 2):
68
+ body -= Pos(x, 0, z_plate) * screw
69
+ return body
@@ -0,0 +1,62 @@
1
+ """Screw-top jar and lid with a standard 70-400 neck
2
+ Pattern: revolve a wall profile for the body, sweep a thread section along a helix for the screw thread (same pitch on both parts, clearance as a radial offset), pattern a cutter round the lid for grip
3
+ Modelled on: wide-mouth jars with a GPI/SPI 70-400 continuous-thread finish (https://www.ebottles.com/blogs/articles/guide-for-fitting-closures-on-bottles)
4
+ Published sizes used: 70-400 finish, converted from the chart's inches: T (thread outside diameter) 68.61 to 69.49 mm; E (neck at the thread root) 66.22 to 67.11 mm; H (finish height) 9.98 to 10.74 mm; S (rim to thread start) 0.79 to 1.55 mm; 6 threads per inch = 4.233 mm pitch; thread depth (T - E)/2 = 1.19 mm (retailer's chart of the standard, URL above). The thread's flank angle is not in the chart: 45 degree flanks are a choice made so it prints.
5
+ Concept: A jar whose lid screws on in one turn. The neck is the standard 70-400 finish, so the printed lid also fits bought 70 mm jars and a bought cap fits this jar, give or take the printer. One turn of thread on the neck pulls the lid down until its inside face seats on the rim: the thread only holds the joint shut, the rim takes the squeeze. Both threads are the same section swept along the same helix; the lid's is moved outwards by the clearance, never scaled, so the pitch matches at every turn. The body is one revolved wall: a rounded floor corner (no stress line, easy to wipe out), a shoulder at 45 degrees so it prints without supports, a rolled rim. The lid has a domed edge and 24 finger scallops. Both print upright as modelled, jar on its floor and lid on its top face, opening up; the thread flanks are 45 degrees. PETG or PLA, 3 walls; not for food unless the filament and printer are.
6
+ What makes this good: a real standard interface, a thread made the way threads are made (one section along a helix), and every wall a single revolved curve.
7
+ """
8
+ import math
9
+ from build123d import *
10
+
11
+ P = {
12
+ "T": 69.0, # thread outside diameter (70-400: 68.61 to 69.49)
13
+ "E": 66.6, # neck diameter at the thread root (66.22 to 67.11)
14
+ "H": 10.4, # finish height, rim to shoulder (9.98 to 10.74)
15
+ "S": 1.2, # rim down to where the thread starts (0.79 to 1.55)
16
+ "pitch": 4.233, # 6 threads per inch
17
+ "turns": 1.0, # a 400 finish has one turn of thread
18
+ "crest": 1.0, # width of the thread's crest; flanks at 45 degrees from there
19
+ "body_d": 82.0, # jar body outside diameter
20
+ "body_h": 58.0, # floor to shoulder top
21
+ "wall": 2.0, # jar and lid wall
22
+ "floor": 2.4,
23
+ "corner": 8.0, # radius of the floor corner
24
+ "fit": 0.35, # radial clearance between the two threads (print allowance)
25
+ "lid_top": 2.4,
26
+ "scallops": 24, # finger scallops round the lid
27
+ "gap_on_plate": 12.0, # space between jar and lid as laid out
28
+ }
29
+
30
+ def thread(root_r, crest_r, z0):
31
+ """One thread: a 45 degree trapezoid swept along a helix. root_r may be larger than crest_r (the lid's thread)."""
32
+ depth = crest_r - root_r
33
+ half_root = P["crest"] / 2 + abs(depth) # 45 degree flanks
34
+ bury = 0.4 * (1 if depth > 0 else -1) # sink the root into the wall so the union is clean
35
+ section = Polygon((root_r - bury, -half_root - 0.4), (crest_r, -P["crest"] / 2), (crest_r, P["crest"] / 2), (root_r - bury, half_root + 0.4), align=None)
36
+ path = Helix(P["pitch"], P["pitch"] * P["turns"], (root_r + crest_r) / 2)
37
+ return Pos(0, 0, z0) * sweep(Plane.XZ * section, path=path, is_frenet=True)
38
+
39
+ def build():
40
+ w, R, top = P["wall"], P["body_d"] / 2, P["body_h"] + P["H"]
41
+ neck_r = P["E"] / 2
42
+ # jar: one closed wall section in the XZ plane, revolved; the shoulder rises at 45 degrees to the neck
43
+ shoulder_z = P["body_h"] - (R - neck_r)
44
+ outer = Polyline((0, 0), (R, 0), (R, shoulder_z), (neck_r, P["body_h"]), (neck_r, top), (neck_r - w, top),
45
+ (neck_r - w, P["body_h"] - 0.8), (R - w, shoulder_z - 0.8), (R - w, P["floor"]), (0, P["floor"]), close=True)
46
+ wall = make_face(outer)
47
+ wall = fillet(wall.vertices().filter_by_position(Axis.Y, -0.1, P["floor"] + 0.1).filter_by_position(Axis.X, R - w - 0.1, R + 0.1), P["corner"] / 2)
48
+ jar = revolve(Plane.XZ * wall, Axis.Z)
49
+ z_thread = top - P["S"] - (P["crest"] / 2 + (P["T"] - P["E"]) / 2) - P["pitch"] * P["turns"]
50
+ jar += thread(neck_r, P["T"] / 2, z_thread)
51
+
52
+ # lid: a cup over the neck, opening up as printed; its thread is the same helix moved out by the fit
53
+ lid_in = P["T"] / 2 + P["fit"]
54
+ lid_out = lid_in + w
55
+ lid_h = P["lid_top"] + P["H"] - 1.0
56
+ cup = Cylinder(lid_out, lid_h, align=(Align.CENTER, Align.CENTER, Align.MIN))
57
+ cup = fillet(cup.edges().group_by(Axis.Z)[0], 1.6) # the domed edge, on the bed
58
+ cup -= Pos(0, 0, P["lid_top"]) * Cylinder(lid_in, lid_h, align=(Align.CENTER, Align.CENTER, Align.MIN))
59
+ scallop = Pos(lid_out + 2.2, 0, 0) * Cylinder(3.0, lid_h, align=(Align.CENTER, Align.CENTER, Align.MIN))
60
+ cup -= [Rot(0, 0, i * 360 / P["scallops"]) * scallop for i in range(P["scallops"])]
61
+ lid = cup + Pos(0, 0, 0) * thread(lid_in, neck_r + P["fit"], P["lid_top"] + P["S"] + 0.6)
62
+ return Compound([jar, Pos(R + lid_out + P["gap_on_plate"], 0, 0) * lid])
@@ -0,0 +1,95 @@
1
+ """Trigger capo for a steel-string acoustic guitar
2
+ Pattern: two rigid levers on one pivot with a printed hairpin spring; each profile drawn in the plane it bends in, extruded, edges chamfered; one script gives the assembled pose and the print plate
3
+ Modelled on: Kyser Quick-Change KG6 (https://kysermusical.com/products/acoustic-guitar-capo) and Dunlop Trigger 83CB (https://www.jimdunlop.com/37083002001-trigger-capo-acoustic/)
4
+ Published sizes used: 44.45 mm = Martin D-28 fingerboard width at the nut, 53.98 mm at the 12th fret (maker, https://www.martinguitar.com/guitars/standard-series/D-28.html), so 48 mm where a capo sits; 406.4 mm (16 in) = the D-28's published saddle radius, used for the bar's curve (maker, same page; the fingerboard radius itself is not on it); 29 to 74 N = clamp force measured on bought spring capos, too little buzzes and too much pulls sharp (G7th, https://www.g7th.com/force-testing-at-sheehans); 4.5 mm = M4 clearance hole (ISO 273 medium). The neck depth (23.5 mm, string tops to the back of the neck) is not published by the maker: measure the guitar.
5
+ Concept: A capo is a spring clamp that frets all six strings at once, put on and taken off with one hand. This is the trigger kind every shop sells: two rigid levers on one pivot beside the neck. The upper lever's bar lies across the strings (curved to the fingerboard, thickest at its root where the bending is greatest) and the lower lever curls round the back of the neck to a cradle under its centre; both jaws carry a 2 mm soft pad, because bare plastic buzzes on strings and marks lacquer. Their tails are the handles: squeezing them opens the jaws, and a hairpin spring printed as part of the lower lever pushes them apart again. Load path: spring, handles, pivot screw, jaws, pads, strings and neck. The spring's two 2.94 mm legs bend in the print plane; standing 18 degrees open off the guitar it is unstrained, on the neck it gives about 34 N at the strings at about 1.5 % strain, and fully open about 2.9 % for a moment (beam estimate, PETG, E about 2000 MPa: not a measurement). Each lever prints flat on its side, so every layer runs the length of the lever and the spring; the levers are halved at the pivot (a half-lap) so both lie flat with no supports, the upper one turned over. PETG, 4 walls. Add an M4 x 20 screw with a self-locking nut, and two pads (TPU, or self-adhesive silicone strip). Take it off the guitar when you stop playing: held bent, PETG slowly relaxes.
6
+ What makes this good: it is the product (two levers, a pivot, a spring, pads, handles a hand can squeeze) with every part drawn in the plane it bends in, and it rests unstrained.
7
+ """
8
+ import math
9
+ from build123d import *
10
+
11
+ P = {
12
+ "pose": "assembled", # "assembled": clamped on the neck, standing as used; "plate": both arms flat, as printed
13
+ "neck_width": 48.0, # fingerboard width where the capo sits (frets 1 to 7)
14
+ "neck_depth": 23.5, # string tops to the back of the neck there
15
+ "board_radius": 406.4, # fingerboard radius (16 in)
16
+ "width": 16.0, # capo width along the neck = print height of each arm
17
+ "pad": 2.0, # soft pad on both jaws (TPU, or a bought silicone strip)
18
+ "bar_tip": 6.0, # string bar thickness at its free end
19
+ "bar_root": 10.0, # and at its root, where the bending moment is greatest
20
+ "arm": 8.0, # thickness of the neck arm and the handles
21
+ "pivot_out": 17.0, # pivot centre: this far outside the bass edge of the fingerboard
22
+ "pivot_down": 9.0, # and this far below the string tops
23
+ "pivot_d": 4.5, # clearance hole for an M4 screw (ISO 273, medium)
24
+ "lug_r": 8.0, # pivot lug radius
25
+ "handle": 54.0, # handle length from the pivot
26
+ "handle_deg": 30.0, # each handle's angle from the horizontal, clamped
27
+ "spring_t": 2.94, # hairpin leg thickness: 7 lines of 0.42
28
+ "spring_set": 18.0, # degrees the free spring stands open beyond its seat: gives the clamp force
29
+ "edge": 1.2, # chamfer on every long edge a hand or the guitar touches
30
+ "gap": 0.3, # clearance between the arms at the pivot, and under each pad
31
+ }
32
+
33
+ def polar(c, r, deg):
34
+ return (c[0] + r * math.cos(math.radians(deg)), c[1] + r * math.sin(math.radians(deg)))
35
+
36
+ def stroke(curve, w): # a curve given width, with round ends
37
+ return trace(curve, w) + Pos((curve @ 0).X, (curve @ 0).Y) * Circle(w / 2) + Pos((curve @ 1).X, (curve @ 1).Y) * Circle(w / 2)
38
+
39
+ def build():
40
+ W, pad, half, arm, H, g = P["neck_width"], P["pad"], P["neck_width"] / 2, P["arm"], P["width"], P["gap"]
41
+ piv = (W + P["pivot_out"], -P["pivot_down"])
42
+ sag = P["board_radius"] - math.sqrt(P["board_radius"] ** 2 - half ** 2) # the fingerboard's crown
43
+ lug = Pos(*piv) * Circle(P["lug_r"])
44
+
45
+ # upper arm: string bar (thickest at its root), shoulder down to the pivot, handle up and out
46
+ x0, x1 = -3.0, W + 3.0
47
+ under = ThreePointArc((x0, pad - sag), (half, pad), (x1, pad - sag)) # follows the fingerboard radius
48
+ over = Spline((x1, pad + P["bar_root"]), (half, pad + (P["bar_tip"] + P["bar_root"]) / 2 + 0.8), (x0, pad + P["bar_tip"]))
49
+ bar = make_face([under, Line(under @ 1, over @ 0), over, Line(over @ 1, under @ 0)])
50
+ bar = fillet(bar.vertices().sort_by(Axis.X)[:2], 2.5) # round the free tip
51
+ shoulder = stroke(Spline((x1 - 5, pad + P["bar_root"] / 2), (x1 + 5, pad + 2), piv), P["bar_root"])
52
+ up_tip = polar(piv, P["handle"], P["handle_deg"])
53
+ upper = bar + shoulder + lug + stroke(Spline(piv, polar(piv, P["handle"] * 0.5, P["handle_deg"] + 6), up_tip), arm) + Pos(*up_tip) * Circle(arm * 0.8)
54
+
55
+ # lower arm: an elliptical C round the back of the neck to a cradle under its centre, handle down and out
56
+ cx, cy = half, -2.5
57
+ a, b = half + 3.0 + arm / 2, P["neck_depth"] + cy + pad + arm / 2 # the C's centre line
58
+ ell = lambda t, da=0.0: (cx + (a + da) * math.cos(math.radians(t)), cy + (b + da) * math.sin(math.radians(t)))
59
+ lo_tip = polar(piv, P["handle"], -P["handle_deg"])
60
+ lower = stroke(Spline(piv, *[ell(t) for t in range(-30, -119, -11)]), arm) + lug
61
+ lower += stroke(Spline(piv, polar(piv, P["handle"] * 0.5, -P["handle_deg"] - 6), lo_tip), arm) + Pos(*lo_tip) * Circle(arm * 0.8)
62
+
63
+ # hairpin spring, part of the lower arm, in the wedge between the handles: from the lower handle's tip in
64
+ # towards the pivot, round a bend, and out to bear under the upper handle. Both legs bend in the print plane.
65
+ t, rb = P["spring_t"], 6.0
66
+ bend = polar(piv, 28.0, 0)
67
+ seat_deg = P["handle_deg"] - math.degrees(math.asin((arm / 2 + t / 2 + g) / (P["handle"] - 8)))
68
+ open_deg = P["spring_set"] if P["pose"] == "plate" else 0.0 # free shape on the plate, seated when assembled
69
+ root = polar(piv, P["handle"] - 2, -P["handle_deg"] + 4)
70
+ nose = polar(piv, P["handle"] - 8, seat_deg + open_deg)
71
+ lo_b, up_b = polar(bend, rb, -90), polar(bend, rb, 90 + open_deg)
72
+ hairpin = stroke(Line(root, lo_b), t) + stroke(ThreePointArc(lo_b, polar(bend, rb, 180 + open_deg / 2), up_b), t) + stroke(Line(up_b, nose), t)
73
+
74
+ # solids: extrude, round the long edges, then halve each arm at the pivot (a half-lap) so both print flat
75
+ hole = Pos(*piv) * Circle(P["pivot_d"] / 2)
76
+ lap = Pos(*piv) * Circle(P["lug_r"] + 5.0)
77
+ def solid(sketch, keep_low, spring=None):
78
+ body = extrude(sketch - hole, H)
79
+ # break both faces' edges with a chamfer: on an outline built from many curves a chamfer always succeeds
80
+ # where OCCT's fillet often fails, and on the bed face it also takes up the first layer's flare
81
+ body = chamfer(body.edges().group_by(Axis.Z)[0] + body.edges().group_by(Axis.Z)[-1], P["edge"])
82
+ if spring: # the spring keeps square edges: it is thinner than two chamfers
83
+ body += extrude(spring, H)
84
+ cut = extrude(lap, H / 2 + g / 2 + 1)
85
+ return body - (Pos(0, 0, H / 2 - g / 2) * cut if keep_low else Pos(0, 0, -1) * cut)
86
+ upper3, lower3 = solid(upper, False), solid(lower, True, hairpin)
87
+
88
+ if P["pose"] == "plate": # as printed: each arm on its side, the upper one turned over so its half-lap is on the bed
89
+ return Compound([lower3, Pos(0, 50, H) * Rot(180, 0, 0) * upper3])
90
+ # soft pads, shown in place: under the bar on the strings, and in the cradle on the back of the neck
91
+ string_pad = make_face([ThreePointArc((x0 + 1, -sag), (half, 0), (x1 - 1, -sag)), Line((x1 - 1, -sag), (x1 - 1, pad - sag - g)),
92
+ ThreePointArc((x1 - 1, pad - sag - g), (half, pad - g), (x0 + 1, pad - sag - g)), Line((x0 + 1, pad - sag - g), (x0 + 1, -sag))])
93
+ neck_pad = trace(Spline(*[ell(t, -arm / 2 - pad / 2 - g) for t in range(-112, -67, 11)]), pad)
94
+ pads = [Pos(0, 0, 1) * extrude(s, H - 2) for s in (string_pad, neck_pad)]
95
+ return Pos(0, 0, 40) * Rot(90, 0, 0) * Compound([upper3, lower3, *pads]) # stand it up: the neck runs along Y
@@ -0,0 +1,65 @@
1
+ """Screw-on wall coat hook (single curved arm with a ball tip)
2
+ Pattern: loft elliptical sections placed along a spline (an arm that tapers), ball tip, fillet the arm into the back plate
3
+ Modelled on: classic cast single coat hook; screw is SPAX 4.0 mm flat countersunk (https://www.ahlsell.se/en/products/mounting/wood-screw/wood-screw-spax/71333788---traskruv-tft-spax-svart-4.0x25h-200fp-eta-120114)
4
+ Published sizes used: 4.0 mm = screw thread diameter, 8.0 mm = head diameter, 2.4 mm = head height (retailer listing for SPAX, URL above); plate and arm sizes are design choices (no hook maker publishes them)
5
+ Concept: A coat hook for one heavy coat or bag. Frame: the wall is the XZ plane at y = 0, the hook reaches towards -y (towards the front view), Z is up. The coat's weight bends the arm like a cantilever, so the arm is deepest (in Z) where it meets the plate and thins towards the tip; the root is filleted so the stress does not peak at a sharp corner; the plate turns that bending into a pull on the top screw and a push on the wall at the bottom. The ball tip is fatter than the arm so a loop cannot slide off. Print it lying on its side (X up, one flank of the plate on the bed) so every layer contains the whole curve of the arm: printed plate-down, the arm would snap along a layer at the root. On its side the arm floats a few mm above the bed, so it needs supports under the arm and a brim. PETG or PLA, 4 walls.
6
+ What makes this good: the arm is a tapering loft along a curve with a filleted root and ball tip, like a cast hook, not a bent strip.
7
+ """
8
+ from build123d import *
9
+
10
+ P = {
11
+ "plate_w": 30.0, # back plate width (X)
12
+ "plate_h": 96.0, # back plate height (Z)
13
+ "plate_t": 6.0, # back plate thickness (Y); leaves 3.6 mm under the screw head
14
+ "plate_edge_r": 2.0, # soft front edge of the plate
15
+ "screw_d": 4.0, # screw thread diameter (published)
16
+ "screw_head_d": 8.0, # screw head diameter (published)
17
+ "screw_head_h": 2.4, # screw head height (published); sets the countersink depth
18
+ "screw_clear": 0.5, # added to thread and head diameters so the screw drops in
19
+ "screw_pitch": 68.0, # distance between the two screws, one above and one below the arm
20
+ "reach": 46.0, # how far the tip stands off the plate face
21
+ "dip": 9.0, # how far the arm sags below its root before turning up (the coat sits here)
22
+ "rise": 15.0, # tip height above the root
23
+ "root_w": 15.0, # arm width (X) at the plate
24
+ "root_h": 21.0, # arm depth (Z) at the plate: deep where the bending is highest
25
+ "tip_d": 10.0, # arm diameter just under the ball
26
+ "ball_d": 14.0, # ball tip diameter
27
+ "root_fillet": 4.0, # blend of the arm into the plate
28
+ }
29
+
30
+
31
+ def build():
32
+ t = P["plate_t"]
33
+ # back plate: a slot outline (round ends) pulled off the wall, front edge softened
34
+ plate = extrude(Plane.XZ * SlotOverall(P["plate_h"], P["plate_w"], rotation=90), t)
35
+ plate = fillet(plate.edges().group_by(Axis.Y)[0], P["plate_edge_r"])
36
+
37
+ # arm centreline in the YZ plane: leaves the plate square (so the root section stays
38
+ # inside the plate), dips, then turns up to the tip
39
+ spine = Spline(
40
+ [(0, -1, 0), (0, -t - 0.5 * P["reach"], -P["dip"]), (0, -t - P["reach"], P["rise"])],
41
+ tangents=[(0, -1, 0), (0, 0, 1)],
42
+ )
43
+ # ellipses square to the spine: deep and wide at the root, round at the tip
44
+ sections = []
45
+ for i in range(5):
46
+ u = i / 4
47
+ w = P["root_w"] + (P["tip_d"] - P["root_w"]) * u**0.6
48
+ h = P["root_h"] + (P["tip_d"] - P["root_h"]) * u**0.6
49
+ sections.append(Plane(spine @ u, x_dir=(1, 0, 0), z_dir=spine % u) * Ellipse(w / 2, h / 2))
50
+ # ball tip; trimming 0.05 mm off the sphere's poles keeps the exported mesh watertight
51
+ ball = Sphere(P["ball_d"] / 2) & Box(P["ball_d"], P["ball_d"], P["ball_d"] - 0.1)
52
+ arm = loft(sections) + Pos(spine @ 1) * ball
53
+
54
+ body = plate + arm
55
+ # the seam where the arm meets the plate face is the only spline edge on that face
56
+ seam = body.edges().filter_by_position(Axis.Y, -t - 0.01, -t + 0.01).filter_by(GeomType.BSPLINE)
57
+ body = fillet(seam, P["root_fillet"])
58
+
59
+ # two countersunk screw holes through the plate, heads flush with the front face
60
+ hole_r = (P["screw_d"] + P["screw_clear"]) / 2
61
+ head_r = (P["screw_head_d"] + P["screw_clear"]) / 2
62
+ screw = Cylinder(hole_r, 3 * t) + Cone(hole_r, head_r, P["screw_head_h"], align=(Align.CENTER, Align.CENTER, Align.MAX))
63
+ for z in (P["screw_pitch"] / 2, -P["screw_pitch"] / 2):
64
+ body -= Pos(0, -t, z) * Rot(90, 0, 0) * screw
65
+ return body
@@ -0,0 +1,77 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ /**
6
+ * The code engine's cookbook: worked build123d designs, each modelled on the best bought version of the thing, kept as
7
+ * plain scripts in src/cad/examples/. A design worker reaches them only through this MCP: the cad_design prompt names
8
+ * each pattern in one line, and the read-only cad_examples tool returns one script on request, so the prompt pays a
9
+ * line per example instead of a script per example.
10
+ *
11
+ * A script's header (its docstring) is the record: title on the first line, then "Pattern:", "Modelled on:",
12
+ * "Published sizes used:", "Concept:" and "What makes this good:".
13
+ */
14
+ const DIR = fileURLToPath(new URL("../../src/cad/examples/", import.meta.url));
15
+ const FIELDS = {
16
+ "Pattern": "pattern",
17
+ "Modelled on": "modelled_on",
18
+ "Published sizes used": "published_sizes",
19
+ "Concept": "concept",
20
+ "What makes this good": "what_makes_this_good",
21
+ } as const;
22
+ type Field = (typeof FIELDS)[keyof typeof FIELDS];
23
+ export type CadExample = { name: string; title: string; script: string } & Record<Field, string>;
24
+
25
+ /** Simplest first: the order the list and the prompt present them in. */
26
+ export const CAD_EXAMPLE_ORDER = [
27
+ "cable_clip", "wall_hook", "knurled_knob", "phone_stand", "swept_hook", "loft_handle", "threaded_jar",
28
+ "bag_clip", "hinged_box", "bistable_clicker", "chainmail", "trigger_capo",
29
+ ];
30
+
31
+ function parse(name: string, script: string): CadExample {
32
+ const header = /^\s*"""([\s\S]*?)"""/.exec(script)?.[1] ?? "";
33
+ const lines = header.split("\n");
34
+ const example = { name, title: (lines.shift() ?? name).trim(), script } as CadExample;
35
+ let field: Field | undefined;
36
+ for (const line of lines) {
37
+ const start = /^([A-Z][A-Za-z ]+):\s*(.*)$/.exec(line);
38
+ const key = start && (FIELDS as Record<string, Field>)[start[1]];
39
+ if (start && key) { field = key; example[key] = start[2].trim(); }
40
+ else if (field && line.trim()) example[field] += " " + line.trim();
41
+ }
42
+ for (const key of Object.values(FIELDS)) example[key] ??= "";
43
+ return example;
44
+ }
45
+
46
+ let cache: CadExample[] | undefined;
47
+ /** Every example on disk, in cookbook order (unlisted files last, by name). Empty when the folder is missing. */
48
+ export function cadExamples(): CadExample[] {
49
+ if (cache) return cache;
50
+ let files: string[] = [];
51
+ try { files = fs.readdirSync(DIR).filter((f) => /^[a-z0-9_]+\.py$/.test(f)); } catch { /* no cookbook shipped */ }
52
+ const rank = (n: string) => { const i = CAD_EXAMPLE_ORDER.indexOf(n); return i < 0 ? CAD_EXAMPLE_ORDER.length : i; };
53
+ cache = files.map((f) => parse(f.slice(0, -3), fs.readFileSync(path.join(DIR, f), "utf8")))
54
+ .sort((a, b) => rank(a.name) - rank(b.name) || a.name.localeCompare(b.name));
55
+ return cache;
56
+ }
57
+
58
+ /** One line per example for the cad_design prompt: "name: what it is; the pattern it shows". */
59
+ export function cadExampleLines(): string {
60
+ return cadExamples().map((e) => `${e.name}: ${e.title}; ${e.pattern}`).join("\n");
61
+ }
62
+
63
+ /** cad_examples: without a name, the list; with one, that example's record and script. */
64
+ export function cadExamplesTool(args: Record<string, unknown>): Record<string, unknown> {
65
+ const extra = Object.keys(args).filter((k) => k !== "name");
66
+ if (extra.length) throw new Error("cad_examples accepts only name.");
67
+ const all = cadExamples();
68
+ if (args.name === undefined)
69
+ return {
70
+ examples: all.map(({ name, title, pattern, modelled_on }) => ({ name, title, pattern, modelled_on })),
71
+ usage: "Call cad_examples with one name to read its concept and script. Adapt the pattern to the request and to the product the person means; do not paste an example's sizes onto a different object.",
72
+ };
73
+ if (typeof args.name !== "string") throw new Error("name must be a string.");
74
+ const found = all.find((e) => e.name === args.name);
75
+ if (!found) throw new Error(`No example named ${JSON.stringify(args.name)}. Examples: ${all.map((e) => e.name).join(", ")}.`);
76
+ return { ...found };
77
+ }
@@ -1,11 +1,11 @@
1
- """Independent geometry checks, six orthographic views and triangle-exact surface separation."""
1
+ """Independent geometry checks, six orthographic views, a perspective view and triangle-exact surface separation."""
2
2
  from pathlib import Path
3
3
  import json
4
4
  import math
5
5
  import numpy as np
6
6
  import trimesh
7
7
  import manifold3d as mf
8
- from PIL import Image, ImageDraw
8
+ from PIL import Image, ImageDraw, ImageFont
9
9
 
10
10
 
11
11
  def mesh(file):
@@ -31,6 +31,9 @@ def inspect(request):
31
31
  step_bounds = [list(sb.min), list(sb.max)] if sb is not None else None
32
32
  checks = {'watertight': bool(m.is_watertight), 'winding_consistent': bool(m.is_winding_consistent), 'positive_volume': bool(m.is_volume),
33
33
  'manifold': mm.status() == mf.Error.NoError, 'step_valid': bool(step.is_valid) if step is not None else None,
34
+ # A solid design whose STEP holds only shells (seen after rounding a sketch by offsetting it out and
35
+ # back) is not the B-rep it claims to be, however good its mesh looks.
36
+ 'step_solids': bool(len(step.solids()) >= 1) if step is not None else None,
34
37
  'stl_step_bounds_agree': bool(np.max(np.abs(m.bounds - np.array(step_bounds))) <= 0.2) if step_bounds is not None else None}
35
38
  try:
36
39
  assembly = bodies(step, request) if step is not None else None
@@ -287,12 +290,127 @@ def render(m, folder):
287
290
  draw.line([tuple(xy[i, j]), tuple(xy[i, (j + 1) % 3])], fill=(27, 62, 70), width=2)
288
291
  draw.text((24, 22), name + ' | ' + ', '.join(f'{x:.2f}' for x in m.extents) + ' mm', fill='black')
289
292
  file = folder / (name + '.png'); im.save(file); paths[name] = str(file); images.append(im)
290
- sheet = Image.new('RGB', (1600, 2400), 'white')
291
- for i, im in enumerate(images): sheet.paste(im, ((i % 2) * 800, (i // 2) * 800))
293
+ # The view a person judges a shape from: three-quarter, in perspective, large on the sheet beside the six.
294
+ big = perspective(m, 1600)
295
+ label = 'perspective, from the front right and above | ' + ' x '.join(f'{x:.1f}' for x in m.extents) + ' mm'
296
+ ImageDraw.Draw(big).text((28, 24), label, fill='black', font=ImageFont.load_default(size=30))
297
+ file = folder / 'perspective.png'; big.resize((800, 800), Image.LANCZOS).save(file); paths['perspective'] = str(file)
298
+ sheet = Image.new('RGB', (1600 + 2 * 534, 1602), 'white')
299
+ sheet.paste(big, (0, 0))
300
+ for i, im in enumerate(images): sheet.paste(im.resize((534, 534), Image.LANCZOS), (1600 + (i % 2) * 534, (i // 2) * 534))
292
301
  sheet.save(folder / 'contact.png'); paths['contact'] = str(folder / 'contact.png')
293
302
  return paths
294
303
 
295
304
 
305
+ def perspective(m, size=1600, azimuth=35.0, elevation=26.0):
306
+ """A three-quarter view in true perspective with a depth buffer (large flat faces defeat depth sorting at an
307
+ angle). Seen from the front (-Y) turned `azimuth` degrees towards +X and raised `elevation` degrees, through a
308
+ 28 degree lens, framed to fill the picture. Smooth shading across facets that meet within 40 degrees, so a
309
+ lofted or filleted surface reads as one surface and a real edge stays an edge; outlines where the surface steps
310
+ in depth or creases by more than 35 degrees. Every array operation is over all triangles at once."""
311
+ V, F, N = np.asarray(m.vertices, float), np.asarray(m.faces), np.asarray(m.face_normals, float)
312
+ centre, radius = m.bounds.mean(axis=0), max(float(np.linalg.norm(m.extents)) / 2, 1e-9)
313
+ az, el = math.radians(azimuth), math.radians(elevation)
314
+ to_eye = np.array([math.sin(az) * math.cos(el), -math.cos(az) * math.cos(el), math.sin(el)])
315
+ d = -to_eye
316
+ r = np.cross(d, [0, 0, 1.0]); r /= np.linalg.norm(r)
317
+ u = np.cross(r, d)
318
+ eye = centre + to_eye * radius / math.sin(math.radians(14)) * 1.06
319
+ q = V - eye
320
+ zc = q @ d
321
+ tx, ty = (q @ r) / zc, (q @ u) / zc
322
+ zoom = 0.86 * size / max(float(np.ptp(tx)), float(np.ptp(ty)), 1e-12)
323
+ X = size / 2 + zoom * (tx - (tx.min() + tx.max()) / 2)
324
+ Y = size / 2 - zoom * (ty - (ty.min() + ty.max()) / 2)
325
+ W = 1.0 / zc # inverse depth is affine across a triangle on screen
326
+ # light: key from the upper left of the viewer, a weaker fill from the right
327
+ key = -0.55 * r + 0.75 * u - 0.45 * d; key /= np.linalg.norm(key)
328
+ fill = 0.8 * r + 0.15 * u - 0.6 * d; fill /= np.linalg.norm(fill)
329
+ lum = lambda n: 0.26 + 0.58 * np.clip(n @ key, 0, None) + 0.2 * np.clip(n @ fill, 0, None)
330
+ vn = np.asarray(m.vertex_normals, float)
331
+ corner = vn[F] # (T, 3, 3): use the vertex normal only where it is this face's
332
+ smooth = np.einsum('tkj,tj->tk', corner, N) > 0.766
333
+ L = np.where(smooth, lum(corner.reshape(-1, 3)).reshape(-1, 3), lum(N)[:, None])
334
+ facing = np.einsum('ij,ij->i', N, V[F].mean(axis=1) - eye) < 0
335
+ if m.is_watertight:
336
+ front = facing # a closed solid: its back faces are never seen
337
+ else: # an open scan is seen from both sides: light the side that faces the eye
338
+ front = np.ones(len(F), bool)
339
+ L = np.where(facing[:, None], L, np.where(smooth, lum(-corner.reshape(-1, 3)).reshape(-1, 3), lum(-N)[:, None]))
340
+ N = np.where(facing[:, None], N, -N)
341
+ x, y, w, L = X[F][front], Y[F][front], W[F][front], L[front]
342
+ Nf = N[front]
343
+ det = (x[:, 1] - x[:, 0]) * (y[:, 2] - y[:, 0]) - (x[:, 2] - x[:, 0]) * (y[:, 1] - y[:, 0])
344
+ ok = np.abs(det) > 1e-12
345
+ x, y, w, L, Nf, det = x[ok], y[ok], w[ok], L[ok], Nf[ok], det[ok]
346
+ if not len(x): # nothing faces the eye (a mesh seen exactly edge-on)
347
+ return Image.new('RGB', (size, size), '#f5f5f2')
348
+ def plane(a): # a(px, py) = a0 + gx (px - x0) + gy (py - y0)
349
+ gx = ((a[:, 1] - a[:, 0]) * (y[:, 2] - y[:, 0]) - (a[:, 2] - a[:, 0]) * (y[:, 1] - y[:, 0])) / det
350
+ gy = ((a[:, 2] - a[:, 0]) * (x[:, 1] - x[:, 0]) - (a[:, 1] - a[:, 0]) * (x[:, 2] - x[:, 0])) / det
351
+ return a[:, 0], gx, gy
352
+ w0, wx, wy = plane(w)
353
+ l0, lx, ly = plane(L)
354
+ # rows each triangle covers (pixel centres at +0.5), then the columns of each row
355
+ r0 = np.clip(np.ceil(y.min(axis=1) - 0.5), 0, size - 1).astype(np.int64)
356
+ r1 = np.clip(np.floor(y.max(axis=1) - 0.5), 0, size - 1).astype(np.int64)
357
+ rows = np.maximum(r1 - r0 + 1, 0)
358
+ t = np.repeat(np.arange(len(x)), rows)
359
+ row = r0[t] + (np.arange(len(t)) - np.repeat(np.cumsum(rows) - rows, rows))
360
+ yc = row + 0.5
361
+ lo, hi = np.full(len(t), np.inf), np.full(len(t), -np.inf)
362
+ for a, b in ((0, 1), (1, 2), (2, 0)):
363
+ ya, yb, xa, xb = y[t, a], y[t, b], x[t, a], x[t, b]
364
+ crosses = ((ya <= yc) & (yc < yb)) | ((yb <= yc) & (yc < ya))
365
+ xi = xa + (yc - ya) * (xb - xa) / np.where(crosses, yb - ya, 1.0)
366
+ lo, hi = np.where(crosses, np.minimum(lo, xi), lo), np.where(crosses, np.maximum(hi, xi), hi)
367
+ c0 = np.clip(np.ceil(np.where(np.isfinite(lo), lo, 0) - 0.5), 0, size - 1).astype(np.int64)
368
+ c1 = np.clip(np.floor(np.where(np.isfinite(hi), hi, -1) - 0.5), -1, size - 1).astype(np.int64)
369
+ cols = np.maximum(c1 - c0 + 1, 0)
370
+ cols[~np.isfinite(lo)] = 0
371
+ k = np.repeat(np.arange(len(t), dtype=np.int32), cols)
372
+ px = (c0[k] + (np.arange(len(k)) - np.repeat(np.cumsum(cols) - cols, cols))).astype(np.int32)
373
+ tri, py = t[k].astype(np.int32), row[k].astype(np.int32)
374
+ del k
375
+ dx, dy = (px + 0.5 - x[tri, 0]).astype(np.float32), (py + 0.5 - y[tri, 0]).astype(np.float32)
376
+ wv = w0[tri] + wx[tri] * dx + wy[tri] * dy
377
+ pix = py.astype(np.int64) * size + px
378
+ del px, py
379
+ zbuf = np.zeros(size * size)
380
+ np.maximum.at(zbuf, pix, wv)
381
+ win = wv >= zbuf[pix]
382
+ tid = np.full(size * size, -1, dtype=np.int32)
383
+ tid[pix[win]] = tri[win]
384
+ shade = np.zeros(size * size, dtype=np.float32)
385
+ shade[pix[win]] = np.clip(l0[tri[win]] + lx[tri[win]] * dx[win] + ly[tri[win]] * dy[win], 0, 1)
386
+ del tri, dx, dy, wv, pix, win
387
+ tid, zbuf, shade = tid.reshape(size, size), zbuf.reshape(size, size), shade.reshape(size, size)
388
+ solid = tid >= 0
389
+ ti = np.where(solid, tid, 0)
390
+ gx, gy, nrm = wx[ti], wy[ti], Nf[ti].astype(np.float32)
391
+ edge = np.zeros((size, size), bool)
392
+ for sy, sx in ((0, 1), (1, 0), (0, -1), (-1, 0)):
393
+ other = np.roll(solid, (-sy, -sx), axis=(0, 1))
394
+ wj = np.roll(zbuf, (-sy, -sx), axis=(0, 1))
395
+ nj = np.roll(nrm, (-sy, -sx), axis=(0, 1))
396
+ inside = np.ones((size, size), bool)
397
+ if sx == 1: inside[:, -1] = False
398
+ if sx == -1: inside[:, 0] = False
399
+ if sy == 1: inside[-1, :] = False
400
+ if sy == -1: inside[0, :] = False
401
+ step = np.abs(wj - (zbuf + gx * sx + gy * sy)) > 1.6 * zbuf / zoom
402
+ crease = np.einsum('ijk,ijk->ij', nrm, nj) < math.cos(math.radians(35))
403
+ edge |= solid & inside & ((~other) | (other & (wj < zbuf) & step) | (other & crease & (sx + sy > 0)))
404
+ edge |= np.roll(edge, 1, axis=0) & solid | np.roll(edge, 1, axis=1) & solid # two pixels wide before scaling down
405
+ del gx, gy, nrm, ti
406
+ rgb = np.empty((size, size, 3), dtype=np.float32)
407
+ ramp = np.linspace(0, 1, size)[:, None]
408
+ for c, (base, dark, top, bottom) in enumerate(((79, 22, 247, 240), (166, 46, 247, 240), (186, 52, 244, 238))):
409
+ rgb[:, :, c] = np.where(solid, base * shade + dark * (1 - shade), top + (bottom - top) * ramp)
410
+ rgb[edge] = (27, 62, 70)
411
+ return Image.fromarray(rgb.clip(0, 255).astype(np.uint8), 'RGB')
412
+
413
+
296
414
  def triangle_distance(a, b):
297
415
  """Distance for one A triangle against N B triangles: vertex/face and all 9 edge pairs."""
298
416
  n = len(b)
@@ -207,6 +207,9 @@ ${r.readonly
207
207
  (file) => !(r.inputs ?? []).includes(file),
208
208
  ))
209
209
  args.push("--ro-bind", file, file);
210
+ // bubblewrap makes the folders above each bind on its own root tmpfs; left writable (bubblewrap 0.11), a script
211
+ // could create files beside the job folder (never on the host) and setup's forbidden-write proof fails
212
+ args.push("--remount-ro", "/");
210
213
  args.push("--chdir", r.job);
211
214
  return { command: "bwrap", args };
212
215
  }
package/src/cad/worker.py CHANGED
@@ -2,6 +2,7 @@
2
2
  Inspection is a fresh process: user stdout, globals and check claims are never receipts.
3
3
  """
4
4
  import ast
5
+ import errno
5
6
  import json
6
7
  import math
7
8
  import os
@@ -142,6 +143,9 @@ def main():
142
143
  else: os.listdir(target)
143
144
  except (PermissionError, FileNotFoundError):
144
145
  pass
146
+ except OSError as e:
147
+ # A read-only sandbox root refuses the write with EROFS: that is a rejection too.
148
+ if e.errno != errno.EROFS: raise
145
149
  else:
146
150
  raise RuntimeError('CAD confinement did not reject ' + operation)
147
151
  sock = socket.socket()