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.

Quick Remesh (#121): Shift+R or N held on the background remeshes the active Part; Remesh after each stroke

islandmed51fa3595a2e2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e3e3d17..90b0bc90 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,7 @@ add_library(sculptforge_core STATIC
src/core/SplatCapture.cpp
src/core/Sculptable.cpp
src/core/Voxel.cpp
+ src/core/QuickRemesh.cpp
src/core/EnginePresets.cpp
src/core/Masking.cpp
src/core/Cut.cpp
diff --git a/changes/feat-quick-remesh.md b/changes/feat-quick-remesh.md
new file mode 100644
index 00000000..b62cb955
--- /dev/null
+++ b/changes/feat-quick-remesh.md
@@ -0,0 +1,24 @@
+---
+whats_new: **Quick Remesh**: turn it on in **Tool > Remesh**, then press **Shift+R**, or hold **N** and drag on the
+ background, to remesh the active Part in the background while you keep sculpting. **Remesh after each stroke**
+ does it by itself when a stroke stretched the surface.
+highlight: Remesh with one key, or after each stroke
+added: **Quick Remesh** (Tool > Remesh, #121, thanks Zoldyck-Kill): with it on, Shift+R, or N held while clicking or
+ dragging on the background, remeshes the active Part at the Voxel Remesh resolution in the background (progress
+ bar and Cancel as the button; Keep Masked and Keep Texture apply). One undo step per remesh; a stroke or undo made
+ while it runs is never overwritten (it remeshes again). Both keys are free in every key style and change in
+ Preferences > Hotkeys; on the model a press stays a brush stroke.
+added: **Remesh after each stroke** (Tool > Remesh, off by default, #121): after pen-up, a stroke that stretched
+ edges past 1.6 times their length remeshes the active Part in the background; sculpting never waits for it. Not
+ on Parts with subdivision levels, sculpt layers or a painted texture.
+testers:
+ - Any OS: Tool > Remesh > Quick Remesh on; sculpt, press Shift+R and keep sculpting. The status bar counts up,
+ the remesh lands when you lift the pen, Ctrl+Z undoes just the remesh.
+ - Hold N and drag on the background in each key style (Preferences > Input): it remeshes, the view doesn't turn.
+ Without N the drag turns the view as before; with N on the model it is a normal stroke.
+ - Remesh after each stroke on: a long Move pull remeshes after pen-up; small Standard strokes don't.
+ - Windows, pen: the same with the pen tip on the background while N is held.
+---
+Shift+R and N were the only free keys in all four styles (Classic, SculptForge, Blender, Maya): every modifier
+combination of a left drag on the background is already taken (Ctrl mask shapes, Ctrl+Shift hide shapes, Alt pan,
+Shift snap/roll, Blender Shift/Ctrl/Alt navigation, Maya Alt navigation), so the drag uses a held key instead.
diff --git a/docs/guide/geometry.md b/docs/guide/geometry.md
index 9c4728c8..cc889c43 100644
--- a/docs/guide/geometry.md
+++ b/docs/guide/geometry.md
@@ -94,6 +94,30 @@ What happens to your data:
To remesh several Parts into one, first combine them with **Merge visible...** or **Merge down...** in
[Parts](parts.md#merge-parts).
+### Quick Remesh
+
+Remesh as you sculpt, without going to the palette (#121). Turn on **Tool > Remesh > Quick Remesh**, then:
+
+- press <kbd>Shift</kbd>+<kbd>R</kbd>, or
+- hold <kbd>N</kbd> and click or drag on the background (anywhere off the model; on the model it stays a brush
+ stroke).
+
+Either one remeshes the active Part at the **Resolution** above, with **Keep Masked** and **Keep Texture** as set
+there. It runs in the background with the same progress bar and **Cancel**, so you can keep sculpting; the status
+bar says when it's done and how many triangles the Part has now. Each remesh is one undo step. If you sculpt or
+undo while it runs, it doesn't throw that work away: it remeshes the Part again as it is now.
+
+Both keys change in **Edit > Preferences > Hotkeys** (*Quick Remesh* and *Quick Remesh (hold and drag)*). Neither
+<kbd>Shift</kbd>+<kbd>R</kbd> nor <kbd>N</kbd> is used by any key style, and holding <kbd>N</kbd> changes no other
+drag on the background: without it, a drag there turns, pans or zooms the view, or draws the mask and hide shapes,
+exactly as your key style says. With Quick Remesh off, the keys only tell you where to turn it on.
+
+**Remesh after each stroke** (off by default) does it for you: when you lift the pen after a stroke that stretched
+the surface (edges pulled to more than 1.6 times their length, as a long Move or Snake Hook pull does), the active
+Part is remeshed in the background. Strokes that don't stretch anything, and masking or painting, never remesh.
+Sculpting never waits for it. It skips Parts with subdivision levels, sculpt layers or a painted texture (Keep
+Texture), where a remesh would bake or drop them; use the button or <kbd>Shift</kbd>+<kbd>R</kbd> there.
+
## Quad Remesh
**Tool > Geometry > Quad Remesh** is automatic quad retopology: it rebuilds the Part as
diff --git a/docs/guide/shortcuts.md b/docs/guide/shortcuts.md
index 0d50cfd7..92cd6d77 100644
--- a/docs/guide/shortcuts.md
+++ b/docs/guide/shortcuts.md
@@ -155,6 +155,8 @@ generated from SculptForge's action registry, the same source as the Controls wi
| Lower Res | <kbd>Shift</kbd>+<kbd>D</kbd> | Step one subdivision level down (fewer polygons, for big forms). The detail of the higher levels is kept. |
| Mask All | <kbd>Ctrl</kbd>+<kbd>A</kbd> | Mask the whole visible Part. |
| Preview | <kbd>A</kbd> | Show the skin Make Mesh would build instead of the spheres. Turn it off to edit the spheres again. |
+| Quick Remesh | <kbd>Shift</kbd>+<kbd>R</kbd> | With Tool > Remesh > Quick Remesh on: remesh the active Part at the Voxel Remesh resolution, in the background. |
+| Quick Remesh (hold and drag) | <kbd>N</kbd> | With Tool > Remesh > Quick Remesh on: hold this key and click or drag on the background (not on the model) to remesh the active Part. |
### Transform
diff --git a/src/app/App.cpp b/src/app/App.cpp
index bdb2a10b..1fa28d60 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -1348,6 +1348,7 @@ void App::dispatchEvent(const SDL_Event& event) {
if (radial_.hold != RadialHold::None) closeRadialMenu(); // its key or button's release won't come here
if (strokePopup_.held) closeStrokePopup();
spaceHeld_ = false; // Space let go in another window never reaches us
+ quickRemeshDragKey_ = SDLK_UNKNOWN; // (the same for the Quick Remesh drag key)
break;
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: // dragged to a monitor at another scale, or the system setting changed
case SDL_EVENT_WINDOW_DISPLAY_CHANGED:
@@ -1397,12 +1398,14 @@ void App::dispatchEvent(const SDL_Event& event) {
spaceHeld_ = true;
break;
}
+ if (!io.WantCaptureKeyboard && !e.key.repeat) quickRemeshKey(e.key.key, e.key.mod, true); // held: drag remeshes
if (!io.WantCaptureKeyboard && !e.key.repeat) onKey(e.key.key, e.key.mod);
else if (!io.WantCaptureKeyboard && (e.key.key == SDLK_LEFTBRACKET || e.key.key == SDLK_RIGHTBRACKET))
onKey(e.key.key, e.key.mod);
break;
case SDL_EVENT_KEY_UP:
if (e.key.key == SDLK_SPACE) spaceHeld_ = false;
+ quickRemeshKey(e.key.key, e.key.mod, false);
if (e.key.key == SDLK_SPACE) quickMenuKeyUp(); // a held Space closes the QuickMenu when let go
radialKeyUp(e.key.key); // a radial menu's held key: run the slot pointed at
strokePopupKeyUp(e.key.key); // the stroke popup's held key: pick the item pointed at
@@ -1552,6 +1555,10 @@ void App::onMouseDown(float x, float y, Uint8 button) {
rightClick_.pending = false;
return;
}
+ if (button == SDL_BUTTON_LEFT && quickRemeshDragDown(x, y)) { // the Quick Remesh key held (#121, PanelRetopo.cpp)
+ rightClick_.pending = false;
+ return;
+ }
if (blenderStyle() && blenderNavigationDown(button)) return; // middle / Alt+left / right drags navigate
if (mayaStyle() && mayaNavigationDown(button)) return; // Alt+left / middle / right: orbit / pan / zoom
if (button == SDL_BUTTON_LEFT) {
@@ -1725,6 +1732,7 @@ void App::onMouseMove(float x, float y, float dx, float dy, bool fromPen) {
case Drag::Capture: captureMouseMove(x, y); break;
case Drag::ForgeSphere: forgesphereDragTo(x, y); break;
case Drag::AirStroke: airStrokeTo(x, y); break;
+ case Drag::QuickRemesh: break; // (remeshes when let go)
case Drag::SizeScrub:
sizeScrubDx_ += dx;
radiusPx_ = drawSizeScrub(sizeScrubStart_, sizeScrubDx_);
@@ -1781,6 +1789,7 @@ void App::onMouseUp() {
orbitStarted_ = false;
panFromAlt_ = false;
if (drag_ == Drag::Select) selectionMouseUp();
+ if (drag_ == Drag::QuickRemesh) quickRemesh(RemeshTrigger::Quick);
if (drag_ == Drag::Insert) {
// The drag's length on screen, as a size at the surface point's depth (at least a small default).
const float px = std::max(insertPx_, 12.0f * uiScale_);
diff --git a/src/app/App.h b/src/app/App.h
index d65088b4..591db14a 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -157,7 +157,7 @@ public:
private:
enum class Drag { None, Stroke, Orbit, Pan, Zoom, Roll, MaskCanvas, PartClick, Select, Gizmo, Guide, Sculptable, ForgeSphere, Insert, Capture,
- AirStroke, UvTool, SizeScrub }; // AirStroke: a stroke begun off the model, waiting to reach it (#62)
+ AirStroke, UvTool, SizeScrub, QuickRemesh }; // AirStroke: a stroke begun off the model, waiting to reach it (#62)
void handleEvent(const SDL_Event& e); // the pen's mouse events first (penMouseEvents), then dispatchEvent
void dispatchEvent(const SDL_Event& e);
@@ -1063,9 +1063,22 @@ private:
void drawKeepTextureCheckbox(const char* id, const char* path); // Keep Texture under Remesh and QRemesh (PanelTexture.cpp)
// Voxel Remesh of a painted Part with Keep Texture: the remesh, Auto UV and texture transfer run on a
// worker thread (PanelRetopo.cpp); otherwise Voxel Remesh is the plain remesh command.
- void startVoxelRemesh();
+ // Who asked (#121): the button, Quick Remesh (its key or the held-key drag on the background) or Remesh after
+ // each stroke. The quick ones never land over strokes made while they ran: they remesh again instead.
+ enum class RemeshTrigger { Button, Quick, AfterStroke };
+ void startVoxelRemesh(RemeshTrigger trigger = RemeshTrigger::Button);
void pollVoxelRemesh();
+ void quickRemesh(RemeshTrigger trigger); // Quick Remesh / Remesh after each stroke: checks, then startVoxelRemesh
+ void drawQuickRemeshContents(); // their checkboxes under Tool > Remesh (PanelRetopo.cpp)
+ void strokeEndedForRemesh(const UndoRecord& stroke); // Remesh after each stroke: did it stretch the surface?
+ bool quickRemeshDragDown(float x, float y); // a press on the background with the drag key held
+ void quickRemeshKey(SDL_Keycode key, SDL_Keymod mods, bool down); // tracks the held drag key
+ SDL_Keycode quickRemeshDragKey_ = SDLK_UNKNOWN; // the "hold and drag" key while it is down
+ bool autoRemeshDue_ = false; // a stroke stretched the surface: remesh once nothing waits
+ size_t lastStrokeStretched_ = 0; // the last stroke's stretched edges (UI tests: stroke_stretched)
struct VoxelRemeshJob {
+ RemeshTrigger trigger = RemeshTrigger::Button;
+ uint64_t revision = 0; // doc_.undo.revision() when it began (the quick ones land only on that state)
std::future<bool> done;
std::shared_ptr<std::atomic<float>> progress;
std::shared_ptr<std::atomic<bool>> cancel;
diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cpp
index 334bf4be..ef620d33 100644
--- a/src/app/AsyncStroke.cpp
+++ b/src/app/AsyncStroke.cpp
@@ -393,6 +393,7 @@ void App::finishStrokeNow() {
finishPaintStroke(r);
if (r.topology && !r.topology->uvs.empty())
status_ = "Dynamic topology removed the UVs of the remeshed Part (Undo brings them back)";
+ strokeEndedForRemesh(r); // Tool > Remesh > Remesh after each stroke (#121): stretched enough to remesh?
if (!r.empty()) {
doc_.undo.push(std::move(r));
doc_.modified = true;
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index dfcff921..8ddd8021 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -99,6 +99,8 @@ Json toJson(const UiPrefs& p) {
j.set("emulate3Button", p.emulate3Button);
j.set("mayaZoomHorizontal", p.mayaZoomHorizontal);
j.set("invertZoom", p.invertZoom);
+ j.set("quickRemesh", p.quickRemesh);
+ j.set("remeshAfterStroke", p.remeshAfterStroke);
j.set("alongNormal", std::string(p.alongNormal == 1 ? "always" : p.alongNormal == 2 ? "never" : "invert_key"));
j.set("connectedOnly", p.connectedOnly);
j.set("viewFalloff", p.viewFalloff);
@@ -168,6 +170,8 @@ void fromJson(const Json& j, UiPrefs& p) {
p.emulate3Button = j["emulate3Button"].asBool(p.emulate3Button);
p.mayaZoomHorizontal = j["mayaZoomHorizontal"].asBool(p.mayaZoomHorizontal);
p.invertZoom = j["invertZoom"].asBool(p.invertZoom);
+ p.quickRemesh = j["quickRemesh"].asBool(p.quickRemesh);
+ p.remeshAfterStroke = j["remeshAfterStroke"].asBool(p.remeshAfterStroke);
if (j["alongNormal"].isString()) {
const std::string a = j["alongNormal"].asString();
p.alongNormal = a == "always" ? 1 : a == "never" ? 2 : 0;
diff --git a/src/app/Config.h b/src/app/Config.h
index 45493bfe..379612a1 100644
--- a/src/app/Config.h
+++ b/src/app/Config.h
@@ -53,6 +53,9 @@ struct UiPrefs {
// vertical as the other styles. invertZoom turns every zoom drag around.
bool mayaZoomHorizontal = true;
bool invertZoom = false;
+ // Tool > Remesh (#121): Quick Remesh (Shift+R, or hold N and drag on the background, remeshes the active Part at
+ // the Voxel Resolution) and Remesh after each stroke (a stroke that stretched the surface remeshes it).
+ bool quickRemesh = false, remeshAfterStroke = false;
// Along the normal (from the discussions): 0 = with the invert key (Alt; Ctrl in the Blender and Maya styles),
// 1 = always, 2 = never. For Move, Tendril, Elastic Tendril and KelvinGrab.
int alongNormal = 0;
diff --git a/src/app/I18nSpanish.cpp b/src/app/I18nSpanish.cpp
index e0eecd51..d9939963 100644
--- a/src/app/I18nSpanish.cpp
+++ b/src/app/I18nSpanish.cpp
@@ -98,6 +98,7 @@ constexpr Entry kSpanish[] = {
{"Import / Export", "Importar / Exportar"},
{"From an image", "A partir de una imagen"},
{"Voxel Remesh", "Remallado por vóxeles"},
+ {"Quick Remesh", "Remallado rápido"},
{"Modify Topology", "Modificar topología"},
{"Game Ready", "Listo para juegos"},
{"Navigation", "Navegación"},
@@ -426,6 +427,7 @@ constexpr Entry kSpanish[] = {
{"Distance to the sculpt: %.3f%% mean, %.2f%% max", "Distancia a la escultura: %.3f%% de media, %.2f%% máx."},
{"Resolution", "Resolución"},
{"Remeshing", "Remallando"},
+ {"Remesh after each stroke", "Remallar tras cada trazo"},
{"Cancel", "Cancelar"},
{"Stop the remesh; the Part stays as it is.", "Detén el remallado; la pieza se queda como está."},
{"Voxels across the model: higher keeps more detail and makes more triangles.",
diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cpp
index 4cc673cf..6973fd39 100644
--- a/src/app/Palettes.cpp
+++ b/src/app/Palettes.cpp
@@ -834,6 +834,7 @@ void App::drawPalette_Tool() {
drawKeepTextureCheckbox("Keep Texture##remesh", "Tool > Remesh"); // only for a painted Part
}
}
+ drawQuickRemeshContents(); // Quick Remesh, Remesh after each stroke (#121, PanelRetopo.cpp)
}
if (subpalette("tool.deformation", "Deformation")) {
tray::Section section;
diff --git a/src/app/PanelRetopo.cpp b/src/app/PanelRetopo.cpp
index f1b58017..ddafaafa 100644
--- a/src/app/PanelRetopo.cpp
+++ b/src/app/PanelRetopo.cpp
@@ -13,6 +13,7 @@
#include "app/I18n.h"
#include "core/KeepMasked.h"
+#include "core/QuickRemesh.h"
#include "core/TextureTransfer.h"
#include "core/Voxel.h"
@@ -190,15 +191,17 @@ void App::startQRemesh() {
" quads...";
}
-void App::startVoxelRemesh() {
+void App::startVoxelRemesh(RemeshTrigger trigger) {
if (voxelRemesh_) return;
Args args{{"resolution", double(voxelResolution_)}};
if (voxelKeepMasked_) args["keep_masked"] = true;
- if (!memoryAllows("remesh", args, [this] { startVoxelRemesh(); })) return;
+ if (!memoryAllows("remesh", args, [this, trigger] { startVoxelRemesh(trigger); })) return;
// Always in the background with progress, so the UI never freezes (keeping a texture adds Auto UV of the
// result, seconds to minutes); the result lands as the remesh command's would (pollVoxelRemesh).
if (doc_.sculptor.strokeActive()) endStroke();
auto job = std::make_unique<VoxelRemeshJob>();
+ job->trigger = trigger;
+ job->revision = doc_.undo.revision();
job->progress = std::make_shared<std::atomic<float>>(0.0f);
job->cancel = std::make_shared<std::atomic<bool>>(false);
job->result = std::make_shared<Mesh>();
@@ -247,14 +250,28 @@ void App::startVoxelRemesh() {
}
promise.set_value(ok);
}).detach();
+ const int res = job->resolution;
+ autoRemeshDue_ = false; // (this remesh covers every stroke so far)
voxelRemesh_ = std::move(job);
- status_ = texture ? "Voxel Remesh: remeshing and keeping the texture..." : "Voxel Remesh: remeshing...";
+ status_ = trigger == RemeshTrigger::AfterStroke ? "Remesh after stroke: the stroke stretched the surface, remeshing at " +
+ std::to_string(res) + "..."
+ : trigger == RemeshTrigger::Quick ? "Quick Remesh: remeshing at resolution " + std::to_string(res) + "..."
+ : texture ? "Voxel Remesh: remeshing and keeping the texture..."
+ : "Voxel Remesh: remeshing...";
}
void App::pollVoxelRemesh() {
+ // Remesh after each stroke: a stretching stroke asks; the remesh starts once no stroke or job is in the way.
+ if (autoRemeshDue_ && !voxelRemesh_ && !jobWaitsForStroke()) {
+ autoRemeshDue_ = false;
+ quickRemesh(RemeshTrigger::AfterStroke);
+ }
if (!voxelRemesh_) return;
+ const char* name = voxelRemesh_->trigger == RemeshTrigger::Quick ? "Quick Remesh: "
+ : voxelRemesh_->trigger == RemeshTrigger::AfterStroke ? "Remesh after stroke: "
+ : "Voxel Remesh: ";
if (voxelRemesh_->done.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
- status_ = "Voxel Remesh: " + std::to_string(int(voxelRemesh_->progress->load() * 100.0f)) + "%";
+ status_ = name + std::to_string(int(voxelRemesh_->progress->load() * 100.0f)) + "%";
return;
}
if (jobWaitsForStroke()) return; // (the result lands when the stroke ends)
@@ -263,6 +280,12 @@ void App::pollVoxelRemesh() {
status_ = *job->error;
return;
}
+ if (job->trigger != RemeshTrigger::Button && doc_.undo.revision() != job->revision) {
+ // Sculpted (or undone) while it ran: landing would throw that work away, so it remeshes the Part as it is now.
+ status_ = std::string(name) + "the Part changed while it was remeshed, remeshing again...";
+ startVoxelRemesh(job->trigger);
+ return;
+ }
int index = -1;
for (int i = 0; i < doc_.partCount(); ++i)
if (doc_.parts[size_t(i)].id == job->part) index = i;
@@ -272,7 +295,12 @@ void App::pollVoxelRemesh() {
}
const JobPart part(*this, index);
doc_.replaceMeshUndoable(std::move(*job->result), "Remesh"); // as the remesh command
- CommandResult r{true, "Remeshed to " + std::to_string(doc_.mesh.triangleCount()) + " triangles" + *job->note};
+ CommandResult r{true, std::string(job->trigger == RemeshTrigger::Quick ? "Quick Remesh: remeshed"
+ : job->trigger == RemeshTrigger::AfterStroke ? "Remeshed after the stroke"
+ : "Remeshed") +
+ " to " + std::to_string(doc_.mesh.triangleCount()) + " triangles" + *job->note};
+ if (job->trigger != RemeshTrigger::Button) r.message += " (resolution " + std::to_string(job->resolution) + "; " +
+ actions_.shortcutText("edit.undo") + " undoes it)";
if (const std::string notice = doc_.takeNotice(); !notice.empty()) r.message += ". " + notice; // levels dropped
status_ = r.message;
lastCommandOk_ = true;
@@ -286,6 +314,82 @@ void App::pollVoxelRemesh() {
consoleEcho("remesh", echo, r);
}
+// ---------------------------------------------------------------------------
+// Quick Remesh and Remesh after each stroke (#121)
+// ---------------------------------------------------------------------------
+
+void App::quickRemesh(RemeshTrigger trigger) {
+ const char* name = trigger == RemeshTrigger::AfterStroke ? "Remesh after stroke: " : "Quick Remesh: ";
+ if (voxelRemesh_) {
+ if (trigger == RemeshTrigger::Quick) status_ = std::string(name) + "already remeshing (Tool > Remesh > Cancel stops it)";
+ return; // (a stroke made meanwhile: the running quick remesh starts again when it finishes)
+ }
+ if (doc_.mesh.triangleCount() == 0) {
+ status_ = std::string(name) + "the active Part has no surface to remesh";
+ return;
+ }
+ if (!doc_.activePartInfo().visible) {
+ status_ = std::string(name) + "the active Part is hidden";
+ return;
+ }
+ startVoxelRemesh(trigger);
+}
+
+void App::strokeEndedForRemesh(const UndoRecord& stroke) {
+ lastStrokeStretched_ = 0;
+ if (!uiPrefs_.remeshAfterStroke || stroke.positions.empty() || stroke.layer >= 0 || stroke.topology || stroke.mesh ||
+ stroke.micro || stroke.subdiv)
+ return;
+ // Not where a remesh would throw work away unasked: subdivision levels, sculpt layers, a painted texture.
+ if (doc_.mesh.multires || !doc_.mesh.layers.empty() || (hasTexture(doc_.mesh) && keepTexture_)) return;
+ const StrokeStretch s = strokeStretch(doc_.mesh, stroke.positions.indices, stroke.positions.values);
+ lastStrokeStretched_ = s.stretched;
+ if (stretchWantsRemesh(s)) autoRemeshDue_ = true; // pollVoxelRemesh starts it once nothing is in the way
+}
+
+void App::quickRemeshKey(SDL_Keycode key, SDL_Keymod mods, bool down) {
+ if (!down) {
+ if (key == quickRemeshDragKey_) quickRemeshDragKey_ = SDLK_UNKNOWN;
+ return;
+ }
+ const Action* a = actions_.actionForChord(chordFromEvent(key, mods));
+ if (a && a->id == "geometry.quick_remesh_drag" && uiPrefs_.quickRemesh) quickRemeshDragKey_ = key;
+}
+
+// With the drag key held (N by default, Preferences > Hotkeys), a press on the background (no surface under it)
+// remeshes when it's let go. On the model the press stays a stroke. The key is unbound in every input style, so
+// no empty-canvas drag of any style (turn, pan, zoom, mask and hide shapes) changes.
+bool App::quickRemeshDragDown(float x, float y) {
+ if (quickRemeshDragKey_ == SDLK_UNKNOWN || !uiPrefs_.quickRemesh) return false;
+ RayHit hit;
+ if (previewLod_ < 0 && pick(x, y, hit)) return false;
+ drag_ = Drag::QuickRemesh;
+ status_ = "Quick Remesh: let go to remesh the active Part";
+ return true;
+}
+
+void App::drawQuickRemeshContents() {
+ tray::GroupLabel(*this, "Quick Remesh");
+ bool quick = uiPrefs_.quickRemesh;
+ if (ImGui::Checkbox(tr("Quick Remesh##remesh.quick"), &quick)) uiPrefs_.quickRemesh = quick;
+ const std::string key = actions_.shortcutText("geometry.quick_remesh");
+ const std::string drag = actions_.shortcutText("geometry.quick_remesh_drag");
+ const std::string help =
+ "When on, " + (key.empty() ? std::string("the Quick Remesh key (Preferences > Hotkeys)") : key) +
+ " remeshes the active Part at the Resolution above, in the background (progress and Cancel here)" +
+ (drag.empty() ? std::string(".") : "; so does holding " + drag + " and clicking or dragging on the background.") +
+ " Keep Masked and Keep Texture apply. Both keys change in Preferences > Hotkeys.";
+ ui::HelpText("Quick Remesh", nullptr, help.c_str(), "Tool > Remesh");
+ bool after = uiPrefs_.remeshAfterStroke;
+ if (ImGui::Checkbox(tr("Remesh after each stroke##remesh.after_stroke"), &after)) uiPrefs_.remeshAfterStroke = after;
+ ui::HelpText("Remesh after each stroke", nullptr,
+ "After a stroke that stretched the surface (edges pulled to more than 1.6 times their length), the "
+ "active Part is remeshed at the Resolution above in the background. Sculpting never waits: a stroke "
+ "made meanwhile remeshes again. Each remesh is one undo step. Not on a Part with subdivision levels, "
+ "sculpt layers or a painted texture.",
+ "Tool > Remesh");
+}
+
void App::pollQRemesh() {
pollVoxelRemesh(); // polled with QRemesh, its sibling rebuild job
if (!qremesh_) return;
diff --git a/src/app/Shell.cpp b/src/app/Shell.cpp
index 4a9e4f64..5d03f7de 100644
--- a/src/app/Shell.cpp
+++ b/src/app/Shell.cpp
@@ -607,6 +607,27 @@ void App::registerShellActions() {
"Rebuild as an even, watertight surface (like Voxel Remesh): merges parts, fixes scans and generated models.",
"Tool > Remesh", "", "remesh",
[this] { startVoxelRemesh(); }, nullptr, [this] { return !voxelRemesh_; }});
+ // Quick Remesh (#121): Shift+R, and N held while clicking or dragging on the background (quickRemeshDragDown).
+ // Neither key is taken in any input style (Input.cpp applyInputStyle).
+ add({"geometry.quick_remesh", "Quick Remesh", nullptr,
+ "With Tool > Remesh > Quick Remesh on: remesh the active Part at the Voxel Remesh resolution, in the background.",
+ "Tool > Remesh", "Shift+R", "",
+ [this] {
+ if (uiPrefs_.quickRemesh) quickRemesh(RemeshTrigger::Quick);
+ else status_ = "Quick Remesh is off: turn it on in Tool > Remesh";
+ },
+ nullptr, nullptr});
+ add({"geometry.quick_remesh_drag", "Quick Remesh (hold and drag)", nullptr,
+ "With Tool > Remesh > Quick Remesh on: hold this key and click or drag on the background (not on the model) to "
+ "remesh the active Part.",
+ "Tool > Remesh", "N", "",
+ [this] {
+ const std::string key = actions_.shortcutText("geometry.quick_remesh_drag");
+ status_ = !uiPrefs_.quickRemesh ? "Quick Remesh is off: turn it on in Tool > Remesh"
+ : key.empty() ? "Quick Remesh: give this a key in Preferences > Hotkeys, then hold it and drag on the background"
+ : "Quick Remesh: hold " + key + " and click or drag on the background";
+ },
+ nullptr, nullptr});
add({"geometry.to_splats", "Sculpt to Splats", nullptr, "Turn the sculpt into Gaussian splats.", "Splats", "",
"mesh_to_splats", [this] { runCommand("mesh_to_splats"); }, nullptr, nullptr});
add({"color.fill", "Fill", ICON_LC_PAINT_BUCKET, "Fill the unmasked area with the colour (FillObject).", "Color", "",
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 9febcd45..5acdc935 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -128,6 +128,7 @@
// roughness differs from the default), shown_mean_r (mean red the viewport is sent),
// layer_channel_<id> (1 when the active texture layer has channel <id> on, e.g. roughness)
// auto_uv_running, qremesh_running (QRemesh working in the background),
+// voxel_remesh_running, quick_remesh / remesh_after_stroke (Tool > Remesh, #121), stroke_stretched,
// qremesh_guides (guide curves on the active Part), qremesh_guide_loops (closed ones),
// guides_mode (1 while the QRemesh Guides brush is picked),
// quads (quad pairs in the active Part), quad_percent (quads among its polygons)
@@ -455,6 +456,10 @@ double Demo::query(const std::string& name, bool& known) const {
if (const double v = app_.splatTrainTestValue(name); !std::isnan(v)) return v; // splat_training, ...
if (const double v = app_.sculptableTestValue(name); !std::isnan(v)) return v;
if (name == "qremesh_running") return app_.qremesh_ ? 1.0 : 0.0;
+ if (name == "voxel_remesh_running") return app_.voxelRemesh_ ? 1.0 : 0.0;
+ if (name == "quick_remesh") return app_.uiPrefs_.quickRemesh ? 1.0 : 0.0;
+ if (name == "remesh_after_stroke") return app_.uiPrefs_.remeshAfterStroke ? 1.0 : 0.0;
+ if (name == "stroke_stretched") return double(app_.lastStrokeStretched_);
if (name == "qremesh_guides") return double(app_.doc_.qremeshGuides.size());
if (name == "selection_sets") return m.selectionSets ? double(m.selectionSets->sets.size()) : 0.0;
if (name == "morph_target") return m.selectionSets && !m.selectionSets->morphTarget.empty() ? 1.0 : 0.0;
diff --git a/src/core/QuickRemesh.cpp b/src/core/QuickRemesh.cpp
new file mode 100644
index 00000000..7f789478
--- /dev/null
+++ b/src/core/QuickRemesh.cpp
@@ -0,0 +1,42 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+#include "core/QuickRemesh.h"
+
+#include <algorithm>
+#include <glm/geometric.hpp>
+#include <utility>
+#include <vector>
+
+namespace sf {
+
+StrokeStretch strokeStretch(const Mesh& mesh, std::span<const uint32_t> moved, std::span<const glm::vec3> before) {
+ StrokeStretch s;
+ const size_t n = std::min(moved.size(), before.size());
+ if (n == 0) return s;
+ // The old position of a moved vertex, by binary search (vertices the stroke didn't move are where they were).
+ std::vector<std::pair<uint32_t, uint32_t>> order(n);
+ for (size_t i = 0; i < n; ++i) order[i] = {moved[i], uint32_t(i)};
+ std::sort(order.begin(), order.end());
+ const auto find = [&](uint32_t v) -> const glm::vec3* {
+ const auto it = std::lower_bound(order.begin(), order.end(), std::make_pair(v, 0u));
+ return it != order.end() && it->first == v ? &before[it->second] : nullptr;
+ };
+ const size_t vertices = mesh.positions.size();
+ for (const auto& [v, i] : order) {
+ if (v >= vertices) continue;
+ for (const uint32_t w : mesh.neighbors(v)) {
+ if (w >= vertices) continue;
+ const glm::vec3* wBefore = find(w);
+ if (wBefore && w < v) continue; // both moved: counted once, from the lower index
+ const float old = glm::distance(before[i], wBefore ? *wBefore : mesh.positions[w]);
+ if (old <= 1e-12f) continue;
+ const float ratio = glm::distance(mesh.positions[v], mesh.positions[w]) / old;
+ ++s.edges;
+ s.worst = std::max(s.worst, ratio);
+ if (ratio > kStretchRatio) ++s.stretched;
+ }
+ }
+ return s;
+}
+
+} // namespace sf
diff --git a/src/core/QuickRemesh.h b/src/core/QuickRemesh.h
new file mode 100644
index 00000000..e95ed3ba
--- /dev/null
+++ b/src/core/QuickRemesh.h
@@ -0,0 +1,30 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// Tool > Remesh > Remesh after each stroke (#121): whether a stroke stretched the surface enough to remesh it.
+// The stroke's undo step holds the moved vertices' old positions; each edge at a moved vertex is compared before
+// and after the stroke.
+#pragma once
+
+#include "core/Mesh.h"
+
+#include <glm/vec3.hpp>
+#include <span>
+
+namespace sf {
+
+struct StrokeStretch {
+ size_t edges = 0; // edges at the moved vertices
+ size_t stretched = 0; // of them, longer than kStretchRatio times their length before the stroke
+ float worst = 1.0f; // the largest new / old length ratio
+};
+
+inline constexpr float kStretchRatio = 1.6f; // an edge this much longer than before the stroke is stretched
+inline constexpr size_t kStretchedEdges = 6; // this many stretched edges remesh (one stray edge doesn't)
+
+// moved[i] is a vertex the stroke moved and before[i] its position before the stroke (UndoRecord::positions of a
+// base-mesh stroke); the mesh holds the positions after it.
+StrokeStretch strokeStretch(const Mesh& mesh, std::span<const uint32_t> moved, std::span<const glm::vec3> before);
+inline bool stretchWantsRemesh(const StrokeStretch& s) { return s.stretched >= kStretchedEdges; }
+
+} // namespace sf
diff --git a/tests/test_quick_remesh.cpp b/tests/test_quick_remesh.cpp
new file mode 100644
index 00000000..1b9ce36e
--- /dev/null
+++ b/tests/test_quick_remesh.cpp
@@ -0,0 +1,82 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Tool > Remesh > Remesh after each stroke (#121): which strokes stretched the surface enough to remesh.
+#include "TestHarness.h"
+
+#include "core/Primitives.h"
+#include "core/QuickRemesh.h"
+
+#include <vector>
+
+using namespace sf;
+
+namespace {
+
+// Moves the vertices `moved` to `to(position)`, returning their old positions (as a stroke's undo step holds them).
+template <class F> std::vector<glm::vec3> moveVertices(Mesh& mesh, const std::vector<uint32_t>& moved, F to) {
+ std::vector<glm::vec3> before;
+ for (uint32_t v : moved) {
+ before.push_back(mesh.positions[v]);
+ mesh.positions[v] = to(mesh.positions[v]);
+ }
+ return before;
+}
+
+} // namespace
+
+TEST(quick_remesh_no_stroke_no_stretch) {
+ Mesh mesh = makeIcosphere(3);
+ const StrokeStretch s = strokeStretch(mesh, {}, {});
+ CHECK(s.edges == 0);
+ CHECK(!stretchWantsRemesh(s));
+}
+
+TEST(quick_remesh_gentle_stroke_keeps_the_mesh) {
+ // Every vertex 20% further out: every edge 1.2 times as long, under the 1.6 threshold.
+ Mesh mesh = makeIcosphere(3);
+ std::vector<uint32_t> all;
+ for (uint32_t v = 0; v < mesh.positions.size(); ++v) all.push_back(v);
+ const std::vector<glm::vec3> before = moveVertices(mesh, all, [](glm::vec3 p) { return p * 1.2f; });
+ const StrokeStretch s = strokeStretch(mesh, all, before);
+ CHECK(s.edges > 0);
+ CHECK(s.stretched == 0);
+ CHECK(s.worst > 1.15f && s.worst < 1.25f);
+ CHECK(!stretchWantsRemesh(s));
+}
+
+TEST(quick_remesh_pulled_vertex_remeshes) {
+ // One vertex pulled far out (a Move or Snake Hook pull): its whole ring of edges stretched. (Vertex 20 has six
+ // neighbours; the twelve first ones, the icosahedron's corners, have five, one short of kStretchedEdges.)
+ Mesh mesh = makeIcosphere(3);
+ CHECK(mesh.neighbors(20).size() == 6);
+ const std::vector<uint32_t> moved{20};
+ const std::vector<glm::vec3> before = moveVertices(mesh, moved, [](glm::vec3 p) { return p * 3.0f; });
+ const StrokeStretch s = strokeStretch(mesh, moved, before);
+ CHECK(s.edges == mesh.neighbors(20).size());
+ CHECK(s.stretched == s.edges);
+ CHECK(s.worst > 5.0f);
+ CHECK(stretchWantsRemesh(s));
+}
+
+TEST(quick_remesh_edges_between_moved_vertices_count_once) {
+ // Everything scaled 3x: each edge is counted once (both ends moved) and every one is stretched.
+ Mesh mesh = makeIcosphere(2);
+ std::vector<uint32_t> all;
+ size_t ends = 0;
+ for (uint32_t v = 0; v < mesh.positions.size(); ++v) {
+ all.push_back(v);
+ ends += mesh.neighbors(v).size();
+ }
+ const std::vector<glm::vec3> before = moveVertices(mesh, all, [](glm::vec3 p) { return p * 3.0f; });
+ const StrokeStretch s = strokeStretch(mesh, all, before);
+ CHECK(s.edges == ends / 2);
+ CHECK(s.stretched == s.edges);
+ CHECK(stretchWantsRemesh(s));
+}
+
+TEST(quick_remesh_vertices_out_of_range_are_skipped) {
+ Mesh mesh = makeIcosphere(1);
+ const std::vector<uint32_t> moved{uint32_t(mesh.positions.size()) + 5};
+ const std::vector<glm::vec3> before{glm::vec3(0.0f)};
+ CHECK(strokeStretch(mesh, moved, before).edges == 0);
+}
diff --git a/tests/ui/quick_remesh.sfui b/tests/ui/quick_remesh.sfui
new file mode 100644
index 00000000..ca8d90b1
--- /dev/null
+++ b/tests/ui/quick_remesh.sfui
@@ -0,0 +1,125 @@
+# #121: Tool > Remesh > Quick Remesh (Shift+R, or N held while clicking or dragging on the background) and Remesh
+# after each stroke. Both remesh the active Part at the Voxel Remesh resolution in the background, one undo step each.
+run ui_look look=classic layout=classic # written for the Classic look and the classic palette bar and shelves
+run new_sphere subdivisions=4
+key f
+camera 0 0
+remember triangles before
+
+# Off by default: Shift+R only says where to turn it on.
+click "Remesh##tool.remesh"
+expect_value quick_remesh == 0
+expect_value remesh_after_stroke == 0
+key shift+r
+expect_status Quick Remesh is off
+expect_value voxel_remesh_running == 0
+hold ctrl
+hover "Quick Remesh##remesh.quick"
+expect_help "Shift+R"
+hover "Remesh after each stroke##remesh.after_stroke"
+expect_help "stretched"
+hold none
+
+# On: Shift+R remeshes in the background; one undo step.
+click "Quick Remesh##remesh.quick"
+expect_value quick_remesh == 1
+key shift+r
+expect_value voxel_remesh_running == 1
+wait_idle 120
+expect_status Quick Remesh: remeshed
+expect_value triangles != $before
+shot quick_remesh_panel
+key ctrl+z
+expect_value triangles == $before
+
+# N held and a drag on the background: remeshes, and the view stays put.
+remember camera_yaw yaw0
+key_down n
+drag_path 0.03 0.03 0.1 0.05
+key_up n
+expect_value camera_yaw == $yaw0
+wait_idle 120
+expect_status Quick Remesh: remeshed
+expect_value triangles != $before
+key ctrl+z
+expect_value triangles == $before
+# Without N the same drag turns the view, as before.
+drag_path 0.03 0.03 0.1 0.05
+expect_value camera_yaw != $yaw0
+expect_value voxel_remesh_running == 0
+camera 0 0
+# N held on the model: still a brush stroke.
+key_down n
+stroke 0.4 0.5 0.6 0.5
+key_up n
+expect_value can_undo == 1
+expect_value voxel_remesh_running == 0
+expect_value triangles == $before
+key ctrl+z
+
+# Remesh after each stroke: a gentle stroke leaves the mesh alone; a long Move pull remeshes it after pen-up.
+click "Remesh after each stroke##remesh.after_stroke"
+expect_value remesh_after_stroke == 1
+stroke 0.4 0.5 0.6 0.5
+expect_value can_undo == 1
+wait_idle 30
+expect_value voxel_remesh_running == 0
+expect_value triangles == $before
+key ctrl+z
+click "Move##brush.move"
+snapshot
+stroke 0.86 0.5 0.98 0.38
+expect_value moved > 0
+expect_value stroke_stretched >= 6
+wait_idle 120
+expect_status Remeshed after the stroke
+expect_value triangles != $before
+shot remesh_after_stroke
+# One undo step for the remesh: the pulled surface comes back with its old triangles; one more undoes the pull.
+key ctrl+z
+expect_value triangles == $before
+expect_value can_undo == 1
+key ctrl+z
+expect_value can_undo == 0
+click "Remesh after each stroke##remesh.after_stroke"
+click "Standard##brush.standard"
+
+# Neither key is taken in any input style, and the drag works with each style's empty-canvas drags.
+input_style classic
+expect_shortcut geometry.quick_remesh Shift+R
+expect_shortcut geometry.quick_remesh_drag N
+expect_value shortcut_conflicts == 0
+input_style blender
+expect_shortcut geometry.quick_remesh Shift+R
+expect_shortcut geometry.quick_remesh_drag N
+expect_value shortcut_conflicts == 0
+camera 0 0
+remember camera_yaw yaw1
+key_down n
+drag_path 0.03 0.03 0.1 0.05
+key_up n
+expect_value camera_yaw == $yaw1
+wait_idle 120
+expect_status Quick Remesh: remeshed
+key ctrl+z
+expect_value triangles == $before
+input_style maya
+expect_shortcut geometry.quick_remesh Shift+R
+expect_shortcut geometry.quick_remesh_drag N
+expect_value shortcut_conflicts == 0
+input_style sculptforge
+expect_shortcut geometry.quick_remesh Shift+R
+expect_shortcut geometry.quick_remesh_drag N
+expect_value shortcut_conflicts == 0
+input_style classic
+
+# Off again: the held key does nothing special (the drag turns the view).
+click "Quick Remesh##remesh.quick"
+expect_value quick_remesh == 0
+camera 0 0
+key_down n
+drag_path 0.03 0.03 0.1 0.05
+key_up n
+expect_value camera_yaw != $yaw1
+expect_value voxel_remesh_running == 0
+camera 0 0