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.

QRemesh Guides brush: draw curves on the model (snapped, mirrored with symmetry, Alt+click deletes), overlay with occlusion, Geometry > QRemesh > Guides controls (Delete Last, Clear, Curves Strength), F3 entries; UI test

islandmedc0a91e028724
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 51952133..0d0af295 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -688,6 +688,7 @@ void App::onMouseDown(float x, float y, Uint8 button) {
if (polygroupMouseDown(x, y, mod)) return;
if (maskSelectMouseDown(x, y, mod)) return;
if (gizmoMouseDown(x, y, mod)) return; // Gizmo 3D handles, pivot clicks (Gizmo.cpp)
+ if (guideMouseDown(x, y, mod)) return; // the QRemesh Guides brush (PanelRetopo.cpp)
// Alt+click on another SubTool selects it (ZBrush); Alt+drag stays an inverted stroke or a pan.
// Shift+Alt+click selects and frames it (ZBrush), the active one too.
const bool frameClick = (mod & SDL_KMOD_ALT) && (mod & SDL_KMOD_SHIFT) && !ctrlDown(mod);
@@ -769,6 +770,7 @@ void App::onMouseMove(float x, float y, float dx, float dy, bool fromPen) {
case Drag::SubToolClick: subtoolClickMove(x, y); break;
case Drag::Select: selectionMove(x, y); break;
case Drag::Gizmo: gizmoDragTo(x, y); break;
+ case Drag::Guide: guideDragTo(x, y); break;
case Drag::None: break;
}
}
@@ -810,6 +812,7 @@ void App::onMouseUp() {
else if (drag_ == Drag::Stroke) endStroke();
if (drag_ == Drag::MaskCanvas) maskCanvasRelease();
if (drag_ == Drag::SubToolClick) subtoolClickRelease();
+ if (drag_ == Drag::Guide) guideRelease();
gizmoRelease();
drag_ = Drag::None;
dragFromPen_ = false;
@@ -1282,9 +1285,12 @@ void App::drawUi() {
}
const ImVec2 mouse(mouseX_, mouseY_);
drawGizmo(); // Gizmo 3D handles and panel (Gizmo.cpp)
- // In Gizmo mode the brush ring shows only while Ctrl masks.
+ drawQRemeshGuides(); // QRemesh Guides curves (PanelRetopo.cpp)
+ // In Gizmo mode (and with the QRemesh Guides brush) the brush ring shows only while Ctrl masks or Shift smooths.
+ const bool ringOff = gizmoActive() || (guidesMode_ && !(inputMods() & SDL_KMOD_SHIFT));
if (((!ImGui::GetIO().WantCaptureMouse && canvasRect().contains(mouse.x, mouse.y)) || drag_ == Drag::Stroke) &&
- !hideBrushCursor_ && drag_ != Drag::Select && (!gizmoActive() || drag_ == Drag::Stroke || ctrlDown(inputMods())))
+ !hideBrushCursor_ && drag_ != Drag::Select && drag_ != Drag::Guide &&
+ (!ringOff || drag_ == Drag::Stroke || ctrlDown(inputMods())))
drawBrushCursor();
drawSelectionOverlay();
drawBrushLibraryPopups();
diff --git a/src/app/App.h b/src/app/App.h
index 60a85ca9..31616c2e 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -99,7 +99,7 @@ public:
void queueFile(FileAction action, std::string path);
private:
- enum class Drag { None, Stroke, Orbit, Pan, Zoom, Roll, MaskCanvas, SubToolClick, Select, Gizmo };
+ enum class Drag { None, Stroke, Orbit, Pan, Zoom, Roll, MaskCanvas, SubToolClick, Select, Gizmo, Guide };
void handleEvent(const SDL_Event& e);
void onMouseDown(float x, float y, Uint8 button);
@@ -496,6 +496,28 @@ private:
int projectBlur = 0;
bool projectMean = false, projectGeometry = true, projectPolypaint = true;
} retopo_;
+ // QRemesh Guides (PanelRetopo.cpp, core/QRemeshGuides.h): the "QRemesh Guides" brush draws curves on the
+ // surface for QRemesh to follow. It is a mode beside the brushes: picking any brush (or the Gizmo) leaves it.
+ void setGuidesMode(bool on);
+ void syncGuidesMode(); // leaves the mode when another brush was picked
+ bool guideMouseDown(float x, float y, SDL_Keymod mod); // true if it took the click
+ void guideDragTo(float x, float y);
+ void guideRelease();
+ void drawQRemeshGuides(); // the curves over the model, and the one being drawn
+ void drawQRemeshGuideControls(); // Geometry > QRemesh > Guides
+ int guideAt(float x, float y) const; // the guide drawn under the cursor, or -1
+ bool guidesMode_ = false;
+ struct GuidesFrom { // the brush picked when the mode started
+ BrushType brush = BrushType::Standard;
+ int recipe = -1;
+ bool paint = false;
+ } guidesFrom_;
+ std::vector<glm::vec3> guidePath_; // the curve being drawn (points on the surface)
+ float guidePathLast_[2] = {0.0f, 0.0f};
+ float curvesStrength_ = 50.0f; // Curves Strength 0-100 (QRemeshOptions::guideStrength x 100)
+ // Which guide points face the camera (drawn solid; the others faint), cached per view and guide set.
+ std::vector<std::vector<uint8_t>> guideVisible_;
+ uint64_t guideVisibleKey_ = 0;
const BrushRecipe* strokeRecipe() const; // recipe the current stroke sculpts with (none for Smooth / paint only)
// ZBrush GoZ bridge and GoZ/STL files (PanelGoz.cpp).
void drawGozMenu();
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index 73590b9d..55d5403e 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -280,8 +280,9 @@ void App::initActions() {
brush_ = type;
doc_.activeBrush = -1;
paintMode_ = false;
+ guidesMode_ = false; // leaves the QRemesh Guides brush
},
- ICON_LC_BRUSH, nullptr, [this, type] { return brush_ == type && doc_.activeBrush < 0 && !paintMode_; }, nullptr,
+ ICON_LC_BRUSH, nullptr, [this, type] { return brush_ == type && doc_.activeBrush < 0 && !paintMode_ && !guidesMode_; }, nullptr,
(std::string("Sculpt with the ") + brushName(type) + " brush.").c_str());
}
diff --git a/src/app/LightBox.cpp b/src/app/LightBox.cpp
index e8fc8000..59596ae2 100644
--- a/src/app/LightBox.cpp
+++ b/src/app/LightBox.cpp
@@ -222,6 +222,8 @@ void LightBox::rootEntries(App& app, std::vector<AssetEntry>& out) {
case BrushItem::Kind::File:
e.kind = AssetKind::BrushFile;
break;
+ case BrushItem::Kind::Guides: // a tool, not a brush file: only in the pickers
+ continue;
}
out.push_back(std::move(e));
}
diff --git a/src/app/PanelRetopo.cpp b/src/app/PanelRetopo.cpp
index ae9eff10..0e993d28 100644
--- a/src/app/PanelRetopo.cpp
+++ b/src/app/PanelRetopo.cpp
@@ -4,7 +4,8 @@
// Geometry > QRemesh and SubTool > Project: ZBrush's ZRemesher and ProjectAll. QRemesh (core/QRemesh.h) runs
// on a worker thread with a progress bar and Cancel, then replaces the SubTool as one undo step (optionally
// keeping the original as a hidden SubTool below it). ProjectAll (core/Projection.h) is quick, so it runs
-// as the project_all command. The console shows both as script lines.
+// as the project_all command. The console shows both as script lines. The QRemesh Guides brush (ZBrush's
+// ZRemesher Guides, core/QRemeshGuides.h) draws the curves QRemesh follows.
#include "app/App.h"
#include "app/Demo.h"
#include "app/Ui.h"
@@ -12,7 +13,11 @@
#include "core/TextureTransfer.h"
#include "core/Voxel.h"
+#include <IconsLucide.h>
+
#include <algorithm>
+#include <cmath>
+#include <cstring>
#include <thread>
namespace sf {
@@ -27,6 +32,15 @@ size_t faceCount(const Mesh& m) { return m.triangleCount() - m.quadCount(); }
int symmetryAxis(const Symmetry& s) { return s.y && !s.x ? 1 : s.z && !s.x && !s.y ? 2 : 0; }
+bool ctrlHeld(SDL_Keymod mod) { return (mod & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) != 0; }
+
+// Distance from p to the segment ab, on screen.
+float segmentDistance(ImVec2 p, ImVec2 a, ImVec2 b) {
+ const float dx = b.x - a.x, dy = b.y - a.y, l2 = dx * dx + dy * dy;
+ const float t = l2 > 0.0f ? std::clamp(((p.x - a.x) * dx + (p.y - a.y) * dy) / l2, 0.0f, 1.0f) : 0.0f;
+ return std::hypot(a.x + dx * t - p.x, a.y + dy * t - p.y);
+}
+
} // namespace
void App::registerRetopoUiActions() {
@@ -48,6 +62,26 @@ void App::registerRetopoUiActions() {
"edge loops follow the forms, close to Target Polygons. Runs in the background (Cancel stops it); undoable. "
"Then divide it and use SubTool > Project > ProjectAll to bring the detail back.",
"qremesh");
+ {
+ Action a;
+ a.id = "brush.qremesh_guides";
+ a.label = "QRemesh Guides";
+ a.icon = ICON_LC_SPLINE;
+ a.palette = kQRemeshPath;
+ a.run = [this] { setGuidesMode(!guidesMode_); };
+ a.checked = [this] { return guidesMode_; };
+ a.description = "The QRemesh Guides brush (ZBrush's ZRemesher Guides): drag on the model to draw a curve for "
+ "QRemesh's edge loops to follow, around an eye, the mouth or a joint. A curve that ends where "
+ "it started becomes a loop. Symmetry mirrors it; Alt+click a curve to delete it. Pick any "
+ "brush to sculpt again.";
+ actions_.add(std::move(a));
+ }
+ add("geometry.qremesh_guides_delete_last", "Delete Last", kQRemeshPath,
+ [this] { runCommand("qremesh_guide_delete_last"); }, [this] { return !doc_.qremeshGuides.empty(); },
+ "Delete the last QRemesh guide curve drawn (with its mirror copies).", "qremesh_guide_delete_last");
+ add("geometry.qremesh_guides_clear", "Clear", kQRemeshPath, [this] { runCommand("qremesh_guides_clear"); },
+ [this] { return !doc_.qremeshGuides.empty(); }, "Delete every QRemesh guide curve of this SubTool.",
+ "qremesh_guides_clear");
add("subtool.project_all", "ProjectAll", kProjectPath, [this] {
runCommand("project_all", {{"distance", double(retopo_.projectDist)}, {"mean", retopo_.projectMean},
{"blur", double(retopo_.projectBlur)}, {"geometry", retopo_.projectGeometry},
@@ -74,6 +108,8 @@ void App::startQRemesh() {
o.detectEdges = retopo_.detectEdges;
o.usePolypaint = retopo_.usePolypaint;
o.symmetryAxis = retopo_.symmetry ? symmetryAxis(symmetry_) : -1;
+ o.guides = doc_.qremeshGuides;
+ o.guideStrength = std::clamp(curvesStrength_, 0.0f, 100.0f) / 100.0f;
auto job = std::make_unique<QRemeshJob>();
job->progress = std::make_shared<std::atomic<float>>(0.0f);
@@ -90,6 +126,7 @@ void App::startQRemesh() {
if (o.usePolypaint) job->args["use_polypaint"] = true;
if (o.symmetryAxis >= 0) job->args["symmetry"] = std::string(1, char('x' + o.symmetryAxis));
if (job->keepOriginal) job->args["keep_original"] = true;
+ if (!o.guides.empty() && std::abs(curvesStrength_ - 50.0f) > 0.01f) job->args["curves_strength"] = double(curvesStrength_);
const bool keepTexture = keepTexture_;
if (!keepTexture && hasTexture(doc_.mesh)) job->args["keep_texture"] = false;
job->textureNote = std::make_shared<std::string>();
@@ -303,6 +340,235 @@ void App::drawQRemeshContents() {
ImGui::SameLine(half + style.ItemSpacing.x);
drawKeepTextureCheckbox("Keep Texture##qremesh", kQRemeshPath);
}
+ drawQRemeshGuideControls();
+}
+
+// ---------------------------------------------------------------------------
+// QRemesh Guides
+// ---------------------------------------------------------------------------
+
+void App::drawQRemeshGuideControls() {
+ const ImGuiStyle& style = ImGui::GetStyle();
+ const float full = ImGui::GetContentRegionAvail().x;
+ const float half = (full - style.ItemSpacing.x) * 0.5f;
+ ImGui::SeparatorText("Guides");
+ ui::ActionButton(*this, "brush.qremesh_guides", ImVec2(half, 0));
+ ImGui::SameLine();
+ ImGui::AlignTextToFramePadding();
+ size_t loops = 0;
+ for (const QRemeshGuide& g : doc_.qremeshGuides) loops += g.closed;
+ if (doc_.qremeshGuides.empty()) ImGui::TextDisabled("no curves");
+ else ImGui::TextDisabled("%zu curves (%zu loops)", doc_.qremeshGuides.size(), loops);
+ ui::ActionButton(*this, "geometry.qremesh_guides_delete_last", ImVec2(half, 0));
+ ImGui::SameLine();
+ ui::ActionButton(*this, "geometry.qremesh_guides_clear", ImVec2(-1, 0));
+ ImGui::SetNextItemWidth(-1);
+ ui::SliderInside("##qcurves", &curvesStrength_, 0.0f, 100.0f, "Curves Strength %.0f");
+ ui::HelpText("Curves Strength", nullptr,
+ "How far around each guide curve the edge flow follows it: 0 = only the edge loop on the curve, 100 = "
+ "about six quads to each side (ZBrush's Curves Strength). The loop on the curve is always made.",
+ kQRemeshPath);
+}
+
+void App::setGuidesMode(bool on) {
+ if (drag_ == Drag::Guide) return;
+ guidesMode_ = on;
+ guidePath_.clear();
+ if (on) {
+ guidesFrom_ = {brush_, doc_.activeBrush, paintMode_};
+ if (gizmoActive()) setGizmoMode(GizmoMode::Off);
+ status_ = "QRemesh Guides: drag on the model to draw a curve for QRemesh to follow (end where you started for a "
+ "loop); Alt+click a curve deletes it";
+ } else {
+ status_ = "Draw";
+ }
+}
+
+void App::syncGuidesMode() {
+ // Picking a brush (picker, shelf, keys, LightBox), Paint or the Gizmo leaves the guides brush.
+ if (guidesMode_ && drag_ != Drag::Guide &&
+ (brush_ != guidesFrom_.brush || doc_.activeBrush != guidesFrom_.recipe || paintMode_ != guidesFrom_.paint ||
+ gizmoActive()))
+ setGuidesMode(false);
+}
+
+int App::guideAt(float x, float y) const {
+ int best = -1;
+ float bestD = 10.0f * uiScale_;
+ for (size_t g = 0; g < doc_.qremeshGuides.size(); ++g) {
+ const QRemeshGuide& guide = doc_.qremeshGuides[g];
+ const size_t n = guide.points.size();
+ ImVec2 prev;
+ bool havePrev = false;
+ for (size_t i = 0; i <= n; ++i) {
+ if (i == n && !guide.closed) break;
+ ImVec2 p;
+ if (!gizmoProject(guide.points[i % n], p)) {
+ havePrev = false;
+ continue;
+ }
+ if (havePrev) {
+ const float d = segmentDistance(ImVec2(x, y), prev, p);
+ if (d < bestD) bestD = d, best = int(g);
+ }
+ prev = p;
+ havePrev = true;
+ }
+ }
+ return best;
+}
+
+bool App::guideMouseDown(float x, float y, SDL_Keymod mod) {
+ if (!guidesMode_ || ctrlHeld(mod) || (mod & SDL_KMOD_SHIFT)) return false; // Ctrl masks, Shift smooths as usual
+ if (mod & SDL_KMOD_ALT) { // delete the curve under the cursor (and its mirror copies)
+ const int g = guideAt(x, y);
+ if (g < 0) return false;
+ const uint32_t stroke = doc_.qremeshGuides[size_t(g)].stroke;
+ auto& guides = doc_.qremeshGuides;
+ guides.erase(std::remove_if(guides.begin(), guides.end(), [&](const QRemeshGuide& q) { return q.stroke == stroke; }),
+ guides.end());
+ doc_.modified = true;
+ status_ = "QRemesh guide deleted; " + std::to_string(guides.size()) + " left";
+ return true;
+ }
+ RayHit hit;
+ if (previewLod_ >= 0 || !pick(x, y, hit)) return false; // the background navigates
+ guidePath_ = {hit.position};
+ guidePathLast_[0] = x;
+ guidePathLast_[1] = y;
+ drag_ = Drag::Guide;
+ return true;
+}
+
+void App::guideDragTo(float x, float y) {
+ if (std::hypot(x - guidePathLast_[0], y - guidePathLast_[1]) < 2.0f * uiScale_) return;
+ RayHit hit;
+ if (!pick(x, y, hit)) return; // off the model: the curve continues where it comes back
+ guidePath_.push_back(hit.position);
+ guidePathLast_[0] = x;
+ guidePathLast_[1] = y;
+}
+
+void App::guideRelease() {
+ std::vector<glm::vec3> path = std::move(guidePath_);
+ guidePath_.clear();
+ doc_.syncBvh();
+ const int added = path.size() >= 2 ? addQRemeshGuide(doc_.qremeshGuides, doc_.mesh, doc_.bvh, path, symmetry_) : 0;
+ if (added == 0) {
+ status_ = "QRemesh Guides: the curve is too short (drag across the model)";
+ return;
+ }
+ doc_.modified = true;
+ const QRemeshGuide& g = doc_.qremeshGuides[doc_.qremeshGuides.size() - size_t(added)];
+ status_ = std::string("QRemesh guide added (") + (g.closed ? "a loop" : "a curve") + (added > 1 ? ", mirrored" : "") +
+ "); " + std::to_string(doc_.qremeshGuides.size()) + " curves. Run QRemesh to use them";
+}
+
+void App::drawQRemeshGuides() {
+ syncGuidesMode();
+ const std::vector<QRemeshGuide>& guides = doc_.qremeshGuides;
+ if ((guides.empty() && guidePath_.empty()) || !doc_.activeSubtoolInfo().visible) return;
+ ImDrawList* dl = ImGui::GetBackgroundDrawList(); // under the panels, over the model
+ const CanvasRect cr = canvasRect();
+ dl->PushClipRect(ImVec2(cr.x, cr.y), ImVec2(cr.x + cr.w, cr.y + cr.h), true);
+ const float s = uiScale_;
+
+ // Which points the model hides: a ray from the eye to each one (refreshed when the view or the guides change;
+ // at most ~2000 rays a frame, the points between them follow their neighbours).
+ {
+ const glm::mat4 vp = camera_.projection() * camera_.view();
+ uint64_t key = 1469598103934665603ull;
+ auto mix = [&](const void* data, size_t bytes) {
+ const auto* b = static_cast<const unsigned char*>(data);
+ for (size_t i = 0; i < bytes; ++i) key = (key ^ b[i]) * 1099511628211ull;
+ };
+ mix(&vp, sizeof vp);
+ mix(&cr, sizeof cr);
+ const uint64_t rev = doc_.undo.revision(), sub = doc_.activeSubtoolInfo().id;
+ mix(&rev, sizeof rev);
+ mix(&sub, sizeof sub);
+ size_t points = 0;
+ for (const QRemeshGuide& g : guides) {
+ points += g.points.size();
+ if (!g.points.empty()) mix(&g.points.back(), sizeof(glm::vec3));
+ }
+ mix(&points, sizeof points);
+ if (key != guideVisibleKey_ || guideVisible_.size() != guides.size()) {
+ guideVisibleKey_ = key;
+ guideVisible_.assign(guides.size(), {});
+ doc_.syncBvh();
+ const float eps = 0.01f * glm::length(doc_.mesh.bounds().extent());
+ const size_t stride = std::max<size_t>(1, points / 2000);
+ for (size_t g = 0; g < guides.size(); ++g) {
+ const auto& pts = guides[g].points;
+ auto& vis = guideVisible_[g];
+ vis.assign(pts.size(), 1);
+ for (size_t i = 0; i < pts.size(); i += stride) {
+ ImVec2 sp;
+ if (!gizmoProject(pts[i], sp)) {
+ vis[i] = 0;
+ continue;
+ }
+ glm::vec3 origin, dir;
+ canvasRay(sp.x, sp.y, origin, dir);
+ const float t = glm::dot(pts[i] - origin, dir) / std::max(glm::dot(dir, dir), 1e-20f);
+ RayHit hit;
+ vis[i] = !doc_.bvh.raycast(doc_.mesh, origin, dir, hit) || hit.t > t - eps / std::sqrt(glm::dot(dir, dir));
+ }
+ for (size_t i = 0; i < pts.size(); ++i)
+ if (i % stride) vis[i] = vis[i - i % stride];
+ }
+ }
+ }
+
+ const ImVec2 mouse(mouseX_, mouseY_);
+ const bool altHover = guidesMode_ && drag_ == Drag::None && (inputMods() & SDL_KMOD_ALT) &&
+ !ImGui::GetIO().WantCaptureMouse && cr.contains(mouse.x, mouse.y);
+ const int doomed = altHover ? guideAt(mouse.x, mouse.y) : -1;
+ const uint32_t doomedStroke = doomed >= 0 ? guides[size_t(doomed)].stroke : 0;
+ for (size_t g = 0; g < guides.size(); ++g) {
+ const QRemeshGuide& guide = guides[g];
+ const size_t n = guide.points.size();
+ const bool dead = doomed >= 0 && guide.stroke == doomedStroke;
+ // Solid while the brush is picked; thin and faint otherwise, so the edge loop QRemesh put there shows.
+ const ImU32 front = dead ? IM_COL32(255, 90, 80, 255) : IM_COL32(255, 196, 64, guidesMode_ ? 255 : 110);
+ const ImU32 back = dead ? IM_COL32(255, 90, 80, 70) : IM_COL32(255, 196, 64, guidesMode_ ? 55 : 30);
+ const float width = guidesMode_ ? 2.5f : 1.25f;
+ ImVec2 prev;
+ bool havePrev = false, prevVis = false;
+ for (size_t i = 0; i <= n; ++i) {
+ if (i == n && !guide.closed) break;
+ ImVec2 p;
+ if (!gizmoProject(guide.points[i % n], p)) {
+ havePrev = false;
+ continue;
+ }
+ const bool vis = guideVisible_[g][i % n] != 0;
+ if (havePrev) {
+ const bool both = vis && prevVis;
+ dl->AddLine(prev, p, both ? front : back, (both ? width : 1.25f) * s);
+ }
+ prev = p;
+ prevVis = vis;
+ havePrev = true;
+ }
+ }
+ // The curve being drawn, with its mirror images.
+ if (drag_ == Drag::Guide && guidePath_.size() >= 2)
+ for (const glm::vec3& m : Sculptor::mirrors(symmetry_)) {
+ const bool own = m == glm::vec3(1.0f);
+ for (size_t i = 1; i < guidePath_.size(); ++i) {
+ ImVec2 a, b;
+ if (gizmoProject(guidePath_[i - 1] * m, a) && gizmoProject(guidePath_[i] * m, b))
+ dl->AddLine(a, b, own ? IM_COL32(255, 230, 140, 255) : IM_COL32(255, 230, 140, 120), (own ? 2.5f : 1.5f) * s);
+ }
+ }
+ // The guides brush's cursor: a small ring with a dot.
+ if (guidesMode_ && !ImGui::GetIO().WantCaptureMouse && cr.contains(mouse.x, mouse.y)) {
+ dl->AddCircle(mouse, 7.0f * s, IM_COL32(255, 196, 64, 230), 20, 1.5f * s);
+ dl->AddCircleFilled(mouse, 1.8f * s, IM_COL32(255, 196, 64, 255));
+ }
+ dl->PopClipRect();
}
void App::drawProjectContents() {
diff --git a/src/app/Pickers.cpp b/src/app/Pickers.cpp
index a6eff97c..e25a605a 100644
--- a/src/app/Pickers.cpp
+++ b/src/app/Pickers.cpp
@@ -305,6 +305,8 @@ std::string BrushItem::id() const {
return "recipe:" + name;
case Kind::File:
return "file:" + path;
+ case Kind::Guides:
+ return "qremesh_guides";
}
return {};
}
@@ -319,6 +321,8 @@ std::string brushActionId(const BrushItem& item) {
return "brush.recipe." + item.name;
case BrushItem::Kind::File:
return "brush.file." + item.path;
+ case BrushItem::Kind::Guides:
+ return "brush.qremesh_guides";
}
return {};
}
@@ -374,6 +378,12 @@ std::vector<BrushItem> PickerUi::brushItems(App& app, bool libraryFiles) {
paint.name = "Paint";
paint.description = brushTypeDescription(kPaintBrush);
items.push_back(std::move(paint));
+ BrushItem guides;
+ guides.kind = BrushItem::Kind::Guides;
+ guides.name = "QRemesh Guides";
+ guides.description = "ZBrush's ZRemesher Guides: draw curves on the model for QRemesh's edge loops to follow (a curve "
+ "that ends where it started makes a loop). Alt+click a curve to delete it.";
+ items.push_back(std::move(guides));
for (int i = 0; i < int(app.doc_.brushes.size()); ++i) {
const BrushRecipe& r = app.doc_.brushes[size_t(i)];
BrushItem b;
@@ -427,18 +437,21 @@ std::vector<BrushItem> PickerUi::brushItems(App& app, bool libraryFiles) {
bool PickerUi::isActive(const App& app, const BrushItem& item) {
switch (item.kind) {
case BrushItem::Kind::Type:
- return !app.paintMode_ && app.doc_.activeBrush < 0 && int(app.brush_) == item.index;
+ return !app.paintMode_ && !app.guidesMode_ && app.doc_.activeBrush < 0 && int(app.brush_) == item.index;
case BrushItem::Kind::Paint:
- return app.paintMode_;
+ return app.paintMode_ && !app.guidesMode_;
case BrushItem::Kind::Recipe:
- return !app.paintMode_ && app.doc_.activeBrush == item.index;
+ return !app.paintMode_ && !app.guidesMode_ && app.doc_.activeBrush == item.index;
case BrushItem::Kind::File:
return false;
+ case BrushItem::Kind::Guides:
+ return app.guidesMode_;
}
return false;
}
void PickerUi::select(App& app, const BrushItem& item) {
+ if (item.kind != BrushItem::Kind::Guides) app.guidesMode_ = false;
switch (item.kind) {
case BrushItem::Kind::Type:
app.brush_ = BrushType(item.index);
@@ -460,6 +473,9 @@ void PickerUi::select(App& app, const BrushItem& item) {
app.runCommand("brush_load", {{"path", item.path}});
if (app.lastCommandOk_) app.paintMode_ = false;
break;
+ case BrushItem::Kind::Guides:
+ app.setGuidesMode(true);
+ return;
}
}
@@ -474,6 +490,7 @@ ImTextureID PickerUi::thumbnail(App& app, const BrushItem& item) {
? app.thumbs_.recipe(app.doc_.brushes[size_t(item.index)])
: ImTextureID(0);
case BrushItem::Kind::File:
+ case BrushItem::Kind::Guides:
return ImTextureID(0);
}
return ImTextureID(0);
@@ -583,13 +600,16 @@ void drawBrushGrid(App& app, GridMode mode) {
if (idx == i) badge[0] = char(std::toupper(static_cast<unsigned char>(c)));
const std::string id = b.name + "##" + section + std::to_string(i);
const ImTextureID tex = PickerUi::thumbnail(app, b);
- const char* glyph = b.kind == BrushItem::Kind::Paint ? ICON_LC_PAINTBRUSH : ICON_LC_BRUSH;
+ const char* glyph = b.kind == BrushItem::Kind::Paint ? ICON_LC_PAINTBRUSH
+ : b.kind == BrushItem::Kind::Guides ? ICON_LC_SPLINE
+ : ICON_LC_BRUSH;
const bool picked = AssetTile(id.c_str(), tex, glyph, b.name, tile, PickerUi::isActive(app, b),
badge[0] ? badge : nullptr, b.kind == BrushItem::Kind::File);
std::string footer = b.kind == BrushItem::Kind::Recipe
? brushOriginText(app.doc_.brushes[size_t(b.index)])
- : b.kind == BrushItem::Kind::File ? "Library file - pick to load it"
- : "Built-in brush";
+ : b.kind == BrushItem::Kind::File ? "Library file - pick to load it"
+ : b.kind == BrushItem::Kind::Guides ? "Tool > Geometry > QRemesh"
+ : "Built-in brush";
quickInfo(tex, glyph, b.name, b.description, footer);
ui::HelpText(b.name.c_str(), nullptr, b.description.c_str(), "Brush");
if (ImGui::BeginPopupContextItem()) {
@@ -657,7 +677,9 @@ void drawBrushGrid(App& app, GridMode mode) {
};
const Section sections[] = {
{"Built-in",
- [](const BrushItem& b) { return b.kind == BrushItem::Kind::Type || b.kind == BrushItem::Kind::Paint; }},
+ [](const BrushItem& b) {
+ return b.kind == BrushItem::Kind::Type || b.kind == BrushItem::Kind::Paint || b.kind == BrushItem::Kind::Guides;
+ }},
{"Custom", [](const BrushItem& b) { return b.kind == BrushItem::Kind::Recipe; }},
{"Library", [](const BrushItem& b) { return b.kind == BrushItem::Kind::File; }},
};
@@ -870,7 +892,9 @@ void drawPickers(App& app) {
// Remember what was picked recently, from anywhere (picker, shelf, keys, scripts).
{
BrushItem active;
- if (app.paintMode_)
+ if (app.guidesMode_)
+ active.kind = BrushItem::Kind::Guides;
+ else if (app.paintMode_)
active.kind = BrushItem::Kind::Paint;
else if (app.doc_.activeBrush >= 0 && app.doc_.activeBrush < int(app.doc_.brushes.size())) {
active.kind = BrushItem::Kind::Recipe;
diff --git a/src/app/Pickers.h b/src/app/Pickers.h
index 7b312211..343e5b97 100644
--- a/src/app/Pickers.h
+++ b/src/app/Pickers.h
@@ -34,7 +34,7 @@ void drawStrokeGrid(App& app, GridMode mode);
// One brush of the picker, the LightBox Brush tab and the shelves.
struct BrushItem {
- enum class Kind { Type, Paint, Recipe, File } kind = Kind::Type;
+ enum class Kind { Type, Paint, Recipe, File, Guides } kind = Kind::Type; // Guides: QRemesh Guides (PanelRetopo.cpp)
int index = -1; // BrushType (Type) or doc.brushes index (Recipe)
std::string name; // shown under the tile
std::string path; // .sfbrush (File)
diff --git a/src/app/Shell.cpp b/src/app/Shell.cpp
index 4053a63a..704b1c17 100644
--- a/src/app/Shell.cpp
+++ b/src/app/Shell.cpp
@@ -290,8 +290,9 @@ void App::registerShellActions() {
brush_ = type;
doc_.activeBrush = -1;
paintMode_ = false;
+ guidesMode_ = false; // leaves the QRemesh Guides brush
};
- a.checked = [this, type] { return brush_ == type && doc_.activeBrush < 0 && !paintMode_; };
+ a.checked = [this, type] { return brush_ == type && doc_.activeBrush < 0 && !paintMode_ && !guidesMode_; };
add(std::move(a));
}
add({"draw.sculpt", "Sculpt", nullptr,
@@ -1417,16 +1418,19 @@ bool tileFrame(const char* id, ImVec2 size, ImFont* font, const std::string& cap
void App::drawBrushTile(const char* id, ImVec2 size) {
const float s = uiScale_;
const BrushRecipe* recipe = activeRecipe();
- const std::string name = paintMode_ ? "Paint" : recipe ? recipe->name : brushName(brush_);
+ const std::string name = guidesMode_ ? "QRemesh Guides" : paintMode_ ? "Paint" : recipe ? recipe->name : brushName(brush_);
ImVec2 a, b;
const bool clicked = tileFrame(id, size, fontSmall_, name, s, a, b);
ImDrawList* dl = ImGui::GetWindowDrawList();
- ImTextureID tex = paintMode_ ? ImTextureID(0) : recipe ? thumbs_.recipe(*recipe) : thumbs_.brush(int(brush_));
+ ImTextureID tex = paintMode_ || guidesMode_ ? ImTextureID(0) : recipe ? thumbs_.recipe(*recipe) : thumbs_.brush(int(brush_));
const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);
const float r = (b.x - a.x) * 0.36f;
if (tex) {
dl->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s), ImVec2(0, 0), ImVec2(1, 1),
IM_COL32_WHITE, 4.0f * s);
+ } else if (guidesMode_) { // QRemesh Guides (PanelRetopo.cpp)
+ dl->AddCircleFilled(c, r, theme::u32(theme::tile), 32);
+ centredText(dl, fontIcons_, a, b, IM_COL32(255, 196, 64, 255), ICON_LC_SPLINE);
} else if (paintMode_) {
const glm::vec3 pc = linearToSrgb(doc_.paintColor);
dl->AddCircleFilled(c, r, theme::u32(ImVec4(pc.x, pc.y, pc.z, 1.0f)), 32);
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 19e3146f..ee369f62 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -64,6 +64,8 @@
// texture_painted (texels of the texture composite that aren't white),
// texture_mean_r / texture_mean_g / texture_mean_b (mean composite, sRGB 0-255),
// auto_uv_running, qremesh_running (QRemesh working in the background),
+// qremesh_guides (guide curves on the active SubTool), qremesh_guide_loops (closed ones),
+// guides_mode (1 while the QRemesh Guides brush is picked),
// quads (quad pairs in the active SubTool), quad_percent (quads among its polygons)
// sdiv (the current subdivision level, 1 = base; 0 without levels), sdiv_levels (0 = none)
// antialiasing (Preferences > Performance: 1, 2, 4, 8), view_samples (what the interactive
@@ -254,6 +256,13 @@ double Demo::query(const std::string& name, bool& known) const {
if (name == "auto_uv_running") return app_.autoUv_ ? 1.0 : 0.0;
if (const double v = app_.bakeTestValue(name); !std::isnan(v)) return v;
if (name == "qremesh_running") return app_.qremesh_ ? 1.0 : 0.0;
+ if (name == "qremesh_guides") return double(app_.doc_.qremeshGuides.size());
+ if (name == "qremesh_guide_loops") {
+ size_t n = 0;
+ for (const QRemeshGuide& g : app_.doc_.qremeshGuides) n += g.closed;
+ return double(n);
+ }
+ if (name == "guides_mode") return app_.guidesMode_ ? 1.0 : 0.0;
if (name == "quads") return double(m.quadCount());
if (name == "quad_percent")
return m.triangleCount() ? 100.0 * double(m.quadCount()) / double(m.triangleCount() - m.quadCount()) : 0.0;
diff --git a/tests/ui/qremesh_guides.sfui b/tests/ui/qremesh_guides.sfui
new file mode 100644
index 00000000..9e7b33f5
--- /dev/null
+++ b/tests/ui/qremesh_guides.sfui
@@ -0,0 +1,87 @@
+# QRemesh Guides (ZBrush's ZRemesher Guides brush): draw a loop round an "eye" on a sphere with X symmetry (it is
+# mirrored), an open curve across the middle (its own mirror image, so kept once), Delete Last, Alt+click a curve to
+# delete it, then QRemesh follows the loops: an edge loop round each eye. Guides are saved with the project.
+run new_sphere subdivisions=6
+click "Geometry##tool.geometry"
+expect "QRemesh/QRemesh Guides"
+expect_value qremesh_guides == 0
+
+# Ctrl-hover help on the new controls.
+hold ctrl
+hover "QRemesh/QRemesh Guides"
+expect_help "ZRemesher Guides"
+hover "QRemesh/Delete Last"
+expect_help "last QRemesh guide"
+hover "QRemesh/Clear"
+expect_help "every QRemesh guide"
+hover "QRemesh/##qcurves"
+expect_help "six quads"
+hold none
+
+# Pick the brush and draw a loop round the right eye: X symmetry mirrors it onto the left one.
+click "QRemesh/QRemesh Guides"
+expect_value guides_mode == 1
+expect_status "QRemesh Guides"
+snapshot
+drag_path 0.790 0.380 0.785 0.414 0.769 0.445 0.745 0.469 0.714 0.485 0.680 0.490 0.646 0.485 0.615 0.469 0.591 0.445 0.575 0.414 0.570 0.380 0.575 0.346 0.591 0.315 0.615 0.291 0.646 0.275 0.680 0.270 0.714 0.275 0.745 0.291 0.769 0.315 0.785 0.346 0.790 0.380
+expect_value qremesh_guides == 2
+expect_value qremesh_guide_loops == 2
+expect_status "a loop, mirrored"
+expect_value moved == 0
+expect_text "2 curves (2 loops)"
+shot guides-drawn
+
+# An open curve across the middle is its own mirror image: one curve.
+drag_path 0.3 0.72 0.4 0.76 0.5 0.77 0.6 0.76 0.7 0.72
+expect_value qremesh_guides == 3
+expect_value qremesh_guide_loops == 2
+click "QRemesh/Delete Last"
+expect_value qremesh_guides == 2
+
+# Alt+click on a curve deletes it with its mirror; the background still navigates.
+hold alt
+click_subtool Sphere 0.79 0.38
+hold none
+expect_value qremesh_guides == 0
+expect_status "deleted"
+drag_path 0.760 0.400 0.755 0.431 0.741 0.459 0.719 0.481 0.691 0.495 0.660 0.500 0.629 0.495 0.601 0.481 0.579 0.459 0.565 0.431 0.560 0.400 0.565 0.369 0.579 0.341 0.601 0.319 0.629 0.305 0.660 0.300 0.691 0.305 0.719 0.319 0.741 0.341 0.755 0.369 0.760 0.400
+expect_value qremesh_guides == 2
+remember camera_yaw yaw
+orbit 60 0
+expect_value camera_yaw != $yaw
+expect_value qremesh_guides == 2
+
+# QRemesh follows them: a loop round each eye.
+drag_item "QRemesh/##qtarget" -16 0
+click "QRemesh/QRemesh"
+wait_idle 120
+expect_status "100% quads"
+expect_status "followed 2 guides"
+expect_value quad_percent == 100
+expect_value qremesh_guides == 2
+key ctrl+z
+expect_value quads == 0
+key ctrl+shift+z
+orbit -60 0
+click "PolyF##view.polyf"
+shot guides-qremesh-polyf
+click "PolyF##view.polyf"
+
+# Picking a brush leaves the guides brush; the guides stay (shown fainter).
+click "Clay##brush.clay"
+expect_value guides_mode == 0
+expect_value qremesh_guides == 2
+
+# The F3 command palette finds the brush; picking the brush that was active before leaves it again.
+key f3
+type "##Command palette" "qremesh guides"
+expect_text "QRemesh Guides"
+key enter
+expect_value guides_mode == 1
+expect_text "QRemesh Guides"
+click "Clay##brush.clay"
+expect_value guides_mode == 0
+# Clear deletes every curve.
+click "QRemesh/Clear"
+expect_value qremesh_guides == 0
+expect_text "no curves"