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
Shift+Alt+click a SubTool selects and frames it (ZBrush); unit test for Focal Shift's falloff
islandmed69a5f15ab9e3
diff --git a/src/app/App.cpp b/src/app/App.cppindex c595140c..a126150d 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -684,9 +684,13 @@ void App::onMouseDown(float x, float y, Uint8 button) {if (maskSelectMouseDown(x, y, mod)) return;if (gizmoMouseDown(x, y, mod)) return; // Gizmo 3D handles, pivot clicks (Gizmo.cpp)// Alt+click on another SubTool selects it (ZBrush); Alt+drag stays an inverted stroke or a pan.- if ((mod & SDL_KMOD_ALT) && !ctrlDown(mod) && !(mod & SDL_KMOD_SHIFT) && doc_.subtoolCount() > 1) {+ // 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);+ if ((mod & SDL_KMOD_ALT) && !ctrlDown(mod) && (frameClick || !(mod & SDL_KMOD_SHIFT)) &&+ (doc_.subtoolCount() > 1 || frameClick)) {const int target = pickSubtool(x, y);- if (target >= 0 && target != doc_.activeSubtool) {+ subtoolClickFrame_ = frameClick;+ if (target >= 0 && (target != doc_.activeSubtool || frameClick)) {drag_ = Drag::SubToolClick;subtoolClickTarget_ = target;subtoolClickX_ = x;diff --git a/src/app/App.h b/src/app/App.hindex 57b63dd1..9481bd70 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -570,6 +570,7 @@ private:void subtoolClickMove(float x, float y); // Alt press on another SubTool: dragging turns it into a strokevoid subtoolClickRelease(); // ... and releasing without dragging selects itint subtoolClickTarget_ = -1;+ bool subtoolClickFrame_ = false; // Shift+Alt+click: frame the SubTool as wellfloat subtoolClickX_ = 0.0f, subtoolClickY_ = 0.0f;uint32_t renamingSubtool_ = 0; // SubTool id being renamed inline (0: none)uint32_t listedActiveSubtool_ = 0; // the list scrolls to the active SubTool when it changesdiff --git a/src/app/PanelSubTools.cpp b/src/app/PanelSubTools.cppindex 6db1a726..d5476f08 100644--- a/src/app/PanelSubTools.cpp+++ b/src/app/PanelSubTools.cpp@@ -103,9 +103,12 @@ void App::subtoolClickMove(float x, float y) {}void App::subtoolClickRelease() {- if (subtoolClickTarget_ >= 0 && subtoolClickTarget_ < doc_.subtoolCount())- runCommand("subtool_select", {{"index", double(subtoolClickTarget_)}});+ if (subtoolClickTarget_ >= 0 && subtoolClickTarget_ < doc_.subtoolCount()) {+ if (subtoolClickTarget_ != doc_.activeSubtool) runCommand("subtool_select", {{"index", double(subtoolClickTarget_)}});+ if (subtoolClickFrame_) camera_.frame(doc_.mesh.bounds()); // Shift+Alt+click: frame it too+ }subtoolClickTarget_ = -1;+ subtoolClickFrame_ = false;}void App::drawSubToolsContents() {diff --git a/tests/test_brushes.cpp b/tests/test_brushes.cppindex e2c2540c..3ea24aa7 100644--- a/tests/test_brushes.cpp+++ b/tests/test_brushes.cpp@@ -83,6 +83,35 @@ TEST(round_alpha_leaves_existing_brushes_unchanged) {CHECK(std::abs(d.mesh.positions[nearest(d.mesh, glm::vec3(0))].y - 0.3f * 0.06f * 0.5f) < 1e-5f);}+// ZBrush Focal Shift: 0 leaves the falloff (and so every brush) exactly as before; below 0 the tip is broader+// and harder, above 0 a softer point; the cursor's inner ring sits where the falloff is one half.+TEST(focal_shift_shapes_the_falloff) {+ for (float d : {0.0f, 0.1f, 0.33f, 0.5f, 0.77f, 1.0f}) {+ const float t = std::clamp(1.0f - d, 0.0f, 1.0f);+ CHECK(brushFalloff(d, 1.0f, 0.0f) == t * t * (3.0f - 2.0f * t));+ CHECK(brushFalloff(d, 1.0f, -0.6f) >= brushFalloff(d, 1.0f));+ CHECK(brushFalloff(d, 1.0f, 0.6f) <= brushFalloff(d, 1.0f));+ }+ CHECK(brushFalloff(0.0f, 1.0f, 0.8f) == 1.0f);+ CHECK(brushFalloff(1.0f, 1.0f, -0.8f) == 0.0f);+ for (float f : {-1.0f, -0.4f, 0.0f, 0.5f, 1.0f})+ CHECK(std::abs(brushFalloff(focalRingFraction(f), 1.0f, f) - 0.5f) < 1e-4f);+ CHECK(std::abs(focalRingFraction(0.0f) - 0.5f) < 1e-6f);+ CHECK(focalRingFraction(-0.5f) > 0.5f && focalRingFraction(0.5f) < 0.5f);++ // On a brush: focal 0 is bit-identical to no focal at all; a soft point raises less away from the centre.+ Document a = planeDoc(), b = planeDoc(), c = planeDoc();+ DabParams p = dabAt(glm::vec3(0.0f));+ stroke(a, BrushType::Standard, p);+ p.focal = 0.0f;+ stroke(b, BrushType::Standard, p);+ CHECK(a.mesh.positions == b.mesh.positions);+ p.focal = 0.7f;+ stroke(c, BrushType::Standard, p);+ const uint32_t off = nearest(c.mesh, glm::vec3(0.15f, 0.0f, 0.0f));+ CHECK(c.mesh.positions[off].y < a.mesh.positions[off].y);+}+TEST(dam_standard_carves_sharp_pinched_groove) {Document d = planeDoc();const auto before = d.mesh.positions;diff --git a/tests/ui/subtools.sfui b/tests/ui/subtools.sfuiindex 85b3ec3c..d79d8a15 100644--- a/tests/ui/subtools.sfui+++ b/tests/ui/subtools.sfui@@ -39,6 +39,21 @@ expect_value active_subtool == 0expect_value edited_subtools == 0shot alt-click+# Shift+Alt+click selects a SubTool and frames it (ZBrush): the camera moves in on the Cube.+remember camera_distance far+hold shift+alt+click_subtool Cube+hold none+expect_value active_subtool == 2+expect_value camera_distance < $far+expect_value edited_subtools == 0+shot shift-alt-frame+key f+hold alt+click_subtool Body+hold none+expect_value active_subtool == 0+# A stroke changes only the active SubTool; undo history is per SubTool.click "Clay##brush.clay"stroke 0.3 0.4 0.6 0.6