From 19c36b984f655477c6e996bfa50375629ee45cf5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 16:10:21 +0100 Subject: [PATCH 1/7] brokkr.kit.v0: an extrude shape, a PROFILES section along a polyline through core.sweep; wedge and gusset sections core.SHAPES gains extrude (section, w, h, t, path, up, loop?, at?, rot?). check_kit refuses a section PROFILES does not have, a path outside 2 to 64 points (3 with loop), and anything that is not an expression where one belongs; _extrude builds through profile and sweep and re-raises what either refuses under the shape's name. PROFILES gains wedge (a right trapezoid) and gusset (a right triangle with its tips cut square). No sweep, profile or circle signature changes. Co-Authored-By: Claude Fable 5.2 --- surfaces/blender/brokkr_kitbash/core.py | 54 ++++++++++++--- surfaces/blender/tests/test_kitbash.py | 88 ++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 10 deletions(-) diff --git a/surfaces/blender/brokkr_kitbash/core.py b/surfaces/blender/brokkr_kitbash/core.py index d6156c9..e4b68ba 100644 --- a/surfaces/blender/brokkr_kitbash/core.py +++ b/surfaces/blender/brokkr_kitbash/core.py @@ -2,9 +2,10 @@ numpy and the standard library only, no Blender: tests/test_kitbash.py runs this file as it is. A kit is data (kits/.v0.json beside this file: mechanical, the machine parts, and cutters, the parts brokkr_kitbash.cut -places to cut a mesh, each with its recess floor as a socket). A part is a list of shapes (tube, box, lathe, and a repeat of one of -them, a step apart or turned about an axis) whose numbers may be expressions over the part's params, and a list of -sockets, each a frame on one of the part's flat faces. A lathe profile point may be marked sharp: its ring of edges +places to cut a mesh, each with its recess floor as a socket; and frame, the beams, truss, portal, gusset and wedge +of a chassis). A part is a list of shapes (tube, box, lathe, extrude: a PROFILES section along a polyline through +sweep; and a repeat of one of them, a step apart or turned about an axis) whose numbers may be expressions over the +part's params, and a list of sockets, each a frame on one of the part's flat faces. A lathe profile point may be marked sharp: its ring of edges is then a crease (Built.sharp). An expression is parsed with ast.parse and walked against a whitelist; nothing in a kit is ever run as Python. @@ -17,8 +18,9 @@ both kits declare the socket's type with the same match rule. surface_frame is t met a surface. closure_residual is how far two sockets stand from meeting as a pin, whatever the roll: what closes a loop the tree of connections cannot state. -The structure under an armor cage is built, not kit parts: PROFILES are the sections (I, C, T, L, box), sweep takes -an outline along a polyline with mitred joints (a longeron, a post), band is the rib beside a section in its plane, +PROFILES are the seven sections (I, C, T, L, box, wedge, gusset) and sweep takes an outline along a polyline with +mitred joints: an extrude shape is the two together, and so is a longeron or a post of the structure under an armor +cage, which is built, not kit parts: band is the rib beside a section in its plane, offset and clipped so that it follows a crease instead of folding in it (away, the distance to a polyline, is what clips it), inset is the step that offsets a mesh inward by its own faces (the surface a rib's edge is cut from), crossings finds where a section line meets a half-plane, resample fills a section's points in, and spans @@ -57,8 +59,10 @@ PLACED = ("at", "rot") SHAPES = {"tube": (("r0", "r1", "length", "segments"), ("inner0", "inner1", "smooth") + PLACED), "box": (("size",), PLACED), "lathe": (("profile", "segments"), ("loop", "smooth") + PLACED), + "extrude": (("section", "w", "h", "t", "path", "up"), ("loop",) + PLACED), "repeat": (("count", "of"), ("step", "around", "center"))} SEGMENTS = (3, 128) +PATH = 64 # the most points an extrude's path may list COPIES = (1, 256) @@ -233,6 +237,21 @@ def _shape(shape: Any, names, where: str, inside_repeat: bool = False) -> dict: if kind == "box": made["size"] = _vector(shape["size"], names, f"{where} size") return made + if kind == "extrude": + section, path = shape["section"], shape["path"] + if not isinstance(section, str) or section not in PROFILES: + raise KitError(f"{where} section: {section!r} is not one of {', '.join(PROFILES)}") + if not isinstance(shape.get("loop", False), bool): + raise KitError(f"{where} loop must be true or false") + made["section"], made["loop"] = section, shape.get("loop", False) + for key in ("w", "h", "t"): + made[key] = parse(shape[key], names, f"{where} {key}") + least = 3 if made["loop"] else 2 + if not isinstance(path, list) or not least <= len(path) <= PATH: + raise KitError(f"{where} path must be an array of {least} to {PATH} [x, y, z] points{' (it is a loop)' if made['loop'] else ''}") + made["path"] = [_vector(point, names, f"{where} path[{i}]") for i, point in enumerate(path)] + made["up"] = _vector(shape["up"], names, f"{where} up") + return made for key in ("loop", "smooth"): if not isinstance(shape.get(key, False), bool): raise KitError(f"{where} {key} must be true or false") @@ -550,8 +569,22 @@ def _box(shape: dict, env): return BOX_SIGNS * size, BOX_FACES.ravel(), np.full(6, 4), np.zeros(6, dtype=bool), NO_SHARP +def _extrude(shape: dict, env): + """A PROFILES section swept along the path: profile and sweep own the geometry (the outline's x is up cross the + path's tangent, its y is up taken off the tangent, the joints are mitred), and what either refuses is refused + here under the shape's name. Every face is flat.""" + size = [shape[key].value(env) for key in ("w", "h", "t")] + path = [[e.value(env) for e in point] for point in shape["path"]] + up = [e.value(env) for e in shape["up"]] + try: + swept = sweep(path, profile(shape["section"], *size), up, shape["loop"]) + except KitError as error: + raise KitError(f"{shape['where']}: {error}") from None + return swept.V, swept.faces, swept.counts, swept.smooth, NO_SHARP + + def _placed(shape: dict, env): - V, faces, counts, smooth, sharp = {"tube": _tube, "box": _box, "lathe": _lathe}[shape["shape"]](shape, env) + V, faces, counts, smooth, sharp = {"tube": _tube, "box": _box, "lathe": _lathe, "extrude": _extrude}[shape["shape"]](shape, env) rotation = _rotation([e.value(env) for e in shape["rot"]]) return V @ rotation.T + np.array([e.value(env) for e in shape["at"]]), faces, counts, smooth, sharp @@ -606,6 +639,7 @@ def build(part: dict, params: dict | None = None) -> Built: # --- structure: sections swept along paths -------------------------------------------------------------------- PROFILES = { # (w, h, t) -> the outline, counter-clockwise in (x across, y along up): flange width, height, wall + # (a wedge's t is its front height and a gusset's the flat that cuts each acute tip square) "I": lambda w, h, t: [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, -h / 2 + t), (t / 2, -h / 2 + t), (t / 2, h / 2 - t), (w / 2, h / 2 - t), (w / 2, h / 2), (-w / 2, h / 2), (-w / 2, h / 2 - t), (-t / 2, h / 2 - t), (-t / 2, -h / 2 + t), (-w / 2, -h / 2 + t)], "C": lambda w, h, t: [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, -h / 2 + t), (-w / 2 + t, -h / 2 + t), (-w / 2 + t, h / 2 - t), (w / 2, h / 2 - t), @@ -613,6 +647,8 @@ PROFILES = { # (w, h, t) -> the outline, counter-clockwise in (x across, y alon "T": lambda w, h, t: [(-t / 2, -h / 2), (t / 2, -h / 2), (t / 2, h / 2 - t), (w / 2, h / 2 - t), (w / 2, h / 2), (-w / 2, h / 2), (-w / 2, h / 2 - t), (-t / 2, h / 2 - t)], "L": lambda w, h, t: [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, -h / 2 + t), (-w / 2 + t, -h / 2 + t), (-w / 2 + t, h / 2), (-w / 2, h / 2)], "box": lambda w, h, t: [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, h / 2), (-w / 2, h / 2)], + "wedge": lambda w, h, t: [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, -h / 2 + t), (-w / 2, h / 2)], + "gusset": lambda w, h, t: [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, -h / 2 + t), (-w / 2 + t, h / 2), (-w / 2, h / 2)], } TURN_LIMIT = 150.0 # degrees a swept path may turn at one point: past it a mitre runs 3.9 times the section's width @@ -620,10 +656,12 @@ TURN_LIMIT = 150.0 # degrees a swept path may turn at one point: past it a mitr def profile(kind: str, w: float, h: float, t: float) -> np.ndarray: """PROFILES[kind] at a width, height and wall, as an (M, 2) array. Refuses a kind PROFILES does not have, a size that is not above 0, and a wall that leaves no section: as wide as the flange, or as thick as the height its - flanges share (two on an I and a C, one on a T and an L). A box has no wall.""" + flanges share (two on an I and a C, one on a T and an L). A box has no wall. A wedge is a right trapezoid, base w, + back height h and front height t, under h; a gusset a right triangle on legs w and h whose two acute tips are cut + square by a flat t long, under half the shorter leg.""" if kind not in PROFILES: raise KitError(f"profile {kind!r} is not one of {', '.join(PROFILES)}") - limit = min(w, h / 2 if kind in ("I", "C") else h) + limit = h if kind == "wedge" else min(w, h) / 2 if kind == "gusset" else min(w, h / 2 if kind in ("I", "C") else h) if not all(finite(v) and v > 0 for v in (w, h, t)) or (kind != "box" and not t < limit): raise KitError(f"profile {kind!r} of width {w}, height {h}, wall {t}: every size must be above 0 and the wall under {limit:.6g}") return np.array(PROFILES[kind](w, h, t), dtype=np.float64) diff --git a/surfaces/blender/tests/test_kitbash.py b/surfaces/blender/tests/test_kitbash.py index 1d66c66..36ccec5 100644 --- a/surfaces/blender/tests/test_kitbash.py +++ b/surfaces/blender/tests/test_kitbash.py @@ -187,6 +187,7 @@ class CheckKitTests(unittest.TestCase): """check-kit-refusals. Mutant M2 (skip the unknown-key check): the 'colour' and 'radius' documents are admitted.""" socket = {"name": "s", "type": "mount", "size": 1, "at": [0, 0, 0], "z": "+z", "y": "+y"} box = {"shape": "box", "size": [1, 1, 1]} + beam = {"shape": "extrude", "section": "I", "w": 0.06, "h": 0.1, "t": 0.012, "path": [[0, 0, 0], [0, 0, 1]], "up": [0, 1, 0]} cases = [ ({**document(), "schema": "brokkr.kit.v1"}, r"schema must be brokkr\.kit\.v0"), ({**document(), "colour": 1}, r"kit has no key 'colour'"), @@ -209,7 +210,20 @@ class CheckKitTests(unittest.TestCase): (document(sockets=[{**socket, "z": {}}]), r"part 'p' socket 's': z must be one of"), (document([{"shape": ["box"], "size": [1, 1, 1]}]), r"part 'p' shape 0: unknown shape \['box'\]"), (document(sockets=[{**socket, "at": [0, 0, 10 ** 400]}]), r"part 'p' socket 's' at\[2\]: 1000\d+ is not a finite number"), + # extrude-refusals. Mutants E2 (the section checked only at build) and E9 (a 65-point path admitted) + (document([{**beam, "section": "Z"}]), r"part 'p' shape 0 \(extrude\) section: 'Z' is not one of I, C, T, L, box, wedge, gusset"), + (document([{**beam, "section": ["I"]}]), r"part 'p' shape 0 \(extrude\) section: \['I'\] is not one of"), + (document([{**beam, "path": [[0, 0, 0]]}]), r"part 'p' shape 0 \(extrude\) path must be an array of 2 to 64 \[x, y, z\] points$"), + (document([{**beam, "loop": True}]), r"part 'p' shape 0 \(extrude\) path must be an array of 3 to 64 \[x, y, z\] points \(it is a loop\)"), + (document([{**beam, "path": [[0, 0, k] for k in range(65)]}]), r"part 'p' shape 0 \(extrude\) path must be an array of 2 to 64"), + (document([{**beam, "path": [[0, 0, 0], [0, 1]]}]), r"part 'p' shape 0 \(extrude\) path\[1\] must be an array of three"), + (document([{**beam, "up": "+y"}]), r"part 'p' shape 0 \(extrude\) up must be an array of three"), + (document([{**beam, "loop": "yes"}]), r"part 'p' shape 0 \(extrude\) loop must be true or false"), + (document([{**beam, "w": "q"}]), r"part 'p' shape 0 \(extrude\) w: 'q' names 'q'"), + (document([{**beam, "smooth": True}]), r"part 'p' shape 0 \(extrude\) has no key 'smooth'"), + (document([{k: v for k, v in beam.items() if k != "t"}]), r"part 'p' shape 0 \(extrude\) lacks 't'"), ] + self.assertEqual(len(core.check_kit(document([{**beam, "path": [[0, 0, k] for k in range(64)]}]))["parts"]["p"]["shapes"][0]["path"]), 64) for doc, message in cases: with self.assertRaisesRegex(core.KitError, message): core.check_kit(doc) @@ -406,6 +420,70 @@ class ShapeTests(unittest.TestCase): self.assertEqual(b.shape.tolist(), [0] * 6 + [1] * 18 + [2] * 10) self.assertEqual((b.shape.dtype, b.shell_count), (np.int32, 5)) + BEAM = {"shape": "extrude", "section": "I", "w": 0.06, "h": 0.1, "t": 0.012, "path": [[0, 0, 0], [0, 0, 0.3]], "up": [0, 1, 0]} + + def test_an_extrude_is_a_section_swept_along_its_path(self): + """extrude-holds. Each of the seven sections along a straight path is one closed shell, wound outward, of the + section's area times the length, every face flat, the outline's x on up cross the tangent and its y on up. + Mutant E6 (up ignored, +z always): the path along z is refused, and the one along x stands its height on z + whatever up says.""" + w, h, t = 0.06, 0.1, 0.012 + self.assertEqual(list(core.PROFILES), ["I", "C", "T", "L", "box", "wedge", "gusset"]) + for section in core.PROFILES: + outline = core.profile(section, w, h, t) + x, y = outline.T + area = float(0.5 * np.sum(x * np.roll(y, -1) - np.roll(x, -1) * y)) + b = built([{**self.BEAM, "section": section, "w": "a", "path": [[0, 0, 0], [0, 0, "5*a"]]}], [param("a", 0.01, 1, w)]) + self.assertTrue(closed_and_oriented(b), section) + self.assertLess(abs(signed_volume(b) - area * 0.3), 1e-12, section) + self.assertEqual((b.shell_count, b.counts.tolist(), bool(b.smooth.any()), b.sharp.shape), (1, [4] * len(outline) + [len(outline)] * 2, False, (0, 2)), section) + self.assertEqual(b.V[:len(outline)].tolist(), [[px, py, 0.0] for px, py in outline.tolist()], section) + self.assertEqual(b.V[len(outline):, 2].tolist(), [0.06 * 5] * len(outline)) + extent = lambda up: np.round(np.ptp(built([{**self.BEAM, "path": [[0, 0, 0], [0.3, 0, 0]], "up": up}]).V, axis=0), 12).tolist() # noqa: E731 + self.assertEqual((extent([0, 0, 1]), extent([0, 1, 0]), extent([0, 5, 5])), ([0.3, w, h], [0.3, h, w], [0.3, round((w + h) / 2 ** 0.5, 12), round((w + h) / 2 ** 0.5, 12)])) + + def test_an_extrude_is_placed_and_repeated_as_every_shape(self): + """extrude-holds, extrude-in-repeat-and-loop. Mutants E1 (an extrude ignores at and rot: the box section stands + at the origin, unturned), E5 (repeat refuses an extrude) and E7 (loop ignored: the ring is an open path with + two caps, 14 faces and three quarters of the volume).""" + rot, at, size = [30, 40, 50], [1, 2, 3], [0.06, 0.1, 0.3] + lifted = (np.array(at) + core._rotation(rot) @ [0, 0, 0.15]).tolist() + swept = built([{**self.BEAM, "section": "box", "rot": rot, "at": at}]) + box = built([{"shape": "box", "size": size, "rot": rot, "at": lifted}]) + order = lambda V: V[np.lexsort(np.round(V, 9).T)] # noqa: E731 + self.assertLess(float(np.abs(order(swept.V) - order(box.V)).max()), 1e-12) + self.assertLess(abs(signed_volume(swept) - 0.06 * 0.1 * 0.3), 1e-12) + area = 2 * 0.06 * 0.012 + (0.1 - 2 * 0.012) * 0.012 + for change, centres in (({"step": [0.5, 0, "a"]}, [[0, 0, 0.15], [0.5, 0, 1.15], [1.0, 0, 2.15]]), + ({"around": "+y", "center": [1, 0, 0]}, [[0, 0, 0.15], [1.5 + 0.15 * 0.75 ** 0.5, 0, 0.75 ** 0.5 - 0.075], [1.5 - 0.15 * 0.75 ** 0.5, 0, -0.75 ** 0.5 - 0.075]])): + b = built([{"shape": "box", "size": [1, 1, 1]}, {"shape": "repeat", "count": 3, **change, "of": self.BEAM}], [param("a")]) + self.assertEqual((b.shell_count, b.shape.tolist()), (4, [0] * 6 + [1] * 14 * 3)) + self.assertTrue(closed_and_oriented(b)) + self.assertLess(abs(signed_volume(b) - 1.0 - 3 * area * 0.3), 1e-12) + self.assertTrue(np.allclose(b.V[8:].reshape(3, 24, 3).mean(axis=1), centres, atol=1e-12), change) + ring = built([{**self.BEAM, "section": "box", "w": 0.1, "h": 0.2, "loop": True, "path": [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], "up": [0, 0, 1]}]) + self.assertEqual((ring.shell_count, ring.counts.tolist(), len(ring.V)), (1, [4] * 16, 16)) + self.assertTrue(closed_and_oriented(ring)) + self.assertLess(abs(signed_volume(ring) - 0.1 * 0.2 * 4.0), 1e-12) # mitred: the area times the path's length + + def test_what_a_sweep_refuses_an_extrude_refuses_by_name(self): + """extrude-refusals, at build. Mutant E8 (the where prefix dropped): each message starts at 'path point' or + 'profile' and names no kit, part or shape.""" + here = r"^kit 't' part 'p' shape 0 \(extrude\): " + for change, message in ( + ({"path": [[0, 0, 0], [1, 0, 0], [0.015, 0.17, 0]], "up": [0, 0, 1]}, here + r"path point 1: the path turns 170\.2 degrees there, over 150$"), + ({"up": [0, 0, 2]}, here + r"path point 0: up \[0\.0, 0\.0, 2\.0\] runs along the path there"), + ({"up": [0, 0, 0]}, here + r"path point 0: up \[0\.0, 0\.0, 0\.0\] runs along the path there \(or is zero\)"), + ({"w": 0.4, "path": [[0, 0, 0], [1, 0, 0], [1, 0.05, 0]], "up": [0, 0, 1]}, here + r"path point 1: the section folds there"), + ({"path": [[0, 0, 0], [0, 0, 0]]}, here + r"path point 0: the segment from it is shorter than 1e-9"), + ({"t": "a"}, here + r"profile 'I' of width 0\.06, height 0\.1, wall 0\.05: every size must be above 0 and the wall under 0\.05$"), + ({"w": "a-0.05"}, here + r"profile 'I' of width 0\.0, ")): + with self.assertRaisesRegex(core.KitError, message): + built([{**self.BEAM, **change}], [param("a", 0, 1, 0.05)]) + with self.assertRaisesRegex(core.KitError, r"^kit 't' part 'p' shape 1 \(repeat\) of \(extrude\): path point 0: up"): + built([{"shape": "box", "size": [1, 1, 1]}, {"shape": "repeat", "count": 2, "step": [1, 0, 0], "of": {**self.BEAM, "up": [0, 0, 1]}}]) + self.assertEqual(len(built([{**self.BEAM, "t": "a"}], [param("a", 0, 1, 0.05)], {"a": 0.04}).counts), 14) + def test_sockets_are_right_handed_frames(self): socket = {"name": "s", "type": "mount", "size": "2*a", "at": ["a", 2, 3], "z": "+x", "y": "+z"} kit = core.check_kit(document(params=[param("a")], sockets=[socket])) @@ -1178,7 +1256,8 @@ class StructureTests(unittest.TestCase): def test_the_profiles_are_counter_clockwise_sections(self): w, h, t = 0.06, 0.1, 0.012 - areas = {"I": 2 * w * t + (h - 2 * t) * t, "C": 2 * w * t + (h - 2 * t) * t, "T": w * t + (h - t) * t, "L": w * t + (h - t) * t, "box": w * h} + areas = {"I": 2 * w * t + (h - 2 * t) * t, "C": 2 * w * t + (h - 2 * t) * t, "T": w * t + (h - t) * t, "L": w * t + (h - t) * t, "box": w * h, + "wedge": w * (h + t) / 2, "gusset": 0.003888} # the gusset's five corners by the shoelace: t*h + (w - t)*(h + t)/2 self.assertEqual(sorted(core.PROFILES), sorted(areas)) for kind, area in areas.items(): outline = core.profile(kind, w, h, t) @@ -1187,7 +1266,12 @@ class StructureTests(unittest.TestCase): self.assertAlmostEqual(float(outline[:, 1].max() - outline[:, 1].min()), h, places=15) self.assertAlmostEqual(self.area(core.circle(0.5, 16)), 0.5 * 16 * 0.25 * math.sin(2 * math.pi / 16), places=15) self.assertEqual(core.circle(0.5, 16)[0].tolist(), [0.5, 0.0]) - for bad in (("Z", w, h, t), ("I", w, h, h / 2), ("T", w, h, w), ("L", 0.0, h, t), ("C", w, h, float("nan")), ("box", w, h, 0.0)): + # profiles-seven. Mutants E3 (a wedge admits t = h: a box) and E4 (a gusset ignores t: three corners, sharp tips) + self.assertEqual(core.profile("wedge", w, h, t).tolist(), [[-w / 2, -h / 2], [w / 2, -h / 2], [w / 2, -h / 2 + t], [-w / 2, h / 2]]) + self.assertEqual(core.profile("gusset", w, h, t).tolist(), [[-w / 2, -h / 2], [w / 2, -h / 2], [w / 2, -h / 2 + t], [-w / 2 + t, h / 2], [-w / 2, h / 2]]) + self.assertEqual((len(core.profile("wedge", w, h, 0.99 * h)), len(core.profile("gusset", w, h, 0.49 * w))), (4, 5)) + for bad in (("Z", w, h, t), ("I", w, h, h / 2), ("T", w, h, w), ("L", 0.0, h, t), ("C", w, h, float("nan")), ("box", w, h, 0.0), + ("wedge", w, h, h), ("gusset", w, h, min(w, h) / 2), ("gusset", h, w, min(w, h) / 2), ("wedge", w, h, 0.0)): with self.assertRaisesRegex(core.KitError, "profile"): core.profile(*bad) for bad in ((0.0, 16), (0.5, 2), (0.5, 129)): -- 2.47.3 From 1882c9c73b9e0be240c90e2b9400ec96d8c9c33c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 16:19:18 +0100 Subject: [PATCH 2/7] kits/frame.v0.json: beams in five sections, a truss, a portal, a gusset and a wedge, each an extrude Nine parts over core.sweep and PROFILES; mount and pivot are mechanical's lines, so a frame part seats on a mechanical one. A truss's diagonals are two repeats a double bay apart (expressions have no floor). FrameKitTests holds every part at its default, minimum, maximum and 16 draws, with a socket seat that reads a section's concave cap by Newell's normal and a crossing count. Co-Authored-By: Claude Fable 5.2 --- .../blender/brokkr_kitbash/kits/frame.v0.json | 172 ++++++++++++++++++ surfaces/blender/tests/test_kitbash.py | 131 ++++++++++++- 2 files changed, 301 insertions(+), 2 deletions(-) create mode 100644 surfaces/blender/brokkr_kitbash/kits/frame.v0.json diff --git a/surfaces/blender/brokkr_kitbash/kits/frame.v0.json b/surfaces/blender/brokkr_kitbash/kits/frame.v0.json new file mode 100644 index 0000000..a61f3c7 --- /dev/null +++ b/surfaces/blender/brokkr_kitbash/kits/frame.v0.json @@ -0,0 +1,172 @@ +{ + "schema": "brokkr.kit.v0", + "kit": "frame", + "doc": "Chassis structure: sectioned beams, a truss, a portal, a gusset and a wedge, each a section swept along a path. Metres.", + "socketTypes": { + "mount": {"match": "fits", "doc": "flat seat; size is the free diameter around the socket"}, + "pivot": {"match": "equal", "doc": "pin joint; size is the pin diameter"} + }, + "parts": [ + { + "name": "beam_i", + "doc": "I beam along +z: two flanges across x joined by a web along y.", + "params": [ + {"name": "length", "type": "number", "min": 0.1, "max": 6.0, "default": 1.0, "doc": "end face to end face (z)"}, + {"name": "w", "type": "number", "min": 0.03, "max": 0.4, "default": 0.08, "doc": "width (x)"}, + {"name": "h", "type": "number", "min": 0.03, "max": 0.4, "default": 0.12, "doc": "height (y)"}, + {"name": "t", "type": "number", "min": 0.003, "max": 0.05, "default": 0.01, "doc": "wall thickness; held under 0.45 of the smaller of w and h"} + ], + "shapes": [ + {"shape": "extrude", "section": "I", "w": "w", "h": "h", "t": "min(t,0.45*min(w,h))", "path": [[0, 0, 0], [0, 0, "length"]], "up": [0, 1, 0]} + ], + "sockets": [ + {"name": "end_a", "type": "mount", "size": "min(w,h)", "at": [0, 0, 0], "z": "-z", "y": "+y"}, + {"name": "end_b", "type": "mount", "size": "min(w,h)", "at": [0, 0, "length"], "z": "+z", "y": "+y"} + ] + }, + { + "name": "channel", + "doc": "Channel (C section) along +z: the web on -x, the flanges opening toward +x. Its end sockets sit on the web.", + "params": [ + {"name": "length", "type": "number", "min": 0.1, "max": 6.0, "default": 1.0, "doc": "end face to end face (z)"}, + {"name": "w", "type": "number", "min": 0.03, "max": 0.4, "default": 0.08, "doc": "width (x)"}, + {"name": "h", "type": "number", "min": 0.03, "max": 0.4, "default": 0.12, "doc": "height (y)"}, + {"name": "t", "type": "number", "min": 0.003, "max": 0.05, "default": 0.01, "doc": "wall thickness; held under 0.45 of the smaller of w and h"} + ], + "shapes": [ + {"shape": "extrude", "section": "C", "w": "w", "h": "h", "t": "min(t,0.45*min(w,h))", "path": [[0, 0, 0], [0, 0, "length"]], "up": [0, 1, 0]} + ], + "sockets": [ + {"name": "end_a", "type": "mount", "size": "min(w,h)", "at": ["min(t,0.45*min(w,h))/2-w/2", 0, 0], "z": "-z", "y": "+y"}, + {"name": "end_b", "type": "mount", "size": "min(w,h)", "at": ["min(t,0.45*min(w,h))/2-w/2", 0, "length"], "z": "+z", "y": "+y"} + ] + }, + { + "name": "tee", + "doc": "Tee along +z: the flange across x at +y, the stem down the middle.", + "params": [ + {"name": "length", "type": "number", "min": 0.1, "max": 6.0, "default": 1.0, "doc": "end face to end face (z)"}, + {"name": "w", "type": "number", "min": 0.03, "max": 0.4, "default": 0.08, "doc": "width (x)"}, + {"name": "h", "type": "number", "min": 0.03, "max": 0.4, "default": 0.12, "doc": "height (y)"}, + {"name": "t", "type": "number", "min": 0.003, "max": 0.05, "default": 0.01, "doc": "wall thickness; held under 0.45 of the smaller of w and h"} + ], + "shapes": [ + {"shape": "extrude", "section": "T", "w": "w", "h": "h", "t": "min(t,0.45*min(w,h))", "path": [[0, 0, 0], [0, 0, "length"]], "up": [0, 1, 0]} + ], + "sockets": [ + {"name": "end_a", "type": "mount", "size": "min(w,h)", "at": [0, 0, 0], "z": "-z", "y": "+y"}, + {"name": "end_b", "type": "mount", "size": "min(w,h)", "at": [0, 0, "length"], "z": "+z", "y": "+y"} + ] + }, + { + "name": "angle", + "doc": "Angle (L section) along +z: one leg along x at -y, one along y at -x. Its end sockets sit on the upright leg.", + "params": [ + {"name": "length", "type": "number", "min": 0.1, "max": 6.0, "default": 1.0, "doc": "end face to end face (z)"}, + {"name": "w", "type": "number", "min": 0.03, "max": 0.4, "default": 0.08, "doc": "width (x)"}, + {"name": "h", "type": "number", "min": 0.03, "max": 0.4, "default": 0.12, "doc": "height (y)"}, + {"name": "t", "type": "number", "min": 0.003, "max": 0.05, "default": 0.01, "doc": "wall thickness; held under 0.45 of the smaller of w and h"} + ], + "shapes": [ + {"shape": "extrude", "section": "L", "w": "w", "h": "h", "t": "min(t,0.45*min(w,h))", "path": [[0, 0, 0], [0, 0, "length"]], "up": [0, 1, 0]} + ], + "sockets": [ + {"name": "end_a", "type": "mount", "size": "min(w,h)", "at": ["min(t,0.45*min(w,h))/2-w/2", 0, 0], "z": "-z", "y": "+y"}, + {"name": "end_b", "type": "mount", "size": "min(w,h)", "at": ["min(t,0.45*min(w,h))/2-w/2", 0, "length"], "z": "+z", "y": "+y"} + ] + }, + { + "name": "box_beam", + "doc": "Solid rectangular bar along +z.", + "params": [ + {"name": "length", "type": "number", "min": 0.1, "max": 6.0, "default": 1.0, "doc": "end face to end face (z)"}, + {"name": "w", "type": "number", "min": 0.03, "max": 0.4, "default": 0.08, "doc": "width (x)"}, + {"name": "h", "type": "number", "min": 0.03, "max": 0.4, "default": 0.12, "doc": "height (y)"} + ], + "shapes": [ + {"shape": "extrude", "section": "box", "w": "w", "h": "h", "t": "w", "path": [[0, 0, 0], [0, 0, "length"]], "up": [0, 1, 0]} + ], + "sockets": [ + {"name": "end_a", "type": "mount", "size": "min(w,h)", "at": [0, 0, 0], "z": "-z", "y": "+y"}, + {"name": "end_b", "type": "mount", "size": "min(w,h)", "at": [0, 0, "length"], "z": "+z", "y": "+y"} + ] + }, + { + "name": "truss", + "doc": "Plane truss along +x in the xz plane: two square chords at z 0 and z height, a vertical at every bay and one diagonal per bay, rising then falling. Bays come in pairs.", + "params": [ + {"name": "length", "type": "number", "min": 0.5, "max": 8.0, "default": 2.0, "doc": "first vertical's axis to the last's (x)"}, + {"name": "height", "type": "number", "min": 0.1, "max": 1.5, "default": 0.3, "doc": "chord axis to chord axis (z)"}, + {"name": "pairs", "type": "integer", "min": 1, "max": 16, "default": 4, "doc": "pairs of bays: a rising diagonal and a falling one"}, + {"name": "chord", "type": "number", "min": 0.02, "max": 0.15, "default": 0.05, "doc": "side of the square chords"}, + {"name": "web", "type": "number", "min": 0.01, "max": 0.1, "default": 0.03, "doc": "side of the square verticals and diagonals"} + ], + "shapes": [ + {"shape": "repeat", "count": 2, "step": [0, 0, "height"], "of": + {"shape": "extrude", "section": "box", "w": "chord", "h": "chord", "t": "chord", "path": [["-web/2", 0, 0], ["length+web/2", 0, 0]], "up": [0, 0, 1]}}, + {"shape": "repeat", "count": "2*pairs+1", "step": ["length/(2*pairs)", 0, 0], "of": + {"shape": "extrude", "section": "box", "w": "web", "h": "web", "t": "web", "path": [[0, 0, 0], [0, 0, "height"]], "up": [0, 1, 0]}}, + {"shape": "repeat", "count": "pairs", "step": ["length/pairs", 0, 0], "of": + {"shape": "extrude", "section": "box", "w": "web", "h": "web", "t": "web", "path": [[0, 0, 0], ["length/(2*pairs)", 0, "height"]], "up": [0, 1, 0]}}, + {"shape": "repeat", "count": "pairs", "step": ["length/pairs", 0, 0], "of": + {"shape": "extrude", "section": "box", "w": "web", "h": "web", "t": "web", "path": [["length/(2*pairs)", 0, "height"], ["length/pairs", 0, 0]], "up": [0, 1, 0]}} + ], + "sockets": [ + {"name": "end_a", "type": "mount", "size": "height", "at": ["-web/2", 0, "height/2"], "z": "-x", "y": "+z"}, + {"name": "end_b", "type": "mount", "size": "height", "at": ["length+web/2", 0, "height/2"], "z": "+x", "y": "+z"} + ] + }, + { + "name": "portal", + "doc": "Portal frame in the xz plane: one I section up a leg, across and down the other, mitred at both corners. Its flanges face +y and -y.", + "params": [ + {"name": "width", "type": "number", "min": 0.5, "max": 4.0, "default": 1.2, "doc": "leg axis to leg axis (x)"}, + {"name": "height", "type": "number", "min": 0.4, "max": 3.0, "default": 0.9, "doc": "feet to the beam's axis (z)"}, + {"name": "w", "type": "number", "min": 0.04, "max": 0.3, "default": 0.1, "doc": "section width, in the frame's plane"}, + {"name": "h", "type": "number", "min": 0.04, "max": 0.3, "default": 0.1, "doc": "section height (y)"}, + {"name": "t", "type": "number", "min": 0.004, "max": 0.04, "default": 0.01, "doc": "wall thickness; held under 0.45 of the smaller of w and h"} + ], + "shapes": [ + {"shape": "extrude", "section": "I", "w": "w", "h": "h", "t": "min(t,0.45*min(w,h))", "path": [["-width/2", 0, 0], ["-width/2", 0, "height"], ["width/2", 0, "height"], ["width/2", 0, 0]], "up": [0, 1, 0]} + ], + "sockets": [ + {"name": "foot_a", "type": "mount", "size": "min(w,h)", "at": ["-width/2", 0, 0], "z": "-z", "y": "+y"}, + {"name": "foot_b", "type": "mount", "size": "min(w,h)", "at": ["width/2", 0, 0], "z": "-z", "y": "+y"} + ] + }, + { + "name": "gusset", + "doc": "Corner plate: a right triangle with its legs along +x and +y from the origin, each acute tip cut square, thickness along +z.", + "params": [ + {"name": "w", "type": "number", "min": 0.04, "max": 0.5, "default": 0.15, "doc": "leg along x"}, + {"name": "h", "type": "number", "min": 0.04, "max": 0.5, "default": 0.15, "doc": "leg along y"}, + {"name": "t", "type": "number", "min": 0.003, "max": 0.05, "default": 0.015, "doc": "flat that cuts each tip; held under 0.45 of the shorter leg"}, + {"name": "thickness", "type": "number", "min": 0.003, "max": 0.05, "default": 0.01, "doc": "plate thickness (z)"} + ], + "shapes": [ + {"shape": "extrude", "section": "gusset", "w": "w", "h": "h", "t": "min(t,0.45*min(w,h))", "path": [[0, 0, 0], [0, 0, "thickness"]], "up": [0, 1, 0], "at": ["w/2", "h/2", 0]} + ], + "sockets": [ + {"name": "leg_a", "type": "mount", "size": "thickness", "at": ["w/2", 0, "thickness/2"], "z": "-y", "y": "+z"}, + {"name": "leg_b", "type": "mount", "size": "thickness", "at": [0, "h/2", "thickness/2"], "z": "-x", "y": "+z"} + ] + }, + { + "name": "wedge", + "doc": "Wedge (a toe cap, a ramp, a chock) along +x: its base on z 0, its tall back at -y, sloping down to a front lip at +y.", + "params": [ + {"name": "length", "type": "number", "min": 0.05, "max": 2.0, "default": 0.3, "doc": "x size"}, + {"name": "w", "type": "number", "min": 0.05, "max": 1.0, "default": 0.25, "doc": "base, back to front (y)"}, + {"name": "h", "type": "number", "min": 0.03, "max": 0.5, "default": 0.12, "doc": "back height (z)"}, + {"name": "t", "type": "number", "min": 0.005, "max": 0.3, "default": 0.03, "doc": "front height; held under 0.9 of h"} + ], + "shapes": [ + {"shape": "extrude", "section": "wedge", "w": "w", "h": "h", "t": "min(t,0.9*h)", "path": [[0, 0, 0], ["length", 0, 0]], "up": [0, 0, 1], "at": [0, 0, "h/2"]} + ], + "sockets": [ + {"name": "base", "type": "mount", "size": "min(length,w)", "at": ["length/2", 0, 0], "z": "-z", "y": "+y"}, + {"name": "back", "type": "mount", "size": "min(length,h)", "at": ["length/2", "-w/2", "h/2"], "z": "-y", "y": "+z"} + ] + } + ] +} diff --git a/surfaces/blender/tests/test_kitbash.py b/surfaces/blender/tests/test_kitbash.py index 36ccec5..a00e264 100644 --- a/surfaces/blender/tests/test_kitbash.py +++ b/surfaces/blender/tests/test_kitbash.py @@ -237,7 +237,7 @@ class CheckKitTests(unittest.TestCase): for name in ("../x", "mechanical.v0", "Mechanical", "", "a/b", "x" * 33, 3): with self.assertRaisesRegex(core.KitError, "must be 1 to 32 of"): core.load_kit(name) - with self.assertRaisesRegex(core.KitError, "no kit named 'absent'; kits: cutters, mechanical"): + with self.assertRaisesRegex(core.KitError, "no kit named 'absent'; kits: cutters, frame, mechanical"): core.load_kit("absent") with self.assertRaisesRegex(core.KitError, "has no part 'wing'; its parts: nozzle, tank"): core.part(core.load_kit("mechanical"), "wing") @@ -752,6 +752,133 @@ class CuttersKitTests(unittest.TestCase): self.assertIn("are of different types", core.mate_refusal(self.kit["socketTypes"], floor, nozzle.sockets[0], mechanical["socketTypes"], names)) +@unittest.skipIf(np is None, "numpy is not installed") +class FrameKitTests(unittest.TestCase): + """The frame kit: every shell an extrude, a PROFILES section along a path. Its mount and pivot are mechanical's, so a + frame part seats on a mechanical one.""" + PARTS = ["beam_i", "channel", "tee", "angle", "box_beam", "truss", "portal", "gusset", "wedge"] + + @classmethod + def setUpClass(cls): + cls.kit = core.load_kit("frame") + cls.mechanical = core.load_kit("mechanical") + + @staticmethod + def seat(b, socket) -> float: + """How far the socket's origin stands off the nearest face that faces its z and holds it: the face's normal by + Newell's sum and the origin inside its outline by crossing count, since a section's cap is not convex (inf + when no face holds it).""" + origin, z = socket["matrix"][:3, 3], socket["matrix"][:3, 2] + best = math.inf + for face in faces_of(b): + p = b.V[face] + normal = np.cross(p, np.roll(p, -1, axis=0)).sum(axis=0) + normal /= np.linalg.norm(normal) + if np.abs(normal - z).max() > 1e-6: + continue + u = np.cross(normal, [1.0, 0.0, 0.0] if abs(normal[0]) < 0.9 else [0.0, 1.0, 0.0]) + q, o = np.stack([p @ u, p @ np.cross(normal, u)], axis=1), np.array([origin @ u, origin @ np.cross(normal, u)]) + a, c = q, np.roll(q, -1, axis=0) + straddles = (a[:, 1] > o[1]) != (c[:, 1] > o[1]) + with np.errstate(divide="ignore", invalid="ignore"): + crossing = a[:, 0] + (o[1] - a[:, 1]) * (c[:, 0] - a[:, 0]) / (c[:, 1] - a[:, 1]) + if int((straddles & (crossing > o[0])).sum()) % 2: + best = min(best, float(abs((origin - p[0]) @ normal))) + return best + + def draws(self, name): + part = self.kit["parts"][name] + rng = random.Random(f"frame.{name}") + draws = [{p["name"]: p[key] for p in part["params"]} for key in ("default", "min", "max")] + for _ in range(16): + draws.append({p["name"]: rng.randint(p["min"], p["max"]) if p["type"] == "integer" else rng.uniform(p["min"], p["max"]) + for p in part["params"]}) + return part, draws + + def test_the_kit_is_its_nine_parts_and_two_of_mechanicals_socket_types(self): + """frame-kit-holds. Mutant E10 (frame's mount declared 'equal'): the types differ from mechanical's.""" + self.assertEqual(list(self.kit["parts"]), self.PARTS) + self.assertEqual(self.kit["socketTypes"], {name: self.mechanical["socketTypes"][name] for name in ("mount", "pivot")}) + lines = lambda name: [line for line in (core.KITS / f"{name}.v0.json").read_text(encoding="utf-8").split("\n") if line.startswith((' "mount"', ' "pivot"'))] # noqa: E731 + self.assertEqual((lines("frame"), len(lines("frame"))), (lines("mechanical"), 2)) # byte for byte + ends = [("end_a", "mount"), ("end_b", "mount")] + self.assertEqual({name: [(s["name"], s["type"]) for s in part["sockets"]] for name, part in self.kit["parts"].items()}, { + "beam_i": ends, "channel": ends, "tee": ends, "angle": ends, "box_beam": ends, "truss": ends, + "portal": [("foot_a", "mount"), ("foot_b", "mount")], "gusset": [("leg_a", "mount"), ("leg_b", "mount")], + "wedge": [("base", "mount"), ("back", "mount")]}) + kinds = {s["of"]["shape"] if s["shape"] == "repeat" else s["shape"] for part in self.kit["parts"].values() for s in part["shapes"]} + self.assertEqual(kinds, {"extrude"}) + + def test_every_part_holds_everywhere(self): + """frame-kit-holds: at the default, every minimum, every maximum and 16 seeded draws each part is closed shells + wound outward, of positive volume and under 20000 faces, each socket a right-handed frame on a face that + faces its z and holds its origin.""" + for name in self.PARTS: + part, draws = self.draws(name) + for given in draws: + b = core.build(part, given) + self.assertTrue(closed_and_oriented(b), f"{name} {given}") + self.assertLessEqual(len(b.counts), 20000) + self.assertGreater(signed_volume(b), 0.0) + self.assertFalse(bool(b.smooth.any())) + self.assertEqual(len(b.sockets), 2) + for socket in b.sockets: + frame = socket["matrix"][:3, :3] + self.assertLess(np.abs(frame.T @ frame - np.eye(3)).max(), 1e-9) + self.assertLess(abs(np.linalg.det(frame) - 1.0), 1e-9) + self.assertLess(self.seat(b, socket), 1e-9, f"{name}.{socket['name']} {given}") + self.assertGreater(socket["size"], 0.0) + + def test_a_truss_is_two_chords_a_vertical_a_bay_and_a_diagonal_a_bay(self): + """frame-kit-holds: 2 + (2*pairs + 1) + 2*pairs shells; the diagonals rise then fall, bay by bay, each from + one chord's axis to the other's.""" + part = self.kit["parts"]["truss"] + for pairs in (1, 4, 16): + b = core.build(part, {"pairs": pairs, "length": 3.2, "height": 0.4}) + self.assertEqual((b.shell_count, len(b.counts)), (2 + (2 * pairs + 1) + 2 * pairs, 6 * (4 * pairs + 3))) + bay = 3.2 / (2 * pairs) + shells = b.V.reshape(-1, 8, 3) + self.assertTrue(np.allclose(shells[2:2 * pairs + 3].mean(axis=1), [[k * bay, 0, 0.2] for k in range(2 * pairs + 1)], atol=1e-12)) + self.assertTrue(np.allclose(shells[2 * pairs + 3:].mean(axis=1), [[(k + 0.5) * bay, 0, 0.2] for k in list(range(0, 2 * pairs, 2)) + list(range(1, 2 * pairs, 2))], atol=1e-12)) + rising, falling = shells[2 * pairs + 3], shells[3 * pairs + 3] + self.assertTrue(np.allclose([rising[:4].mean(axis=0), rising[4:].mean(axis=0)], [[0, 0, 0], [bay, 0, 0.4]], atol=1e-12)) + self.assertTrue(np.allclose([falling[:4].mean(axis=0), falling[4:].mean(axis=0)], [[bay, 0, 0.4], [2 * bay, 0, 0]], atol=1e-12)) + + def test_the_portals_corners_are_mitred(self): + """frame-kit-holds: at each corner every point of the section stands as far from the leg's axis as from the + beam's, which is its own distance across the section (unmitred, 0.707 of it from each).""" + part, draws = self.draws("portal") + for given in draws[:6]: + b = core.build(part, given) + env = b.params + across = np.abs(core.profile("I", env["w"], env["h"], min(env["t"], 0.45 * min(env["w"], env["h"])))[:, 0]) + for ring, corner in ((1, [-env["width"] / 2, 0.0, env["height"]]), (2, [env["width"] / 2, 0.0, env["height"]])): + off = np.abs(b.V[12 * ring:12 * ring + 12] - corner) + self.assertLess(float(np.abs(off[:, [0, 2]] - across[:, None]).max()), 1e-12, given) + self.assertEqual((b.shell_count, b.counts.tolist()), (1, [4] * 36 + [12, 12])) + + def test_builds_are_deterministic(self): + for part in self.kit["parts"].values(): + a, b = core.build(part), core.build(part) + self.assertEqual((a.V.tobytes(), a.faces.tobytes(), a.counts.tobytes(), a.smooth.tobytes()), + (b.V.tobytes(), b.faces.tobytes(), b.counts.tobytes(), b.smooth.tobytes())) + self.assertEqual((a.V.dtype, a.faces.dtype, a.counts.dtype), (np.float64, np.int32, np.int32)) + + def test_a_beam_seats_on_a_mechanical_bracket(self): + """cross-kit-types. Mutant E10: kit 'frame' declares mount 'equal' and kit 'mechanical' 'fits', and nothing mates.""" + names = ("mechanical", "frame") + bracket, beam = core.build(self.mechanical["parts"]["bracket"]), core.build(self.kit["parts"]["beam_i"]) + mount, end = core.joint(self.mechanical["parts"]["bracket"], bracket, "mount", self.kit["parts"]["beam_i"], beam, "end_a") + self.assertEqual((mount["size"], end["size"]), (0.09, 0.08)) + self.assertIsNone(core.mate_refusal(self.mechanical["socketTypes"], mount, end, self.kit["socketTypes"], names)) + seated = core.mate(mount, end) @ end["matrix"] + self.assertLess(float(np.abs(seated[:3, 3]).max()), 1e-12) + self.assertLess(float(np.abs(seated[:3, 2] - [0.0, 0.0, 1.0]).max()), 1e-12) # the beam's end faces the bracket's foot and the beam runs on along -z + wide = core.build(self.kit["parts"]["box_beam"], {"w": 0.2, "h": 0.2}) + self.assertIn("it is larger", core.mate_refusal(self.mechanical["socketTypes"], mount, wide.sockets[0], self.kit["socketTypes"], names)) + self.assertIn("are of different types", core.mate_refusal(self.mechanical["socketTypes"], bracket.sockets[1], end, self.kit["socketTypes"], names)) + + @unittest.skipIf(np is None, "numpy is not installed") class SurfaceFrameTests(unittest.TestCase): """surface-frame: the frame brokkr_kitbash.cut gives a cutter. Bounds: a shipped reading is float rounding (worst @@ -1774,7 +1901,7 @@ class OwnershipTests(unittest.TestCase): return {p.name: p.read_text(encoding="utf-8") for p in sorted((SURFACE / "brokkr_kitbash").rglob("*")) if p.suffix in (".py", ".json")} def test_no_pattern_matches(self): - self.assertEqual(sorted(self.sources()), ["__init__.py", "brokkr_actions.json", "core.py", "cutters.v0.json", "mechanical.v0.json"]) + self.assertEqual(sorted(self.sources()), ["__init__.py", "brokkr_actions.json", "core.py", "cutters.v0.json", "frame.v0.json", "mechanical.v0.json"]) for pattern in self.PACKAGE: for name, text in self.sources().items(): if pattern is self.PACKAGE[2] and name == "__init__.py": -- 2.47.3 From 2d990bf2ea86db538028bbaddc54d5b0c8295afe Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 16:28:02 +0100 Subject: [PATCH 3/7] brokkr_kitbash.ribs row: the longeron enum lists PROFILES' seven sections, as the operator's does The operator's longeron enum is core.PROFILES (__init__.py), and the host refuses a row whose enum differs from its operator's: with wedge and gusset in PROFILES the whole kitbash table failed to load. The row mirrors the seven. This file is outside the cut's stated files (cut-kit-extrude.r1 leaves it to kit-hose); the commit stands alone so it can be dropped for the other answer, an enum of five named in __init__.py. Co-Authored-By: Claude Fable 5.2 --- surfaces/blender/brokkr_kitbash/brokkr_actions.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/surfaces/blender/brokkr_kitbash/brokkr_actions.json b/surfaces/blender/brokkr_kitbash/brokkr_actions.json index 89ed135..2f5db7d 100644 --- a/surfaces/blender/brokkr_kitbash/brokkr_actions.json +++ b/surfaces/blender/brokkr_kitbash/brokkr_actions.json @@ -686,7 +686,9 @@ "C", "T", "L", - "box" + "box", + "wedge", + "gusset" ], "default": "T", "doc": "the longerons' section; its up faces the plate" -- 2.47.3 From 5bf992ab70ea16b77ccaf7fc993a4f74b9b1c0d3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 16:28:03 +0100 Subject: [PATCH 4/7] live kitbash: the frame kit's nine parts placed, a truss re-parameterised in place, a box_beam seated on a mechanical bracket Blender 5.3.0 background, private user dirs: kitbash 91 checks, kitbash_assembly 118, kitbash_pose 46, kitbash_ribs 49, kitbash_shell 82, kitbash_faceted 34, all ok; only kitbash's result file changes. Co-Authored-By: Claude Fable 5.2 --- surfaces/blender/tests/live/kitbash.py | 43 +++++- .../blender/tests/live/kitbash.result.json | 134 ++++++++++++++++++ 2 files changed, 176 insertions(+), 1 deletion(-) diff --git a/surfaces/blender/tests/live/kitbash.py b/surfaces/blender/tests/live/kitbash.py index 6b03a2e..ef5abc9 100644 --- a/surfaces/blender/tests/live/kitbash.py +++ b/surfaces/blender/tests/live/kitbash.py @@ -1,6 +1,7 @@ """Live proof, in a background Blender, that the brokkr_kitbash rows are admitted by Brokkr as host actions and that the mechanical kit goes through run_intent: describe, place_part for all eleven parts, setObjectTransform, -assignMaterial, set_params, report, the refusals, and exportGltf. Not part of the unittest run: it needs Blender. +assignMaterial, set_params, report, the refusals, the frame kit's nine parts (placed, a truss re-parameterised, a beam +seated on a mechanical bracket), and exportGltf. Not part of the unittest run: it needs Blender. blender --background --factory-startup --python-exit-code 1 --python surfaces/blender/tests/live/kitbash.py -- @@ -253,6 +254,46 @@ try: receipt, whole = send("brokkr_kitbash.report") check("with scale back at 1 every part reports again", receipt["status"] == "accepted" and whole and len(whole["parts"]) == 11, receipt["message"]) + # --- the frame kit: every shell an extrude, a section swept along a path -------------------------------------------------- + frame = core.load_kit("frame") + receipt, described = send("brokkr_kitbash.describe", kit="frame") + check("describe of the frame kit lists its nine parts, whole", receipt["status"] == "accepted" and described + and [p["name"] for p in described["parts"]] == list(frame["parts"]) and len(described["parts"]) == 9 and "[truncated]" not in receipt["hostResult"], + [receipt["message"], len(receipt.get("hostResult") or "")]) + R["frame"] = {} + for name, part in frame["parts"].items(): + receipt, report = send("brokkr_kitbash.place_part", kit="frame", part=name, object_name=f"F_{name}") + obj = bpy.data.objects.get(f"F_{name}") + reference = core.build(part) + faces = len(obj.data.polygons) if obj else -1 + flat = np.zeros(max(faces, 0), dtype=bool) + if obj: + obj.data.attributes["sharp_face"].data.foreach_get("value", flat) + check(f"place_part frame {name}: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + receipt["status"] == "accepted" and report and obj is not None and faces == len(reference.counts) == report["faces"] + and report["shells"] == reference.shell_count and not obj.data.validate(verbose=False) and bool(flat.all()) + and np.allclose(np.array([v.co[:] for v in obj.data.vertices]), reference.V, atol=1e-6) and obj.modifiers.get("Kit Bevel") is None + and (obj["kit_kit"], obj["kit_part"]) == ("frame", name) and report["sockets"] == core.socket_rows(reference.sockets), + [receipt["message"], faces, len(reference.counts)]) + R["frame"][name] = {"faces": faces, "shells": reference.shell_count, "sockets": [s["name"] for s in reference.sockets]} + truss = bpy.data.objects["F_truss"] + truss_mesh = truss.data.name + receipt, report = send("brokkr_kitbash.set_params", object_name="F_truss", params="pairs=6") + reference = core.build(frame["parts"]["truss"], {"pairs": 6}) + check("set_params pairs=6 rebuilds the truss in place: 27 shells of core's faces on the same object and mesh", receipt["status"] == "accepted" and report + and report["shells"] == reference.shell_count == 27 and len(truss.data.polygons) == len(reference.counts) == report["faces"] + and bpy.data.objects.get("F_truss") == truss and truss.data.name == truss_mesh and report["params"]["pairs"] == 6 + and np.allclose(np.array([v.co[:] for v in truss.data.vertices]), reference.V, atol=1e-6), [receipt["message"], report]) + receipt, report = send("brokkr_kitbash.attach", object_name="F_box_beam", socket="end_a", parent_name="P_bracket", parent_socket="mount") + beam, bracket = bpy.data.objects["F_box_beam"], bpy.data.objects["P_bracket"] + seat = np.array(bracket.matrix_world) @ np.array(core.build(kit["parts"]["bracket"], json.loads(bracket["kit_params"])).sockets[0]["matrix"]) + end = np.array(beam.matrix_world) @ np.array(core.build(frame["parts"]["box_beam"]).sockets[0]["matrix"]) + # the connection holds within HELD, 1e-5 m, the rule attach and close share (tests/live/kitbash_assembly.py) + check("a frame box_beam's end_a seats on a mechanical bracket's mount across the two kits, and holds", receipt["status"] == "accepted" and report + and beam.parent == bracket and report["connection"]["holds"] is True and report["connection"]["residual"] <= 1e-5 + and float(np.abs(seat[:3, 3] - end[:3, 3]).max()) < 1e-5 and float(np.abs(seat[:3, 2] + end[:3, 2]).max()) < 1e-5, + [receipt["message"], report and report.get("connection")]) + # --- export --------------------------------------------------------------------------------------------------------------- receipt, _ = send("exportGltf", filepath="kit.glb", extras=False, yUp=True, applyModifiers=True, selection=[f"P_{n}" for n in names]) glb = WORK / "kit.glb" diff --git a/surfaces/blender/tests/live/kitbash.result.json b/surfaces/blender/tests/live/kitbash.result.json index 8e751b7..bacf88b 100644 --- a/surfaces/blender/tests/live/kitbash.result.json +++ b/surfaces/blender/tests/live/kitbash.result.json @@ -391,6 +391,66 @@ "ok": true, "detail": null }, + { + "name": "describe of the frame kit lists its nine parts, whole", + "ok": true, + "detail": null + }, + { + "name": "place_part frame beam_i: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "place_part frame channel: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "place_part frame tee: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "place_part frame angle: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "place_part frame box_beam: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "place_part frame truss: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "place_part frame portal: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "place_part frame gusset: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "place_part frame wedge: core's faces, shells and vertices, a valid mesh, every face flat, no Bevel, sockets in the part frame", + "ok": true, + "detail": null + }, + { + "name": "set_params pairs=6 rebuilds the truss in place: 27 shells of core's faces on the same object and mesh", + "ok": true, + "detail": null + }, + { + "name": "a frame box_beam's end_a seats on a mechanical bracket's mount across the two kits, and holds", + "ok": true, + "detail": null + }, { "name": "exportGltf of all eleven parts succeeds", "ok": true, @@ -423,6 +483,80 @@ "brokkr_kitbash.ribs", "brokkr_kitbash.shell" ], + "frame": { + "beam_i": { + "faces": 14, + "shells": 1, + "sockets": [ + "end_a", + "end_b" + ] + }, + "channel": { + "faces": 10, + "shells": 1, + "sockets": [ + "end_a", + "end_b" + ] + }, + "tee": { + "faces": 10, + "shells": 1, + "sockets": [ + "end_a", + "end_b" + ] + }, + "angle": { + "faces": 8, + "shells": 1, + "sockets": [ + "end_a", + "end_b" + ] + }, + "box_beam": { + "faces": 6, + "shells": 1, + "sockets": [ + "end_a", + "end_b" + ] + }, + "truss": { + "faces": 114, + "shells": 19, + "sockets": [ + "end_a", + "end_b" + ] + }, + "portal": { + "faces": 38, + "shells": 1, + "sockets": [ + "foot_a", + "foot_b" + ] + }, + "gusset": { + "faces": 7, + "shells": 1, + "sockets": [ + "leg_a", + "leg_b" + ] + }, + "wedge": { + "faces": 6, + "shells": 1, + "sockets": [ + "base", + "back" + ] + } + }, "placed": { "nozzle": { "faces": 994, -- 2.47.3 From 983dfcdd05171ffa2944684a745f135db52fb88c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 16:31:49 +0100 Subject: [PATCH 5/7] docs/kitbash.md: the extrude shape, its frame rule and seven sections, and the frame kit Co-Authored-By: Claude Fable 5.2 --- surfaces/blender/docs/kitbash.md | 57 +++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/surfaces/blender/docs/kitbash.md b/surfaces/blender/docs/kitbash.md index 1c7f452..586b9ab 100644 --- a/surfaces/blender/docs/kitbash.md +++ b/surfaces/blender/docs/kitbash.md @@ -76,7 +76,8 @@ then y, then z, about the shape's own origin) place it, rotation first; both def | `tube` | `r0`, `r1`, `length`, `segments`, `inner0`?, `inner1`?, `smooth`? | A frustum on +z from radius `r0` at z=0 to `r1` at z=`length`, with n-gon caps. Inner radii above 0 make it hollow (an inner wall and two flat end rings); they are both above 0 or both 0, and below the outer radius. `segments` is 3 to 128. `smooth` shades the walls smooth; caps stay flat. | | `box` | `size` | A box centred on its origin; every size above 0. | | `lathe` | `profile`, `segments`, `loop`?, `smooth`? | A profile of `[r, z]` points revolved about +z into one shell, a ring of `segments` (3 to 128) vertices per point. An open profile's end on the axis (`r` exactly 0) is a pole; an end off the axis gets a flat n-gon cap. With `loop` true the last point joins the first and there are no caps (a ring: 3 points or more). `smooth` shades the walls smooth; a band between two points of one `z` (an annulus) and the caps stay flat. A point written `[r, z, "sharp"]` is a crease. | -| `repeat` | `count`, `of`, and `step` or `around` with `center`? | `count` copies (1 to 256) of one tube, box or lathe: at `k * step`, k from 0, or turned `k * 360 / count` degrees, right-handed, about the axis `around` (one of `+x -x +y -y +z -z`) through `center` (default the origin). Exactly one of `step` and `around`. A repeat cannot hold a repeat. | +| `extrude` | `section`, `w`, `h`, `t`, `path`, `up`, `loop`? | A section (`I`, `C`, `T`, `L`, `box`, `wedge` or `gusset`: a name, never an expression) of width `w`, height `h` and wall `t`, swept along `path`, 2 to 64 `[x, y, z]` points, into one shell with a flat cap at each end. `up` is one `[x, y, z]` vector the section's height stands along. With `loop` true the last point joins the first and there are no caps (3 points or more). Every face is flat. | +| `repeat` | `count`, `of`, and `step` or `around` with `center`? | `count` copies (1 to 256) of one tube, box, lathe or extrude: at `k * step`, k from 0, or turned `k * 360 / count` degrees, right-handed, about the axis `around` (one of `+x -x +y -y +z -z`) through `center` (default the origin). Exactly one of `step` and `around`. A repeat cannot hold a repeat. | A lathe's profile is listed out along the bottom and up the outside, as this flanged stub is: a cap of radius 0.1 at z=0, the flange's rim, its top face, the pipe, and a cap of radius 0.05 at z=0.3. @@ -109,6 +110,31 @@ refused at an open profile's two ends, which are a cap or a pole. No modifier or Shells may overlap (a pad that runs into a tank), and a part is then not one solid: reports give the shell count. +An extrude stands its section on the path by one rule (`core.sweep`, which also makes a rib's longerons). At each +path point the section lies in the plane that bisects the turn there. Its y axis is `up` with the path's direction +taken out of it, and its x axis is that y cross the path's direction: along +z with `up` +y the section's x is +x +and its y is +y, as drawn; along +x with `up` +z its x is +y. A corner is mitred: the section is stretched in the +plane of the turn by 1 / cos(half the turn), so it keeps its size on both sides of the corner. `at` and `rot` then +place the whole shell as they place any shape. + +| section | outline, counter-clockwise in (x, y), centred on its `w` by `h` box | `t` | `t` must be under | +| --- | --- | --- | --- | +| `I` | two flanges across x joined by a web along y | flange and web thickness | `w` and `h / 2` | +| `C` | the web on -x, two flanges opening toward +x | flange and web thickness | `w` and `h / 2` | +| `T` | the flange across x at +y, the stem down the middle | flange and stem thickness | `w` and `h` | +| `L` | one leg along x at -y, one along y at -x | leg thickness | `w` and `h` | +| `box` | the solid `w` by `h` rectangle | unused, but above 0 | | +| `wedge` | a right trapezoid: base `w` at -y, its back `h` tall at -x, its front `t` tall at +x | front height | `h` | +| `gusset` | a right triangle on legs `w` (along x at -y) and `h` (along y at -x), each acute tip cut square | length of the flat that cuts a tip | half the shorter leg | + +Every size is above 0. A build is refused, naming the kit, part and shape, when the section has no room for its +wall, when `up` runs along the path at a point (or is zero), when two path points are closer than 1e-9, when the +path turns more than 150 degrees at a point (past it a mitre runs 3.9 times the section's width), and when the +section folds: the path turns tighter than the section reaches on the inside of the turn. One `up` serves the +whole path, so a path that bends in two planes needs an `up` that crosses every segment and every corner's +bisector; a portal in the xz plane takes `up` +y, which stands an I section's web across the frame's plane. +`smooth` is not a field of an extrude: a section's faces are flat, and its corners take the part's `bevel`. + **`bevel`** is the width of a Bevel modifier `place_part` adds (2 segments, edges sharper than 30 degrees). Keep it well under the part's thinnest feature at its smallest params. @@ -500,7 +526,7 @@ takes planes in the cage's own frame and makes, as one mesh object under the cag - longerons through the ribs: each `{origin, axis, toward}` is the half-plane from the line through `origin` along `axis`, on `toward`'s side. Where it crosses a plane's rib, at the rib's mid-depth, is a station; the longeron runs through the stations in the planes' order and 0.12 of the end gaps past the end ribs, a section - `longeron` (`I`, `C`, `T`, `L` or `box`; `longeron_w`, `longeron_h`, `longeron_t`) with its up toward the plate. + `longeron` (a section of the extrude shape's table: `I`, `C`, `T`, `L`, `box`, `wedge` or `gusset`; `longeron_w`, `longeron_h`, `longeron_t`) with its up toward the plate. A rib's outer edge is where its plane cuts the offset surface (`core.inset` makes it: each vertex of the inner face stepped to where its faces, moved in by `standoff`, meet). Points `step` apart along the section each look @@ -693,6 +719,26 @@ the tank's axis. The bracket's `pivot` face lies on its plate's centre plane, so the same side, turned half (roll 180), pins on the same plane facing the first. An actuator on one and a strut on the other then lie in one plane and can meet at a pin: a braced leg. +## The frame kit + +`kits/frame.v0.json`: nine parts of chassis structure, every shell an extrude. Its socket types are `mount` (fits) +and `pivot` (equal), the same two lines as `mechanical`'s, so a frame part seats on a mechanical one and the other +way round (`place_part` and `describe` take `kit: "frame"`). + +| part | params | what it is | sockets | +| --- | --- | --- | --- | +| `beam_i`, `channel`, `tee`, `angle` | `length`, `w`, `h`, `t` | An I, C, T or L section along +z from 0 to `length`, `w` across x and `h` along y. `t` is held under 0.45 of the smaller of `w` and `h`. | `end_a` (z -z) and `end_b` (z +z), `mount`, size the smaller of `w` and `h`. On a channel and an angle they sit on the web at -x, where the end face is. | +| `box_beam` | `length`, `w`, `h` | A solid rectangular bar along +z. | `end_a`, `end_b`, as a beam's | +| `truss` | `length`, `height`, `pairs`, `chord`, `web` | A plane truss along +x in the xz plane: two square chords at z 0 and z `height`, `2*pairs + 1` verticals and `2*pairs` diagonals, rising then falling: `4*pairs + 3` shells. Bays come in pairs (1 to 16) because an expression has no floor: the diagonals are two repeats a double bay apart. | `end_a` (z -x) and `end_b` (z +x) on the end verticals at mid-height, `mount`, size `height` | +| `portal` | `width`, `height`, `w`, `h`, `t` | One I section up a leg, across and down the other in the xz plane, mitred at both corners; its flanges face +y and -y. | `foot_a`, `foot_b` (z -z), `mount` | +| `gusset` | `w`, `h`, `t`, `thickness` | A corner plate in the xy plane with its right angle at the origin, legs along +x and +y, `thickness` along +z. | `leg_a` on the x leg's edge (z -y) and `leg_b` on the y leg's (z -x), `mount`, size `thickness` | +| `wedge` | `length`, `w`, `h`, `t` | A toe cap, ramp or chock along +x: base on z 0, back `h` tall at -y, sloping to a front `t` tall at +y (`t` held under 0.9 of `h`). | `base` (z -z) and `back` (z -y), `mount` | + +No frame part has a bevel. `core.build` costs, as medians of 21 interleaved builds on the workstation beside the +mechanical actuator's 2.3 ms: a beam, the portal, the gusset or the wedge 0.7 to 0.9 ms; the truss 2.8 ms at +`pairs` 4 (19 shells) and 3.8 ms at `pairs` 16 (67 shells). A repeat sweeps its one shape once and copies it, so +a truss costs four sweeps whatever its bays; the same 19 and 67 shells swept one by one measured 5.9 ms and 20.7 ms. + ## Adding a part or a kit Edit the kit's JSON (or add `kits/.v0.json`, whose `kit` field is ``), then run the tests: @@ -706,10 +752,13 @@ python -m unittest discover -s surfaces/blender/tests -p "test_kitbash.py" -v seated on a face that faces its `z`, and no build passes 20000 faces. Choose param ranges so every combination builds: a `min` or `max` in an expression keeps a derived length positive where two params could cross. A new part of `mechanical` also joins the part and socket list in `test_the_kit_is_the_eleven_parts_and_three_socket_types`. -`CuttersKitTests` holds `cutters` to the same, with each floor on its cutter's bottom, and `SurfaceFrameTests` the +`FrameKitTests` holds `frame` to the same (its seat check reads a section's cap, which is not convex, by the +face's own normal and outline), with the truss's shells, the portal's mitres and a beam seated on a mechanical +bracket. `CuttersKitTests` holds `cutters` to the same, with each floor on its cutter's bottom, and `SurfaceFrameTests` the frame `cut` gives a cutter. `MateTests` covers the mate arithmetic and what may mate, within a kit and across two, `PoseTests` the closed-form rolls. The operators are exercised in a real Blender by -`tests/live/kitbash.py` (placing and re-parameterising), `tests/live/kitbash_assembly.py` (attach, detach, +`tests/live/kitbash.py` (placing and re-parameterising, and the frame kit: its nine parts placed, the truss +re-parameterised, a beam seated on a bracket), `tests/live/kitbash_assembly.py` (attach, detach, `set_params` on assemblies, a braced leg closed by `close`, boolean and apply), `tests/live/kitbash_shell.py` (`cut` and `cut_many` on a cage that is not a kit part, a part on a cutter's floor, the three Boolean modifiers, an object in no collection) and `tests/live/kitbash_pose.py` (roll, aim and reach). -- 2.47.3 From 2f374cc4dedaa3e15f24a8cdd5a631d8188cdcab Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 17:42:06 +0100 Subject: [PATCH 6/7] brokkr.kit.v0 extrude: up is one vector or one per path point; the portal's web stands in its plane core.sweep already took an up for each point; the extrude shape now passes them through, and refuses an array that is not one per path point. The frame kit's portal gives each point the in-plane direction toward the inside of the frame, so its I section's web lies in the xz plane and its flanges run across y. Tests: the portal's web, extents and feet (kills S9, foot_b on foot_a), each beam's w across x and h along y (kills S14, box_beam's w and h swapped), the truss's chord ends, per-point ups at the shape. socket_seat reads a face by Newell's normal and a crossing count, so FrameKitTests' own seat check is gone. SEATED, VOLUME and PLACED sit at the geometric mean of shipped and least-mutant readings (lodur:ruling:deterministic-bound-margin). Co-Authored-By: Claude Fable 5.2 --- surfaces/blender/brokkr_kitbash/core.py | 15 +- .../blender/brokkr_kitbash/kits/frame.v0.json | 8 +- surfaces/blender/docs/kitbash.md | 19 +- surfaces/blender/tests/test_kitbash.py | 184 +++++++++++------- 4 files changed, 139 insertions(+), 87 deletions(-) diff --git a/surfaces/blender/brokkr_kitbash/core.py b/surfaces/blender/brokkr_kitbash/core.py index e4b68ba..c298351 100644 --- a/surfaces/blender/brokkr_kitbash/core.py +++ b/surfaces/blender/brokkr_kitbash/core.py @@ -250,7 +250,13 @@ def _shape(shape: Any, names, where: str, inside_repeat: bool = False) -> dict: if not isinstance(path, list) or not least <= len(path) <= PATH: raise KitError(f"{where} path must be an array of {least} to {PATH} [x, y, z] points{' (it is a loop)' if made['loop'] else ''}") made["path"] = [_vector(point, names, f"{where} path[{i}]") for i, point in enumerate(path)] - made["up"] = _vector(shape["up"], names, f"{where} up") + ups = shape["up"] + if isinstance(ups, list) and ups and all(isinstance(up, list) for up in ups): # one up for each path point + if len(ups) != len(path): + raise KitError(f"{where} up lists {len(ups)} vectors for a path of {len(path)} points: give one [x, y, z] or one for each point") + made["up"] = [_vector(up, names, f"{where} up[{i}]") for i, up in enumerate(ups)] + else: + made["up"] = [_vector(ups, names, f"{where} up")] return made for key in ("loop", "smooth"): if not isinstance(shape.get(key, False), bool): @@ -572,12 +578,13 @@ def _box(shape: dict, env): def _extrude(shape: dict, env): """A PROFILES section swept along the path: profile and sweep own the geometry (the outline's x is up cross the path's tangent, its y is up taken off the tangent, the joints are mitred), and what either refuses is refused - here under the shape's name. Every face is flat.""" + here under the shape's name. `up` is one vector for the whole path or one for each point, as sweep takes them. + Every face is flat.""" size = [shape[key].value(env) for key in ("w", "h", "t")] path = [[e.value(env) for e in point] for point in shape["path"]] - up = [e.value(env) for e in shape["up"]] + ups = [[e.value(env) for e in up] for up in shape["up"]] try: - swept = sweep(path, profile(shape["section"], *size), up, shape["loop"]) + swept = sweep(path, profile(shape["section"], *size), ups[0] if len(ups) == 1 else ups, shape["loop"]) except KitError as error: raise KitError(f"{shape['where']}: {error}") from None return swept.V, swept.faces, swept.counts, swept.smooth, NO_SHARP diff --git a/surfaces/blender/brokkr_kitbash/kits/frame.v0.json b/surfaces/blender/brokkr_kitbash/kits/frame.v0.json index a61f3c7..e25c7fe 100644 --- a/surfaces/blender/brokkr_kitbash/kits/frame.v0.json +++ b/surfaces/blender/brokkr_kitbash/kits/frame.v0.json @@ -118,16 +118,16 @@ }, { "name": "portal", - "doc": "Portal frame in the xz plane: one I section up a leg, across and down the other, mitred at both corners. Its flanges face +y and -y.", + "doc": "Portal frame in the xz plane: one I section up a leg, across and down the other, mitred at both corners. Its web stands in the frame's plane; its flanges run across y on the inside and the outside of the frame.", "params": [ {"name": "width", "type": "number", "min": 0.5, "max": 4.0, "default": 1.2, "doc": "leg axis to leg axis (x)"}, {"name": "height", "type": "number", "min": 0.4, "max": 3.0, "default": 0.9, "doc": "feet to the beam's axis (z)"}, - {"name": "w", "type": "number", "min": 0.04, "max": 0.3, "default": 0.1, "doc": "section width, in the frame's plane"}, - {"name": "h", "type": "number", "min": 0.04, "max": 0.3, "default": 0.1, "doc": "section height (y)"}, + {"name": "w", "type": "number", "min": 0.04, "max": 0.3, "default": 0.1, "doc": "flange width, across the frame's plane (y)"}, + {"name": "h", "type": "number", "min": 0.04, "max": 0.3, "default": 0.1, "doc": "section height, flange to flange in the frame's plane"}, {"name": "t", "type": "number", "min": 0.004, "max": 0.04, "default": 0.01, "doc": "wall thickness; held under 0.45 of the smaller of w and h"} ], "shapes": [ - {"shape": "extrude", "section": "I", "w": "w", "h": "h", "t": "min(t,0.45*min(w,h))", "path": [["-width/2", 0, 0], ["-width/2", 0, "height"], ["width/2", 0, "height"], ["width/2", 0, 0]], "up": [0, 1, 0]} + {"shape": "extrude", "section": "I", "w": "w", "h": "h", "t": "min(t,0.45*min(w,h))", "path": [["-width/2", 0, 0], ["-width/2", 0, "height"], ["width/2", 0, "height"], ["width/2", 0, 0]], "up": [[1, 0, 0], [1, 0, -1], [-1, 0, -1], [-1, 0, 0]]} ], "sockets": [ {"name": "foot_a", "type": "mount", "size": "min(w,h)", "at": ["-width/2", 0, 0], "z": "-z", "y": "+y"}, diff --git a/surfaces/blender/docs/kitbash.md b/surfaces/blender/docs/kitbash.md index 586b9ab..8cbd115 100644 --- a/surfaces/blender/docs/kitbash.md +++ b/surfaces/blender/docs/kitbash.md @@ -76,7 +76,7 @@ then y, then z, about the shape's own origin) place it, rotation first; both def | `tube` | `r0`, `r1`, `length`, `segments`, `inner0`?, `inner1`?, `smooth`? | A frustum on +z from radius `r0` at z=0 to `r1` at z=`length`, with n-gon caps. Inner radii above 0 make it hollow (an inner wall and two flat end rings); they are both above 0 or both 0, and below the outer radius. `segments` is 3 to 128. `smooth` shades the walls smooth; caps stay flat. | | `box` | `size` | A box centred on its origin; every size above 0. | | `lathe` | `profile`, `segments`, `loop`?, `smooth`? | A profile of `[r, z]` points revolved about +z into one shell, a ring of `segments` (3 to 128) vertices per point. An open profile's end on the axis (`r` exactly 0) is a pole; an end off the axis gets a flat n-gon cap. With `loop` true the last point joins the first and there are no caps (a ring: 3 points or more). `smooth` shades the walls smooth; a band between two points of one `z` (an annulus) and the caps stay flat. A point written `[r, z, "sharp"]` is a crease. | -| `extrude` | `section`, `w`, `h`, `t`, `path`, `up`, `loop`? | A section (`I`, `C`, `T`, `L`, `box`, `wedge` or `gusset`: a name, never an expression) of width `w`, height `h` and wall `t`, swept along `path`, 2 to 64 `[x, y, z]` points, into one shell with a flat cap at each end. `up` is one `[x, y, z]` vector the section's height stands along. With `loop` true the last point joins the first and there are no caps (3 points or more). Every face is flat. | +| `extrude` | `section`, `w`, `h`, `t`, `path`, `up`, `loop`? | A section (`I`, `C`, `T`, `L`, `box`, `wedge` or `gusset`: a name, never an expression) of width `w`, height `h` and wall `t`, swept along `path`, 2 to 64 `[x, y, z]` points, into one shell with a flat cap at each end. `up` is the direction the section's height stands along: one `[x, y, z]` vector for the whole path, or an array of one per path point. With `loop` true the last point joins the first and there are no caps (3 points or more). Every face is flat. | | `repeat` | `count`, `of`, and `step` or `around` with `center`? | `count` copies (1 to 256) of one tube, box, lathe or extrude: at `k * step`, k from 0, or turned `k * 360 / count` degrees, right-handed, about the axis `around` (one of `+x -x +y -y +z -z`) through `center` (default the origin). Exactly one of `step` and `around`. A repeat cannot hold a repeat. | A lathe's profile is listed out along the bottom and up the outside, as this flanged stub is: a cap of radius 0.1 @@ -130,9 +130,11 @@ place the whole shell as they place any shape. Every size is above 0. A build is refused, naming the kit, part and shape, when the section has no room for its wall, when `up` runs along the path at a point (or is zero), when two path points are closer than 1e-9, when the path turns more than 150 degrees at a point (past it a mitre runs 3.9 times the section's width), and when the -section folds: the path turns tighter than the section reaches on the inside of the turn. One `up` serves the -whole path, so a path that bends in two planes needs an `up` that crosses every segment and every corner's -bisector; a portal in the xz plane takes `up` +y, which stands an I section's web across the frame's plane. +section folds: the path turns tighter than the section reaches on the inside of the turn. One `up` must cross +every segment and every corner's bisector, so it can only stand a bent path's section across the plane of the +bend. To keep the section's height in that plane give one `up` per point, each in the plane and across the path +there (at a corner, across its bisector): the portal's four point toward the inside of the frame, which stands its +I section's web in the frame's plane. An array of ups that is not one per path point is refused. `smooth` is not a field of an extrude: a section's faces are flat, and its corners take the part's `bevel`. **`bevel`** is the width of a Bevel modifier `place_part` adds (2 segments, edges sharper than 30 degrees). Keep it @@ -730,7 +732,7 @@ way round (`place_part` and `describe` take `kit: "frame"`). | `beam_i`, `channel`, `tee`, `angle` | `length`, `w`, `h`, `t` | An I, C, T or L section along +z from 0 to `length`, `w` across x and `h` along y. `t` is held under 0.45 of the smaller of `w` and `h`. | `end_a` (z -z) and `end_b` (z +z), `mount`, size the smaller of `w` and `h`. On a channel and an angle they sit on the web at -x, where the end face is. | | `box_beam` | `length`, `w`, `h` | A solid rectangular bar along +z. | `end_a`, `end_b`, as a beam's | | `truss` | `length`, `height`, `pairs`, `chord`, `web` | A plane truss along +x in the xz plane: two square chords at z 0 and z `height`, `2*pairs + 1` verticals and `2*pairs` diagonals, rising then falling: `4*pairs + 3` shells. Bays come in pairs (1 to 16) because an expression has no floor: the diagonals are two repeats a double bay apart. | `end_a` (z -x) and `end_b` (z +x) on the end verticals at mid-height, `mount`, size `height` | -| `portal` | `width`, `height`, `w`, `h`, `t` | One I section up a leg, across and down the other in the xz plane, mitred at both corners; its flanges face +y and -y. | `foot_a`, `foot_b` (z -z), `mount` | +| `portal` | `width`, `height`, `w`, `h`, `t` | One I section up a leg, across and down the other in the xz plane, mitred at both corners. Its web stands in the frame's plane: `h` is the section's height in that plane, flange to flange, and `w` the flanges' width across y. | `foot_a`, `foot_b` (z -z), `mount` | | `gusset` | `w`, `h`, `t`, `thickness` | A corner plate in the xy plane with its right angle at the origin, legs along +x and +y, `thickness` along +z. | `leg_a` on the x leg's edge (z -y) and `leg_b` on the y leg's (z -x), `mount`, size `thickness` | | `wedge` | `length`, `w`, `h`, `t` | A toe cap, ramp or chock along +x: base on z 0, back `h` tall at -y, sloping to a front `t` tall at +y (`t` held under 0.9 of `h`). | `base` (z -z) and `back` (z -y), `mount` | @@ -752,9 +754,10 @@ python -m unittest discover -s surfaces/blender/tests -p "test_kitbash.py" -v seated on a face that faces its `z`, and no build passes 20000 faces. Choose param ranges so every combination builds: a `min` or `max` in an expression keeps a derived length positive where two params could cross. A new part of `mechanical` also joins the part and socket list in `test_the_kit_is_the_eleven_parts_and_three_socket_types`. -`FrameKitTests` holds `frame` to the same (its seat check reads a section's cap, which is not convex, by the -face's own normal and outline), with the truss's shells, the portal's mitres and a beam seated on a mechanical -bracket. `CuttersKitTests` holds `cutters` to the same, with each floor on its cutter's bottom, and `SurfaceFrameTests` the +`FrameKitTests` holds `frame` to the same (the seat check reads a cap that is not convex, an I section's, as it +reads a convex one), with the truss's shells and chords, the portal's mitres, its web in the frame's plane and its +feet apart, each beam's `w` across x and `h` along y, and a beam seated on a mechanical +bracket. Its bounds `SEATED`, `VOLUME` and `PLACED` carry their shipped and mutant readings in `tests/test_kitbash.py`. `CuttersKitTests` holds `cutters` to the same, with each floor on its cutter's bottom, and `SurfaceFrameTests` the frame `cut` gives a cutter. `MateTests` covers the mate arithmetic and what may mate, within a kit and across two, `PoseTests` the closed-form rolls. The operators are exercised in a real Blender by `tests/live/kitbash.py` (placing and re-parameterising, and the frame kit: its nine parts placed, the truss diff --git a/surfaces/blender/tests/test_kitbash.py b/surfaces/blender/tests/test_kitbash.py index a00e264..55c0723 100644 --- a/surfaces/blender/tests/test_kitbash.py +++ b/surfaces/blender/tests/test_kitbash.py @@ -5,8 +5,8 @@ Run: python3 -m unittest discover -s surfaces/blender/tests -v (needs numpy; The operators are exercised in a real Blender by tests/live/kitbash.py, tests/live/kitbash_assembly.py and tests/live/kitbash_pose.py. -Bounds follow lodur:ruling:deterministic-bound-margin: a deterministic reading is exact here, so each assertion is -the built value, and each names the mutant it kills. +Bounds follow lodur:ruling:deterministic-bound-margin: SEATED, VOLUME and PLACED, below, carry their shipped and +mutant readings; a reading that is exact is asserted equal. Each check names the mutant it kills. """ from __future__ import annotations @@ -85,44 +85,52 @@ def frustum(r0, r1, h, n) -> float: return h / 3.0 * (a0 + a1 + math.sqrt(a0 * a1)) -def point_triangle(p, a, b, c) -> float: - """Distance from p to triangle abc (Ericson, Real-Time Collision Detection 5.1.5).""" - ab, ac, ap = b - a, c - a, p - a - d1, d2 = ab @ ap, ac @ ap - if d1 <= 0 and d2 <= 0: - return float(np.linalg.norm(ap)) - bp = p - b - d3, d4 = ab @ bp, ac @ bp - if d3 >= 0 and d4 <= d3: - return float(np.linalg.norm(bp)) - vc = d1 * d4 - d3 * d2 - if vc <= 0 and d1 >= 0 and d3 <= 0: - return float(np.linalg.norm(ap - ab * (d1 / (d1 - d3)))) - cp = p - c - d5, d6 = ab @ cp, ac @ cp - if d6 >= 0 and d5 <= d6: - return float(np.linalg.norm(cp)) - vb = d5 * d2 - d1 * d6 - if vb <= 0 and d2 >= 0 and d6 <= 0: - return float(np.linalg.norm(ap - ac * (d2 / (d2 - d6)))) - va = d3 * d6 - d5 * d4 - if va <= 0 and d4 - d3 >= 0 and d5 - d6 >= 0: - return float(np.linalg.norm(bp - (c - b) * ((d4 - d3) / ((d4 - d3) + (d5 - d6))))) - normal = np.cross(ab, ac) - return float(abs(ap @ normal) / np.linalg.norm(normal)) +# Bounds of the extrude shape's and the frame kit's checks (ShapeTests, FrameKitTests), by +# lodur:ruling:deterministic-bound-margin: each sits at the geometric mean of the shipped worst reading and the least +# claimed mutant's. A mutant is one edit of core.py or kits/frame.v0.json; a reading is the worst of every check under +# the bound, over every draw. +# Metres from a frame part's socket origin to the face it sits on. Shipped worst 1.1e-15; least claimed mutant 0.04 +# (a portal foot one wall above its end cap); separation 6.0e6 each side. Also claimed: a truss end on its vertical's +# axis 0.05, a channel's end off its web 0.15, a tee built as an L 0.16, a wedge not lifted onto its base 0.25. +SEATED = 6.7e-9 +# Cubic metres between a swept shell's volume and its section's area times its path's length. Shipped worst 2.7e-15; +# least claimed mutant 0.02 (E7, loop ignored: the ring an open path); separation 2.7e6 each side. A sweep with no +# mitre reads 0.023. +VOLUME = 7.3e-9 +# Metres between a built point, extent or centre and where the part's doc puts it. Shipped worst 8.9e-16; least claimed +# mutant 0.01 (a portal foot one wall above its end cap, read against its cap's middle); separation 3.4e6 each side. +# Also claimed: a truss's chords a web short 0.015, a sweep with no mitre 0.044, S14 (box_beam's w and h swapped) +# 0.075, P1 (the portal on one up +y) 0.3, U1 (only the first of an extrude's ups used) 0.6, S9 (foot_b on foot_a) 1.2, +# a truss's falling diagonals a bay late 1.6, E1 (an extrude ignores at and rot) 3.0. +PLACED = 3.0e-9 def socket_seat(b, socket) -> float: - """Distance from the socket's origin to the nearest face whose normal is the socket's z (inf when none faces it).""" + """Distance from the socket's origin to the nearest face whose normal is the socket's z (inf when none faces it). + The face's normal is Newell's sum; the origin is over the face by crossing count, and beside it the distance is + to the nearest edge: so a cap that is not convex (an I section's) reads as a convex one does.""" origin, z = socket["matrix"][:3, 3], socket["matrix"][:3, 2] best = math.inf for face in faces_of(b): p = b.V[face] - normal = np.cross(p[1] - p[0], p[2] - p[0]) + normal = np.cross(p, np.roll(p, -1, axis=0)).sum(axis=0) normal /= np.linalg.norm(normal) if np.abs(normal - z).max() > 1e-6: continue - best = min([best] + [point_triangle(origin, p[0], p[i], p[i + 1]) for i in range(1, len(face) - 1)]) + u = np.cross(normal, [1.0, 0.0, 0.0] if abs(normal[0]) < 0.9 else [0.0, 1.0, 0.0]) + u /= np.linalg.norm(u) + v = np.cross(normal, u) + a, o = np.stack([p @ u, p @ v], axis=1), np.array([origin @ u, origin @ v]) + c = np.roll(a, -1, axis=0) + straddles = (a[:, 1] > o[1]) != (c[:, 1] > o[1]) + with np.errstate(divide="ignore", invalid="ignore"): + crossing = a[:, 0] + (o[1] - a[:, 1]) * (c[:, 0] - a[:, 0]) / (c[:, 1] - a[:, 1]) + off = float(abs((origin - p[0]) @ normal)) + if not int((straddles & (crossing > o[0])).sum()) % 2: # beside the face: to its nearest edge + edge = c - a + along = np.clip(np.einsum("ij,ij->i", o - a, edge) / np.einsum("ij,ij->i", edge, edge), 0.0, 1.0) + off = math.hypot(off, float(np.linalg.norm(a + along[:, None] * edge - o, axis=1).min())) + best = min(best, off) return best @@ -435,7 +443,7 @@ class ShapeTests(unittest.TestCase): area = float(0.5 * np.sum(x * np.roll(y, -1) - np.roll(x, -1) * y)) b = built([{**self.BEAM, "section": section, "w": "a", "path": [[0, 0, 0], [0, 0, "5*a"]]}], [param("a", 0.01, 1, w)]) self.assertTrue(closed_and_oriented(b), section) - self.assertLess(abs(signed_volume(b) - area * 0.3), 1e-12, section) + self.assertLess(abs(signed_volume(b) - area * 0.3), VOLUME, section) self.assertEqual((b.shell_count, b.counts.tolist(), bool(b.smooth.any()), b.sharp.shape), (1, [4] * len(outline) + [len(outline)] * 2, False, (0, 2)), section) self.assertEqual(b.V[:len(outline)].tolist(), [[px, py, 0.0] for px, py in outline.tolist()], section) self.assertEqual(b.V[len(outline):, 2].tolist(), [0.06 * 5] * len(outline)) @@ -451,20 +459,20 @@ class ShapeTests(unittest.TestCase): swept = built([{**self.BEAM, "section": "box", "rot": rot, "at": at}]) box = built([{"shape": "box", "size": size, "rot": rot, "at": lifted}]) order = lambda V: V[np.lexsort(np.round(V, 9).T)] # noqa: E731 - self.assertLess(float(np.abs(order(swept.V) - order(box.V)).max()), 1e-12) - self.assertLess(abs(signed_volume(swept) - 0.06 * 0.1 * 0.3), 1e-12) + self.assertLess(float(np.abs(order(swept.V) - order(box.V)).max()), PLACED) + self.assertLess(abs(signed_volume(swept) - 0.06 * 0.1 * 0.3), VOLUME) area = 2 * 0.06 * 0.012 + (0.1 - 2 * 0.012) * 0.012 for change, centres in (({"step": [0.5, 0, "a"]}, [[0, 0, 0.15], [0.5, 0, 1.15], [1.0, 0, 2.15]]), ({"around": "+y", "center": [1, 0, 0]}, [[0, 0, 0.15], [1.5 + 0.15 * 0.75 ** 0.5, 0, 0.75 ** 0.5 - 0.075], [1.5 - 0.15 * 0.75 ** 0.5, 0, -0.75 ** 0.5 - 0.075]])): b = built([{"shape": "box", "size": [1, 1, 1]}, {"shape": "repeat", "count": 3, **change, "of": self.BEAM}], [param("a")]) self.assertEqual((b.shell_count, b.shape.tolist()), (4, [0] * 6 + [1] * 14 * 3)) self.assertTrue(closed_and_oriented(b)) - self.assertLess(abs(signed_volume(b) - 1.0 - 3 * area * 0.3), 1e-12) - self.assertTrue(np.allclose(b.V[8:].reshape(3, 24, 3).mean(axis=1), centres, atol=1e-12), change) + self.assertLess(abs(signed_volume(b) - 1.0 - 3 * area * 0.3), VOLUME) + self.assertLess(float(np.abs(b.V[8:].reshape(3, 24, 3).mean(axis=1) - centres).max()), PLACED, change) ring = built([{**self.BEAM, "section": "box", "w": 0.1, "h": 0.2, "loop": True, "path": [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], "up": [0, 0, 1]}]) self.assertEqual((ring.shell_count, ring.counts.tolist(), len(ring.V)), (1, [4] * 16, 16)) self.assertTrue(closed_and_oriented(ring)) - self.assertLess(abs(signed_volume(ring) - 0.1 * 0.2 * 4.0), 1e-12) # mitred: the area times the path's length + self.assertLess(abs(signed_volume(ring) - 0.1 * 0.2 * 4.0), VOLUME) # mitred: the area times the path's length def test_what_a_sweep_refuses_an_extrude_refuses_by_name(self): """extrude-refusals, at build. Mutant E8 (the where prefix dropped): each message starts at 'path point' or @@ -484,6 +492,33 @@ class ShapeTests(unittest.TestCase): built([{"shape": "box", "size": [1, 1, 1]}, {"shape": "repeat", "count": 2, "step": [1, 0, 0], "of": {**self.BEAM, "up": [0, 0, 1]}}]) self.assertEqual(len(built([{**self.BEAM, "t": "a"}], [param("a", 0, 1, 0.05)], {"a": 0.04}).counts), 14) + def test_an_extrude_takes_one_up_or_one_for_each_point(self): + """portal-web-across-plane, at its owner. An L of path in the xz plane: one up +y stands the I section's height + (0.1) across the plane; an up for each point, in the plane and across the path there, stands it in the plane, + at the same volume, mitred. The same up given three times is the one up, byte for byte. Mutants U1 (only the + first of the ups is used: the far leg's up runs along its path and the build is refused) and U2 (an array of + ups of another length than the path is admitted).""" + bent = {**self.BEAM, "path": [[0, 0, 0], [0, 0, 1], [1, 0, 1]]} + across, three, inplane = (built([{**bent, "up": up}]) for up in ([0, 1, 0], [[0, 1, 0]] * 3, [[1, 0, 0], [1, 0, -1], [0, 0, -1]])) + self.assertEqual((across.V.tobytes(), across.faces.tobytes()), (three.V.tobytes(), three.faces.tobytes())) + self.assertTrue(closed_and_oriented(inplane)) + self.assertLess(abs(signed_volume(inplane) - signed_volume(across)), VOLUME) + for b, extents in ((across, [1.03, 0.1, 1.03]), (inplane, [1.05, 0.06, 1.05])): # the path's 1 by 1 and half the section either end + self.assertLess(float(np.abs(np.ptp(b.V, axis=0) - extents).max()), PLACED) + ring = inplane.V.reshape(3, 12, 3) + self.assertLess(float(np.abs(ring[:, 1] - ring[:, 0] - [0.0, -0.06, 0.0]).max()), PLACED) # the flange runs across y at every point + expression = built([{**bent, "up": [["a", 0, 0], ["a", 0, "-a"], [0, 0, "-a"]]}], [param("a")]) + self.assertEqual(expression.V.tobytes(), inplane.V.tobytes()) + for up, message in (([[0, 1, 0]] * 2, r"part 'p' shape 0 \(extrude\) up lists 2 vectors for a path of 3 points: give one \[x, y, z\] or one for each point$"), + ([[0, 1, 0]], r"part 'p' shape 0 \(extrude\) up lists 1 vectors for a path of 3 points"), + ([[0, 1, 0], [0, 1, 0], [0, 1]], r"part 'p' shape 0 \(extrude\) up\[2\] must be an array of three"), + ([[0, 1, 0], [0, 1, 0], [0, "q", 0]], r"part 'p' shape 0 \(extrude\) up\[2\]\[1\]: 'q' names 'q'"), + ([], r"part 'p' shape 0 \(extrude\) up must be an array of three")): + with self.assertRaisesRegex(core.KitError, message): + core.check_kit(document([{**bent, "up": up}])) + with self.assertRaisesRegex(core.KitError, r"^kit 't' part 'p' shape 0 \(extrude\): path point 2: up \[1\.0, 0\.0, 0\.0\] runs along the path there"): + built([{**bent, "up": [[1, 0, 0], [1, 0, -1], [1, 0, 0]]}]) + def test_sockets_are_right_handed_frames(self): socket = {"name": "s", "type": "mount", "size": "2*a", "at": ["a", 2, 3], "z": "+x", "y": "+z"} kit = core.check_kit(document(params=[param("a")], sockets=[socket])) @@ -763,29 +798,6 @@ class FrameKitTests(unittest.TestCase): cls.kit = core.load_kit("frame") cls.mechanical = core.load_kit("mechanical") - @staticmethod - def seat(b, socket) -> float: - """How far the socket's origin stands off the nearest face that faces its z and holds it: the face's normal by - Newell's sum and the origin inside its outline by crossing count, since a section's cap is not convex (inf - when no face holds it).""" - origin, z = socket["matrix"][:3, 3], socket["matrix"][:3, 2] - best = math.inf - for face in faces_of(b): - p = b.V[face] - normal = np.cross(p, np.roll(p, -1, axis=0)).sum(axis=0) - normal /= np.linalg.norm(normal) - if np.abs(normal - z).max() > 1e-6: - continue - u = np.cross(normal, [1.0, 0.0, 0.0] if abs(normal[0]) < 0.9 else [0.0, 1.0, 0.0]) - q, o = np.stack([p @ u, p @ np.cross(normal, u)], axis=1), np.array([origin @ u, origin @ np.cross(normal, u)]) - a, c = q, np.roll(q, -1, axis=0) - straddles = (a[:, 1] > o[1]) != (c[:, 1] > o[1]) - with np.errstate(divide="ignore", invalid="ignore"): - crossing = a[:, 0] + (o[1] - a[:, 1]) * (c[:, 0] - a[:, 0]) / (c[:, 1] - a[:, 1]) - if int((straddles & (crossing > o[0])).sum()) % 2: - best = min(best, float(abs((origin - p[0]) @ normal))) - return best - def draws(self, name): part = self.kit["parts"][name] rng = random.Random(f"frame.{name}") @@ -824,9 +836,9 @@ class FrameKitTests(unittest.TestCase): self.assertEqual(len(b.sockets), 2) for socket in b.sockets: frame = socket["matrix"][:3, :3] - self.assertLess(np.abs(frame.T @ frame - np.eye(3)).max(), 1e-9) - self.assertLess(abs(np.linalg.det(frame) - 1.0), 1e-9) - self.assertLess(self.seat(b, socket), 1e-9, f"{name}.{socket['name']} {given}") + # exact: a frame part's socket axes are named axes, so its frame is a signed permutation + self.assertEqual((float(np.abs(frame.T @ frame - np.eye(3)).max()), float(np.linalg.det(frame))), (0.0, 1.0)) + self.assertLess(socket_seat(b, socket), SEATED, f"{name}.{socket['name']} {given}") self.assertGreater(socket["size"], 0.0) def test_a_truss_is_two_chords_a_vertical_a_bay_and_a_diagonal_a_bay(self): @@ -838,25 +850,55 @@ class FrameKitTests(unittest.TestCase): self.assertEqual((b.shell_count, len(b.counts)), (2 + (2 * pairs + 1) + 2 * pairs, 6 * (4 * pairs + 3))) bay = 3.2 / (2 * pairs) shells = b.V.reshape(-1, 8, 3) - self.assertTrue(np.allclose(shells[2:2 * pairs + 3].mean(axis=1), [[k * bay, 0, 0.2] for k in range(2 * pairs + 1)], atol=1e-12)) - self.assertTrue(np.allclose(shells[2 * pairs + 3:].mean(axis=1), [[(k + 0.5) * bay, 0, 0.2] for k in list(range(0, 2 * pairs, 2)) + list(range(1, 2 * pairs, 2))], atol=1e-12)) + self.assertLess(float(np.abs(np.array([shells[:2, :, 0].min(axis=1), shells[:2, :, 0].max(axis=1)]).T - [-0.015, 3.215]).max()), PLACED) # each chord runs to the end verticals' outer faces + self.assertLess(float(np.abs(shells[2:2 * pairs + 3].mean(axis=1) - [[k * bay, 0, 0.2] for k in range(2 * pairs + 1)]).max()), PLACED) + self.assertLess(float(np.abs(shells[2 * pairs + 3:].mean(axis=1) - [[(k + 0.5) * bay, 0, 0.2] for k in list(range(0, 2 * pairs, 2)) + list(range(1, 2 * pairs, 2))]).max()), PLACED) rising, falling = shells[2 * pairs + 3], shells[3 * pairs + 3] - self.assertTrue(np.allclose([rising[:4].mean(axis=0), rising[4:].mean(axis=0)], [[0, 0, 0], [bay, 0, 0.4]], atol=1e-12)) - self.assertTrue(np.allclose([falling[:4].mean(axis=0), falling[4:].mean(axis=0)], [[bay, 0, 0.4], [2 * bay, 0, 0]], atol=1e-12)) + self.assertLess(float(np.abs(np.array([rising[:4].mean(axis=0), rising[4:].mean(axis=0)]) - [[0, 0, 0], [bay, 0, 0.4]]).max()), PLACED) + self.assertLess(float(np.abs(np.array([falling[:4].mean(axis=0), falling[4:].mean(axis=0)]) - [[bay, 0, 0.4], [2 * bay, 0, 0]]).max()), PLACED) def test_the_portals_corners_are_mitred(self): """frame-kit-holds: at each corner every point of the section stands as far from the leg's axis as from the - beam's, which is its own distance across the section (unmitred, 0.707 of it from each).""" + beam's, which is its own height in the section (unmitred, 0.707 of it from each): the section's height lies in + the frame's plane. Mutant F1 (a sweep with no mitre).""" part, draws = self.draws("portal") for given in draws[:6]: b = core.build(part, given) env = b.params - across = np.abs(core.profile("I", env["w"], env["h"], min(env["t"], 0.45 * min(env["w"], env["h"])))[:, 0]) + across = np.abs(core.profile("I", env["w"], env["h"], min(env["t"], 0.45 * min(env["w"], env["h"])))[:, 1]) for ring, corner in ((1, [-env["width"] / 2, 0.0, env["height"]]), (2, [env["width"] / 2, 0.0, env["height"]])): off = np.abs(b.V[12 * ring:12 * ring + 12] - corner) - self.assertLess(float(np.abs(off[:, [0, 2]] - across[:, None]).max()), 1e-12, given) + self.assertLess(float(np.abs(off[:, [0, 2]] - across[:, None]).max()), PLACED, given) self.assertEqual((b.shell_count, b.counts.tolist()), (1, [4] * 36 + [12, 12])) + def test_the_portal_stands_its_web_in_plane_and_its_feet_apart(self): + """portal-web-across-plane, frame-layout-unpinned. The I section's height h lies in the xz plane and its flanges + run w across y, at every point of the path: the frame is width + h wide, w deep and height + h / 2 tall, and + its web is the plate on y 0. foot_a stands under the leg at -width / 2 and foot_b under the one at +width / 2, + each on its own end cap. Mutants P1 (one up +y: the web across the plane, the frame h deep) and S9 (foot_b at + -width / 2, on foot_a).""" + part = self.kit["parts"]["portal"] + for given in ({"width": 1.2, "height": 0.9, "w": 0.06, "h": 0.2, "t": 0.01}, {"width": 0.8, "height": 1.5, "w": 0.3, "h": 0.05, "t": 0.004}): + b = core.build(part, given) + width, height, w, h, t = (given[key] for key in ("width", "height", "w", "h", "t")) + self.assertLess(float(np.abs(np.ptp(b.V, axis=0) - [width + h, w, height + h / 2]).max()), PLACED, given) + ring = b.V.reshape(4, 12, 3) + self.assertLess(float(np.abs(ring[:, 1] - ring[:, 0] - [0.0, -w, 0.0]).max()), PLACED, given) # a flange's edge runs across y + self.assertLess(float(np.abs(np.abs(ring[:, [3, 4, 9, 10], 1]) - t / 2).max()), PLACED, given) # the web's four corners, t / 2 off the plane + feet = {s["name"]: s["matrix"] for s in b.sockets} + self.assertEqual(list(feet), ["foot_a", "foot_b"]) + for name, side, cap in (("foot_a", -1.0, ring[0]), ("foot_b", 1.0, ring[3])): + self.assertLess(float(np.abs(feet[name][:3, 3] - [side * width / 2, 0.0, 0.0]).max()), PLACED, name) + self.assertLess(float(np.abs(feet[name][:3, 3] - cap.mean(axis=0)).max()), PLACED, name) # at the middle of its own cap + self.assertEqual((feet[name][:3, 2].tolist(), feet[name][:3, 1].tolist()), ([0.0, 0.0, -1.0], [0.0, 1.0, 0.0])) + + def test_a_beam_is_w_across_x_and_h_along_y(self): + """frame-layout-unpinned. Each of the five beams runs length along +z from 0, w wide across x and h tall along + y, about its axis. Mutant S14 (box_beam's w and h swapped).""" + for name in ("beam_i", "channel", "tee", "angle", "box_beam"): + b = core.build(self.kit["parts"][name], {"length": 0.7, "w": 0.05, "h": 0.2}) + self.assertLess(float(np.abs(np.array([b.V.min(axis=0), b.V.max(axis=0)]) - [[-0.025, -0.1, 0.0], [0.025, 0.1, 0.7]]).max()), PLACED, name) + def test_builds_are_deterministic(self): for part in self.kit["parts"].values(): a, b = core.build(part), core.build(part) @@ -872,8 +914,8 @@ class FrameKitTests(unittest.TestCase): self.assertEqual((mount["size"], end["size"]), (0.09, 0.08)) self.assertIsNone(core.mate_refusal(self.mechanical["socketTypes"], mount, end, self.kit["socketTypes"], names)) seated = core.mate(mount, end) @ end["matrix"] - self.assertLess(float(np.abs(seated[:3, 3]).max()), 1e-12) - self.assertLess(float(np.abs(seated[:3, 2] - [0.0, 0.0, 1.0]).max()), 1e-12) # the beam's end faces the bracket's foot and the beam runs on along -z + self.assertLess(float(np.abs(seated[:3, 3]).max()), PLACED) + self.assertEqual(seated[:3, 2].tolist(), [0.0, 0.0, 1.0]) # the beam's end faces the bracket's foot and the beam runs on along -z wide = core.build(self.kit["parts"]["box_beam"], {"w": 0.2, "h": 0.2}) self.assertIn("it is larger", core.mate_refusal(self.mechanical["socketTypes"], mount, wide.sockets[0], self.kit["socketTypes"], names)) self.assertIn("are of different types", core.mate_refusal(self.mechanical["socketTypes"], bracket.sockets[1], end, self.kit["socketTypes"], names)) -- 2.47.3 From 8513bd35e335199eef35dec9ed5544160c4e3adc Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 17:42:08 +0100 Subject: [PATCH 7/7] live kitbash_ribs: wedge and gusset longerons through the legs' ribs, each its section's area along the run Co-Authored-By: Claude Fable 5.2 --- surfaces/blender/tests/live/kitbash_ribs.py | 17 +++++++++++++++++ .../blender/tests/live/kitbash_ribs.result.json | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/surfaces/blender/tests/live/kitbash_ribs.py b/surfaces/blender/tests/live/kitbash_ribs.py index 4b8d756..d593fdf 100644 --- a/surfaces/blender/tests/live/kitbash_ribs.py +++ b/surfaces/blender/tests/live/kitbash_ribs.py @@ -106,6 +106,10 @@ CLEARED = 0.0058 # 5.2e-07; least claimed mutant 0.0021 (K1, a sweep with no mitre: the rib's mid-depth line stands in from where the # facets' offsets meet); separation 64 each side. K9 (the station at the chain's first point) reads 1.2. STATIONED = 3.3e-5 +# A wedge's or a gusset's longerons' volume less a T's, over the difference of the two sections' areas along both runs, +# less 1. Shipped 1.1e-06; least claimed mutant 0.235, computed, not run (a wedge built as a gusset; the section ignored +# and a T built reads 1); separation 460 each side. +SECTIONED = 5.1e-4 # What lightening holes removed from five crossing ribs, over the holes' faceted area times the thickness, less 1. # Shipped 2.7e-08; least claimed mutant 22 (K11, each plane's Manifold Boolean taken over all five ribs' webs, which # cross, with the action's own check of the cut off); separation 28000 each side. @@ -504,6 +508,19 @@ try: receipt["status"] == "accepted" and [s["chains"] for s in report["sections"]] == [2, 2, 2] and report["ribs"] == 6 and [(r["index"], len(r["stations"])) for r in report["longerons"]] == [(0, 3), (1, 3)] and R["readings"].get("stationed", 1.0) < STATIONED and (shape["shells"], shape["nonManifoldEdges"]) == (8, 0) and abs(float(points(ribs)[:, 2].max()) - (0.8 + 0.3 * 0.12)) < 1e-6 and abs(float(points(ribs)[:, 2].min()) - (0.2 - 0.3 * 0.12)) < 1e-6, [receipt["message"], report, R["readings"]]) + # the longeron enum's other sections: a wedge and a gusset through the same ribs. A straight longeron's shells are its + # section's area times its length, so against the T's ribs each differs by the two sections' areas over two legs. + t_volume, run = (shape or {}).get("volume", 0.0), LEVELS[-1] - LEVELS[0] + 2 * 0.3 * 0.12 + area = lambda kind: (lambda x, y: float(0.5 * np.sum(x * np.roll(y, -1) - np.roll(x, -1) * y)))(*core.profile(kind, 0.05, 0.05, 0.008).T) # noqa: E731 + for kind in ("wedge", "gusset"): + receipt, report = send("brokkr_kitbash.ribs", object_name="Legs", ribs_name=f"LegRibs_{kind}", planes=flat(LEVELS), **SIZES, longerons=json.dumps(BEAMS), + longeron=kind, longeron_w=0.05, longeron_h=0.05, longeron_t=0.008) + made = bpy.data.objects.get(f"LegRibs_{kind}") + shape = measure(made.data) if made is not None else {} + check(f"a {kind} longeron through each leg's ribs: the stations a T's has, closed shells, and the {kind}'s area along the run", + receipt["status"] == "accepted" and [(r["index"], len(r["stations"])) for r in report["longerons"]] == [(0, 3), (1, 3)] + and (shape["shells"], shape["nonManifoldEdges"]) == (8, 0) + and reading("sectioned", abs((shape["volume"] - t_volume) / (2 * run * (area(kind) - area("T"))) - 1.0)) < SECTIONED, [receipt["message"], report, R["readings"]]) LEG = {"object_name": "Legs", "ribs_name": "Bad", "planes": flat(LEVELS), **SIZES} refused("a longeron whose half-plane meets no rib", {**LEG, "longerons": json.dumps([{"origin": [0.0, 0.0, 0.0], "axis": [0.0, 0.0, 1.0], "toward": [0.0, 1.0, 0.0]}])}, "longerons[0] does not meet the ribs of planes[0]") diff --git a/surfaces/blender/tests/live/kitbash_ribs.result.json b/surfaces/blender/tests/live/kitbash_ribs.result.json index 396fca8..40360ad 100644 --- a/surfaces/blender/tests/live/kitbash_ribs.result.json +++ b/surfaces/blender/tests/live/kitbash_ribs.result.json @@ -121,6 +121,16 @@ "ok": true, "detail": null }, + { + "name": "a wedge longeron through each leg's ribs: the stations a T's has, closed shells, and the wedge's area along the run", + "ok": true, + "detail": null + }, + { + "name": "a gusset longeron through each leg's ribs: the stations a T's has, closed shells, and the gusset's area along the run", + "ok": true, + "detail": null + }, { "name": "refused, scene unchanged: a longeron whose half-plane meets no rib", "ok": true, @@ -256,6 +266,7 @@ "planar": 1.4e-07, "ring": 2.1e-06, "round": 9.7e-08, + "sectioned": 1.1e-06, "stationed": 5.2e-07, "stood": 6.4e-08, "sunk": 0.0047, -- 2.47.3