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.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
SelectRect / SelectLasso follow X / Y / Z symmetry like the mask selections (#51 follow-up): hide_rect / hide_lasso take symmetry; one shared symmetry argument parser (also used by Insert); unit and UI tests
islandmedf7e71def98b0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f71bae86..f4dd8ff2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -53,6 +53,8 @@ All notable changes to SculptForge are listed here. The format follows- MaskLasso and MaskRect ignored symmetry (#51): the mirror image of the shape is masked too now, as with maskstrokes. A Ctrl+click on the model with MaskLasso or MaskRect blurs the mask (Ctrl+Alt+click sharpens it), aswith MaskPen; it did nothing. A lasso or rectangle that covers none of the model clears the mask.+- SelectRect and SelectLasso (hide / show) ignored symmetry (#51 follow-up): with X / Y / Z on, the mirror image of+ the shape counts as inside too, as with MaskRect and MaskLasso (`hide_rect` / `hide_lasso symmetry=x`).- macOS (#41): reopening in full screen (restored from the last session, #35) left the menu bar and window buttonsunreachable until another display was clicked; full screen is now entered after the window is on screen.diff --git a/docs/guide/polygroups.md b/docs/guide/polygroups.mdindex 7513135d..b3a4e877 100644--- a/docs/guide/polygroups.md+++ b/docs/guide/polygroups.md@@ -80,6 +80,10 @@ it, including triangles on the far side of the model. A lasso that crosses itselencloses twice. You can press or release <kbd>Alt</kbd> while dragging; what counts is whether it is held whenyou let go.+With symmetry on (**X**, **Y**, **Z** on the top shelf), the mirror image of the shape counts as inside too, as with+the mask selections: keeping the left eye keeps the right one, and hiding one ear hides both+(`hide_rect` / `hide_lasso symmetry=x`).+SculptForge refuses a change that would hide everything, as ZBrush does. Every visibility change is one undostep, so <kbd>Ctrl</kbd>+<kbd>Z</kbd> brings back what you just hid.diff --git a/src/app/PanelPolygroups.cpp b/src/app/PanelPolygroups.cppindex 775df54b..db923f7e 100644--- a/src/app/PanelPolygroups.cpp+++ b/src/app/PanelPolygroups.cpp@@ -48,7 +48,10 @@ void App::polygroupMouseUp() {}// Drag: keep the inside of the rectangle or lasso, or with Alt hide it. A shape around nothing (dragged on// the background) reverses the visibility instead (ZBrush).- if (runSelection("hide_rect", "hide_lasso", {{"inside", alt}}) && !lastCommandOk_ && !alt && doc_.mesh.hasHidden())+ // The mirror image of the shape counts too with X / Y / Z symmetry on, as with MaskLasso / MaskRect (#51).+ const std::string symmetry = std::string(symmetry_.x ? "x" : "") + (symmetry_.y ? "y" : "") + (symmetry_.z ? "z" : "");+ if (runSelection("hide_rect", "hide_lasso", {{"inside", alt}, {"symmetry", symmetry}}) && !lastCommandOk_ && !alt &&+ doc_.mesh.hasHidden())runCommand("invert_visibility");}diff --git a/src/core/Masking.cpp b/src/core/Masking.cppindex 812a5d8b..72857371 100644--- a/src/core/Masking.cpp+++ b/src/core/Masking.cpp@@ -58,8 +58,16 @@ bool repeatPass(Mesh& mesh, int iterations, F next) {return changed;}++float smoothstep01(float e0, float e1, float x) {+ float t = std::clamp((x - e0) / std::max(e1 - e0, 1e-6f), 0.0f, 1.0f);+ return t * t * (3.0f - 2.0f * t);+}++} // namespace+// The "symmetry" argument ("x", "xz" ...) as mirror sign vectors (Sculptor::mirrors); none without it.-bool symmetryArg(const Args& a, std::vector<glm::vec3>& mirrors, std::string& error) {+bool symmetryMirrorsArg(const Args& a, std::vector<glm::vec3>& mirrors, std::string& error) {Symmetry sym{false, false, false};for (char c : argString(a, "symmetry")) {const char l = char(std::tolower(static_cast<unsigned char>(c)));@@ -75,13 +83,6 @@ bool symmetryArg(const Args& a, std::vector<glm::vec3>& mirrors, std::string& erreturn true;}-float smoothstep01(float e0, float e1, float x) {- float t = std::clamp((x - e0) / std::max(e1 - e0, 1e-6f), 0.0f, 1.0f);- return t * t * (3.0f - 2.0f * t);-}--} // namespace-bool maskClear(Mesh& mesh) {if (!mesh.hasMask()) return false;const bool changed = std::any_of(mesh.mask.begin(), mesh.mask.end(), [](float m) { return m != 0.0f; });@@ -331,7 +332,7 @@ void registerMaskingCommands(CommandRegistry& registry) {std::string error;if (!viewProjArg(doc.mesh, a, vp, error) || !shape(a, points, error)) return {false, error};std::vector<glm::vec3> mirrors;- if (!symmetryArg(a, mirrors, error)) return {false, error};+ if (!symmetryMirrorsArg(a, mirrors, error)) return {false, error};const ScreenPolygon polygon(points);const bool unmask = argBool(a, "unmask", false);if (argBool(a, "clear_outside", false) && !shapeCoversMesh(doc.mesh, vp, polygon, mirrors)) {diff --git a/src/core/Masking.h b/src/core/Masking.hindex 336795fe..8102d754 100644--- a/src/core/Masking.h+++ b/src/core/Masking.h@@ -8,11 +8,13 @@// changed. The mask_* commands wrap them with an undo step.#pragma once+#include "core/Commands.h"#include "core/Mesh.h"#include <glm/glm.hpp>#include <cstdint>+#include <string>#include <vector>namespace sf {@@ -55,6 +57,10 @@ bool maskInShape(Mesh& mesh, const glm::mat4& viewProj, const ScreenPolygon& shabool shapeCoversMesh(const Mesh& mesh, const glm::mat4& viewProj, const ScreenPolygon& shape,const std::vector<glm::vec3>& mirrors = {});+// The "symmetry" argument of a command ("x", "xz" ...) as mirror sign vectors (Sculptor::mirrors, the first one+// the identity); just the identity without it. False, saying why, for anything but the axes x, y and z.+bool symmetryMirrorsArg(const Args& a, std::vector<glm::vec3>& mirrors, std::string& error);+// Registers mask_clear, mask_all, mask_invert, mask_blur, mask_sharpen,// mask_grow, mask_shrink, mask_by_cavity, mask_by_polygroup, mask_rect and// mask_lasso.diff --git a/src/core/Polygroups.cpp b/src/core/Polygroups.cppindex 81adb479..b73bbef2 100644--- a/src/core/Polygroups.cpp+++ b/src/core/Polygroups.cpp@@ -3,6 +3,7 @@#include "core/Polygroups.h"#include "core/Commands.h"+#include "core/Masking.h"#include "core/ScreenSelect.h"#include <algorithm>@@ -146,14 +147,18 @@ bool groupExists(const Mesh& m, uint32_t group) {// Hides or keeps the visible triangles by whether their centre projects inside a screen shape.template <class Inside>-std::vector<uint8_t> hiddenByShape(const Mesh& mesh, const glm::mat4& viewProj, Inside inside, bool hideInside) {+std::vector<uint8_t> hiddenByShape(const Mesh& mesh, const glm::mat4& viewProj, Inside inside, bool hideInside,+ const std::vector<glm::vec3>& mirrors) {std::vector<uint8_t> hidden = currentHidden(mesh);for (uint32_t t = 0; t < mesh.triangleCount(); ++t) {if (hidden[t]) continue;const glm::uvec3& tri = mesh.triangles[t];const glm::vec3 c = (mesh.positions[tri.x] + mesh.positions[tri.y] + mesh.positions[tri.z]) / 3.0f;glm::vec2 ndc;- if ((projectToNdc(viewProj, c, ndc) && inside(ndc)) == hideInside) hidden[t] = 1;+ bool in = projectToNdc(viewProj, c, ndc) && inside(ndc);+ for (size_t k = 0; k < mirrors.size() && !in; ++k) // or its mirror image, with symmetry (#51)+ in = mirrors[k] != glm::vec3(1.0f) && projectToNdc(viewProj, c * mirrors[k], ndc) && inside(ndc);+ if (in == hideInside) hidden[t] = 1;}return unlessAllHidden(std::move(hidden));}@@ -257,17 +262,17 @@ std::vector<uint8_t> hiddenInverted(const Mesh& mesh) {}std::vector<uint8_t> hiddenByRect(const Mesh& mesh, const glm::mat4& viewProj, glm::vec2 rectMin, glm::vec2 rectMax,- bool hideInside) {+ bool hideInside, const std::vector<glm::vec3>& mirrors) {const glm::vec2 lo = glm::min(rectMin, rectMax), hi = glm::max(rectMin, rectMax);return hiddenByShape(mesh, viewProj, [&](glm::vec2 p) { return p.x >= lo.x && p.x <= hi.x && p.y >= lo.y && p.y <= hi.y; },- hideInside);+ hideInside, mirrors);}std::vector<uint8_t> hiddenByLasso(const Mesh& mesh, const glm::mat4& viewProj, const std::vector<glm::vec2>& lasso,- bool hideInside) {+ bool hideInside, const std::vector<glm::vec3>& mirrors) {const ScreenPolygon polygon(lasso);- return hiddenByShape(mesh, viewProj, [&](glm::vec2 p) { return polygon.contains(p); }, hideInside);+ return hiddenByShape(mesh, viewProj, [&](glm::vec2 p) { return polygon.contains(p); }, hideInside, mirrors);}bool polygroupIsolated(const Mesh& mesh, uint32_t group) {@@ -430,6 +435,10 @@ void registerPolygroupCommands(CommandRegistry& reg) {return {true, visibleSummary(doc.mesh)};}});+ const ParamSpec symmetryParam{"symmetry", T::String,+ "Mirror axes, e.g. \"x\" or \"xz\": the mirror image of the shape counts as inside "+ "too, as the brushes mirror (#51; default none).",+ false};reg.add({"hide_rect","Rectangle selection (ZBrush Ctrl+Shift+drag): keep the visible triangles inside a screen rectangle and ""hide the rest, or hide the inside instead. Coordinates are normalised (-1..1, y up) in the given view; "@@ -439,16 +448,18 @@ void registerPolygroupCommands(CommandRegistry& reg) {{"x1", T::Number, "Rectangle right (-1..1). Default 1.", false},{"y1", T::Number, "Rectangle top (-1..1). Default 1.", false},{"inside", T::Bool, "Hide the inside instead of the outside (ZBrush: Alt held).", false},- {"view_proj", T::String, "Optional 16 numbers: column-major view-projection matrix.", false}},+ {"view_proj", T::String, "Optional 16 numbers: column-major view-projection matrix.", false},+ symmetryParam},[](Document& doc, const Args& a) -> CommandResult {if (doc.mesh.triangleCount() == 0) return {false, "The mesh is empty"};glm::mat4 vp;std::string error;- if (!viewProjArg(doc.mesh, a, vp, error)) return {false, error};+ std::vector<glm::vec3> mirrors;+ if (!viewProjArg(doc.mesh, a, vp, error) || !symmetryMirrorsArg(a, mirrors, error)) return {false, error};const glm::vec2 lo(float(argNumber(a, "x0", -1)), float(argNumber(a, "y0", -1)));const glm::vec2 hi(float(argNumber(a, "x1", 1)), float(argNumber(a, "y1", 1)));const bool inside = argBool(a, "inside", false);- std::vector<uint8_t> hidden = hiddenByRect(doc.mesh, vp, lo, hi, inside);+ std::vector<uint8_t> hidden = hiddenByRect(doc.mesh, vp, lo, hi, inside, mirrors);if (hidden.empty())return {false, inside ? "That would hide everything" : "Nothing visible inside the rectangle"};commitHidden(doc, hidden, inside ? "Hide Inside" : "Hide Outside");@@ -461,15 +472,19 @@ void registerPolygroupCommands(CommandRegistry& reg) {"view; without a view they span the mesh seen from the front (+Z).",{{"points", T::String, "The lasso: at least 3 points as \"x0 y0 x1 y1 ...\" (-1..1, y up).", true},{"inside", T::Bool, "Hide the inside instead of the outside (ZBrush: Alt held).", false},- {"view_proj", T::String, "Optional 16 numbers: column-major view-projection matrix.", false}},+ {"view_proj", T::String, "Optional 16 numbers: column-major view-projection matrix.", false},+ symmetryParam},[](Document& doc, const Args& a) -> CommandResult {if (doc.mesh.triangleCount() == 0) return {false, "The mesh is empty"};glm::mat4 vp;std::vector<glm::vec2> lasso;std::string error;- if (!viewProjArg(doc.mesh, a, vp, error) || !lassoArg(a, lasso, error)) return {false, error};+ std::vector<glm::vec3> mirrors;+ if (!viewProjArg(doc.mesh, a, vp, error) || !lassoArg(a, lasso, error) ||+ !symmetryMirrorsArg(a, mirrors, error))+ return {false, error};const bool inside = argBool(a, "inside", false);- std::vector<uint8_t> hidden = hiddenByLasso(doc.mesh, vp, lasso, inside);+ std::vector<uint8_t> hidden = hiddenByLasso(doc.mesh, vp, lasso, inside, mirrors);if (hidden.empty())return {false, inside ? "That would hide everything" : "Nothing visible inside the lasso"};commitHidden(doc, hidden, inside ? "Hide Inside" : "Hide Outside");diff --git a/src/core/Polygroups.h b/src/core/Polygroups.hindex e36a2e70..0f035796 100644--- a/src/core/Polygroups.h+++ b/src/core/Polygroups.h@@ -50,12 +50,13 @@ std::vector<uint8_t> hiddenInverted(const Mesh& mesh);// Rectangle selection in normalised device coordinates (-1..1, y up) under// `viewProj`: triangles whose centre projects inside stay visible and the rest// are hidden, or with `hideInside` the inside is hidden instead. Triangles-// behind the camera count as outside.+// behind the camera count as outside. `mirrors` (Sculptor::mirrors of the symmetry): a triangle whose mirror+// image's centre projects inside counts as inside too (#51); empty = none.std::vector<uint8_t> hiddenByRect(const Mesh& mesh, const glm::mat4& viewProj, glm::vec2 rectMin, glm::vec2 rectMax,- bool hideInside);+ bool hideInside, const std::vector<glm::vec3>& mirrors = {});// The same with a lasso: a closed polygon of NDC points (even-odd inside test).std::vector<uint8_t> hiddenByLasso(const Mesh& mesh, const glm::mat4& viewProj, const std::vector<glm::vec2>& lasso,- bool hideInside);+ bool hideInside, const std::vector<glm::vec3>& mirrors = {});// True when every triangle of `group` is visible and no other is.bool polygroupIsolated(const Mesh& mesh, uint32_t group);diff --git a/src/core/SubTools.cpp b/src/core/SubTools.cppindex ba452885..07035f05 100644--- a/src/core/SubTools.cpp+++ b/src/core/SubTools.cpp@@ -4,6 +4,7 @@#include "core/Commands.h"#include "core/Dyntopo.h"+#include "core/Masking.h"#include "core/Multires.h"#include "core/Polygroups.h"#include "core/Primitives.h"@@ -246,14 +247,9 @@ bool normalizedPiece(const Mesh& source, float size, Mesh& out) {// point, +Y along the normal, turned by twist, with mirrored copies for symmetry; merged into the active// SubTool as one new polygroup, one undo step.CommandResult insertPiece(Document& doc, Mesh prim, const Args& a, const std::string& label) {- Symmetry sym{false, false, false};- for (char ch : argString(a, "symmetry")) {- const char l = char(std::tolower(static_cast<unsigned char>(ch)));- if (l == 'x') sym.x = true;- else if (l == 'y') sym.y = true;- else if (l == 'z') sym.z = true;- else return {false, "symmetry takes the axes x, y and z"};- }+ std::vector<glm::vec3> mirrors;+ std::string error;+ if (!symmetryMirrorsArg(a, mirrors, error)) return {false, error};const float size = float(std::max(argNumber(a, "size", 0.2), 1e-4));glm::vec3 n(float(argNumber(a, "nx", 0.0)), float(argNumber(a, "ny", 1.0)), float(argNumber(a, "nz", 0.0)));n = glm::length(n) > 1e-8f ? glm::normalize(n) : glm::vec3(0, 1, 0);@@ -283,7 +279,7 @@ CommandResult insertPiece(Document& doc, Mesh prim, const Args& a, const std::st// (inserted on a plane itself) is left out.std::vector<Mesh> copies;std::vector<glm::vec3> placed{at};- for (const glm::vec3& m : Sculptor::mirrors(sym)) {+ for (const glm::vec3& m : mirrors) {const glm::vec3 centre = at * m;if (std::any_of(placed.begin(), placed.end(),[&](const glm::vec3& p) { return glm::length(centre - p) < size * 0.25f; }))diff --git a/tests/test_polygroups.cpp b/tests/test_polygroups.cppindex 40859de7..11740c84 100644--- a/tests/test_polygroups.cpp+++ b/tests/test_polygroups.cpp@@ -373,3 +373,48 @@ TEST(hidden_geometry_skipped_by_pick_and_brushes) {CHECK(reg.execute(d, "show_all").ok);for (uint32_t v = 0; v < d.mesh.vertexCount() / 2; ++v) CHECK(d.mesh.positions[v] == before[v]);}++TEST(visibility_selection_with_symmetry) {+ // #51 follow-up: with symmetry the mirror image of a SelectRect / SelectLasso counts too, as for the mask ones.+ Document d = makeDoc(makeIcosphere(3));+ CommandRegistry reg;+ const std::string identity = "1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"; // NDC = world+ // Keep a box on the right (x > 0.5) with X symmetry: the matching box on the left stays visible too.+ CHECK(reg.execute(d, "hide_rect", {{"x0", 0.5}, {"y0", -2.0}, {"x1", 2.0}, {"y1", 2.0}, {"view_proj", identity},+ {"symmetry", std::string("x")}}).ok);+ int wrong = 0;+ for (uint32_t t = 0; t < d.mesh.triangleCount(); ++t) {+ const float x = centroid(d.mesh, t).x;+ if (std::abs(std::abs(x) - 0.5f) > 1e-3f && d.mesh.triangleHidden(t) != (std::abs(x) < 0.5f)) ++wrong;+ }+ CHECK(wrong == 0 && hiddenCount(d.mesh) > 0);+ CHECK(reg.execute(d, "undo").ok);++ // Alt (inside): hide the box and its mirror image.+ CHECK(reg.execute(d, "hide_rect", {{"x0", 0.5}, {"y0", -2.0}, {"x1", 2.0}, {"y1", 2.0}, {"view_proj", identity},+ {"inside", true}, {"symmetry", std::string("x")}}).ok);+ wrong = 0;+ for (uint32_t t = 0; t < d.mesh.triangleCount(); ++t) {+ const float x = centroid(d.mesh, t).x;+ if (std::abs(std::abs(x) - 0.5f) > 1e-3f && d.mesh.triangleHidden(t) != (std::abs(x) > 0.5f)) ++wrong;+ }+ CHECK(wrong == 0);+ CHECK(reg.execute(d, "show_all").ok);++ // A lasso on the top (y > 0.5) with Y symmetry keeps the bottom cap as well; without symmetry only the top.+ const std::string top = "-2 0.5 2 0.5 2 2 -2 2";+ CHECK(reg.execute(d, "hide_lasso", {{"points", top}, {"view_proj", identity}, {"symmetry", std::string("y")}}).ok);+ size_t bottomVisible = 0, middleVisible = 0;+ for (uint32_t t = 0; t < d.mesh.triangleCount(); ++t) {+ const float y = centroid(d.mesh, t).y;+ if (y < -0.55f) bottomVisible += !d.mesh.triangleHidden(t);+ if (std::abs(y) < 0.45f) middleVisible += !d.mesh.triangleHidden(t);+ }+ CHECK(bottomVisible > 0 && middleVisible == 0);+ CHECK(reg.execute(d, "undo").ok);+ CHECK(reg.execute(d, "hide_lasso", {{"points", top}, {"view_proj", identity}}).ok);+ bottomVisible = 0;+ for (uint32_t t = 0; t < d.mesh.triangleCount(); ++t) bottomVisible += centroid(d.mesh, t).y < -0.55f && !d.mesh.triangleHidden(t);+ CHECK(bottomVisible == 0);+ CHECK(!reg.execute(d, "hide_rect", {{"symmetry", std::string("w")}}).ok);+}diff --git a/tests/ui/mask_lasso.sfui b/tests/ui/mask_lasso.sfuiindex ba19b2dc..1d704cff 100644--- a/tests/ui/mask_lasso.sfui+++ b/tests/ui/mask_lasso.sfui@@ -153,3 +153,23 @@ key ctrl+zexpect_value hidden == $keptclick "Show all"expect_value hidden == 0++# SelectLasso with symmetry X (#51 follow-up): Ctrl+Shift+Alt+drag hides the inside and its mirror image too, as the+# mask selections do.+expect_value symmetry_x == 0+hold ctrl+shift+alt+drag_path 0.05 0.3 0.3 0.3 0.3 0.7 0.05 0.7+hold none+expect_value hidden > 100+remember hidden one_side+key ctrl+z+expect_value hidden == 0+key x+expect_value symmetry_x == 1+hold ctrl+shift+alt+drag_path 0.05 0.3 0.3 0.3 0.3 0.7 0.05 0.7+hold none+expect_value hidden > $one_side*1.6+shot hide_lasso_symmetry+key ctrl+z+expect_value hidden == 0