From 9513d3df485c785c1f2345192ddcd7e0cf9bf0ed Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 15 Jun 2026 03:27:21 +0100 Subject: [PATCH] Add Blender auto command drain --- surfaces/blender/brokkr_bridge/__init__.py | 43 +++++++++++++++++++ .../blender/brokkr_bridge/blender_target.py | 1 + surfaces/blender/docs/install.md | 6 ++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/surfaces/blender/brokkr_bridge/__init__.py b/surfaces/blender/brokkr_bridge/__init__.py index 12e9774..7a6133c 100644 --- a/surfaces/blender/brokkr_bridge/__init__.py +++ b/surfaces/blender/brokkr_bridge/__init__.py @@ -66,6 +66,12 @@ class BrokkrPreferences(bpy.types.AddonPreferences): description="Capture and publish a Blender host snapshot on dependency graph updates", ) + auto_drain_commands: bpy.props.BoolProperty( + name="Auto Drain Commands", + default=False, + description="Poll and execute pending Brokkr Blender command intents on a timer", + ) + serve_host: bpy.props.StringProperty( name="Serve Host", default="127.0.0.1", @@ -251,6 +257,7 @@ class BrokkrPreferences(bpy.types.AddonPreferences): layout.prop(self, "cultlib_py_src") layout.prop(self, "debug_mirror_root") layout.prop(self, "auto_capture") + layout.prop(self, "auto_drain_commands") layout.prop(self, "serve_host") layout.prop(self, "serve_port") layout.prop(self, "max_snapshot_documents") @@ -304,6 +311,7 @@ class BROKKR_PT_status(bpy.types.Panel): row = layout.row(align=True) row.operator("brokkr.capture_snapshot", icon="FILE_REFRESH") row.operator("brokkr.drain_commands", icon="PLAY") + layout.prop(prefs, "auto_drain_commands") server_row = layout.row(align=True) server_row.operator("brokkr.start_server", icon="NETWORK_DRIVE") @@ -337,6 +345,11 @@ class BROKKR_PT_status(bpy.types.Panel): layout.label(text=f"Last receipt: {adapter.last_receipt.get('status', '')}") layout.label(text=adapter.last_receipt.get("message", "")) + if adapter.last_auto_drain_error: + layout.separator() + layout.label(text="Auto drain error:") + layout.label(text=adapter.last_auto_drain_error) + if adapter.last_sync_receipt: layout.separator() layout.label(text=f"Last sync pass: {adapter.last_sync_receipt.get('status', '')}") @@ -515,6 +528,32 @@ def _auto_capture(scene, depsgraph): ) +def _auto_drain_commands(): + context = bpy.context + addon = context.preferences.addons.get(__name__) + adapter = target() + if not addon: + return 1.0 + + prefs = addon.preferences + if not prefs.auto_drain_commands: + adapter.last_auto_drain_error = "" + return 1.0 + + try: + adapter.drain_commands( + context, + prefs.cultmesh_cache_path, + prefs.cultlib_py_src, + prefs.debug_mirror_root, + ) + adapter.last_auto_drain_error = "" + except Exception as exc: + adapter.last_auto_drain_error = str(exc) + + return 1.0 + + classes = ( BrokkrPreferences, BROKKR_PT_status, @@ -534,11 +573,15 @@ def register(): bpy.utils.register_class(cls) if _auto_capture not in bpy.app.handlers.depsgraph_update_post: bpy.app.handlers.depsgraph_update_post.append(_auto_capture) + if not bpy.app.timers.is_registered(_auto_drain_commands): + bpy.app.timers.register(_auto_drain_commands, first_interval=1.0, persistent=True) def unregister(): if _auto_capture in bpy.app.handlers.depsgraph_update_post: bpy.app.handlers.depsgraph_update_post.remove(_auto_capture) + if bpy.app.timers.is_registered(_auto_drain_commands): + bpy.app.timers.unregister(_auto_drain_commands) global _target if _target is not None: _target.stop_server() diff --git a/surfaces/blender/brokkr_bridge/blender_target.py b/surfaces/blender/brokkr_bridge/blender_target.py index e928c11..8ccb08c 100644 --- a/surfaces/blender/brokkr_bridge/blender_target.py +++ b/surfaces/blender/brokkr_bridge/blender_target.py @@ -52,6 +52,7 @@ class BrokkrBlenderTarget: self.last_snapshot: dict[str, Any] | None = None self.last_receipt: dict[str, Any] | None = None self.last_sync_receipt: dict[str, Any] | None = None + self.last_auto_drain_error: str = "" self._node_key: tuple[str, str, str] | None = None self._node: Any | None = None self._documents: dict[str, Any] | None = None diff --git a/surfaces/blender/docs/install.md b/surfaces/blender/docs/install.md index aefc5cf..b2599aa 100644 --- a/surfaces/blender/docs/install.md +++ b/surfaces/blender/docs/install.md @@ -38,7 +38,8 @@ owns the mirror state. 4. Inspect `.brokkr/blender-editor.ccmp`. 5. Drop a command intent JSON file into `.brokkr/blender-editor-debug/blender/commands/{commandId}.json`. -6. Click `Drain Commands`. +6. Click `Drain Commands`, or enable `Auto Drain Commands` to poll command + intents once per second while the add-on is loaded. 7. Inspect `.brokkr/blender-editor.ccmp` or the optional debug export at `.brokkr/blender-editor-debug/blender/receipts/{commandId}.json`. 8. Click `Start Server`. @@ -51,7 +52,8 @@ owns the mirror state. Blender frame/action data and Unity Timeline/Cinemachine lanes. 12. After running `brokkr-daemon sync-once` or `sync-loop`, click `Refresh Sync Receipt` to show the latest daemon sync pass observed in the - Blender mirror. + Blender mirror. Keep `Auto Drain Commands` enabled while `sync-loop` is + running if Blender should continuously consume daemon command intents. 13. To publish an ad hoc sync variable, fill the `Ad Hoc Sync Var` fields in the sidebar or add-on preferences and click `Publish Sync Var`.