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.

Ctrl / Ctrl+Shift brushes: the shelf shows the mask or selection brush, the Brush and Stroke pickers pick them; Polygroups > Group by UVs (polygroup_uv)

islandmed2581eb28b2e0
diff --git a/src/app/App.h b/src/app/App.h
index 88e206bb..c85b1676 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -918,6 +918,21 @@ private:
void registerInputActions();
void applyInputStyle(); // the style's default shortcuts (1-0 brushes or 9 QuickSave; I = RGB or Z Intensity)
bool zbrushStyle() const { return uiPrefs_.inputStyle == 0; }
+ // ZBrush: while Ctrl is held the brush is the mask brush, with Ctrl+Shift the selection (hide) brush. The shelf
+ // tiles show it, and the Brush / Stroke pickers opened then pick among those brushes (PanelMasking.cpp).
+ enum class HeldBrush { None, Mask, Select };
+ HeldBrush heldBrush() const;
+ struct HeldBrushItem {
+ const char* action; // "mask.lasso": the Tool > Masking / Visibility button it stands for
+ const char* brush; // MaskLasso
+ const char* stroke; // Lasso
+ const char* icon;
+ SelectShape shape;
+ };
+ static std::vector<HeldBrushItem> heldBrushItems(HeldBrush held);
+ const HeldBrushItem* heldBrushCurrent(HeldBrush held) const; // the one picked now
+ bool drawHeldBrushGrid(HeldBrush held, bool strokes); // the picker's grid; true when one was picked
+ void drawHeldBrushIcon(ImDrawList* dl, ImVec2 a, ImVec2 b, const char* icon, bool select); // shelf tiles (Shell.cpp)
void drawInputSection(); // Preferences > Input
// Z Intensity (0-100 on screen): Smooth's own while Shift is held or Smooth is the brush, as in ZBrush.
void drawZIntensitySlider(const char* id);
diff --git a/src/app/Input.cpp b/src/app/Input.cpp
index 04fa41ef..787d252a 100644
--- a/src/app/Input.cpp
+++ b/src/app/Input.cpp
@@ -94,6 +94,13 @@ void App::registerInputActions() {
"Turn the masked part into a new polygroup and clear the mask (ZBrush Ctrl+W). With nothing masked, "
"everything visible becomes one group.",
[this] { groupMasked(); });
+ add("polygroup.uv_groups", "Group by UVs", ICON_LC_GRID_2X2, "Tool > Polygroups", "",
+ "One polygroup per UV island (ZBrush UV Groups): triangles that touch without a UV seam share a group. "
+ "Only the visible part is regrouped. Needs UVs (Tool > Texture Map > Auto UV makes some).",
+ [this] {
+ runCommand("polygroup_uv");
+ if (lastCommandOk_) renderSettings_.showPolygroups = true;
+ });
actions_.setDefaultShortcut("config.save", "Ctrl+Shift+Alt+I");
// Preferences > Input: the key style.
diff --git a/src/app/LightBox.cpp b/src/app/LightBox.cpp
index 4fb716cc..86b645a3 100644
--- a/src/app/LightBox.cpp
+++ b/src/app/LightBox.cpp
@@ -1015,7 +1015,9 @@ void App::drawLightBoxUi() {
}
bool App::lightBoxKey(SDL_Keycode key, SDL_Keymod mod) {
- if (mod & (SDL_KMOD_CTRL | SDL_KMOD_ALT | SDL_KMOD_GUI | SDL_KMOD_SHIFT)) return false;
+ // Ctrl+B / Ctrl+Shift+B: the brush picker with the mask / selection brushes (ZBrush: B with Ctrl held).
+ const bool heldPicker = key == SDLK_B && (mod & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) && !(mod & SDL_KMOD_ALT);
+ if (!heldPicker && (mod & (SDL_KMOD_CTRL | SDL_KMOD_ALT | SDL_KMOD_GUI | SDL_KMOD_SHIFT))) return false;
const char* id = key == SDLK_COMMA ? "ui.lightbox"
: key == SDLK_B ? "ui.picker.brush"
: key == SDLK_M ? "ui.picker.material"
diff --git a/src/app/PanelMasking.cpp b/src/app/PanelMasking.cpp
index ed8ef333..49423b72 100644
--- a/src/app/PanelMasking.cpp
+++ b/src/app/PanelMasking.cpp
@@ -6,8 +6,11 @@
// "Masking" section of the Tools panel. The operations themselves are the
// mask_* commands (core/Masking.cpp).
#include "app/App.h"
+#include "app/Pickers.h"
#include "app/Ui.h"
+#include <IconsLucide.h>
+
#include <algorithm>
#include <cmath>
@@ -92,6 +95,58 @@ void App::maskSelectMouseUp() {
runSelection("mask_rect", "mask_lasso", {{"unmask", alt}, {"strength", double(maskStrength_)}});
}
+App::HeldBrush App::heldBrush() const {
+ const SDL_Keymod mod = inputMods();
+ if (!ctrlDown(mod)) return HeldBrush::None;
+ return (mod & SDL_KMOD_SHIFT) ? HeldBrush::Select : HeldBrush::Mask;
+}
+
+std::vector<App::HeldBrushItem> App::heldBrushItems(HeldBrush held) {
+ if (held == HeldBrush::Mask)
+ return {{"mask.pen", "MaskPen", "Dots", ICON_LC_PEN_TOOL, SelectShape::Pen},
+ {"mask.lasso", "MaskLasso", "Lasso", ICON_LC_LASSO, SelectShape::Lasso},
+ {"mask.rect", "MaskRect", "Rect", ICON_LC_SQUARE_DASHED, SelectShape::Rect}};
+ if (held == HeldBrush::Select)
+ return {{"select.rect", "SelectRect", "Rect", ICON_LC_SQUARE_DASHED, SelectShape::Rect},
+ {"select.lasso", "SelectLasso", "Lasso", ICON_LC_LASSO, SelectShape::Lasso}};
+ return {};
+}
+
+const App::HeldBrushItem* App::heldBrushCurrent(HeldBrush held) const {
+ static const std::vector<HeldBrushItem> mask = heldBrushItems(HeldBrush::Mask);
+ static const std::vector<HeldBrushItem> select = heldBrushItems(HeldBrush::Select);
+ const std::vector<HeldBrushItem>& items = held == HeldBrush::Mask ? mask : select;
+ if (held == HeldBrush::None) return nullptr;
+ const SelectShape shape = held == HeldBrush::Mask ? maskShape_ : hideShape_;
+ for (const HeldBrushItem& it : items)
+ if (it.shape == shape) return &it;
+ return nullptr;
+}
+
+bool App::drawHeldBrushGrid(HeldBrush held, bool strokes) {
+ const float tile = 64.0f * uiScale_;
+ const HeldBrushItem* current = heldBrushCurrent(held);
+ bool picked = false;
+ int column = 0;
+ for (const HeldBrushItem& it : heldBrushItems(held)) {
+ if (column++ > 0) ImGui::SameLine(0.0f, 6.0f);
+ const char* label = strokes ? it.stroke : it.brush;
+ const std::string id = std::string(label) + "##held." + it.action;
+ const Action* a = actions_.find(it.action);
+ if (AssetTile(id.c_str(), ImTextureID(0), it.icon, label, tile, current && current->shape == it.shape) && a &&
+ a->run) {
+ actions_.touch(a->id);
+ a->run();
+ status_ = std::string("Brush: ") + it.brush;
+ picked = true;
+ }
+ const std::string help = strokes ? std::string("Stroke of ") + it.brush + ". " + (a ? a->description : "")
+ : (a ? a->description : std::string());
+ ui::HelpText(label, nullptr, help.c_str(), held == HeldBrush::Mask ? "Tool > Masking" : "Tool > Visibility");
+ }
+ return picked;
+}
+
void App::drawMaskingSection() {
ImGui::Checkbox("Show mask", &renderSettings_.showMask);
ImGui::SameLine();
diff --git a/src/app/PanelPolygroups.cpp b/src/app/PanelPolygroups.cpp
index 79325c46..2deda77d 100644
--- a/src/app/PanelPolygroups.cpp
+++ b/src/app/PanelPolygroups.cpp
@@ -86,6 +86,7 @@ void App::drawPolygroupsSection() {
if (ImGui::Button("Merge visible", ImVec2(half, 0))) group("polygroup_merge_visible");
ImGui::SameLine();
if (ImGui::Button("Clear groups", ImVec2(half, 0))) runCommand("polygroup_clear");
+ ui::ActionButton(*this, "polygroup.uv_groups", ImVec2(half, 0));
}
void App::drawVisibilitySection() {
diff --git a/src/app/Pickers.cpp b/src/app/Pickers.cpp
index 3917c969..4f77fa96 100644
--- a/src/app/Pickers.cpp
+++ b/src/app/Pickers.cpp
@@ -76,6 +76,8 @@ struct State {
int openedFrame = -1, closedFrame = -1;
int keysFrom = 0; // frame from which typed keys count (not the key that opened it)
bool addToShelf = false;
+ // Opened with Ctrl (mask brushes) or Ctrl+Shift (selection brushes) held, as in ZBrush: App::HeldBrush.
+ int held = 0;
std::string typed; // brush picker: letters typed so far
// Material hover preview: the material to go back to.
bool previewing = false;
@@ -909,11 +911,15 @@ void openPicker(Picker picker, ImVec2 anchor) {
s.keysFrom = ImGui::GetFrameCount() + 2;
s.typed.clear();
s.addToShelf = false;
+ const SDL_Keymod mods = SDL_GetModState();
+ s.held = !(mods & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) ? 0 : (mods & SDL_KMOD_SHIFT) ? 2 : 1;
+ if (picker != Picker::Brush && picker != Picker::Stroke) s.held = 0;
}
void openBrushPickerForShelf(ImVec2 anchor) {
openPicker(Picker::Brush, anchor);
st().addToShelf = st().open;
+ st().held = 0;
}
bool pickerOpen() { return st().open || st().slider >= 0; }
@@ -963,37 +969,52 @@ void drawPickers(App& app) {
if (s.open) {
const float scale = app.uiScale_;
const float gridW = 6 * (64.0f * scale + 6.0f) + 20.0f + ImGui::GetStyle().ScrollbarSize;
- switch (s.picker) {
- case Picker::Brush:
- if (beginPickerWindow("Brushes##picker", gridW)) {
- pickerTitle(ICON_LC_BRUSH, s.addToShelf ? "Add a brush to the shelf" : "Brushes", "B");
- drawBrushGrid(app, GridMode::Popup);
- }
- ImGui::End();
- break;
- case Picker::Stroke:
- if (beginPickerWindow("Strokes##picker", 4 * (64.0f * scale + 6.0f) + 20.0f)) {
- pickerTitle(ICON_LC_SPLINE, "Stroke", nullptr);
+ if (s.held != 0) { // Ctrl / Ctrl+Shift held: the mask or selection brushes (Brush and Stroke only)
+ if (beginPickerWindow(s.picker == Picker::Brush ? "Brushes##picker" : "Strokes##picker",
+ 3 * (64.0f * scale + 6.0f) + 20.0f)) {
+ const bool strokes = s.picker == Picker::Stroke;
+ pickerTitle(strokes ? ICON_LC_SPLINE : ICON_LC_BRUSH,
+ s.held == 1 ? (strokes ? "Mask stroke (Ctrl)" : "Mask brushes (Ctrl)")
+ : (strokes ? "Selection stroke (Ctrl+Shift)" : "Selection brushes (Ctrl+Shift)"),
+ nullptr);
ImGui::Spacing();
- drawStrokeGrid(app, GridMode::Popup);
- }
- ImGui::End();
- break;
- case Picker::Alpha:
- if (beginPickerWindow("Alphas##picker", gridW)) {
- pickerTitle(ICON_LC_CIRCLE_DASHED, "Alpha", nullptr);
- drawAlphaGrid(app, GridMode::Popup);
+ if (app.drawHeldBrushGrid(s.held == 1 ? App::HeldBrush::Mask : App::HeldBrush::Select, strokes))
+ closePicker();
}
ImGui::End();
- break;
- case Picker::Material:
- if (beginPickerWindow("Materials##picker", gridW)) {
- pickerTitle(ICON_LC_SUN, "Material", "M");
- ImGui::Spacing();
- drawMaterialGrid(app, GridMode::Popup);
+ } else {
+ switch (s.picker) {
+ case Picker::Brush:
+ if (beginPickerWindow("Brushes##picker", gridW)) {
+ pickerTitle(ICON_LC_BRUSH, s.addToShelf ? "Add a brush to the shelf" : "Brushes", "B");
+ drawBrushGrid(app, GridMode::Popup);
+ }
+ ImGui::End();
+ break;
+ case Picker::Stroke:
+ if (beginPickerWindow("Strokes##picker", 4 * (64.0f * scale + 6.0f) + 20.0f)) {
+ pickerTitle(ICON_LC_SPLINE, "Stroke", nullptr);
+ ImGui::Spacing();
+ drawStrokeGrid(app, GridMode::Popup);
+ }
+ ImGui::End();
+ break;
+ case Picker::Alpha:
+ if (beginPickerWindow("Alphas##picker", gridW)) {
+ pickerTitle(ICON_LC_CIRCLE_DASHED, "Alpha", nullptr);
+ drawAlphaGrid(app, GridMode::Popup);
+ }
+ ImGui::End();
+ break;
+ case Picker::Material:
+ if (beginPickerWindow("Materials##picker", gridW)) {
+ pickerTitle(ICON_LC_SUN, "Material", "M");
+ ImGui::Spacing();
+ drawMaterialGrid(app, GridMode::Popup);
+ }
+ ImGui::End();
+ break;
}
- ImGui::End();
- break;
}
}
if (!s.open && s.previewing) { // closed without picking: put the material back
diff --git a/src/app/Shell.cpp b/src/app/Shell.cpp
index ffe89712..08a71126 100644
--- a/src/app/Shell.cpp
+++ b/src/app/Shell.cpp
@@ -1454,8 +1454,24 @@ bool tileFrame(const char* id, ImVec2 size, ImFont* font, const std::string& cap
} // namespace
+void App::drawHeldBrushIcon(ImDrawList* dl, ImVec2 a, ImVec2 b, const char* icon, bool select) {
+ const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);
+ dl->AddCircleFilled(c, (b.x - a.x) * 0.36f, select ? IM_COL32(40, 90, 70, 255) : IM_COL32(90, 40, 40, 255), 32);
+ centredText(dl, fontIcons_, a, b, IM_COL32(255, 255, 255, 230), icon);
+}
+
void App::drawBrushTile(const char* id, ImVec2 size) {
const float s = uiScale_;
+ // ZBrush: Ctrl held shows the mask brush, Ctrl+Shift the selection brush; a click picks among those.
+ if (const HeldBrushItem* held = heldBrushCurrent(heldBrush())) {
+ ImVec2 a, b;
+ const bool clicked = tileFrame(id, size, fontSmall_, held->brush, s, a, b);
+ drawHeldBrushIcon(ImGui::GetWindowDrawList(), a, b, held->icon, heldBrush() == HeldBrush::Select);
+ if (clicked) openPicker(Picker::Brush, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));
+ ui::HelpText("Brush", "B", "Ctrl held: the mask brush (Ctrl+Shift: the selection brush). Click, or press B with Ctrl "
+ "held, to pick MaskPen, MaskLasso or MaskRect (SelectRect or SelectLasso).", "Left shelf");
+ return;
+ }
const BrushRecipe* recipe = activeRecipe();
const std::string name = guidesMode_ ? "QRemesh Guides" : paintMode_ ? "Paint" : recipe ? recipe->name : brushName(brush_);
ImVec2 a, b;
@@ -1485,6 +1501,15 @@ void App::drawBrushTile(const char* id, ImVec2 size) {
void App::drawStrokeTile(const char* id, ImVec2 size) {
const float s = uiScale_;
+ if (const HeldBrushItem* held = heldBrushCurrent(heldBrush())) { // Ctrl / Ctrl+Shift: the mask's stroke
+ ImVec2 a, b;
+ const bool clicked = tileFrame(id, size, fontSmall_, held->stroke, s, a, b);
+ drawHeldBrushIcon(ImGui::GetWindowDrawList(), a, b, held->icon, heldBrush() == HeldBrush::Select);
+ if (clicked) openPicker(Picker::Stroke, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));
+ ui::HelpText("Stroke", nullptr, "Ctrl held: the mask's stroke, Dots (MaskPen), Lasso or Rect (Ctrl+Shift: the "
+ "selection's). Click with Ctrl held to choose.", "Left shelf");
+ return;
+ }
ImVec2 a, b;
const bool clicked = tileFrame(id, size, fontSmall_, strokeTypeName(strokeType_), s, a, b);
ImDrawList* dl = ImGui::GetWindowDrawList();
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index db9dfa2c..d559a97d 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -68,6 +68,7 @@
// 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)
+// mask_shape (0 MaskPen, 1 MaskLasso, 2 MaskRect), hide_shape (1 SelectLasso, 2 SelectRect)
// 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
// view draws with now: 1 while Fast Navigation moves a big scene), multithreading (1 on),
@@ -293,6 +294,8 @@ double Demo::query(const std::string& name, bool& known) const {
if (name == "stroke_type") return double(int(app_.strokeType_)); // 0 Dots, 1 DragRect, 2 DragDot, 3 Spray, 4 LazyMouse
if (name == "vdms") return double(app_.doc_.vdms.size());
if (name == "input_style") return double(app_.uiPrefs_.inputStyle);
+ if (name == "mask_shape") return double(int(app_.maskShape_)); // 0 MaskPen, 1 MaskLasso, 2 MaskRect
+ if (name == "hide_shape") return double(int(app_.hideShape_)); // 1 SelectLasso, 2 SelectRect
if (name == "dynamic") return app_.doc_.sculptor.dyntopo.enabled ? 1.0 : 0.0;
if (name == "dynamic_detail") return std::round(app_.doc_.sculptor.dyntopo.detail * 100.0f);
if (name == "brush_type") return app_.doc_.activeBrush >= 0 || app_.paintMode_ ? -1.0 : double(int(app_.brush_));
diff --git a/src/core/Polygroups.cpp b/src/core/Polygroups.cpp
index 2d3d36aa..81adb479 100644
--- a/src/core/Polygroups.cpp
+++ b/src/core/Polygroups.cpp
@@ -70,7 +70,7 @@ std::vector<uint32_t> floodGroups(const Mesh& m, Accept accept) {
const uint32_t t = stack.back();
stack.pop_back();
forEachEdgeNeighbor(m, t, [&](uint32_t u) {
- if (region[u] != kUnassigned || m.triangleHidden(u) || !accept(seed, u)) return;
+ if (region[u] != kUnassigned || m.triangleHidden(u) || !accept(seed, t, u)) return;
region[u] = id;
stack.push_back(u);
});
@@ -178,7 +178,7 @@ std::vector<uint32_t> groupsByNormals(const Mesh& mesh, float maxAngleDegrees) {
std::vector<glm::vec3> normals(mesh.triangleCount());
for (uint32_t t = 0; t < mesh.triangleCount(); ++t) normals[t] = faceNormal(mesh, t);
const float minDot = std::cos(glm::radians(std::clamp(maxAngleDegrees, 0.0f, 180.0f))) - 1e-5f;
- return floodGroups(mesh, [&](uint32_t seed, uint32_t u) {
+ return floodGroups(mesh, [&](uint32_t seed, uint32_t, uint32_t u) {
// Degenerate slivers have no normal; let them join their neighbours.
if (normals[u] == glm::vec3(0.0f) || normals[seed] == glm::vec3(0.0f)) return true;
return glm::dot(normals[seed], normals[u]) >= minDot;
@@ -186,7 +186,26 @@ std::vector<uint32_t> groupsByNormals(const Mesh& mesh, float maxAngleDegrees) {
}
std::vector<uint32_t> groupsByConnectivity(const Mesh& mesh) {
- return floodGroups(mesh, [](uint32_t, uint32_t) { return true; });
+ return floodGroups(mesh, [](uint32_t, uint32_t, uint32_t) { return true; });
+}
+
+std::vector<uint32_t> groupsByUvs(const Mesh& mesh) {
+ if (!mesh.hasUvs()) return {};
+ // Neighbours join when the corners at both shared vertices have the same UVs (no seam between them).
+ return floodGroups(mesh, [&](uint32_t, uint32_t t, uint32_t u) {
+ const glm::uvec3& a = mesh.triangles[t];
+ const glm::uvec3& b = mesh.triangles[u];
+ int shared = 0;
+ for (int i = 0; i < 3; ++i)
+ for (int j = 0; j < 3; ++j) {
+ if (a[i] != b[j]) continue;
+ if (glm::any(glm::greaterThan(glm::abs(mesh.uvs[3 * size_t(t) + size_t(i)] - mesh.uvs[3 * size_t(u) + size_t(j)]),
+ glm::vec2(1e-6f))))
+ return false;
+ ++shared;
+ }
+ return shared >= 2;
+ });
}
std::vector<uint32_t> groupsFromMask(const Mesh& mesh, size_t* changed) {
@@ -344,6 +363,14 @@ void registerPolygroupCommands(CommandRegistry& reg) {
return {true, groupSummary(doc.mesh)};
}});
+ reg.add({"polygroup_uv",
+ "Give every UV island of the visible mesh its own polygroup (ZBrush Polygroups > UV Groups).", {},
+ [](Document& doc, const Args&) -> CommandResult {
+ if (!doc.mesh.hasUvs()) return {false, "This mesh has no UVs: unwrap it first (Tool > UV Map)"};
+ commitPolygroups(doc, groupsByUvs(doc.mesh), "Group by UVs");
+ return {true, groupSummary(doc.mesh)};
+ }});
+
reg.add({"polygroup_from_mask",
"Move the masked (visible) part of the mesh into a new polygroup, like ZBrush Group Masked.", {},
[](Document& doc, const Args&) -> CommandResult {
diff --git a/src/core/Polygroups.h b/src/core/Polygroups.h
index 24518d7c..e36a2e70 100644
--- a/src/core/Polygroups.h
+++ b/src/core/Polygroups.h
@@ -32,6 +32,9 @@ size_t visiblePolygroupCount(const Mesh& mesh);
std::vector<uint32_t> groupsByNormals(const Mesh& mesh, float maxAngleDegrees);
// One group per edge-connected piece of visible triangles.
std::vector<uint32_t> groupsByConnectivity(const Mesh& mesh);
+// One group per UV island: visible triangles joined across edges whose UVs match at both ends (ZBrush UV Groups).
+// Empty when the mesh has no UVs.
+std::vector<uint32_t> groupsByUvs(const Mesh& mesh);
// Visible triangles whose average vertex mask is >= 0.5 move to a new group;
// `changed` (optional) receives how many did.
std::vector<uint32_t> groupsFromMask(const Mesh& mesh, size_t* changed = nullptr);
diff --git a/tests/test_polygroups.cpp b/tests/test_polygroups.cpp
index ff2eaa0d..40859de7 100644
--- a/tests/test_polygroups.cpp
+++ b/tests/test_polygroups.cpp
@@ -64,7 +64,7 @@ TEST(polygroup_commands_registered) {
CommandRegistry reg;
for (const char* name : {"polygroup_auto_by_normals", "polygroup_by_connectivity", "polygroup_from_mask",
"polygroup_clear", "polygroup_merge_visible", "hide_polygroup", "isolate_polygroup",
- "show_all", "invert_visibility", "hide_rect", "hide_lasso", "delete_hidden"})
+ "show_all", "invert_visibility", "hide_rect", "hide_lasso", "delete_hidden", "polygroup_uv"})
CHECK(reg.find(name) != nullptr);
CHECK(reg.toolSchemaJson().find("\"isolate_polygroup\"") != std::string::npos);
}
@@ -94,6 +94,47 @@ TEST(polygroups_by_normals) {
CHECK(visiblePolygroupCount(s.mesh) > 10);
}
+TEST(polygroups_by_uvs) {
+ // Box mapping: every side of the cube is its own UV island (its corners' UVs depend on the side).
+ Mesh cube = makeCube();
+ for (uint32_t t = 0; t < 12; ++t)
+ for (int c = 0; c < 3; ++c) {
+ const glm::vec3 p = cube.positions[cube.triangles[t][c]];
+ cube.uvs.push_back(glm::vec2(float(t / 2) * 3.0f + p.x, p.y + 0.5f * p.z));
+ }
+ Document d = makeDoc(cube);
+ CommandRegistry reg;
+ CHECK(reg.execute(d, "polygroup_uv").ok);
+ CHECK(visiblePolygroupCount(d.mesh) == 6);
+ for (uint32_t t = 0; t < 12; t += 2) CHECK(d.mesh.polygroups[t] == d.mesh.polygroups[t + 1]);
+ CHECK(reg.execute(d, "undo").ok);
+ CHECK(visiblePolygroupCount(d.mesh) == 1);
+
+ // One continuous island (UVs per vertex, no seams): one group, even across the sides.
+ for (uint32_t t = 0; t < 12; ++t)
+ for (int c = 0; c < 3; ++c) {
+ const glm::vec3 p = d.mesh.positions[d.mesh.triangles[t][c]];
+ d.mesh.uvs[3 * t + uint32_t(c)] = glm::vec2(p.x + 0.25f * p.z, p.y);
+ }
+ CHECK(reg.execute(d, "polygroup_by_connectivity").ok); // start from something else
+ CHECK(reg.execute(d, "polygroup_auto_by_normals", {{"angle", 30.0}}).ok);
+ CHECK(visiblePolygroupCount(d.mesh) == 6);
+ CHECK(reg.execute(d, "polygroup_uv").ok);
+ CHECK(visiblePolygroupCount(d.mesh) == 1);
+
+ // Two separate pieces with the same UVs are still two islands (they don't touch on the model).
+ Document two = makeDoc(makeTwoSpheres(1));
+ two.mesh.uvs.assign(two.mesh.triangleCount() * 3, glm::vec2(0.5f));
+ CHECK(reg.execute(two, "polygroup_uv").ok);
+ CHECK(visiblePolygroupCount(two.mesh) == 2);
+
+ // No UVs: refused with a message, nothing changes.
+ Document none = makeDoc(makeCube());
+ const CommandResult r = reg.execute(none, "polygroup_uv");
+ CHECK(!r.ok && r.message.find("no UVs") != std::string::npos);
+ CHECK(!none.mesh.hasPolygroups() && !none.undo.canUndo());
+}
+
TEST(polygroups_by_connectivity_and_merge) {
Document d = makeDoc(makeTwoSpheres());
const uint32_t half = uint32_t(d.mesh.triangleCount() / 2);
diff --git a/tests/ui/ctrl_brushes.sfui b/tests/ui/ctrl_brushes.sfui
new file mode 100644
index 00000000..a9caf8ca
--- /dev/null
+++ b/tests/ui/ctrl_brushes.sfui
@@ -0,0 +1,121 @@
+# ZBrush's Ctrl brushes: while Ctrl is held the shelf shows the mask brush, and the Brush / Stroke pickers opened
+# with Ctrl held pick MaskPen / MaskLasso / MaskRect; Ctrl+Shift does the same for SelectRect / SelectLasso. Also
+# Polygroups > Group by UVs.
+run new_sphere subdivisions=5
+expect_value mask_shape == 0
+expect_value hide_shape == 2
+
+# Holding Ctrl: the brush tile turns into MaskPen, the stroke tile into its Dots.
+hold ctrl
+wait 0.1
+expect_text MaskPen
+shot ctrl-held-shelf
+hold none
+expect_no_text MaskPen
+
+# Ctrl+B opens the brush picker with the mask brushes.
+hold ctrl
+key ctrl+b
+wait 0.1
+expect "MaskLasso##held.mask.lasso"
+hover "MaskLasso##held.mask.lasso"
+expect_help "lasso"
+shot ctrl-brush-picker
+click "MaskLasso##held.mask.lasso"
+hold none
+expect_value mask_shape == 1
+expect_not "MaskLasso##held.mask.lasso"
+
+# Clicking the shelf's stroke tile with Ctrl held offers the mask's strokes.
+hold ctrl
+click "##tile.stroke"
+wait 0.1
+expect "Rect##held.mask.rect"
+shot ctrl-stroke-picker
+click "Rect##held.mask.rect"
+hold none
+expect_value mask_shape == 2
+
+# The picked MaskRect masks with Ctrl+drag (starting on the background) and Tool > Masking agrees.
+hold ctrl
+drag_path -0.2 -0.2 0.5 1.2
+hold none
+expect_value masked > 1000
+key ctrl+z
+expect_value masked == 0
+click "Masking"
+click "MaskPen##mask.pen"
+expect_value mask_shape == 0
+
+# Without Ctrl the pickers are the usual ones.
+key b
+wait 0.1
+expect_not "MaskLasso##held.mask.lasso"
+key escape
+
+# Ctrl+Shift: the selection brushes. SelectLasso from the brush picker, SelectRect from the stroke picker.
+hold ctrl+shift
+wait 0.1
+expect_text SelectRect
+shot ctrl-shift-held-shelf
+click "##tile.brush"
+wait 0.1
+expect "SelectLasso##held.select.lasso"
+shot ctrl-shift-brush-picker
+click "SelectLasso##held.select.lasso"
+hold none
+expect_value hide_shape == 1
+
+# SelectLasso from the model: Ctrl+Shift keeps the inside, Ctrl+Shift+Alt hides it; same from the background.
+hold ctrl+shift
+drag_path 0.3 0.3 0.7 0.3 0.7 0.7 0.3 0.7
+hold none
+expect_value hidden > 1000
+remember hidden kept
+hold ctrl+shift+alt
+drag_path -0.2 -0.2 0.45 -0.2 0.45 1.2 -0.2 1.2
+hold none
+expect_value hidden > $kept
+click "Visibility"
+click "Show all"
+expect_value hidden == 0
+
+hold ctrl+shift
+click "##tile.stroke"
+wait 0.1
+click "Rect##held.select.rect"
+hold none
+expect_value hide_shape == 2
+# SelectRect from the background, then with Alt from the model.
+hold ctrl+shift
+drag_path -0.2 -0.2 0.5 1.2
+hold none
+expect_value hidden > 1000
+remember hidden kept
+hold ctrl+shift+alt
+drag_path 0.1 0.1 0.3 0.9
+hold none
+expect_value hidden > $kept
+shot select-rect-hidden
+click "Show all"
+
+# Polygroups > Group by UVs: refused without UVs, one group per island after Auto UV.
+click "Polygroups"
+hold ctrl
+hover "Group by UVs##polygroup.uv_groups"
+expect_help "UV island"
+hold none
+click "Group by UVs##polygroup.uv_groups"
+expect_status "no UVs"
+expect_value groups == 1
+click "Texture Map##tool.texture"
+click "Texture Map/Auto UV"
+wait_idle 120
+expect_value uvs == 1
+click "Polygroups"
+click "Group by UVs##polygroup.uv_groups"
+expect_value groups > 1
+expect_value show_polygroups == 1
+shot uv-groups
+key ctrl+z
+expect_value groups == 1