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
Alternate smooth (#40): letting go of Shift mid-stroke smooths keeping the volume; Smooth keeps volume option
islandmedd6ebf34e4cb6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1c9d8bc3..918255f1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,9 @@ All notable changes to SculptForge are listed here. The format follows### Added- Preferences > Tablet > Mouse mode (relative) (#54): for tablets whose driver is set to mouse mode, the pen movesthe cursor by how far it moves, like a mouse.+- Alternate smooth (#40, as in ZBrush): start a stroke with Shift held, then let go of Shift while still pressing,+ and the rest of the stroke smooths without shrinking the form (a Taubin smooth). Brush > Smooth keeps volume+ makes that the Shift / Smooth brush smooth (letting go of Shift then switches to the plain one).- Ctrl+drag on the background with MaskPen draws a mask rectangle while dragging (#48) and masks what it covers;one that covers none of the model clears the mask, as before (and as in ZBrush, without DynaMesh's remesh).diff --git a/docs/guide/coming-from-zbrush.md b/docs/guide/coming-from-zbrush.mdindex 4a67e416..28902982 100644--- a/docs/guide/coming-from-zbrush.md+++ b/docs/guide/coming-from-zbrush.md@@ -16,7 +16,8 @@ keys and gestures by default; where it has habits of its own, they are kept as awith ZBrush's RightClick Navigation turned on, over the model too. <kbd>F</kbd> frames the model. See[Navigating the view](navigation.md).- **Sculpting modifiers.** <kbd>Alt</kbd> swaps Zadd and Zsub, <kbd>Shift</kbd> smooths (Smooth keeps its own Z- Intensity), <kbd>Shift</kbd> pressed after a stroke starts draws a straight line.+ Intensity; let go of <kbd>Shift</kbd> mid-stroke for the alternate smooth that keeps the volume),+ <kbd>Shift</kbd> pressed after a stroke starts draws a straight line.- **Brush keys.** <kbd>B</kbd> then two letters, with ZBrush's letters: <kbd>B</kbd> <kbd>S</kbd> <kbd>T</kbd>Standard, <kbd>B</kbd> <kbd>C</kbd> <kbd>B</kbd> ClayBuildup, <kbd>B</kbd> <kbd>D</kbd> <kbd>S</kbd>DamStandard, <kbd>B</kbd> <kbd>M</kbd> <kbd>V</kbd> Move, <kbd>B</kbd> <kbd>I</kbd> <kbd>N</kbd> Inflate,diff --git a/docs/guide/sculpting.md b/docs/guide/sculpting.mdindex 9b65a1a8..59c2431b 100644--- a/docs/guide/sculpting.md+++ b/docs/guide/sculpting.md@@ -159,6 +159,20 @@ Smooth keeps a Z Intensity of its own, as in ZBrush, so a gentle Standard strokespeed. Hold <kbd>Shift</kbd> (or pick the Smooth brush) and the Z Intensity slider shows **Smooth Z Intensity**:change it there, or hold <kbd>Shift</kbd> and press <kbd>U</kbd>. It starts at 50.+### Smooth that keeps the volume++The plain smooth evens out bumps by pulling each point towards its neighbours, so with every pass the form+shrinks a little too: a cheek flattens, a sphere gets smaller. The other smooth keeps the volume: it removes the+bumps but leaves the form where it is (a Taubin smooth, one step in and a slightly larger one back out).++- **Alternate smooth**, as in ZBrush: start a stroke with <kbd>Shift</kbd> held, then let go of <kbd>Shift</kbd>+ while still pressing. The rest of the stroke uses the other smooth, and the status line says which.+- **Smooth keeps volume** in the **Brush** palette makes the volume-keeping smooth the one <kbd>Shift</kbd> and+ the Smooth brush use; letting go of <kbd>Shift</kbd> mid-stroke then switches to the plain one. Saved with the+ project.++On a micro level (see [Micro levels](micro-levels.md)) Smooth is always the plain one for now.+## Sculpt, Paint, Zadd, Zsub, Rgb and Frontdiff --git a/src/app/App.cpp b/src/app/App.cppindex 02b6f5e5..202958a8 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -1371,6 +1371,7 @@ void App::beginStroke(float x, float y, const RayHit& hit) {strokeBrush_ = activeBrush();straight_ = {};straight_.shiftAtStart = (inputMods() & SDL_KMOD_SHIFT) != 0;+ strokeAltSmooth_ = false;strokeInvert_ = invertToggle_ != (((inputMods() & SDL_KMOD_ALT) != 0) || (erasing() && eraserAction() == PenAction::Invert));// Shift still smooths geometry while the Paint brush is active (ZBrush behaviour).strokePaint_ = strokeBrush_ != BrushType::Smooth && (paintMode_ || paintRgb_);@@ -1456,6 +1457,12 @@ void App::strokeTo(float x, float y) {pointerLatestAt_ = double(SDL_GetTicksNS()) * 1e-9;penPredictor_.add(pointerLatest_, pointerLatestAt_);}+ // ZBrush's alternate smooth (#40): Shift let go while the stroke it began goes on.+ if (strokeBrush_ == BrushType::Smooth && straight_.shiftAtStart && !strokeAltSmooth_ && !strokeMask_ &&+ !(inputMods() & SDL_KMOD_SHIFT)) {+ strokeAltSmooth_ = true;+ status_ = smoothKeepVolume_ ? "Smooth: plain (Shift let go)" : "Smooth: keeping volume (Shift let go)";+ }if (maskClickPending_) { // Ctrl+press on the model: a drag past the click slop paints the mask after allif (std::hypot(x - maskClickX_, y - maskClickY_) < 4.0f) return;maskClickPending_ = false;@@ -1619,6 +1626,7 @@ void App::dabAt(float x, float y, float pressure) {cam.worldPerPixel(hit.position, dabView_ ? dabView_->canvas.h : canvasHeight()) * dabRadiusScale_;// Smooth keeps its own Z Intensity (ZBrush), whether picked or held with Shift.p.strength = (st.brush == BrushType::Smooth ? st.smoothStrength : st.strength) * dabStrengthScale_;+ p.keepVolume = st.brush == BrushType::Smooth && st.smoothKeepVolume;p.pressure = st.pressureStrength ? pressure : 1.0f;p.invert = st.invert;p.frontFacesOnly = st.frontFacesOnly;diff --git a/src/app/App.h b/src/app/App.hindex 8068514e..8a2653b8 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -259,6 +259,7 @@ private:struct DabSettings {float radiusPx = 60.0f, strength = 0.5f, smoothStrength = 0.5f, focal = 0.0f, maskStrength = 1.0f;float sprayScatter = 1.0f;+ bool smoothKeepVolume = false; // Smooth keeps the volume (smoothKeepVolume_, or the alternate smooth)bool pressureSize = false, pressureStrength = true, invert = false, frontFacesOnly = false;bool mask = false, paint = false, sculpt = true, visible = true;BrushType brush = BrushType::Standard;@@ -1323,6 +1324,10 @@ private:// snapped to 45 degree steps on screen. Returns the point to draw towards.glm::vec2 constrainStroke(float x, float y);float smoothStrength_ = 0.5f; // Smooth's own Z Intensity (Shift+stroke, or the Smooth brush)+ bool smoothKeepVolume_ = false; // Brush > Smooth keeps volume: a Taubin smooth instead of the plain one (#40)+ // ZBrush's alternate smooth (#40): a stroke begun with Shift held that lets go of Shift while still pressing+ // smooths the other way (keeping the volume, or plainly when Smooth keeps volume) for the rest of the stroke.+ bool strokeAltSmooth_ = false;float rgbIntensity_ = 1.0f; // paint strength (ZBrush RGB Intensity, 100 by default)float focalShift_ = 0.0f; // -1..1 (ZBrush Focal Shift -100..100)struct QuickMenu {diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cppindex c5abee2e..e4cad169 100644--- a/src/app/AsyncStroke.cpp+++ b/src/app/AsyncStroke.cpp@@ -310,6 +310,7 @@ App::DabSettings App::dabSettings() const {st.radiusPx = radiusPx_;st.strength = strength_;st.smoothStrength = smoothStrength_;+ st.smoothKeepVolume = smoothKeepVolume_ != strokeAltSmooth_;st.focal = focalShift_;st.maskStrength = maskStrength_;st.sprayScatter = sprayScatter_;diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cppindex 58c24740..7dc00e34 100644--- a/src/app/Palettes.cpp+++ b/src/app/Palettes.cpp@@ -230,6 +230,12 @@ void App::drawPalette_Brush() {ImGui::SameLine();ImGui::Checkbox("Invert (Alt)", &invertToggle_);ui::HelpText("Invert", "Alt", "Brushes subtract instead of add (ZBrush Zsub). Holding Alt flips it for one stroke.", "Brush");+ ImGui::Checkbox("Smooth keeps volume##smooth_keep_volume", &smoothKeepVolume_);+ ui::HelpText("Smooth keeps volume", nullptr,+ "The Smooth brush (and Shift) removes bumps without shrinking the form, instead of the plain smooth "+ "that also flattens it. Either way, let go of Shift while still pressing a Shift-smooth stroke to "+ "switch to the other smooth for the rest of the stroke (ZBrush's alternate smooth).",+ "Brush");if (BrushRecipe* recipe = doc_.activeBrush >= 0 && doc_.activeBrush < int(doc_.brushes.size())? &doc_.brushes[size_t(doc_.activeBrush)]: nullptr) {diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cppindex 47554d17..928a49e6 100644--- a/src/app/PanelProject.cpp+++ b/src/app/PanelProject.cpp@@ -245,6 +245,7 @@ void App::storeProjectSettings() {brush.set("radius_px", double(radiusPx_));brush.set("strength", double(strength_));brush.set("smooth_strength", double(smoothStrength_));+ brush.set("smooth_keep_volume", smoothKeepVolume_);brush.set("rgb_intensity", double(rgbIntensity_));brush.set("focal_shift", double(focalShift_));brush.set("invert", invertToggle_);@@ -341,6 +342,7 @@ void App::applyProjectSettings() {rgbIntensity_ = std::clamp(rgbIntensity_, 0.0f, 1.0f);focalShift_ = std::clamp(focalShift_, -1.0f, 1.0f);readBool(b, "invert", invertToggle_);+ readBool(b, "smooth_keep_volume", smoothKeepVolume_);readBool(b, "front_faces_only", frontFacesOnly_);readBool(b, "pressure_strength", pressureStrength_);readVec3(b["paint_color"], doc_.paintColor);diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex a3514c4b..aefe15ba 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -72,6 +72,8 @@// moved_masked (masked vertices that moved), mask_soft (vertices partly masked),// selection_shown (1 while a rectangle / lasso selection is drawn), symmetry_x,// tablet_mouse_mode (Preferences > Tablet > Mouse mode),+// smooth_keep_volume (Brush > Smooth keeps volume), stroke_keep_volume (1 when Smooth+// dabs keep the volume now: the option, flipped by letting go of Shift mid-stroke),// moved_out (summed movement along the snapshot's normals: > 0 out, < 0 in),// pen_pressure (raw), brush_pressure (after the curve; 1 for the mouse),// stroking (1 while a stroke is open), cursor_x / cursor_y (the brush cursor, pixels),@@ -401,6 +403,8 @@ double Demo::query(const std::string& name, bool& known) const {}// ZBrush feel (Input.cpp): the intensities and Focal Shift as shown (0-100, -100..100).if (name == "z_intensity") return std::round(app_.strength_ * 100.0f);+ if (name == "smooth_keep_volume") return app_.smoothKeepVolume_ ? 1.0 : 0.0;+ if (name == "stroke_keep_volume") return app_.dabSettings().smoothKeepVolume ? 1.0 : 0.0; // (Smooth's dabs)if (name == "smooth_intensity") return std::round(app_.smoothStrength_ * 100.0f);if (name == "rgb_intensity") return std::round(app_.rgbIntensity_ * 100.0f);if (name == "focal_shift") return std::round(app_.focalShift_ * 100.0f);diff --git a/src/core/Sculpt.cpp b/src/core/Sculpt.cppindex b0a445a1..13bf2f0a 100644--- a/src/core/Sculpt.cpp+++ b/src/core/Sculpt.cpp@@ -59,6 +59,9 @@ namespace {glm::vec3 projectOnPlane(const glm::vec3& v, const glm::vec3& n) { return v - n * glm::dot(v, n); }+// Smooth's keep-volume steps (Sculptor::taubinShrink): Taubin's own values, pass band 1/lambda + 1/mu = 0.1.+constexpr float kTaubinLambda = 0.6307f, kTaubinMu = -0.6732f;+// --- Procedural 3D patterns (deterministic, so texture sticks to the surface) ---uint32_t hash3(int x, int y, int z) {@@ -569,6 +572,8 @@ void Sculptor::dabSingle(Mesh& mesh, BVH& bvh, BrushType type, const DabParams&const float strokeLen = glm::length(p.strokeDelta);const glm::vec3 strokeDir = strokeLen > 1e-12f ? p.strokeDelta / strokeLen : glm::vec3(0.0f);if (type == BrushType::Layer) prepareLayer(mesh, r * 0.08f * std::clamp(p.strength, 0.0f, 1.0f));+ const bool keepVolume = type == BrushType::Smooth && p.keepVolume;+ if (keepVolume) taubinShrink(mesh);scratch_.resize(verts_.size());// Each vertex's offset depends only on the positions before the dab (and, for Layer, on its own state).@@ -592,6 +597,18 @@ void Sculptor::dabSingle(Mesh& mesh, BVH& bvh, BrushType type, const DabParams&auto ring = mesh.neighbors(v);if (ring.empty()) break;glm::vec3 avg(0.0f);+ if (keepVolume) {+ // The inflate half of the Taubin step, from the shrunk positions (neighbours outside the brush+ // didn't shrink).+ for (uint32_t n : ring) {+ const auto at = std::lower_bound(shrunkIndex_.begin(), shrunkIndex_.end(), std::make_pair(n, 0u));+ avg += at != shrunkIndex_.end() && at->first == n ? shrunk_[at->second] : pos[n];+ }+ avg /= static_cast<float>(ring.size());+ const glm::vec3 q = shrunk_[i];+ d = (q + kTaubinMu * (avg - q) - x) * std::min(1.0f, s * f);+ break;+ }for (uint32_t n : ring) avg += pos[n];avg /= static_cast<float>(ring.size());d = (avg - x) * std::min(1.0f, s * f);@@ -690,6 +707,29 @@ void Sculptor::dabSingle(Mesh& mesh, BVH& bvh, BrushType type, const DabParams&finishDab(mesh, bvh, clock);}+// Taubin's lambda | mu smoothing ("A signal processing approach to fair surface design", 1995): a Laplacian step+// forward (lambda), then a slightly larger one back (mu < -lambda). Bumps (high frequencies) shrink in both steps;+// the large form (low frequencies) shrinks in the first and grows back in the second, so the volume stays.+void Sculptor::taubinShrink(const Mesh& mesh) {+ const auto& pos = mesh.positions;+ shrunk_.resize(verts_.size());+ shrunkIndex_.resize(verts_.size());+ for (size_t i = 0; i < verts_.size(); ++i) shrunkIndex_[i] = {verts_[i], uint32_t(i)};+ std::sort(shrunkIndex_.begin(), shrunkIndex_.end());+ poolFor(verts_.size(), [&](size_t begin, size_t end) {+ for (size_t i = begin; i < end; ++i) {+ const uint32_t v = verts_[i];+ auto ring = mesh.neighbors(v);+ shrunk_[i] = pos[v];+ if (ring.empty()) continue;+ glm::vec3 avg(0.0f);+ for (uint32_t n : ring) avg += pos[n];+ avg /= static_cast<float>(ring.size());+ shrunk_[i] += kTaubinLambda * (avg - pos[v]);+ }+ });+}+// The BVH after a mirror's dab moved (some of) the vertices its query returned, verts_ (the kernel ran since// `clock`). The next mirror's query needs the new boxes; normals wait until every mirror moved its vertices// (updateDabNormals), so where mirrors overlap they are updated once.diff --git a/src/core/Sculpt.h b/src/core/Sculpt.hindex 258ec4b8..65f43beb 100644--- a/src/core/Sculpt.h+++ b/src/core/Sculpt.h@@ -59,6 +59,9 @@ struct DabParams {glm::vec3 alphaUp{0.0f, 1.0f, 0.0f}; // world direction of the alpha's top edge (screen up, or rotated)float focal = 0.0f; // ZBrush Focal Shift, -1..1 (see brushFalloff); recipes keep their own tipconst VectorDisplacement* vdm = nullptr; // the Vdm brush's map (null = the built-in Horn); top edge = alphaUp+ // Smooth: keep the volume (#40). A Taubin step, one shrink then one inflate, removes bumps as the plain+ // (Laplacian) smooth does without shrinking the form. Not on micro levels (they smooth plainly).+ bool keepVolume = false;};struct Symmetry {@@ -252,6 +255,10 @@ private:bool draft_ = false; // this stroke is a draftstd::vector<uint32_t> draftLeaves_; // the BVH leaves its dabs touched (flushDraft)std::vector<glm::vec3> scratch_;+ // Smooth with keepVolume: each brush vertex's shrunk position, and (vertex, index) sorted to look it up.+ void taubinShrink(const Mesh& mesh);+ std::vector<glm::vec3> shrunk_;+ std::vector<std::pair<uint32_t, uint32_t>> shrunkIndex_;std::vector<float> weights_, influence_;std::vector<uint8_t> firstTouch_;std::vector<uint32_t> blockFirst_;diff --git a/tests/test_core.cpp b/tests/test_core.cppindex f2474a59..365a4b62 100644--- a/tests/test_core.cpp+++ b/tests/test_core.cpp@@ -145,6 +145,61 @@ TEST(smooth_reduces_noise) {CHECK(spread() < before * 0.5f);}+TEST(smooth_keep_volume_keeps_volume) {+ // #40: the plain (Laplacian) Smooth shrinks a sphere; with keepVolume (a Taubin step) it barely changes the+ // volume, yet still removes bumps.+ auto volume = [](const Mesh& m) {+ double v = 0.0;+ for (const glm::uvec3& t : m.triangles)+ v += double(glm::dot(m.positions[t.x], glm::cross(m.positions[t.y], m.positions[t.z]))) / 6.0;+ return v;+ };+ auto spread = [](const Mesh& m) { // roughness: mean distance of each vertex from its neighbours' average+ double sum = 0.0;+ for (uint32_t v = 0; v < m.vertexCount(); ++v) {+ glm::vec3 avg(0.0f);+ for (uint32_t u : m.neighbors(v)) avg += m.positions[u];+ avg /= float(m.neighbors(v).size());+ sum += glm::distance(avg, m.positions[v]);+ }+ return sum / double(m.vertexCount());+ };+ auto smoothed = [&](bool keepVolume, bool noisy, double& volumeBefore, double& spreadBefore) {+ Document d = makeDoc(makeIcosphere(4));+ if (noisy)+ for (size_t i = 0; i < d.mesh.vertexCount(); ++i)+ d.mesh.positions[i] *= 1.0f + 0.04f * (float((i * 2654435761u) % 7) / 7.0f - 0.5f);+ d.mesh.recomputeAllNormals();+ d.bvh.build(d.mesh);+ volumeBefore = volume(d.mesh);+ spreadBefore = spread(d.mesh);+ DabParams p;+ p.radius = 3.0f; // the whole sphere, at full strength in the middle+ p.strength = 1.0f;+ p.keepVolume = keepVolume;+ d.sculptor.beginStroke(d.mesh, "Smooth");+ for (int i = 0; i < 20; ++i) {+ p.center = glm::vec3(0, 0, i % 2 ? -1.0f : 1.0f);+ p.viewDir = -p.center;+ d.sculptor.dab(d.mesh, d.bvh, BrushType::Smooth, p, Symmetry{false, false, false});+ }+ d.sculptor.endStroke();+ return d.mesh;+ };+ double v0 = 0.0, s0 = 0.0;+ const Mesh plain = smoothed(false, false, v0, s0);+ const double plainLoss = (v0 - volume(plain)) / v0;+ const Mesh kept = smoothed(true, false, v0, s0);+ const double keptChange = std::abs(volume(kept) - v0) / v0;+ std::printf(" sphere volume change: plain %.2f%%, keep volume %.2f%%\n", 100.0 * plainLoss, 100.0 * keptChange);+ CHECK(plainLoss > 0.02); // the Laplacian shrinks the sphere noticeably+ CHECK(keptChange < plainLoss * 0.25); // the Taubin step keeps (nearly) all of it+ // It still smooths: the bumps of a noisy sphere mostly go.+ const Mesh noisy = smoothed(true, true, v0, s0);+ CHECK(spread(noisy) < s0 * 0.7);+ CHECK(std::abs(volume(noisy) - v0) / v0 < 0.02);+}+TEST(move_brush_drags_region) {Document d = makeDoc(makeIcosphere(4));DabParams p;diff --git a/tests/ui/alternate_smooth.sfui b/tests/ui/alternate_smooth.sfuinew file mode 100644index 00000000..85049fad--- /dev/null+++ b/tests/ui/alternate_smooth.sfui@@ -0,0 +1,73 @@+# Alternate smooth (#40, ZBrush): a stroke begun with Shift held smooths plainly (the sphere shrinks under it);+# letting go of Shift while still pressing switches to the smooth that keeps the volume for the rest of the+# stroke. Brush > Smooth keeps volume makes that the Shift smooth, and letting go then switches to the plain one.+run new_sphere subdivisions=5+expect_value smooth_keep_volume == 0+snapshot++# Shift held all along: the plain smooth pulls the surface in.+hold shift+drag_path 0.3 0.35 0.35 0.35 keep+expect_value stroking == 1+expect_value stroke_keep_volume == 0+drag_path 0.35 0.35 0.7 0.35 0.7 0.65 0.3 0.65 0.3 0.4 keep+expect_value stroke_keep_volume == 0+release+hold none+expect_value moved_out < 0+remember moved_out plain+expect_value can_undo == 1+key ctrl+z+expect_value moved == 0++# The same stroke, letting go of Shift just after it starts: the rest keeps the volume.+hold shift+drag_path 0.3 0.35 0.35 0.35 keep+expect_value stroke_keep_volume == 0+hold none+drag_path 0.35 0.35 0.7 0.35 0.7 0.65 0.3 0.65 0.3 0.4 keep+expect_value stroking == 1+expect_value stroke_keep_volume == 1+expect_status keeping volume+release+expect_value moved > 100+expect_value moved_out > $plain*0.3+remember moved_out alternate+key ctrl+z+expect_value moved == 0+# The next stroke starts plain again.+hold shift+drag_path 0.3 0.35 0.35 0.35 keep+expect_value stroke_keep_volume == 0+release+hold none+key ctrl+z++# Brush > Smooth keeps volume: Shift smooths keeping the volume, and letting go of Shift switches to the plain one.+click "Brush##palette.brush"+click "Brush/##totray"+wait 0.3+hold ctrl+hover "Smooth keeps volume##smooth_keep_volume"+expect_help without shrinking+hold none+click "Smooth keeps volume##smooth_keep_volume"+expect_value smooth_keep_volume == 1+hold shift+drag_path 0.3 0.35 0.35 0.35 keep+drag_path 0.35 0.35 0.7 0.35 0.7 0.65 0.3 0.65 0.3 0.4 keep+expect_value stroke_keep_volume == 1+release+hold none+expect_value moved_out > $plain*0.3+key ctrl+z+hold shift+drag_path 0.3 0.35 0.35 0.35 keep+hold none+drag_path 0.35 0.35 0.7 0.35 0.7 0.65 0.3 0.65 0.3 0.4 keep+expect_value stroke_keep_volume == 0+release+expect_value moved_out < $alternate+key ctrl+z+click "Smooth keeps volume##smooth_keep_volume"+expect_value smooth_keep_volume == 0