Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Blender bridge: no second SculptForge when Blender sends again right away

islandmed33877ea2d02e
diff --git a/addons/blender/sculptforge_bridge/__init__.py b/addons/blender/sculptforge_bridge/__init__.py
index 71bfa971..6d893509 100644
--- a/addons/blender/sculptforge_bridge/__init__.py
+++ b/addons/blender/sculptforge_bridge/__init__.py
@@ -39,6 +39,7 @@ FACE_SETS = ".sculpt_face_set"
class _State:
sent = False # this session sent something: what SculptForge sends back loads by itself
+ launched = 0.0 # when this session last started SculptForge (time.time())
inbox_time = 0 # last seen modification time of to_blender/manifest.json
seen = -1 # revision last loaded (or present when the add-on started)
message = "" # last result, shown in the panel
@@ -321,8 +322,10 @@ def send(context):
exchange.write_manifest(folder, entries, bpy.app.version_string)
state.sent = True
count = "%d object%s" % (len(entries), "" if len(entries) == 1 else "s")
- # A running SculptForge loads it within a second (it beats only once the folder exists: wait for that).
- if exchange.sculptforge_running(root) or (first and exchange.wait_for_heartbeat(root, 2.5)):
+ # A running SculptForge loads it within a second. It beats only once the folder exists, and one this session
+ # started may still be starting: wait for its heartbeat rather than start a second one.
+ starting = time.time() - state.launched < 60.0
+ if exchange.sculptforge_running(root) or ((first or starting) and exchange.wait_for_heartbeat(root, 5.0 if starting else 2.5)):
return "INFO", "Sent %s to SculptForge" % count
path = exchange.find_sculptforge(root, p.sculptforge_path if p else "")
if not path:
@@ -330,6 +333,7 @@ def send(context):
"start it and use File > Blender > Receive from Blender" % count)
try:
exchange.launch_sculptforge(path)
+ state.launched = time.time()
except OSError as e:
return "WARNING", "Sent %s, but SculptForge could not be started (%s): %s" % (count, path, e)
return "INFO", "Sent %s; starting SculptForge" % count
diff --git a/docs/blender.md b/docs/blender.md
index 823af8d9..f8150786 100644
--- a/docs/blender.md
+++ b/docs/blender.md
@@ -97,9 +97,10 @@ quads, reversed back for a mirrored object.
## Starting SculptForge
-On send, the add-on treats SculptForge as running when `alive.json` is less than 6 seconds old. On the very first
-send (when it creates `to_sculptforge/`) it waits up to 2.5 s, because SculptForge only beats once that folder
-exists. Otherwise it starts SculptForge with `--blender` (macOS: `open -n <app> --args --blender`), found from
+On send, the add-on treats SculptForge as running when `alive.json` is less than 6 seconds old. SculptForge beats
+as soon as it starts (once `to_sculptforge/` exists), every 2 s after that, and right after its own Send to
+Blender. On the very first send (when it creates `to_sculptforge/`) the add-on waits up to 2.5 s for a beat, and
+within a minute of starting SculptForge itself up to 5 s, so a slow start never gets a second copy. Otherwise it starts SculptForge with `--blender` (macOS: `open -n <app> --args --blender`), found from
the add-on preference, `app.json`, `PATH`, then the usual install folders. `--blender` loads the pending send at
start; without it, a send that was already there when SculptForge started is not loaded by itself.
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index ff3190fe..514240d8 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -241,7 +241,10 @@ void App::initActions() {
nullptr, [this] { return !pendingUnreal_.valid(); },
"Export a game-ready FBX and import it into the running Unreal Editor (Python remote execution).");
// Blender bridge (PanelBlender.cpp, addons/blender).
- add("file.send_blender", "Send to Blender", "File > Blender", nullptr, [this] { runCommand("blender_send"); },
+ add("file.send_blender", "Send to Blender", "File > Blender", nullptr, [this] {
+ runCommand("blender_send");
+ blenderLastBeatNs_ = 0; // beat now: the add-on must see this SculptForge as running when Blender sends next
+ },
ICON_LC_SEND, "blender_send", nullptr, nullptr,
"Send the visible SubTools back to Blender (the SculptForge add-on): objects that came from Blender update "
"in place, keeping their transform, materials and modifiers; new SubTools become new objects.");
diff --git a/src/app/PanelBlender.cpp b/src/app/PanelBlender.cpp
index 1af85031..c43e0f64 100644
--- a/src/app/PanelBlender.cpp
+++ b/src/app/PanelBlender.cpp
@@ -8,6 +8,7 @@
#include "io/BlenderBridge.h"
+#include <algorithm>
#include <cstdlib>
#include <filesystem>
@@ -86,16 +87,20 @@ void App::pollBlender() {
blenderSeenRevision_ = bridgeRevision(inbox);
if (options_.blender && blenderInboxTime_) receiveFromBlender();
}
- // UI tests check every frame (their frames are simulated); the app once a second.
+ // UI tests check every frame (their frames are simulated); the app once a second, and at once when a heartbeat
+ // is due (at start, and after Send to Blender).
const Uint64 now = SDL_GetTicksNS();
const Uint64 interval = options_.uiTest.empty() ? 1'000'000'000ull : 0;
- if (now - blenderLastPollNs_ < interval) return;
+ if (blenderLastBeatNs_ != 0 && blenderLastPollNs_ != 0 && now - blenderLastPollNs_ < interval) return;
blenderLastPollNs_ = now;
std::error_code ec;
if (!std::filesystem::is_directory(std::filesystem::path(std::u8string(inbox.begin(), inbox.end())), ec))
+ {
+ blenderLastBeatNs_ = std::max<Uint64>(blenderLastBeatNs_, 1); // nothing due: back to once a second
return; // the add-on has never sent anything: no heartbeat either
- if (now - blenderLastBeatNs_ >= 2'000'000'000ull) {
+ }
+ if (blenderLastBeatNs_ == 0 || now - blenderLastBeatNs_ >= 2'000'000'000ull) { // at once, then every 2 s
blenderLastBeatNs_ = now;
writeBridgeHeartbeat(root);
}