diff --git a/surfaces/blender/brokkr_kitbash/__init__.py b/surfaces/blender/brokkr_kitbash/__init__.py index 5546959..bc64a05 100644 --- a/surfaces/blender/brokkr_kitbash/__init__.py +++ b/surfaces/blender/brokkr_kitbash/__init__.py @@ -1285,13 +1285,12 @@ class BROKKR_KITBASH_OT_follow(PolishOperator): context.view_layer.update() return {**part_report(obj, part, built), "cleared": [o.name for o in cleared]} driver = mesh_object(given["driver"]) - pair = (obj,) if ratio else (obj.parent, obj) - if not ratio: - connection(obj.parent, "the follower's parent: a loop's two unknowns are the closing part's joint and its parent's") - closing = closure(obj) + pair, closing = (obj,) if ratio else (obj.parent, obj), closure(obj) if not ratio and (closing is None or closing[1] is None or not closure_report(obj, part, built)["holds"]): raise Refused(f"{obj.name!r} states no closure that holds: a loop follower is the part that states the closure (brokkr_kitbash.close, where the " "two sockets meet), and its joint and its parent's are solved to keep it; nothing changed.") + if not ratio: + connection(obj.parent, "the follower's parent: a loop's two unknowns are the closing part's joint and its parent's") if not ratio and CLOSE in obj.parent: raise Refused(f"{obj.parent.name!r}, the parent of {obj.name!r}, states a closure itself: a loop's parent follower states none; nothing changed.") driver_sockets, driver_stated, _ = connection(driver, "the driver") @@ -1307,9 +1306,6 @@ class BROKKR_KITBASH_OT_follow(PolishOperator): raise Refused(f"{o.name!r} already follows: clear it first (brokkr_kitbash.follow with record null); nothing changed.") if followers(o): raise Refused(f"{o.name!r} drives {followers(o)[0].name!r}: a driver is never a follower (one joint, one driver); nothing changed.") - if ratio and joint_record(driver)["limits"] is None: - raise Refused(f"{driver.name!r} states no limits: a ratio's driver states them (its value is then one number, not one of many a turn apart); " - "brokkr_kitbash.joint gives it limits; nothing changed.") if not ratio: moving = {driver, *followers(driver)} # what moves when the driver is posed: it, what follows it, and what hangs from either diff --git a/surfaces/blender/brokkr_kitbash/brokkr_actions.json b/surfaces/blender/brokkr_kitbash/brokkr_actions.json index 93be89c..f70394f 100644 --- a/surfaces/blender/brokkr_kitbash/brokkr_actions.json +++ b/surfaces/blender/brokkr_kitbash/brokkr_actions.json @@ -176,7 +176,7 @@ }, { "name": "brokkr_kitbash.roll", - "doc": "Turn an attached kit part to a roll about its parent socket's normal, in place: its parent and both sockets stay, and what is attached to it follows. Refuses a part that is not attached and, on a revolute joint with limits, a roll with no turn of itself inside them (the roll written is the one inside). Reports the part and closures, every closure in the scene as {part, to, holds}, its own first: a roll can open one and never seats one.", + "doc": "Turn an attached kit part to a roll about its parent socket's normal, in place: its parent and both sockets stay, and what is attached to it follows. Refuses a part that is not attached and, on a revolute joint with limits, a roll with no turn of itself inside them (the roll written is the one inside). Refused on a follower (a part whose connection states follows), naming its driver: its value is derived. On a driver, every follower moves with it in the same action, and a follower outside its own limits or a loop that cannot close refuses the pose with nothing changed; the report's followers lists each as {part, value}. Reports the part and closures, every closure in the scene as {part, to, holds}, its own first: a roll can open one and seats none but those of the loops that follow the part.", "changesScene": true, "editModeSafe": false, "result": "brokkr_mesh_polish_result", @@ -201,7 +201,7 @@ }, { "name": "brokkr_kitbash.aim", - "doc": "Turn an attached kit part about its pin until one of its own axes points as near a world direction as the pin lets it. The roll is solved exactly, not searched. On a revolute joint with limits the roll stays inside them: where the free roll is outside, the end of the limits that points the axis nearer. Refuses an axis or a direction that lies along the pin (within about 0.06 degrees), and a zero direction. Reports the part, aimed: {roll, dot} (dot 1 when the axis reaches the direction) and closures as roll does.", + "doc": "Turn an attached kit part about its pin until one of its own axes points as near a world direction as the pin lets it. The roll is solved exactly, not searched. On a revolute joint with limits the roll stays inside them: where the free roll is outside, the end of the limits that points the axis nearer. Refuses an axis or a direction that lies along the pin (within about 0.06 degrees), and a zero direction. Refused on a follower, and moves a driver's followers, as roll does. Reports the part, aimed: {roll, dot} (dot 1 when the axis reaches the direction) and closures as roll does.", "changesScene": true, "editModeSafe": false, "result": "brokkr_mesh_polish_result", @@ -254,7 +254,7 @@ }, { "name": "brokkr_kitbash.reach", - "doc": "Turn an attached kit part about its pin until one of its sockets' origins stands at a height along a world direction (by default world z): of the two rolls that do it, the one nearer the roll it has. Solved exactly. On a revolute joint with limits only a roll inside them is taken; with neither inside it refuses, naming both rolls and the limits. Refuses a height the socket cannot reach, naming the range it can (either end of the range is taken), and a socket that lies on the pin. Reports the part, reached: {roll, residual} and closures as roll does.", + "doc": "Turn an attached kit part about its pin until one of its sockets' origins stands at a height along a world direction (by default world z): of the two rolls that do it, the one nearer the roll it has. Solved exactly. On a revolute joint with limits only a roll inside them is taken; with neither inside it refuses, naming both rolls and the limits. Refuses a height the socket cannot reach, naming the range it can (either end of the range is taken), and a socket that lies on the pin. Reports the part, reached: {roll, residual} and closures as roll does. Refused on a follower, and moves a driver's followers, as roll does.", "changesScene": true, "editModeSafe": false, "result": "brokkr_mesh_polish_result", @@ -310,7 +310,7 @@ }, { "name": "brokkr_kitbash.joint", - "doc": "State the joint record of an attached kit part's connection. The connection's DOF is its parent socket's type's: revolute (its value is the roll, degrees) or prismatic (the slide, metres). record is a JSON object of any of limits ([lo, hi] or null), mechanism (a label of 1 to 32 a-z, 0-9 and _, or null) and compliance ({\"hertz\": over 0 to 30, \"damping_ratio\": 0 to 2} or null: a slide in the load path that settles under load, a record for a runtime, solved by nothing here); a key left out keeps what is stated and null clears it. Refuses a rigid connection naming its socket type, limits that do not hold the value the joint has, revolute limits spanning over 360 degrees or with an end past 360, prismatic limits with an end past 10 m, and compliance on a revolute joint or without limits. Moves nothing but a roll to its turn inside the limits. Reports the part and closures as roll does.", + "doc": "State the joint record of an attached kit part's connection. The connection's DOF is its parent socket's type's: revolute (its value is the roll, degrees) or prismatic (the slide, metres). record is a JSON object of any of limits ([lo, hi] or null), mechanism (a label of 1 to 32 a-z, 0-9 and _, or null) and compliance ({\"hertz\": over 0 to 30, \"damping_ratio\": 0 to 2} or null: a slide in the load path that settles under load, a record for a runtime, solved by nothing here); a key left out keeps what is stated and null clears it. Refuses a rigid connection naming its socket type, limits that do not hold the value the joint has, revolute limits spanning over 360 degrees or with an end past 360, prismatic limits with an end past 10 m, and compliance on a revolute joint or without limits. Moves nothing but a roll to its turn inside the limits: a follower keeps its derived value (limits that do not hold it are refused), and a driver's followers are derived again where it stands. Limits cannot be cleared from a driver a ratio follows. Reports the part and closures as roll does.", "changesScene": true, "editModeSafe": false, "result": "brokkr_mesh_polish_result", @@ -335,7 +335,7 @@ }, { "name": "brokkr_kitbash.slide", - "doc": "Slide an attached kit part along its parent socket's normal, in place, on a prismatic connection (a ram_rod in a ram_barrel's bore: slide 0 is closed, the slide is the extension): its parent and both sockets stay, and what is attached to it follows. Refuses a revolute or rigid connection naming its socket type, and a slide outside the joint's limits. Reports the part and closures as roll does.", + "doc": "Slide an attached kit part along its parent socket's normal, in place, on a prismatic connection (a ram_rod in a ram_barrel's bore: slide 0 is closed, the slide is the extension): its parent and both sockets stay, and what is attached to it follows. Refuses a revolute or rigid connection naming its socket type, and a slide outside the joint's limits. Reports the part and closures as roll does. Refused on a follower, and moves a driver's followers, as roll does.", "changesScene": true, "editModeSafe": false, "result": "brokkr_mesh_polish_result", @@ -360,7 +360,7 @@ }, { "name": "brokkr_kitbash.joints", - "doc": "The joints of the tree of kit parts attached under a root part, as {schema: brokkr.joints, version: 1, root, frame, rigid, joints}. A row per revolute or prismatic connection, depth first with children by name, so a joint's parent row comes before it: id (the child object), parent (the id of the nearest joint above, or null: rigid connections fold into it and are counted in rigid), part, socket ('Object:socket', the parent socket), kind, axis and origin (that socket's z and origin in the root object's frame: Blender axes, +Z up, metres), value (the roll in degrees or the slide in metres now), limits ([lo, hi] or null), min and max (the limits less the value: the travel either way from this pose), mechanism and compliance. Axis, origin and order are derived at each report from the kits and the parent tree; nothing stores them. Rows a receipt cannot carry are counted in jointsOmitted. Refuses a connection that cannot be read. Evaluates no modifier.", + "doc": "The joints of the tree of kit parts attached under a root part, as {schema: brokkr.joints, version: 2, root, frame, rigid, unlimited, next, joints}. A row per revolute or prismatic connection, depth first with children by name, so a joint's parent row comes before it; a root that itself states a revolute or prismatic connection has its own row first, parent null: id (the child object), parent (the id of the nearest joint above, or null: rigid connections fold into it and are counted in rigid), part, socket ('Object:socket', the parent socket), kind, axis and origin (that socket's z and origin in the root object's frame: Blender axes, +Z up, metres), value (the roll in degrees or the slide in metres now), limits ([lo, hi] or null), min and max (the limits less the value: the travel either way from this pose), mechanism, compliance and driven (null, or {by: the driver's id, kind: ratio | loop, k, offset}: the value is derived from the driver's, so a rig makes a driven bone and not a DOF). kind is revolute or prismatic: Aetheria's ShipJoint calls them rotate and slide, one to one. unlimited lists the ids of the rows that are not driven and state no limits, in the whole tree: an exporter that needs limits refuses by this one field. Axis, origin and order are derived at each report from the kits and the parent tree; nothing stores them. Rows a receipt cannot carry are counted in jointsOmitted, and next is then the id of the last row carried (else null): call again with after set to it for the rows that follow. after refuses an id that is no row's. Refuses a connection that cannot be read. Evaluates no modifier.", "changesScene": false, "editModeSafe": true, "result": "brokkr_mesh_polish_result", @@ -372,6 +372,38 @@ "minLength": 1, "maxLength": 63, "doc": "the root: a kit part" + }, + { + "name": "after", + "type": "string", + "maxLength": 63, + "default": "", + "doc": "empty, or the next of the report before: the rows after that id" + } + ] + }, + { + "name": "brokkr_kitbash.follow", + "doc": "State that an attached kit part's joint follows another's: its roll or slide is then derived from the driver's whenever the driver is posed, and roll, aim, reach and slide on it are refused. record is JSON. {\"driver\": name, \"kind\": \"ratio\", \"k\": number, \"offset\": number}: the value is k x the driver's value + offset (a kneecap at k 0.5, a pinion at minus ring over pinion, a crosshead's slide in metres per degree of a roll); the driver states limits, so its value is one number. {\"driver\": name, \"kind\": \"loop\"}: object_name is a part that states a closure that holds; its joint and its parent's are the two unknowns solved so the closure keeps holding (a rocker and coupler closing on a crank; a ram's barrel and rod closing on the part it pushes; a torque link's two arms), and both follow the driver. Exactly one end of the loop, the parent's parent or the part closed on, moves with the driver: it is the driver, follows it, or hangs from one that does. The loop is planar: its pins are parallel. null clears the statement, and a loop partner's with it. The follower moves at once and the report's followers lists every follower of the driver as {part, value}. Refuses, with nothing changed: a rigid connection; a driver that is the follower, below it, or itself a follower; a follower that already follows or that drives another; a ratio whose driver states no limits; a value outside the follower's own limits; a loop with no closure that holds, with both ends or neither moving with the driver, that is not planar, or at a dead centre (its two joints in line). Nothing stores a pin or a linkage: a loop is solved from the kits' socket frames each time, and no Blender driver or constraint is made.", + "changesScene": true, + "editModeSafe": false, + "result": "brokkr_mesh_polish_result", + "fields": [ + { + "name": "object_name", + "type": "string", + "required": true, + "minLength": 1, + "maxLength": 63, + "doc": "the follower: a part attached on a revolute or prismatic socket; for a loop, the part that states the closure" + }, + { + "name": "record", + "type": "string", + "required": true, + "minLength": 4, + "maxLength": 400, + "doc": "{driver, kind: ratio, k, offset}, {driver, kind: loop}, or null" } ] }, diff --git a/surfaces/blender/tests/live/kitbash_follows.py b/surfaces/blender/tests/live/kitbash_follows.py new file mode 100644 index 0000000..335207b --- /dev/null +++ b/surfaces/blender/tests/live/kitbash_follows.py @@ -0,0 +1,475 @@ +"""Live proof, in a background Blender, of brokkr_kitbash followers through run_intent: brokkr_kitbash.follow states a +ratio or a loop, posing a driver derives every follower in the same action (core.close_loop for a loop), a follower +refuses to be posed, brokkr.joints version 2 marks driven rows and pages, and each refusal changes nothing. Not part of +the unittest run: it needs Blender. + + blender --background --factory-startup --python-exit-code 1 --python surfaces/blender/tests/live/kitbash_follows.py -- + +Run it with private BLENDER_USER_CONFIG, BLENDER_USER_EXTENSIONS and BLENDER_USER_SCRIPTS directories (it refuses +without them). is an absolute path; writes .result.json and exits 1 when a check failed. The checks run +inside one try: an uncaught error is a failed check that names the check before it. + +The scene, every strut 0.09 wide so its pins take a ram's: a four-bar (Crank on the root Ground, Rocker on the root +Base, Coupler closing on the crank); a ram (A_Barrel on the root Pad, A_Rod in its bore, closing on the rocker), named +to sort before the four-bar it waits on; ratio followers of the crank (Cap, Pinion, and X_Rod's slide in X_Barrel); a +torque link (T_Rod sliding in the root T_Barrel, T_Upper and T_Lower closing on T_Lug, a strut pinned on the rod's +rod_end_back: a strut's two pins face one way, so two arms from the barrel's pin cannot face the rod's own); Idle +and Tip for the refusals; a chain of 80 struts for a joints report over a receipt. Bounds follow +lodur:ruling:deterministic-bound-margin, both readings beside each; the result file carries the readings. +""" +import importlib.util +import json +import math +import os +import sys +import tempfile +import time +import traceback +import types +from pathlib import Path + +import bpy +import numpy as np +from mathutils import Matrix + +SURFACE = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(SURFACE / "tools")) +import private_dirs # noqa: E402 + +_refused = private_dirs.refusal(os.environ, os.path.expanduser("~"), lambda kind: bpy.utils.user_resource(kind)) +if _refused: + raise SystemExit(_refused) +OUT = sys.argv[sys.argv.index("--") + 1] +if not Path(OUT).is_absolute(): + raise SystemExit(f"{OUT!r} is not an absolute path") +package = types.ModuleType("brokkr_bridge") +package.__path__ = [str(SURFACE / "brokkr_bridge")] +sys.modules["brokkr_bridge"] = package +from brokkr_bridge import blender_target as bt # noqa: E402 + +import addon_utils # noqa: E402 + +spec = importlib.util.spec_from_file_location("brokkr_kitbash_core_reference", SURFACE / "brokkr_kitbash" / "core.py") +core = importlib.util.module_from_spec(spec) # core as the unit tests load it: the frames every reading here is taken against +spec.loader.exec_module(core) + +sys.path.append(str(SURFACE)) +bpy.ops.wm.read_factory_settings(use_empty=True) +for module in ("brokkr_mesh_polish", "brokkr_kitbash"): + addon_utils.enable(module, default_set=True) +target = bt.BrokkrBlenderTarget(bpy) +WORK = Path(tempfile.mkdtemp(prefix="brokkr-kitbash-follows-")) +target.configure_action_dirs("", str(WORK)) +target.reload_host_actions() +R = {"blender": bpy.app.version_string, "checks": [], "hostErrors": target.host_actions()[1], "readings": {}} +COUNT = [0] +kit = core.load_kit("mechanical") +# Each mutant's reading below is its least over the cases here that it changes; the shipped reading is the worst. +# Metres (or a difference of unit vectors) between a loop's closing socket and the socket it closes on, read from the two +# world matrices after a driver was posed. Shipped worst 1.9e-06 (float32 matrices); least claimed mutant 0.018 (F11, the +# ram solved before the four-bar its rocker follows, at the smallest turn here); separation 97 each side. +CLOSED = 1.8e-4 +# Degrees between a loop follower's roll and the one this file solves by its own steps of core.close_loop from the rest +# pose. Shipped worst 2.3e-05 (an action's roll is a float32 field); least claimed mutant 8.9 (F11 again: the barrel +# aimed at where the rocker was); separation 620 each side. +SOLVED = 1.4e-2 +# Metres between a ratio follower's slide, or degrees between its roll, and k x the driver's value + offset, read from +# the stored values. Shipped 0 (the same doubles), taken as one float32 step of the largest value here, 1.5e-05; least +# claimed mutant 15 (a ratio follower not moved by a 30 degree turn of its driver at k 0.5); separation 1e3 each side. +RATIO = 1.5e-2 +ROT = [0.3, -0.2, 0.5] # the roots' rotation: no axis of the scene lines up with the world's +D0, REST = 30.0, (-40.0, 70.0) # the four-bar at rest: the crank's roll, and the rocker's and coupler's +RAM_REST = (200.0, 0.1) # the ram at rest: the barrel's roll and the rod's slide + + +def check(name, ok, detail=None): + try: + json.dumps(detail, default=str) + except TypeError: + detail = repr(detail) + R["checks"].append({"name": name, "ok": bool(ok), "detail": None if ok else detail}) + + +def reading(name, value): + R["readings"][name] = max(R["readings"].get(name, 0.0), float(value)) + return float(value) + + +def send(action, **fields): + COUNT[0] += 1 + receipt = target.run_intent(bpy.context, {"commandId": f"live-{COUNT[0]}", "requestedBy": "test/driver", "action": action, **fields}) + result = None + if receipt.get("hostResult"): + try: + result = json.loads(receipt["hostResult"]) + except ValueError: + result = None + if not action.endswith(("place_part", "attach")) or receipt["status"] != "accepted": + print("SEND", action, receipt["status"], str(receipt["message"])[:300], flush=True) + return receipt, result + + +def place(name, part, params="", world=None): + send("brokkr_kitbash.place_part", part=part, object_name=name, params=params) + if world is not None: + world = Matrix(np.asarray(world).tolist()) + send("setObjectTransform", targetObjectName=name, location=list(world.translation), rotationEuler=list(world.to_euler("XYZ"))) + return bpy.data.objects[name] + + +def attach(name, socket_name, parent, parent_socket, roll=0.0): + receipt, _ = send("brokkr_kitbash.attach", object_name=name, socket=socket_name, parent_name=parent, parent_socket=parent_socket, roll=roll) + return receipt["status"] == "accepted" + + +def socket(obj, name): + built = core.build(core.part(kit, obj["kit_part"]), json.loads(obj["kit_params"])) + return next(s for s in built.sockets if s["name"] == name) + + +def world(obj): + return np.array(obj.matrix_world, dtype=np.float64) + + +def frame(obj, name): + """A socket's world frame, from the object's matrix_world and core's build of its stored params.""" + return world(obj) @ socket(obj, name)["matrix"] + + +def apart(obj, name, other, other_name): + """How far two sockets stand from meeting as a pin, read from the scene: origins apart, or normals not opposed.""" + a, b = frame(obj, name), frame(other, other_name) + return max(float(np.abs(a[:3, 3] - b[:3, 3]).max()), float(np.abs(a[:3, 2] + b[:3, 2]).max())) + + +def connection(name): + receipt, report = send("brokkr_kitbash.report", object_name=name) + return report["parts"][0]["connection"] if report else {"error": receipt["message"]} + + +def scene_state(): + return {o.name: (o.parent and o.parent.name, np.round(np.array(o.matrix_basis), 6).tolist(), np.round(np.array(o.matrix_parent_inverse), 6).tolist(), len(o.data.vertices), + {k: repr(o[k]) for k in sorted(o.keys()) if k.startswith("kit_")}) for o in bpy.data.objects} + + +def refused(label, action, fields, *expected): + state = scene_state() + receipt, _ = send(action, **fields) + check(f"refused, scene unchanged: {label}", receipt["status"] != "accepted" and all(text in str(receipt["message"]) for text in expected) and scene_state() == state, + [receipt["status"], receipt["message"], expected]) + + +def stepped(solve, seed, start, end, step): + """This file's own derivation: the loop's two values after the input goes from start to end in steps of at most `step`.""" + count = max(1, math.ceil(abs(end - start) / step)) + for index in range(1, count + 1): + seed, _ = solve(start + (end - start) * index / count, seed) + return seed + + +def turned(a, b): + return abs((a - b + 180.0) % 360.0 - 180.0) + + +try: + rows = [row["name"] for row in target.host_actions()[0] if row["name"].startswith("brokkr_kitbash.")] + check("follow loads as a host action after joints, with no errors", not R["hostErrors"] and "brokkr_kitbash.joints" in rows + and rows[rows.index("brokkr_kitbash.joints") + 1] == "brokkr_kitbash.follow", [R["hostErrors"], rows]) + + # --- the four-bar ----------------------------------------------------------------------------------------------------- + turn = np.eye(4) + turn[:3, :3] = core._rotation([math.degrees(v) for v in ROT]) + turn[:3, 3] = [1.0, 2.0, 3.0] + W = "width=0.09; " + ground = place("Ground", "strut", W + "length=0.8", turn) + crank, rocker, coupler = place("Crank", "strut", W + "length=0.5"), place("Rocker", "strut", W + "length=0.9"), place("Coupler", "strut", W + "length=0.7") + attach("Crank", "end_a", "Ground", "end_a", D0) + + def crank_pin(roll, name="end_b"): + return world(ground) @ core.mate(socket(ground, "end_a"), socket(crank, "end_a"), roll) @ socket(crank, name)["matrix"] + + def rocker_world(base_world, roll): + return base_world @ core.mate(socket(ground, "end_a"), socket(rocker, "end_a"), roll) + + end = rocker_world(turn, REST[0]) @ core.mate(socket(rocker, "end_b"), socket(coupler, "end_a"), REST[1]) @ socket(coupler, "end_b")["matrix"] + shift = np.eye(4) + shift[:3, 3] = crank_pin(D0)[:3, 3] - end[:3, 3] + base = place("Base", "strut", W + "length=0.8", shift @ turn) # where the loop closes at rest + attach("Rocker", "end_a", "Base", "end_a", REST[0]) + attach("Coupler", "end_a", "Rocker", "end_b", REST[1]) + receipt, report = send("brokkr_kitbash.close", object_name="Coupler", socket="end_b", other_name="Crank", other_socket="end_b") + check("the four-bar stands closed at rest: crank on Ground, rocker on Base, the coupler's end closing on the crank's", receipt["status"] == "accepted" + and report["closure"]["holds"] is True, [receipt["message"], report and report["closure"]]) + four_bar = [(socket(base, "end_a"), socket(rocker, "end_a"), "revolute"), (socket(rocker, "end_b"), socket(coupler, "end_a"), "revolute")] + + def solve_four_bar(roll, seed): + return core.close_loop(world(base), four_bar, socket(coupler, "end_b"), crank_pin(roll), seed) + + # --- parts for the refusals --------------------------------------------------------------------------------------------- + place("Idle", "strut", W), place("Tip", "strut", W), place("Loose", "strut", W) + attach("Idle", "end_a", "Ground", "end_b", 15.0) + attach("Tip", "end_a", "Idle", "end_b", 0.0) + tank = place("Tank", "tank", "radius=0.3; length=1.2") + place("Brk", "bracket") + attach("Brk", "mount", "Tank", "lug_b") + loop = '{"driver": "Crank", "kind": "loop"}' + refused("a loop whose two ends both stand still when the driver moves (F7)", "brokkr_kitbash.follow", {"object_name": "Coupler", "record": '{"driver": "Idle", "kind": "loop"}'}, + "'Base' (the base) and 'Crank' (closed on), neither moves with 'Idle'") + refused("a loop follower that states no closure", "brokkr_kitbash.follow", {"object_name": "Rocker", "record": loop}, "'Rocker' states no closure that holds") + refused("a follower on a rigid connection", "brokkr_kitbash.follow", {"object_name": "Brk", "record": '{"driver": "Crank", "kind": "ratio", "k": 1, "offset": 0}'}, + "socket type 'mount' states no dof") + refused("a follower that is not attached", "brokkr_kitbash.follow", {"object_name": "Loose", "record": loop}, "'Loose' (the follower) is not attached") + refused("a part that follows itself", "brokkr_kitbash.follow", {"object_name": "Idle", "record": '{"driver": "Idle", "kind": "ratio", "k": 1, "offset": 0}'}, "'Idle' is the follower itself") + refused("a driver below its follower", "brokkr_kitbash.follow", {"object_name": "Idle", "record": '{"driver": "Tip", "kind": "ratio", "k": 1, "offset": 0}'}, "'Tip' is below 'Idle'") + for bad in ('{"driver": "Crank", "kind": "ratio", "k": 0, "offset": 0}', '{"driver": "Crank", "kind": "ratio", "k": 1}', '{"driver": "Crank", "kind": "gear"}', + '{"driver": "Crank", "kind": "loop", "k": 1}', "[1, 2]", '{"a"'): + refused(f"a record that is not one of the three shapes: {bad}", "brokkr_kitbash.follow", {"object_name": "Idle", "record": bad}, "record must be") + refused("clearing a part that follows nothing", "brokkr_kitbash.follow", {"object_name": "Idle", "record": "null"}, "'Idle' follows nothing") + + # --- a loop follows ----------------------------------------------------------------------------------------------------- + receipt, report = send("brokkr_kitbash.follow", object_name="Coupler", record=loop) + rocker_row, coupler_row = connection("Rocker"), report["connection"] if report else None + check("follow states the loop on the closing part and its parent, both following the crank, and the report lists them as written", + receipt["status"] == "accepted" and [f["part"] for f in report["followers"]] == ["Rocker", "Coupler"] + and coupler_row["follows"] == {"driver": "Crank", "kind": "loop", "k": None, "offset": None, "holds": True, "reason": None} == rocker_row["follows"] + and json.loads(rocker["kit_follows"]) == {"kind": "loop"} == json.loads(coupler["kit_follows"]) and rocker["kit_follows_driver"] == crank == coupler["kit_follows_driver"], + [receipt["message"], report and report.get("followers"), rocker_row, coupler_row]) + seed = REST + for roll, label in ((75.0, "a 45 degree turn"), (150.0, "to 120 past rest"), (D0, "and back to rest"), (0.0, "30 the other way")): + was = crank["kit_roll"] + receipt, report = send("brokkr_kitbash.roll", object_name="Crank", roll=roll) + seed = stepped(solve_four_bar, seed, was, roll, 5.0) + ok = receipt["status"] == "accepted" and reading("closed", apart(coupler, "end_b", crank, "end_b")) < CLOSED + ok = ok and max(reading("solved", turned(rocker["kit_roll"], seed[0])), reading("solved", turned(coupler["kit_roll"], seed[1]))) < SOLVED + check(f"rolling the crank {label} moves rocker and coupler with it: the closure holds in the scene and the rolls are this file's own stepped solve", + ok and [f["part"] for f in report["followers"]] == ["Rocker", "Coupler"] and report["closures"][0] == {"part": "Coupler", "to": "Crank", "holds": True} + and connection("Rocker")["holds"] and connection("Coupler")["holds"], [receipt["message"], R["readings"], report and report.get("followers"), seed]) + refused("the crank driven past the loop's dead centre, naming the driver's value and the closing part", "brokkr_kitbash.roll", {"object_name": "Crank", "roll": -5.0}, + "'Crank' at -5: the loop 'Coupler' closes on 'Crank' ('Rocker' and 'Coupler' follow): the loop is at a dead centre", "nothing changed") + send("brokkr_kitbash.roll", object_name="Crank", roll=-2.0) # beside the toggle: 32 back from rest + seed = stepped(solve_four_bar, seed, 0.0, -2.0, 5.0) + receipt, report = send("brokkr_kitbash.roll", object_name="Crank", roll=47.0) + seed = stepped(solve_four_bar, seed, -2.0, 47.0, 5.0) + direct = stepped(solve_four_bar, REST, D0, 47.0, 5.0) + check("a 49 degree jump from beside the toggle ends on the stepped answer, the branch the linkage is on (F2: one solve from the stated value is thrown through the dead centre)", + receipt["status"] == "accepted" and reading("solved", turned(rocker["kit_roll"], direct[0])) < SOLVED and reading("solved", turned(coupler["kit_roll"], direct[1])) < SOLVED + and reading("closed", apart(coupler, "end_b", crank, "end_b")) < CLOSED, [receipt["message"], rocker["kit_roll"], coupler["kit_roll"], direct, seed]) + send("brokkr_kitbash.roll", object_name="Crank", roll=D0) + seed = stepped(solve_four_bar, seed, 47.0, D0, 5.0) + + # --- followers are derived only --------------------------------------------------------------------------------------- + for name in ("Rocker", "Coupler"): + refused(f"roll on the follower {name}, naming its driver (F4)", "brokkr_kitbash.roll", {"object_name": name, "roll": 10.0}, f"{name!r} follows 'Crank' (loop): its value is derived") + refused("aim on a follower", "brokkr_kitbash.aim", {"object_name": "Rocker", "axis": "+z", "direction_x": 1.0, "direction_y": 0.0, "direction_z": 0.0}, "'Rocker' follows 'Crank'") + refused("reach on a follower", "brokkr_kitbash.reach", {"object_name": "Rocker", "socket": "end_b", "direction_x": 0.0, "direction_y": 0.0, "direction_z": 1.0, "height": 3.0}, "'Rocker' follows 'Crank'") + was = rocker["kit_roll"] + receipt, report = send("brokkr_kitbash.joint", object_name="Rocker", record='{"limits": [-100, 20], "mechanism": "rocker"}') + check("joint on a follower states limits and a mechanism and keeps its derived value and its statement", receipt["status"] == "accepted" and rocker["kit_roll"] == was + and report["connection"]["limits"] == [-100.0, 20.0] and report["connection"]["mechanism"] == "rocker" and report["connection"]["follows"]["holds"] is True, + [receipt["message"], report and report["connection"]]) + refused("joint limits on a follower that do not hold its derived value", "brokkr_kitbash.joint", {"object_name": "Rocker", "record": '{"limits": [0, 20]}'}, "is outside the joint's limits") + refused("a driver that is itself a follower", "brokkr_kitbash.follow", {"object_name": "Idle", "record": '{"driver": "Rocker", "kind": "ratio", "k": 1, "offset": 0}'}, + "'Rocker' is itself a follower") + refused("a follower that drives another", "brokkr_kitbash.follow", {"object_name": "Crank", "record": '{"driver": "Idle", "kind": "ratio", "k": 1, "offset": 0}'}, + "'Crank' drives 'Coupler': a driver is never a follower") + refused("a follower that already follows", "brokkr_kitbash.follow", {"object_name": "Coupler", "record": loop}, "'Rocker' already follows") + refused("a closure stated by a loop's parent follower", "brokkr_kitbash.close", {"object_name": "Rocker", "socket": "end_a_back", "other_name": "Loose", "other_socket": "end_a"}, + "'Rocker' follows as the parent of a loop") + + # --- ratios ----------------------------------------------------------------------------------------------------------------- + place("Cap", "strut", W), place("Pinion", "strut", W), place("X_Barrel", "ram_barrel"), place("X_Rod", "ram_rod") + attach("Cap", "end_a", "Crank", "end_a_back", 0.0) + attach("Pinion", "end_a", "Ground", "end_b_back", 0.0) + attach("X_Barrel", "base", "Ground", "end_a_back", 90.0) + attach("X_Rod", "piston", "X_Barrel", "bore", 0.0) + cap, pinion, x_rod = (bpy.data.objects[name] for name in ("Cap", "Pinion", "X_Rod")) + half = '{"driver": "Crank", "kind": "ratio", "k": 0.5, "offset": 0}' + refused("a ratio whose driver states no limits (F3)", "brokkr_kitbash.follow", {"object_name": "Cap", "record": half}, "'Cap' follows it by ratio, and a ratio's driver states limits") + send("brokkr_kitbash.joint", object_name="Crank", record='{"limits": [-2, 160], "mechanism": "crank"}') + receipts = [send("brokkr_kitbash.follow", object_name="Cap", record=half), send("brokkr_kitbash.follow", object_name="Pinion", record='{"driver": "Crank", "kind": "ratio", "k": -3, "offset": 10}'), + send("brokkr_kitbash.follow", object_name="X_Rod", record='{"driver": "Crank", "kind": "ratio", "k": 0.001, "offset": 0.02}')] + + def ratios(): + at = crank["kit_roll"] + return max(reading("ratio", turned(cap["kit_roll"], 0.5 * at)), reading("ratio", turned(pinion["kit_roll"], -3.0 * at + 10.0)), reading("ratio", abs(x_rod["kit_slide"] - (0.001 * at + 0.02)))) + + check("a kneecap at k 0.5, a pinion at k -3 and a crosshead's slide at 0.001 m a degree follow the crank at once: each is k x its roll + offset", + all(receipt["status"] == "accepted" for receipt, _ in receipts) and ratios() < RATIO and abs(cap["kit_roll"] - 15.0) < RATIO and abs(x_rod["kit_slide"] - 0.05) < RATIO + and [f["part"] for f in receipts[2][1]["followers"]] == ["Cap", "Pinion", "X_Rod", "Rocker", "Coupler"] + and receipts[2][1]["connection"]["follows"] == {"driver": "Crank", "kind": "ratio", "k": 0.001, "offset": 0.02, "holds": True, "reason": None} + and connection("X_Rod")["holds"] and connection("Cap")["holds"], [[r["message"] for r, _ in receipts], R["readings"], receipts[2][1] and receipts[2][1].get("followers")]) + receipt, report = send("brokkr_kitbash.roll", object_name="Crank", roll=120.0) + seed = stepped(solve_four_bar, seed, D0, 120.0, 5.0) + check("rolling the crank moves ratio followers and the loop in one action: ratios first in the report, the pinion's roll brought inside a turn", + receipt["status"] == "accepted" and ratios() < RATIO and abs(pinion["kit_roll"] - 10.0) < RATIO and abs(x_rod["kit_slide"] - 0.14) < RATIO + and reading("closed", apart(coupler, "end_b", crank, "end_b")) < CLOSED and reading("solved", turned(rocker["kit_roll"], seed[0])) < SOLVED + and reading("slid", float(np.linalg.norm(frame(x_rod, "piston")[:3, 3] - frame(x_rod.parent, "bore")[:3, 3] - 0.14 * frame(x_rod.parent, "bore")[:3, 2]))) < CLOSED + and [f["part"] for f in report["followers"]] == ["Cap", "Pinion", "X_Rod", "Rocker", "Coupler"], [receipt["message"], R["readings"], pinion["kit_roll"], x_rod["kit_slide"]]) + refused("slide on a follower", "brokkr_kitbash.slide", {"object_name": "X_Rod", "slide": 0.1}, "'X_Rod' follows 'Crank' (ratio): its value is derived") + send("brokkr_kitbash.joint", object_name="Cap", record='{"limits": [0, 70]}') + refused("a pose of the driver that takes a follower outside its own limits: the driver is not written either (F5)", "brokkr_kitbash.roll", {"object_name": "Crank", "roll": 150.0}, + "'Cap' on 'Crank': its roll 75 is outside the joint's limits 0 to 70") + refused("clearing the limits of a driver a ratio follows", "brokkr_kitbash.joint", {"object_name": "Crank", "record": '{"limits": null}'}, "'Cap' follows it by ratio, and a ratio's driver states limits") + receipt, report = send("brokkr_kitbash.follow", object_name="Pinion", record="null") + cleared = receipt["status"] == "accepted" and report["cleared"] == ["Pinion"] and report["connection"]["follows"] is None and "kit_follows" not in pinion and "kit_follows_driver" not in pinion + receipt, report = send("brokkr_kitbash.roll", object_name="Pinion", roll=33.0) + check("follow with null clears the statement, and the part is posed by hand again", cleared and receipt["status"] == "accepted" and abs(pinion["kit_roll"] - 33.0) < RATIO, [receipt["message"]]) + + # --- two loops: a ram closing on the rocker, solved after the four-bar --------------------------------------------------- + send("brokkr_kitbash.roll", object_name="Crank", roll=D0) + seed = stepped(solve_four_bar, seed, 120.0, D0, 5.0) + a_barrel, a_rod = place("A_Barrel", "ram_barrel"), place("A_Rod", "ram_rod") + + def rod_end(pad_world, values): + return pad_world @ core.mate(socket(ground, "end_a"), socket(a_barrel, "base"), values[0]) @ core.mate(socket(a_barrel, "bore"), socket(a_rod, "piston"), 0.0, values[1]) @ socket(a_rod, "rod_end")["matrix"] + + shift = np.eye(4) + shift[:3, 3] = frame(rocker, "end_b_back")[:3, 3] - rod_end(turn, RAM_REST)[:3, 3] + pad = place("Pad", "strut", W + "length=0.8", shift @ turn) + attach("A_Barrel", "base", "Pad", "end_a", RAM_REST[0]) + attach("A_Rod", "piston", "A_Barrel", "bore", 0.0) + send("brokkr_kitbash.slide", object_name="A_Rod", slide=RAM_REST[1]) + send("brokkr_kitbash.close", object_name="A_Rod", socket="rod_end", other_name="Rocker", other_socket="end_b_back") + receipt, report = send("brokkr_kitbash.follow", object_name="A_Rod", record=loop) + check("a ram on its own ground pin closes on the rocker and follows the crank: the end it closes on follows the driver", + receipt["status"] == "accepted" and [f["part"] for f in report["followers"]] == ["Cap", "X_Rod", "Rocker", "Coupler", "A_Barrel", "A_Rod"] + and report["connection"]["follows"]["holds"] is True, [receipt["message"], report and report.get("followers")]) + ram_loop = [(socket(pad, "end_a"), socket(a_barrel, "base"), "revolute"), (socket(a_barrel, "bore"), socket(a_rod, "piston"), "prismatic")] + ram_seed = RAM_REST + for roll in (60.0, 110.0, 45.0): + was = crank["kit_roll"] + receipt, report = send("brokkr_kitbash.roll", object_name="Crank", roll=roll) + count = max(1, math.ceil(abs(roll - was) / 5.0)) + for index in range(1, count + 1): # this file's own derivation: at each step the four-bar, then the ram against the rocker where that step put it + seed, _ = solve_four_bar(was + (roll - was) * index / count, seed) + pin = rocker_world(world(base), seed[0]) @ socket(rocker, "end_b_back")["matrix"] + ram_seed, _ = core.close_loop(world(pad), ram_loop, socket(a_rod, "rod_end"), pin, ram_seed) + check(f"rolling the crank to {roll:g} solves the four-bar and then the ram that closes on its rocker (F11): both closures hold and the barrel's roll and rod's slide are this file's own", + receipt["status"] == "accepted" and reading("closed", apart(a_rod, "rod_end", rocker, "end_b_back")) < CLOSED and reading("closed", apart(coupler, "end_b", crank, "end_b")) < CLOSED + and reading("solved", turned(a_barrel["kit_roll"], ram_seed[0])) < SOLVED and reading("closed", abs(a_rod["kit_slide"] - ram_seed[1])) < CLOSED + and [f["part"] for f in report["followers"]][-4:] == ["Rocker", "Coupler", "A_Barrel", "A_Rod"] + and [row for row in report["closures"] if not row["holds"]] == [], [receipt["message"], R["readings"], a_barrel["kit_roll"], a_rod["kit_slide"], ram_seed]) + + # --- a torque link: a slide drives two arms --------------------------------------------------------------------------------- + far = np.eye(4) + far[:3, 3] = [0.0, -8.0, 0.0] + t_barrel, t_rod = place("T_Barrel", "ram_barrel", "", far @ turn), place("T_Rod", "ram_rod") + t_upper, t_lower, t_lug = place("T_Upper", "strut", W + "length=0.5"), place("T_Lower", "strut", W + "length=0.5"), place("T_Lug", "strut", W + "length=0.3") + attach("T_Rod", "piston", "T_Barrel", "bore", 0.0) + send("brokkr_kitbash.joint", object_name="T_Rod", record='{"limits": [0, 0.3], "mechanism": "oleo", "compliance": {"hertz": 3, "damping_ratio": 0.6}}') + send("brokkr_kitbash.slide", object_name="T_Rod", slide=0.05) + attach("T_Lug", "end_a", "T_Rod", "rod_end_back", 90.0) + link = [(socket(t_barrel, "base_back"), socket(t_upper, "end_a"), "revolute"), (socket(t_upper, "end_b"), socket(t_lower, "end_a"), "revolute")] + + def lug_pin(slide): + return (world(t_barrel) @ core.mate(socket(t_barrel, "bore"), socket(t_rod, "piston"), 0.0, slide) @ core.mate(socket(t_rod, "rod_end_back"), socket(t_lug, "end_a"), 90.0) + @ socket(t_lug, "end_b")["matrix"]) + + def solve_link(slide, values): + return core.close_loop(world(t_barrel), link, socket(t_lower, "end_b"), lug_pin(slide), values) + + arms = None + for guess in ((40.0, 100.0), (-40.0, -100.0), (140.0, 100.0), (-140.0, -100.0), (90.0, 90.0), (-90.0, -90.0), (10.0, 150.0), (-10.0, -150.0)): + try: + arms, _ = solve_link(0.05, guess) + break + except core.KitError: + continue + check("the torque link's rest pose is found: two arms from the barrel's pin to the lug on the rod", arms is not None, "no guess closed the loop") + arms = tuple(core._wrapped(v) for v in arms) + attach("T_Upper", "end_a", "T_Barrel", "base_back", arms[0]) + attach("T_Lower", "end_a", "T_Upper", "end_b", arms[1]) + send("brokkr_kitbash.close", object_name="T_Lower", socket="end_b", other_name="T_Lug", other_socket="end_b") + receipt, report = send("brokkr_kitbash.follow", object_name="T_Lower", record='{"driver": "T_Rod", "kind": "loop"}') + check("the arms follow the rod's slide as a loop: its base is the barrel, above the driver, and it closes on a part that hangs from the driver", + receipt["status"] == "accepted" and [f["part"] for f in report["followers"]] == ["T_Upper", "T_Lower"], [receipt["message"], report and report.get("followers")]) + for slide in (0.15, 0.0, 0.11): + was = t_rod["kit_slide"] + receipt, report = send("brokkr_kitbash.slide", object_name="T_Rod", slide=slide) + arms = stepped(solve_link, arms, was, slide, 0.02) + check(f"sliding the rod to {slide:g} folds the arms: the closure holds in the scene and the rolls are this file's own stepped solve", + receipt["status"] == "accepted" and reading("closed", apart(t_lower, "end_b", t_lug, "end_b")) < CLOSED + and max(reading("solved", turned(t_upper["kit_roll"], arms[0])), reading("solved", turned(t_lower["kit_roll"], arms[1]))) < SOLVED + and report["closures"][0]["holds"] is True, [receipt["message"], R["readings"], t_upper["kit_roll"], t_lower["kit_roll"], arms]) + refused("a slide outside the driver's limits", "brokkr_kitbash.slide", {"object_name": "T_Rod", "slide": 0.4}, "its slide 0.4 is outside the joint's limits 0 to 0.3") + + # --- joints, version 2 ---------------------------------------------------------------------------------------------------------- + receipt, joints = send("brokkr_kitbash.joints", object_name="Ground") + table = {row["id"]: row for row in (joints or {}).get("joints", [])} + check("joints is version 2: a driven row names what drives it (F6), and unlimited lists the rows that are not driven and state no limits", + receipt["status"] == "accepted" and joints["version"] == 2 and [row["id"] for row in joints["joints"]] == ["Crank", "Cap", "Idle", "Tip", "Pinion", "X_Barrel", "X_Rod"] + and table["Crank"]["driven"] is None and table["Cap"]["driven"] == {"by": "Crank", "kind": "ratio", "k": 0.5, "offset": 0.0} + and table["X_Rod"]["driven"] == {"by": "Crank", "kind": "ratio", "k": 0.001, "offset": 0.02} and table["X_Rod"]["kind"] == "prismatic" + and joints["unlimited"] == ["Idle", "Tip", "Pinion", "X_Barrel"] and joints["next"] is None and "jointsOmitted" not in joints, [receipt["message"], joints]) + receipt, joints = send("brokkr_kitbash.joints", object_name="Base") + check("a loop's two followers are driven rows, kind loop", receipt["status"] == "accepted" and [(row["id"], row["driven"]) for row in joints["joints"]] == [ + ("Rocker", {"by": "Crank", "kind": "loop", "k": None, "offset": None}), ("Coupler", {"by": "Crank", "kind": "loop", "k": None, "offset": None})] and joints["unlimited"] == [], joints) + receipt, joints = send("brokkr_kitbash.joints", object_name="T_Rod") + check("a root that states a DOF connection has its own row first, parent null", receipt["status"] == "accepted" + and [(row["id"], row["parent"], row["kind"]) for row in joints["joints"]] == [("T_Rod", None, "prismatic"), ("T_Lug", "T_Rod", "revolute")] + and joints["joints"][0]["compliance"] == {"damping_ratio": 0.6, "hertz": 3.0} and joints["rigid"] == 0, joints) + receipt, joints = send("brokkr_kitbash.joints", object_name="Ground", after="Idle") + check("after carries the rows after an id (F12)", receipt["status"] == "accepted" and [row["id"] for row in joints["joints"]] == ["Tip", "Pinion", "X_Barrel", "X_Rod"] + and joints["joints"][0]["parent"] == "Idle" and joints["unlimited"] == ["Idle", "Tip", "Pinion", "X_Barrel"], joints) + refused("after an id that is no row's", "brokkr_kitbash.joints", {"object_name": "Ground", "after": "Base"}, "after 'Base' is not the id of a joint under 'Ground'") + place("L00", "strut", W + "length=0.3", far @ far @ turn) + for index in range(1, 81): + place(f"L{index:02d}", "strut", W + "length=0.3") + attach(f"L{index:02d}", "end_a", f"L{index - 1:02d}", "end_b", 7.0) + receipt, first = send("brokkr_kitbash.joints", object_name="L00") + carried = [row["id"] for row in (first or {}).get("joints", [])] + receipt, second = send("brokkr_kitbash.joints", object_name="L00", after=(first or {}).get("next") or "") + R["readings"]["rows in one receipt"] = len(carried) + check("a tree of 80 joints is two reports: the first counts what it omits and names the last id it carries as next, and after it the second carries the rest", + receipt["status"] == "accepted" and 0 < len(carried) < 80 and first["jointsOmitted"] == 80 - len(carried) and first["next"] == carried[-1] + and carried + [row["id"] for row in second["joints"]] == [f"L{index:02d}" for index in range(1, 81)] and second["next"] is None and "jointsOmitted" not in second + and len(first["unlimited"]) == 80, [receipt["message"], len(carried), first and first.get("next"), second and [row["id"] for row in second["joints"]][:3]]) + + # --- the joint-records Lows ------------------------------------------------------------------------------------------------- + send("brokkr_kitbash.joint", object_name="Idle", record='{"limits": [0, 30]}') + idle = bpy.data.objects["Idle"] + idle["kit_roll"] = 50.0 # by hand: no action writes a roll outside its limits + refused("set_params of a part whose roll was written by hand outside its limits (F9): the mesh is not rebuilt", "brokkr_kitbash.set_params", {"object_name": "Idle", "params": "length=0.6"}, + "'Idle' on 'Ground': its roll 50 is outside the joint's limits 0 to 30") + refused("and of its parent", "brokkr_kitbash.set_params", {"object_name": "Ground", "params": "length=0.9"}, "'Idle' on 'Ground': its roll 50 is outside the joint's limits 0 to 30") + idle["kit_roll"], idle["kit_slide"] = 15.0, 0.1 + refused("set_params of a part with a slide written by hand on a revolute connection", "brokkr_kitbash.set_params", {"object_name": "Idle", "params": "length=0.6"}, + "socket type 'pivot' is revolute: only a prismatic connection slides") + del idle["kit_slide"] + idle["kit_compliance"] = '{"damping_ratio": 0.7, "hertz": 4.0}' # by hand: a compliance is a prismatic joint's + receipt, joints = send("brokkr_kitbash.joints", object_name="Idle") + row = connection("Idle") + check("a compliance written by hand on a revolute joint reads null in the report and the joints report (F10), and the limits beside it still read", + receipt["status"] == "accepted" and row["compliance"] is None and row["limits"] == [0.0, 30.0] and joints["joints"][0]["id"] == "Idle" and joints["joints"][0]["compliance"] is None, [row, joints]) + receipt, report = send("brokkr_kitbash.set_params", object_name="Idle", params="length=0.6") + check("set_params seats through the one writer: the part is rebuilt, its child seated on the moved socket, and the hand-written compliance is gone", + receipt["status"] == "accepted" and "kit_compliance" not in idle and connection("Tip")["holds"] and reading("closed", apart(bpy.data.objects["Tip"], "end_a", idle, "end_b")) < CLOSED, + [receipt["message"], sorted(idle.keys())]) + + # --- detach --------------------------------------------------------------------------------------------------------------------- + receipt, report = send("brokkr_kitbash.detach", object_name="T_Lower") + upper_row = connection("T_Upper") + check("detaching a loop's closing follower clears its partner's statement too", receipt["status"] == "accepted" and upper_row["follows"] is None + and not [k for o in (t_upper, t_lower) for k in o.keys() if k.startswith("kit_follows")], [receipt["message"], upper_row, sorted(t_upper.keys())]) + receipt, report = send("brokkr_kitbash.roll", object_name="T_Upper", roll=12.0) + check("and the partner is posed by hand again", receipt["status"] == "accepted", receipt["message"]) + receipt, report = send("brokkr_kitbash.detach", object_name="Crank") + cap_row, coupler_row = connection("Cap"), connection("Coupler") + check("detaching a driver leaves its followers' statements, which report that the driver states no DOF connection", + receipt["status"] == "accepted" and cap_row["follows"] == {"driver": "Crank", "kind": "ratio", "k": 0.5, "offset": 0.0, "holds": False, "reason": "the driver states no DOF connection"} + and coupler_row["follows"]["holds"] is False and coupler_row["follows"]["reason"] == "the driver states no DOF connection", [receipt["message"], cap_row, coupler_row]) + bpy.data.objects.remove(crank) + coupler_row = connection("Coupler") + check("and once the driver is deleted, that it is gone", coupler_row["follows"]["driver"] is None and coupler_row["follows"]["reason"] == "the driver is gone: deleted, or in no collection", coupler_row) + constrained = [o.name for o in bpy.data.objects if o.constraints or (o.animation_data and o.animation_data.drivers)] + check("no Blender driver or constraint was made", constrained == [], constrained) +except Exception: # noqa: BLE001 whatever it was, it is a failed check with a name, printed and written, not a missing result file + check(f"no uncaught error after: {R['checks'][-1]['name'] if R['checks'] else 'the start'}", False, traceback.format_exc().splitlines()[-8:]) + +R["ok"] = all(c["ok"] for c in R["checks"]) +R["readings"] = {name: float(f"{value:.2g}") for name, value in sorted(R["readings"].items())} +for c in R["checks"]: + print("CHECK", "ok " if c["ok"] else "FAIL", c["name"], "" if c["ok"] else c["detail"], flush=True) +Path(OUT + ".result.json").write_text(json.dumps(R, indent=1, default=str), encoding="utf-8") +print("READINGS", R["readings"], flush=True) +sys.exit(0 if R["ok"] else 1) diff --git a/surfaces/blender/tests/test_kitbash.py b/surfaces/blender/tests/test_kitbash.py index 2e9b476..029da85 100644 --- a/surfaces/blender/tests/test_kitbash.py +++ b/surfaces/blender/tests/test_kitbash.py @@ -2153,7 +2153,7 @@ class SheetTests(unittest.TestCase): ROWS = ["brokkr_kitbash.place_part", "brokkr_kitbash.set_params", "brokkr_kitbash.describe", "brokkr_kitbash.report", "brokkr_kitbash.attach", "brokkr_kitbash.detach", "brokkr_kitbash.roll", "brokkr_kitbash.aim", "brokkr_kitbash.reach", - "brokkr_kitbash.joint", "brokkr_kitbash.slide", "brokkr_kitbash.joints", "brokkr_kitbash.close", + "brokkr_kitbash.joint", "brokkr_kitbash.slide", "brokkr_kitbash.joints", "brokkr_kitbash.follow", "brokkr_kitbash.close", "brokkr_kitbash.boolean", "brokkr_kitbash.cut", "brokkr_kitbash.cut_many", "brokkr_kitbash.freeze", "brokkr_kitbash.thaw", "brokkr_kitbash.ribs", "brokkr_kitbash.shell", "brokkr_kitbash.hose"]