From 2d6f0c736ba4de2ad9ebd0217d601f8bc820e2bf Mon Sep 17 00:00:00 2001 From: Libby Date: Tue, 10 Nov 2026 07:11:01 +0000 Subject: [PATCH] Blender node actions: Soul fix pass (muted state on restored link, removeModifier by any name) A refused link restores the displaced link's is_muted; removeModifier no longer applies the creation-name pattern to a lookup, so hand-made Unicode modifier names are removable; the pattern message lists the space it allows. Live: 166 checks pass on Blender 5.2.3. Co-Authored-By: Claude Sonnet 5.5 --- .../blender/brokkr_bridge/node_actions.py | 13 +++-- surfaces/blender/docs/node-actions.md | 2 +- surfaces/blender/tests/live/gn_actions.py | 14 +++++ .../blender/tests/live/gn_actions.result.json | 53 +++++++++++++++++-- surfaces/blender/tests/test_node_actions.py | 17 +++++- 5 files changed, 87 insertions(+), 12 deletions(-) diff --git a/surfaces/blender/brokkr_bridge/node_actions.py b/surfaces/blender/brokkr_bridge/node_actions.py index 2f46eeb..caba5ed 100644 --- a/surfaces/blender/brokkr_bridge/node_actions.py +++ b/surfaces/blender/brokkr_bridge/node_actions.py @@ -43,7 +43,7 @@ def text(command: dict[str, Any], key: str, pattern: re.Pattern, label: str, *, raise ActionRefused(f"{label} is required.") return "" if not isinstance(value, str) or not pattern.fullmatch(value): - raise ActionRefused(f"{label} must be 1..63 characters of letters, digits, '.', '_' or '-'.") + raise ActionRefused(f"{label} must be 1..63 characters of letters, digits, space, '.', '_' or '-'.") return value @@ -260,12 +260,12 @@ class NodeActions: into = self._socket(target.inputs, str(command.get("toSocket", "")), "toSocket") if reaches(tree, target, source): # includes a self link raise ActionRefused(f"Link {source.get('brokkr_id')} -> {target.get('brokkr_id')} would make a cycle.") - displaced = [l.from_socket for l in tree.links if l.to_socket == into] if not getattr(into, "is_multi_input", False) else [] + displaced = [(l.from_socket, l.is_muted) for l in tree.links if l.to_socket == into] if not getattr(into, "is_multi_input", False) else [] link = tree.links.new(out, into) # replaces whatever single link the input had if not link.is_valid: tree.links.remove(link) - for old in displaced: - tree.links.new(old, into) + for old, muted in displaced: + tree.links.new(old, into).is_muted = muted raise ActionRefused(f"Link {out.name} -> {into.name} is not valid (type or field/single-value mismatch).") return f"Linked {source.get('brokkr_id')}.{out.identifier} -> {target.get('brokkr_id')}.{into.identifier}.", tree.name @@ -298,7 +298,10 @@ class NodeActions: def _removeModifier(self, command: dict[str, Any]) -> tuple[str, str]: obj = self._object(command) - name = text(command, "modifierName", KEY_PATTERN, "modifierName", required=False) or "Brokkr GeoNodes" + # A lookup, not a creation: a modifier made by hand may have any name Blender allows. + name = command.get("modifierName") or "Brokkr GeoNodes" + if not isinstance(name, str) or len(name) > 255 or "\0" in name: + raise ActionRefused("modifierName must be a string of at most 255 characters.") modifier = obj.modifiers.get(name) if modifier is None: return f"Modifier {name!r} was already absent.", obj.name diff --git a/surfaces/blender/docs/node-actions.md b/surfaces/blender/docs/node-actions.md index f98e702..d998fae 100644 --- a/surfaces/blender/docs/node-actions.md +++ b/surfaces/blender/docs/node-actions.md @@ -28,7 +28,7 @@ world space. Above 1,000,000 vertices only counts are read (`positionsSkipped`); `instancesComplete` is false when the depsgraph scan stopped at 100,000 items (`instanceCount` and the instance bounds are then lower bounds); the scan is what costs time (about 5 microseconds per instance in Python), so a 2000 x 2000 grid instanced on points captures in 1.4 s on the test machine where an unbounded scan took 22 s. `instanceCount` is `null` for an object the stopped scan never reached (unknown, not zero); the 100,000 budget is shared across all objects in depsgraph order, so a host after a heavy one can be starved. Otherwise `instanceCount` counts evaluated instances whose parent is the object, so a curve, point or volume result also reads as one instance. `mesh` stays the base mesh. -Known edges: a node duplicated by hand copies its `brokkr_id`, so id lookups act on the first match; `gin`/`gout` are protected by id, and a group whose output node was deleted by hand cannot get a new one through `addNode`; a group left with no users stays in the file until it is saved and reloaded. +Known edges: a node duplicated by hand copies its `brokkr_id`, so id lookups act on the first match; `gin`/`gout` are protected by id, and a group whose output node was deleted by hand cannot get a new one through `addNode`; removing a group's last modifier does not delete the group (it may stay in the file until it is saved and reloaded; `addModifier` can reuse it); `removeModifier` takes any modifier name Blender allows because it only looks the modifier up. Not built: zones, item sockets, multi-input ordering, library groups, group-in-group nodes, batches/rollback across intents, an expectedRevision check, per-node cost estimates. Int values are capped at +-4096 and floats at +-1e9, diff --git a/surfaces/blender/tests/live/gn_actions.py b/surfaces/blender/tests/live/gn_actions.py index af669ae..1d9e329 100644 --- a/surfaces/blender/tests/live/gn_actions.py +++ b/surfaces/blender/tests/live/gn_actions.py @@ -229,6 +229,20 @@ refused = [act(t5, action="linkSockets", treeKey="C", fromNode=ids[-1], fromSock R["cycle_probe_seconds"] = round(time.time() - t0, 3) check("every closing link on a 60-node chain with skip links is refused", all(refused) and len(bpy.data.node_groups["C"].links) == before, (sum(refused), len(refused), R["cycle_probe_seconds"])) + +# ---- fix-pass checks: muted state survives a refused link; hand-made Unicode modifier names are removable +t6 = fresh() +graph(t6, "Mu", GEO_OUT, [dict(id="cube", blIdname="GeometryNodeMeshCube"), dict(id="m", blIdname="ShaderNodeMath"), dict(id="iop", blIdname="GeometryNodeInstanceOnPoints")], [("cube", "Mesh", "iop", "Points")]) +for l in bpy.data.node_groups["Mu"].links: + if l.to_node.get("brokkr_id") == "iop": l.is_muted = True +r = act(t6, action="linkSockets", treeKey="Mu", fromNode="m", fromSocket="Value", toNode="iop", toSocket="Points") +muted = [l.is_muted for l in bpy.data.node_groups["Mu"].links if l.to_node.get("brokkr_id") == "iop"] +check("refused link restores the displaced link's muted state", r["status"] == "failed" and muted == [True], (r["message"], muted)) +ok(t6, action="createObject", objectType="MESH", name="U") +bpy.data.objects["U"].modifiers.new("G\u00e9 x", "NODES") +r = act(t6, action="removeModifier", objectName="U", modifierName="G\u00e9 x") +check("hand-made Unicode modifier name is removable", r["status"] == "accepted" and len(bpy.data.objects["U"].modifiers) == 0, r["message"]) + # ---- cost: a heavy graph must not stall capture def heavy(n, instanced): tt = fresh() diff --git a/surfaces/blender/tests/live/gn_actions.result.json b/surfaces/blender/tests/live/gn_actions.result.json index 1e4e68e..cdcc1f5 100644 --- a/surfaces/blender/tests/live/gn_actions.result.json +++ b/surfaces/blender/tests/live/gn_actions.result.json @@ -514,7 +514,7 @@ { "name": "trailing newline in an id refused", "ok": true, - "detail": "id must be 1..63 characters of letters, digits, '.', '_' or '-'." + "detail": "id must be 1..63 characters of letters, digits, space, '.', '_' or '-'." }, { "name": "createNodeGroup Off", @@ -958,6 +958,51 @@ 0.008 ] }, + { + "name": "createNodeGroup Mu", + "ok": true, + "detail": "Created node group; interface identifiers: output Geometry=Socket_0" + }, + { + "name": "addNode cube", + "ok": true, + "detail": "Node added." + }, + { + "name": "addNode m", + "ok": true, + "detail": "Node added." + }, + { + "name": "addNode iop", + "ok": true, + "detail": "Node added." + }, + { + "name": "linkSockets Mu", + "ok": true, + "detail": "Linked cube.Mesh -> iop.Points." + }, + { + "name": "refused link restores the displaced link's muted state", + "ok": true, + "detail": [ + "Link Value -> Points is not valid (type or field/single-value mismatch).", + [ + true + ] + ] + }, + { + "name": "createObject ", + "ok": true, + "detail": "Blender object created." + }, + { + "name": "hand-made Unicode modifier name is removable", + "ok": true, + "detail": "Modifier removed." + }, { "name": "createNodeGroup Heavy", "ok": true, @@ -1007,7 +1052,7 @@ "name": "2000x2000 instanced grid: capture is bounded", "ok": true, "detail": [ - 1.29, + 1.2, 99999, false ] @@ -1047,6 +1092,6 @@ } ], "cycle_probe_seconds": 0.008, - "capture_2000_grid_instanced_seconds": 1.285, - "capture_2000_grid_mesh_seconds": 0.054 + "capture_2000_grid_instanced_seconds": 1.198, + "capture_2000_grid_mesh_seconds": 0.045 } \ No newline at end of file diff --git a/surfaces/blender/tests/test_node_actions.py b/surfaces/blender/tests/test_node_actions.py index 80adb79..62d496b 100644 --- a/surfaces/blender/tests/test_node_actions.py +++ b/surfaces/blender/tests/test_node_actions.py @@ -94,7 +94,7 @@ class Links(list): def new(self, a, b): for old in [l for l in self if l.to_socket is b]: # a single-link input loses its old link, as in Blender list.remove(self, old) - link = NS(from_socket=a, to_socket=b, from_node=Proxy(a.node), to_node=Proxy(b.node), is_valid=self.valid(a, b) if callable(self.valid) else self.valid) + link = NS(from_socket=a, to_socket=b, from_node=Proxy(a.node), to_node=Proxy(b.node), is_muted=False, is_valid=self.valid(a, b) if callable(self.valid) else self.valid) self.append(link) return link @@ -431,8 +431,11 @@ class NodeActionTests(unittest.TestCase): self.assertEqual(host.tagged, tags + 1) self.assertIn("already absent", self.accepted(action="removeModifier", objectName="Host", modifierName="GN")["message"]) self.refused(action="removeModifier", objectName="Nope", modifierName="GN") - for bad in (["x"], "x" * 64, "a/b"): + for bad in (["x"], "x" * 256, "a\0b", 5): self.refused(action="removeModifier", objectName="Host", modifierName=bad) + host.modifiers.new("Gé x/y", "NODES") # made by hand: any name Blender allows can be removed + self.accepted(action="removeModifier", objectName="Host", modifierName="Gé x/y") + self.assertEqual([m.name for m in host.modifiers], ["Sub"]) # setObjectCustomProperty on a Geometry Nodes host def test_custom_property_naming_a_modifier_input_identifier_is_refused(self): @@ -469,6 +472,16 @@ class NodeActionTests(unittest.TestCase): self.refused(action="linkSockets", treeKey="G", fromNode="b", fromSocket="Out", toNode="c", toSocket="A") self.assertEqual([(l.from_socket, l.to_socket) for l in tree.links], [(tree.nodes[2].outputs[0], tree.nodes[4].inputs[0])]) + def test_refused_link_restores_the_displaced_link_muted_state(self): + tree = self.group() + for node_id in ("a", "b", "c"): + self.accepted(action="addNode", treeKey="G", id=node_id, blIdname="ShaderNodeMath") + self.accepted(action="linkSockets", treeKey="G", fromNode="a", fromSocket="Out", toNode="c", toSocket="A") + tree.links[0].is_muted = True + tree.links.valid = lambda a, b: False + self.refused(action="linkSockets", treeKey="G", fromNode="b", fromSocket="Out", toNode="c", toSocket="A") + self.assertEqual([l.is_muted for l in tree.links], [True]) + def test_ints_are_capped_and_patterns_reject_trailing_newlines(self): self.group() self.accepted(action="addNode", treeKey="G", id="ok", blIdname="ShaderNodeMath")