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.

Predictive strokes: batches sized so packing stays under half the work; after release every dab left goes in one batch with the stroke's end work

islandmedb8a8675e5565
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 2961b36a..cb799463 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -1295,7 +1295,7 @@ void App::beginStroke(float x, float y, const RayHit& hit) {
lastY_ = y;
strokePath_.reset(x, y);
dabQueue_.clear();
- dabSeconds_ = 0.0; // measured again: the mesh and the brush may have changed
+ dabSeconds_ = prepSeconds_ = 0.0; // measured again: the mesh and the brush may have changed
// Predictive strokes (AsyncStroke.cpp): the solver thread, the ghost's first estimate (the picked triangle).
asyncStroke_ = asyncStrokeAllowed();
pointerLatest_ = glm::vec2(x, y);
diff --git a/src/app/App.h b/src/app/App.h
index 26a1a58d..e72cf4ad 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -255,6 +255,7 @@ private:
glm::vec2 pointerLatest_{0.0f}; // the newest pointer sample of the stroke (window pixels)
double pointerLatestAt_ = 0.0; // its time (seconds)
double frameSeconds_ = 1.0 / 60.0; // running mean of the frame interval (how far ahead to predict)
+ double prepSeconds_ = 0.0; // running mean of what packing a batch's upload costs (the batch size)
Sculptor::DabFrame ghostFrame_; // the last placed dab's frame (the ghost's estimates start from it)
float ghostEdge_ = 0.0f; // mean edge length of the triangle the stroke began on (the preview's cavities)
float ghostCurvature_ = 0.0f; // the surface's curvature along the stroke (1 / radius, > 0 convex; 0 flat)
diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cpp
index 987c0e84..b9d48b46 100644
--- a/src/app/AsyncStroke.cpp
+++ b/src/app/AsyncStroke.cpp
@@ -81,6 +81,7 @@ void App::StrokeSolver::loop() {
const auto prepStart = std::chrono::steady_clock::now();
uploadReady = prepare && app.renderer_.prepareStrokeUpload(uploadId, app.doc_.mesh, upload, app.doc_.sculptor.strokeCurvature());
if (finalize && uploadReady) app.renderer_.refineStrokeBoundsInto(uploadId, app.doc_.mesh, upload);
+ prepSeconds = finalize ? 0.0 : std::chrono::duration<double>(std::chrono::steady_clock::now() - prepStart).count();
static const bool log = std::getenv("SF_STROKE_LOG") != nullptr;
if (log) {
const SculptTimings& t = app.doc_.sculptor.timings;
@@ -172,6 +173,7 @@ void App::commitSolverBatch() {
syncScene(); // (the regular sync: a new grid, or a mesh the two-part upload doesn't handle)
}
if (strokeProbe_) strokeProbe_->insert(strokeProbe_->end(), s.probe.begin(), s.probe.end());
+ if (s.prepSeconds > 0.0) prepSeconds_ = prepSeconds_ > 0.0 ? prepSeconds_ * 0.7 + s.prepSeconds * 0.3 : s.prepSeconds;
if (!s.batch.empty()) {
lastDabScreen_ = glm::vec2(s.batch.back().x, s.batch.back().y);
if (s.dabSeconds > 0.0) dabSeconds_ = dabSeconds_ > 0.0 ? dabSeconds_ * 0.8 + s.dabSeconds * 0.2 : s.dabSeconds;
@@ -244,11 +246,16 @@ void App::pumpStroke() {
if (strokeFinishing_) finishStrokeNow(); // released, and every dab is on the GPU
return;
}
- // The next batch: about kBatchSeconds of work (at least one dab), oldest first.
+ // The next batch, oldest first: about kBatchSeconds of work, or as much as packing its upload costs (so the
+ // packing, per batch, stays at most about half the work), at least one dab; once the pen has lifted, every
+ // dab left (the preview shows them all: only the end result is waited for), with the stroke's end work.
StrokeSolver& s = *solver_;
- const size_t n = dabSeconds_ > 0.0 ? size_t(std::clamp(kBatchSeconds / dabSeconds_, 1.0, 64.0)) : 1;
+ const double target = std::max(kBatchSeconds, prepSeconds_);
+ size_t n = dabSeconds_ > 0.0 ? size_t(std::clamp(target / dabSeconds_, 1.0, 64.0)) : 1;
+ if (strokeFinishing_) n = 64;
s.batch.clear();
while (!dabQueue_.empty() && s.batch.size() < n) s.batch.push_back(dabQueue_.pop());
+ s.finalize = strokeFinishing_ && dabQueue_.empty();
s.view.camera = camera_;
s.view.canvas = canvasRect();
s.view.probe = strokeProbe_ ? &s.probe : nullptr;
diff --git a/src/app/AsyncStroke.h b/src/app/AsyncStroke.h
index 5734af48..9d42df94 100644
--- a/src/app/AsyncStroke.h
+++ b/src/app/AsyncStroke.h
@@ -31,6 +31,7 @@ struct App::StrokeSolver {
DabView view;
std::vector<glm::vec2> probe; // --measure-stroke: where the batch's dabs went
double dabSeconds = 0.0; // the batch's mean cost per dab
+ double prepSeconds = 0.0; // what packing its upload cost
uint32_t uploadId = 0; // the active SubTool's renderer slot
bool prepare = true; // pack the upload on the thread
bool finalize = false; // before the batch: Sculptor::flushDraft (a draft stroke's end)