diff --git a/surfaces/blender/brokkr_kitbash/__init__.py b/surfaces/blender/brokkr_kitbash/__init__.py index 6b16ba1..94ae606 100644 --- a/surfaces/blender/brokkr_kitbash/__init__.py +++ b/surfaces/blender/brokkr_kitbash/__init__.py @@ -442,6 +442,45 @@ def followers(driver) -> list: key=lambda o: o.name) +def loop_drivers(closing, parent=None, joint=None): + """What the two ends of the loop `closing` closes depend on beside its driver: (driver, (the base, the part + closed on), {another driver: why}), or None for a loop that is derived by nothing (its driver is gone or states + no DOF connection, it closes on nothing, or its parent does not follow with it). Each revolute or prismatic + joint between an end and the nearest part both ends hang from (or the root, when they share none) is the + driver, follows it, or is held by limits of one value; one that follows another driver, or follows nothing and + has travel, is another driver. A joint both ends hang from moves them together and is not counted. The one + reading of the rule: one_driver refuses a write by it, reading the scene as the write would leave it (`parent` + and `joint` are then its own), and a report reads the scene as it stands (follows_report, the joints + report's manyDrivers), so a loop with a second driver that no write made is told by every read of it.""" + if parent is None: + def parent(o): + return o.parent + if joint is None: + def joint(o): + kind = connection_kind(o)[0] + record = joint_record(o) if kind is not None else None + return (kind, record["limits"], record["follows"]) if kind is not None else (None, None, None) + follows, upper, to = joint(closing)[2], parent(closing), closure(closing)[1] + driver = follows["driver"] if follows is not None and follows["kind"] == "loop" else None + if driver is None or to is None or upper is None or parent(upper) is None or joint(driver)[0] is None or joint(upper)[2] != follows: + return None + ends, chains = (parent(upper), to), [[], []] # each end and what it hangs from, up to the root + for found, o in zip(chains, ends): + while o is not None: + found.append(o) + o = parent(o) + others = {} # {a part whose pose moves one end against the other, and is not the driver: why} + for o in (o for found in chains for o in found if not (o in chains[0] and o in chains[1])): + kind, limits, its = joint(o) + if kind is None or o == driver or its is not None and its["driver"] in (None, driver): + continue + if its is not None: + others.setdefault(its["driver"], f"{o.name!r} follows it") + elif limits is None or limits[0] < limits[1]: # limits of one value hold a joint still + others.setdefault(o, "it follows nothing and its joint has travel, so it is posed by hand") + return driver, ends, dict(sorted(others.items(), key=lambda item: item[0].name)) + + def one_driver(stating: dict) -> None: """The one-driver rule, over each loop a write touches, as it would stand after the write: the driver of a loop is the only input its two ends (the parent follower's parent, and the part closed on) depend on. `stating` is @@ -460,7 +499,8 @@ def one_driver(stating: dict) -> None: and set_params before it rebuilds a mesh), detach and parent_refusal (Brokkr's setObjectParent) ask here before they write, so no action (attach, detach, clearing a follower, limits widened or cleared, any pose, a new follow, set_params, a new parent) gives a loop a second driver, and a loop edited by hand into one is - refused the next write that touches it.""" + refused the next write that touches it. Which joints are drivers is loop_drivers' reading, the one the reports + take of the scene as it stands.""" known, kits, hangs = {}, {}, {} # each part's joint and each kit file are read once; hangs: {part: whether it, or a part it hangs from, is in stating} def parent(o): @@ -488,27 +528,10 @@ def one_driver(stating: dict) -> None: for closing in sorted((o for o in bpy.data.objects if CLOSE in o and (FOLLOWS in o or o in stating)), key=lambda o: o.name): if not (touched(closing) or touched(closing.get(CLOSE_TO)) or touched(closing.get(FOLLOWS_DRIVER))) or not closing.users_collection: continue # this write changes nothing the loop's ends depend on (the pointers are read as stored: users_collection searches the scene, so it is asked of a touched loop alone) - follows, upper, to = joint(closing)[2], parent(closing), closure(closing)[1] - driver = follows["driver"] if follows is not None and follows["kind"] == "loop" else None - if driver is None or to is None or upper is None or parent(upper) is None or joint(driver)[0] is None or joint(upper)[2] != follows: - continue - ends, chains = (parent(upper), to), [[], []] # each end and what it hangs from, up to the root - for found, o in zip(chains, ends): - while o is not None: - found.append(o) - o = parent(o) - others = {} # {a part whose pose moves one end against the other, and is not the driver: why} - for o in (o for found in chains for o in found if not (o in chains[0] and o in chains[1])): - kind, limits, its = joint(o) - if kind is None or o == driver or its is not None and its["driver"] in (None, driver): - continue - if its is not None: - others.setdefault(its["driver"], f"{o.name!r} follows it") - elif limits is None or limits[0] < limits[1]: # limits of one value hold a joint still - others.setdefault(o, "it follows nothing and its joint has travel, so it is posed by hand") + driver, ends, others = loop_drivers(closing, parent, joint) or (None, None, None) if others: raise Refused(f"the two ends of the loop {closing.name!r} closes, {ends[0].name!r} (the base) and {ends[1].name!r} (closed on), depend on more than one driver: {driver.name!r} and " - f"{', '.join(f'{o.name!r} ({why})' for o, why in sorted(others.items(), key=lambda item: item[0].name))}. A follower takes its value from " + f"{', '.join(f'{o.name!r} ({why})' for o, why in others.items())}. A follower takes its value from " "one driver, and a pose of another would open the loop: every joint between the two ends is the driver, follows it, or is held by " f"limits of one value. Give it that first, or clear the loop (brokkr_kitbash.follow on {closing.name!r} with record null); nothing changed.") @@ -652,8 +675,10 @@ def driven(driver, sockets, stated, roll: float, slide: float, record, stating=N def follows_report(obj, record: dict, kind, stated) -> dict | None: """None for a connection that follows nothing, else {driver, kind, k, offset, holds, reason}. A ratio holds when - the value stands within HELD of k x the driver's + offset (a roll: of a turn of it); a loop when the closure its - closing part states holds. holds is false with a reason when the driver is gone or states no DOF connection. + the value stands within HELD of k x the driver's + offset (a roll: of a turn of it); a loop when its two ends + depend on its one driver (loop_drivers) and the closure its closing part states holds: a loop with a second + driver (limits widened by hand, a saved file) reads false and names each, whether or not the closure stands + closed, since a pose of the other would open it. holds is false with a reason when the driver is gone or states no DOF connection. Derived at each report; stored nowhere.""" follows = record["follows"] if follows is None: @@ -673,8 +698,12 @@ def follows_report(obj, record: dict, kind, stated) -> dict | None: else: pair = loop_pair(obj) found = closure_report(pair[1], *built_part(pair[1])) if pair is not None else None + others = (loop_drivers(pair[1]) or (None, None, {}))[2] if pair is not None else {} if found is None: row["reason"] = "its loop has no partner: a closing part and its parent, both following the driver" + elif others: + row["reason"] = (f"the loop {pair[1].name!r} closes has more than one driver: {driver.name!r} and {', '.join(f'{o.name!r} ({why})' for o, why in others.items())}. " + "Hold that joint by limits of one value, have it follow the driver, or clear the loop (brokkr_kitbash.follow with record null)") elif not found["holds"]: row["reason"] = f"the closure {pair[1].name!r} states does not hold ({found['reason']}): pose the driver" row["holds"] = row["reason"] is None @@ -1317,11 +1346,12 @@ class BROKKR_KITBASH_OT_joints(PolishOperator): @kit_work def work(self, context): - root, kits, entries = mesh_object(self.object_name), {}, [] + root, kits, entries, tree = mesh_object(self.object_name), {}, [], set() built_part(root, kits) todo = [root] while todo: # depth first, children by name: the order core.joint_rows reads a joint's parent joint in child = todo.pop() + tree.add(child) if child != root or link(child) is not None and child.parent is not None and PART in child.parent: # the root's own joint comes first, parent null part, built = built_part(child, kits) stated = link(child) @@ -1337,7 +1367,11 @@ class BROKKR_KITBASH_OT_joints(PolishOperator): rows, rigid_count = core.joint_rows(np.array(root.matrix_world, dtype=np.float64), entries) ids = [row["id"] for row in rows] report = {"schema": "brokkr.joints", "version": 2, "root": root.name, "frame": "the root object's: Blender axes (+Z up), metres", "rigid": rigid_count, - "unlimited": [], "next": max(ids, key=lambda name: len(json.dumps(name)), default=None)} + "unlimited": [], "manyDrivers": [], "next": max(ids, key=lambda name: len(json.dumps(name)), default=None)} + for closing in sorted((o for o in bpy.data.objects if CLOSE in o and FOLLOWS in o and o.users_collection), key=lambda o: o.name): + driver, ends, others = loop_drivers(closing) or (None, None, None) # of the whole tree, as rigid is: every page carries it + if others and tree & {closing, closing.parent, driver, *ends, *others}: + report["manyDrivers"].append({"loop": closing.name, "drivers": [driver.name, *(o.name for o in others)]}) if self.after: if self.after not in ids: raise Refused(f"after {self.after!r} is not the id of a joint under {root.name!r}: it is the `next` of the report before, or empty.") diff --git a/surfaces/blender/brokkr_kitbash/brokkr_actions.json b/surfaces/blender/brokkr_kitbash/brokkr_actions.json index 8a2f11c..fd8bf94 100644 --- a/surfaces/blender/brokkr_kitbash/brokkr_actions.json +++ b/surfaces/blender/brokkr_kitbash/brokkr_actions.json @@ -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: 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), held (true when the limits are of one value: the joint has no travel, as a torque link's lug held at [90, 90], so a rig makes a fixed bone and not a DOF; such a row is in neither unlimited nor rigid), 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 this report carries that are not driven and state no limits: an exporter that needs limits refuses by this one field of each report. 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 and their unlimited ids; a report is never over a receipt and always carries a row. after refuses an id that is no row's. 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, manyDrivers, 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), held (true when the limits are of one value: the joint has no travel, as a torque link's lug held at [90, 90], so a rig makes a fixed bone and not a DOF; such a row is in neither unlimited nor rigid), 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 this report carries that are not driven and state no limits: an exporter that needs limits refuses by this one field of each report. manyDrivers lists each loop with more than one driver that has a part in the tree (a limit widened by hand, a saved file: no action writes one), as {loop: the closing part, drivers: [the loop's driver, each other one]}: its driven rows are not a function of one driver, so a rig refuses the tree while the list is not empty; it is of the whole tree and every page carries it. 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 and their unlimited ids; a report is never over a receipt and always carries a row. 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", diff --git a/surfaces/blender/docs/kitbash.md b/surfaces/blender/docs/kitbash.md index fe94903..0e587bf 100644 --- a/surfaces/blender/docs/kitbash.md +++ b/surfaces/blender/docs/kitbash.md @@ -267,8 +267,13 @@ every write that touches it (a write of a connection, a `set_params` or a `setOb or of a part it hangs from, whether or not that write is the fault) until the joint is held again, follows the driver, or the loop is cleared. A write that touches no such loop is made: a camera, an empty or a part of another mechanism is posed and given a parent as before, and so is an object parented under a part of the loop. A connection's row in a report carries `follows: {driver, kind, k, offset, holds, reason}`: -`holds` is false, with a reason, when the value stands off the ratio, the loop's closure does not hold, or the -driver is gone or states no revolute or prismatic connection. Detaching a driver leaves its followers' +`holds` is false, with a reason, when the value stands off the ratio, the loop has more than one driver, the loop's +closure does not hold, or the driver is gone or states no revolute or prismatic connection. A loop with a second +driver reads `holds: false` on both its followers whether or not its closure stands closed, and the reason names +the loop, its driver and each other one: the remedy is to hold that joint, have it follow the driver or clear the +loop, not to pose the driver. The joints report lists the same loops in `manyDrivers`. Both read the scene as it +stands by the reading the refusals use, so a second driver that no action wrote is told by the next report and +not first by a refused write. Detaching a driver leaves its followers' statements; detaching a loop follower clears its partner's. No Blender driver or constraint is made: a follower's pose is its stored value, as every connection's is. @@ -284,7 +289,7 @@ nothing: ```json {"schema": "brokkr.joints", "version": 2, "root": "Tank", "frame": "the root object's: Blender axes (+Z up), metres", - "rigid": 2, "unlimited": ["Barrel"], "next": null, "joints": [ + "rigid": 2, "unlimited": ["Barrel"], "manyDrivers": [], "next": null, "joints": [ {"id": "Strut", "parent": null, "part": "strut", "socket": "Mount:pivot", "kind": "revolute", "axis": [0.0, 1.0, 0.0], "origin": [0.436, 0.0, 0.85368], "value": -113.019997, "limits": [-116.02, -40.02], "min": -3.000003, "max": 72.999997, "mechanism": "knee", "compliance": null, "held": false, "driven": null}, @@ -311,7 +316,11 @@ alone and is not the free `mechanism` label: a joint labelled `"held"` that has (`by` the driver's id, `kind`, `k`, `offset`): a driven row's value is derived, so the rig generator will make a driven bone for it and not a degree of freedom. `unlimited` lists the ids of the rows this report carries that are not driven and state no limits, so an exporter that needs limits on every degree of freedom refuses by reading one field of each -report. A tree whose rows a receipt cannot carry (about 60 rows, 33 with names of 62 characters) is read in pages: +report. `manyDrivers` lists each loop with more than one driver that has a part in the tree under the root (its +closing part, that part's parent, the part closed on, the base, or one of its drivers), as +`{"loop": the closing part, "drivers": [the loop's driver, each other one]}` by the closing part's name: its +driven rows are not a function of one driver, so a rig generator refuses the tree while the list is not empty. It +is of the whole tree, as `rigid` is, and every page carries it. A tree whose rows a receipt cannot carry (about 60 rows, 33 with names of 62 characters) is read in pages: `jointsOmitted` counts the rows left off, `next` is then the id of the last row carried, and a call with `after` set to it carries the rows that follow, with their own `unlimited`. A row and its id in `unlimited` are kept or left off together, so a report is never over a receipt and always carries a row. @@ -1362,7 +1371,7 @@ under such load (five runs), and reading a 336-face part takes 27 to 37 ms. | `brokkr_kitbash.reach` | `object_name`, `socket` (one of the part's), `height` (metres, -1000 to 1000), `direction_x`, `direction_y`, `direction_z` (world; default 0, 0, 1) | Solves the roll that brings the socket's origin to `height` along the direction, the nearer of the two, and turns the part to it. Refuses a height out of reach, naming the range. Reports the part, `reached: {roll, residual}` and `closures`. | | `brokkr_kitbash.joint` | `object_name`, `record` (a JSON object of any of `limits`: `[lo, hi]` or null; `mechanism`: a label or null; `compliance`: `{hertz, damping_ratio}` or null) | States the joint record of an attached part's connection; a key left out keeps what is stated and null clears it. A follower keeps its derived value, and a driver's followers are derived again. Refuses a rigid connection naming its socket type, limits that do not hold the value the joint has, revolute limits over a turn or past 360, prismatic limits past 10 m, and compliance on a revolute joint or without limits. Reports the part and `closures` as `roll` does | | `brokkr_kitbash.slide` | `object_name`, `slide` (metres, -10 to 10) | Slides an attached part along its parent socket's normal on a prismatic connection, where it hangs, and every follower of it with it. Refuses a revolute or rigid connection naming its socket type, a slide outside the joint's limits, and a follower. Reports the part and `closures` as `roll` does | -| `brokkr_kitbash.joints` | `object_name` (the root, a kit part), `after` (default empty: an id, the `next` of the report before) | Reports the joints of the tree attached under the root as `brokkr.joints` version 2: a row per revolute or prismatic connection, parents first and the root's own first when it states one, with `id`, `parent`, `part`, `socket`, `kind`, `axis`, `origin`, `value`, `limits`, `min`, `max`, `held`, `mechanism`, `compliance` and `driven`, in the root's frame, and `unlimited` and `next` beside them ("Joint records"). With `after`, the rows after that id. Changes nothing and evaluates no modifier. | +| `brokkr_kitbash.joints` | `object_name` (the root, a kit part), `after` (default empty: an id, the `next` of the report before) | Reports the joints of the tree attached under the root as `brokkr.joints` version 2: a row per revolute or prismatic connection, parents first and the root's own first when it states one, with `id`, `parent`, `part`, `socket`, `kind`, `axis`, `origin`, `value`, `limits`, `min`, `max`, `held`, `mechanism`, `compliance` and `driven`, in the root's frame, and `unlimited`, `manyDrivers` (the loops with more than one driver) and `next` beside them ("Joint records"). With `after`, the rows after that id. Changes nothing and evaluates no modifier. | | `brokkr_kitbash.follow` | `object_name` (the follower; for a loop, the part that states the closure), `record` (JSON: `{driver, kind: "ratio", k, offset}`, `{driver, kind: "loop"}` or null) | States that the part's joint follows the driver's, by a ratio or by keeping its closure closed with its parent's joint, and moves it there at once; null clears the statement, and a loop partner's with it ("Followers"). Refuses a rigid connection, a driver that is the follower, below it or itself a follower, a follower that already follows or drives another, a ratio whose driver states no limits, and a loop without a closure that holds, with both ends or neither moving with the driver, whose ends depend on another driver or on a joint posed by hand, that is not planar or that stands at a dead centre. Reports the part, `followers` and `closures`. | | `brokkr_kitbash.close` | `object_name` (the closing part), `socket`, `other_name`, `other_socket` | States that the closing part's socket meets the other part's, closing a loop. Accepted only when they already meet; moves nothing. Reports the closing part. | | `brokkr_kitbash.boolean` | `object_name` (any mesh), `cutter`, `operation` (`DIFFERENCE`, `UNION` or `INTERSECT`; default `DIFFERENCE`) | Adds the cutter to the collection of the target's one live Exact Boolean for the operation, above the Bevel. Refuses a cutter that is the target, is not a mesh, or already cuts it, and a scaled target. Reports the part (or `object` for a mesh that is not one), `booleans: [{cutter, operation}]` (difference, union, intersect; each in the order added; `booleansOmitted` counts rows a receipt had no room for) and `evaluated`. | diff --git a/surfaces/blender/tests/live/kitbash_follows.py b/surfaces/blender/tests/live/kitbash_follows.py index a574528..bd86bb8 100644 --- a/surfaces/blender/tests/live/kitbash_follows.py +++ b/surfaces/blender/tests/live/kitbash_follows.py @@ -18,7 +18,7 @@ barrel, so a lug with no travel is the mechanism and not a way around the kit; a two arms from the barrel's pin cannot face the rod's own); a second crank (Crank2 on the root Ground2) whose ram closes on the rocker, and a loop hung from its own driver (K3, B3, Rk3, Cp3 on the root G3), for the one-driver refusals at the statement, and after it an attach, a clear, widened limits, a pose over limits written by hand and a -detach that would each give a stated loop a second driver; Idle and Tip for the refusals and for the writes a two-driver loop does not refuse; a tree of 264 struts with 62-character names for a joints +detach that would each give a stated loop a second driver, and the reads that tell of one made by hand (follows.holds, the joints report's manyDrivers); Idle and Tip for the refusals and for the writes a two-driver loop does not refuse; a tree of 264 struts with 62-character names for a joints report over several receipts. Bounds follow lodur:ruling:deterministic-bound-margin, both readings beside each; the result file carries the readings. """ @@ -472,6 +472,20 @@ try: refused("a pose of the driver after the lug's limits were widened by hand: the writer reads the rule before it writes", "brokkr_kitbash.slide", {"object_name": "T_Rod", "slide": 0.1}, "depend on more than one driver: 'T_Rod' and 'T_Lug' (it follows nothing and its joint has travel") refused("and a pose of the lug itself", "brokkr_kitbash.roll", {"object_name": "T_Lug", "roll": 95.0}, "depend on more than one driver: 'T_Rod' and 'T_Lug'") + # a second driver no write made is told by every read of the loop, while its closure still stands closed (finding two-driver-loop-reported-nowhere): + # each follower's follows row reads holds false and names both drivers, and the joints report of a tree the loop is in lists the loop by its closing part + told = "the loop 'T_Lower' closes has more than one driver: 'T_Rod' and 'T_Lug' (it follows nothing and its joint has travel, so it is posed by hand)" + rows = {name: send("brokkr_kitbash.report", object_name=name)[1]["parts"][0] for name in ("T_Upper", "T_Lower")} + check("a loop given a second driver by hand reads follows.holds false on both followers, naming both drivers, while its closure holds", + all(row["connection"]["follows"]["holds"] is False and row["connection"]["follows"]["reason"].startswith(told) for row in rows.values()) + and rows["T_Lower"]["closure"]["holds"] is True, [{name: row["connection"] for name, row in rows.items()}, rows["T_Lower"]["closure"]]) + receipt, joints = send("brokkr_kitbash.joints", object_name="T_Barrel") + receipt2, joints2 = send("brokkr_kitbash.joints", object_name="T_Lug") + receipt3, joints3 = send("brokkr_kitbash.joints", object_name="Ground") + check("the joints report lists a loop with a second driver in manyDrivers, by its closing part and with both drivers: in a report of the whole mechanism, " + "in one of the second driver's own sub-tree, and not in one of a tree the loop is no part of", + all(r["status"] == "accepted" for r in (receipt, receipt2, receipt3)) and joints["manyDrivers"] == [{"loop": "T_Lower", "drivers": ["T_Rod", "T_Lug"]}] == joints2["manyDrivers"] + and joints3["manyDrivers"] == [], [receipt["message"], joints and joints.get("manyDrivers"), joints2 and joints2.get("manyDrivers"), joints3 and joints3.get("manyDrivers")]) # the rule judges the write, not the scene: with the torque link holding a second driver, a write is refused when it touches that loop (a part of it, # or one it hangs from) or would give another loop a second driver, and every other write is made (finding parent-hook-gates-on-scene-not-change) shape = lambda *names: {name: np.array([v.co[:] for v in bpy.data.objects[name].data.vertices]).tobytes() for name in names} # noqa: E731 @@ -527,6 +541,11 @@ try: t_lug["kit_min"], t_lug["kit_max"] = 90.0, 90.0 receipt, report = send("brokkr_kitbash.slide", object_name="T_Rod", slide=0.11) check("with the lug held again the driver is posed", receipt["status"] == "accepted" and report["closures"][0]["holds"] is True, receipt["message"]) + receipt, report = send("brokkr_kitbash.report", object_name="T_Lower") + receipt2, joints = send("brokkr_kitbash.joints", object_name="T_Barrel") + check("and with one driver again the follower's follows row holds and the joints report lists no loop", + receipt["status"] == "accepted" and receipt2["status"] == "accepted" and report["parts"][0]["connection"]["follows"] == {"driver": "T_Rod", "kind": "loop", "k": None, "offset": None, "holds": True, "reason": None} + and joints["manyDrivers"] == [], [receipt["message"], report and report["parts"][0]["connection"], joints and joints.get("manyDrivers")]) receipt, joints = send("brokkr_kitbash.joints", object_name="T_Barrel") check("the torque link has one degree of freedom: the rod's slide is its one row with travel that nothing drives, the lug is its one held row, the arms are driven, and no row is unlimited", receipt["status"] == "accepted" and [(row["id"], row["kind"], row["driven"] and row["driven"]["by"], row["min"], row["max"], row["held"]) for row in joints["joints"]] == [ diff --git a/surfaces/blender/tests/live/kitbash_follows.result.json b/surfaces/blender/tests/live/kitbash_follows.result.json index 6b6bdea..c285ef5 100644 --- a/surfaces/blender/tests/live/kitbash_follows.result.json +++ b/surfaces/blender/tests/live/kitbash_follows.result.json @@ -321,6 +321,16 @@ "ok": true, "detail": null }, + { + "name": "a loop given a second driver by hand reads follows.holds false on both followers, naming both drivers, while its closure holds", + "ok": true, + "detail": null + }, + { + "name": "the joints report lists a loop with a second driver in manyDrivers, by its closing part and with both drivers: in a report of the whole mechanism, in one of the second driver's own sub-tree, and not in one of a tree the loop is no part of", + "ok": true, + "detail": null + }, { "name": "refused, scene unchanged: set_params of the part a two-driver loop closes on (finding set-params-writes-before-the-guard): the rule is read before the mesh is rebuilt", "ok": true, @@ -371,6 +381,11 @@ "ok": true, "detail": null }, + { + "name": "and with one driver again the follower's follows row holds and the joints report lists no loop", + "ok": true, + "detail": null + }, { "name": "the torque link has one degree of freedom: the rod's slide is its one row with travel that nothing drives, the lug is its one held row, the arms are driven, and no row is unlimited", "ok": true, diff --git a/surfaces/blender/tests/test_kitbash.py b/surfaces/blender/tests/test_kitbash.py index b73e2f2..7507714 100644 --- a/surfaces/blender/tests/test_kitbash.py +++ b/surfaces/blender/tests/test_kitbash.py @@ -2550,6 +2550,16 @@ class OwnershipTests(unittest.TestCase): # clear, widened limits, a pose, a set_params, a detach and a new parent after the loop is stated are each refused) rule = source.split("\ndef one_driver(")[1].split("\n\n\n")[0] self.assertEqual((source.count("one_driver("), source.count("depend on more than one driver")), (4, 1)) + # which joints are a loop's drivers is read in one place, loop_drivers: the rule refuses by it and the reads tell by it (finding + # two-driver-loop-reported-nowhere), so a second driver no write made is in a follower's follows row and the joints report's manyDrivers + # (live: 'a loop given a second driver by hand reads follows.holds false' and 'the joints report lists a loop with a second driver') + self.assertEqual((source.count("loop_drivers("), source.count("it follows nothing and its joint has travel"), rule.count("loop_drivers(closing, parent, joint)")), (4, 1, 1)) + teller = source.split("\ndef follows_report(")[1].split("\n\n\n")[0] + self.assertLess(teller.index("loop_drivers(pair[1])"), teller.index("elif others:")) + self.assertLess(teller.index("elif others:"), teller.index('elif not found["holds"]:')) # a second driver is told before an open closure: 'pose the driver' is not its remedy + joints = source.split("class BROKKR_KITBASH_OT_joints(")[1].split("class BROKKR_KITBASH_OT_")[0] + self.assertIn('report["manyDrivers"].append({"loop": closing.name, "drivers": [driver.name, *(o.name for o in others)]})', joints) + self.assertIsNone(re.search(r"\.parent\s*=(?!=)|\bseat\(|\w+\[[A-Z_]+\]\s*=(?!=)|\bdel ", source.split("\ndef loop_drivers(")[1].split("\n\n\n")[0])) asker = source.split("\ndef brokkr_parent_refusal(")[1].split("\n\n\n")[0] self.assertIn("one_driver({obj: (parent, kind,", asker) self.assertIsNone(re.search(r"\.parent\s*=(?!=)|\bseat\(|\w+\[\w+\]\s*=(?!=)|\bdel ", asker + asked))