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.

Merge feat/brushes: new brushes, stroke types and alphas

islandmeda1932ab0a40b
diff --cc CMakeLists.txt
index ec8ec752,97e8ddbe..8cf0a580
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@@ -42,7 -41,8 +42,9 @@@ add_library(sculptforge_core STATI
src/core/Splats.cpp
src/core/Voxel.cpp
src/core/EnginePresets.cpp
+ src/core/Masking.cpp
+ src/core/BrushAlpha.cpp
+ src/core/Stroke.cpp
src/io/ObjIO.cpp
src/io/FbxIO.cpp
third_party/ufbx/ufbx.c
@@@ -105,8 -105,7 +107,9 @@@ if(SCULPTFORGE_BUILD_APP
src/app/main.cpp
src/app/App.cpp
src/app/Demo.cpp
+ src/app/PanelMasking.cpp
+ src/app/PanelPolygroups.cpp
+ src/app/PanelBrushes.cpp
src/render/GL.cpp
src/render/Camera.cpp
src/render/Renderer.cpp
diff --cc src/app/App.cpp
index d68ddee8,84420ec3..33e2da15
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@@ -590,6 -591,19 +602,19 @@@ void App::strokeTo(float x, float y)
grabLast_ = p;
return;
}
+ if (strokeBrush_ == BrushType::SnakeHook && !recipe) {
+ snakeHookTo(x, y);
+ return;
+ }
- if (strokeType_ == StrokeType::DragRect) {
++ if (strokeType_ == StrokeType::DragRect && !strokeMask_) { // mask strokes paint dots
+ dragRectTo(x, y);
+ return;
+ }
+ if (strokeType_ == StrokeType::LazyMouse) {
+ const glm::vec2 lazy = lazyMouse_.follow(glm::vec2(x, y));
+ x = lazy.x;
+ y = lazy.y;
+ }
// Place dabs at even screen-space spacing along the cursor path.
const float spacing = std::max(1.0f, radiusPx_ * (recipe ? recipe->spacing : 0.15f));
@@@ -634,15 -658,12 +669,17 @@@ void App::dabAt(float x, float y)
p.pressure = pressureStrength_ ? pressure : 1.0f;
p.invert = strokeInvert_;
p.frontFacesOnly = frontFacesOnly_;
+ if (strokeMask_) {
+ p.strength = maskStrength_;
+ doc_.sculptor.dabMask(doc_.mesh, doc_.bvh, p, symmetry_);
+ return;
+ }
+ p.alpha = &doc_.brushAlpha;
+ p.alphaUp = screenUpVector(dabAngle_);
+ p.strokeDelta = haveLastDab_ ? hit.position - lastDabHit_ : glm::vec3(0.0f);
+ lastDabHit_ = hit.position;
+ haveLastDab_ = true;
if (recipe) {
- p.strokeDelta = haveLastDab_ ? hit.position - lastDabHit_ : glm::vec3(0.0f);
- lastDabHit_ = hit.position;
- haveLastDab_ = true;
doc_.sculptor.dabRecipe(doc_.mesh, doc_.bvh, *recipe, p, symmetry_);
return;
}
@@@ -884,17 -903,9 +921,17 @@@ void App::drawUi()
"Smooth Hold Shift while sculpting\n"
"Rotate Left drag on background / right drag\n"
"Pan Alt + left drag background / middle drag\n"
- "Zoom Mouse wheel / Ctrl + left drag background\n"
+ "Zoom Mouse wheel / Ctrl + middle drag\n"
+ " (Ctrl + left drag background when nothing is masked)\n"
+ "Paint mask Hold Ctrl while stroking (Ctrl+Alt erases)\n"
+ "Invert mask Ctrl + click background\n"
+ "Clear mask Ctrl + drag background\n"
+ "Isolate polygroup Ctrl+Shift+click (again: invert)\n"
+ "Hide polygroup Ctrl+Shift+Alt+click\n"
+ "Show all Ctrl+Shift+click background\n"
+ "Hide outside rect Ctrl+Shift+drag (Alt: inside)\n"
"Brush size [ and ]\n"
-- "Brushes 1-8\n"
++ "Brushes 1-9, 0\n"
"Symmetry X X\n"
"Wireframe W\n"
"Frame model F\n"
diff --cc src/app/App.h
index 32bb1a1e,8246b201..be19435a
--- a/src/app/App.h
+++ b/src/app/App.h
@@@ -230,27 -231,22 +231,43 @@@ private
std::mutex pendingMutex_;
std::vector<PendingFile> pendingFiles_;
+ // Masking (PanelMasking.cpp): Ctrl strokes paint mask, Ctrl+Alt erases;
+ // Ctrl+click on the background inverts it, Ctrl+drag there clears it.
+ void drawMaskingSection();
+ void beginMaskStroke(float x, float y);
+ void maskCanvasMove(float x, float y);
+ void maskCanvasRelease();
+ bool strokeMask_ = false; // the current stroke edits the mask
+ float maskStrength_ = 1.0f;
+ int maskIterations_ = 1;
+ float cavityThreshold_ = 0.02f;
+ int maskGroup_ = 0;
+ float maskCanvasX_ = 0.0f, maskCanvasY_ = 0.0f;
+ bool maskCanvasMoved_ = false;
+ // Polygroups & visibility (PanelPolygroups.cpp): Ctrl+Shift click/drag.
+ bool polygroupMouseDown(float x, float y, SDL_Keymod mod); // true if it took the click
+ void polygroupMouseUp();
+ void drawPolygroupsSection();
+ void drawPolygroupOverlay();
+ bool hideRectActive_ = false;
+ float hideRectX_ = 0.0f, hideRectY_ = 0.0f;
+ float polygroupAngle_ = 30.0f;
+ // Stroke types, alphas and the extra brushes (PanelBrushes.cpp).
+ void drawBrushOptions();
+ void snakeHookTo(float x, float y);
+ void dragRectTo(float x, float y);
+ glm::vec3 screenUpVector(float angle) const; // camera up rotated by `angle` around the view axis
+ static void SDLCALL onAlphaChosen(void* userdata, const char* const* files, int filter);
+ StrokeType strokeType_ = StrokeType::Dots;
+ LazyMouse lazyMouse_;
+ Spray spray_;
+ float sprayScatter_ = 1.0f; // jitter radius as a fraction of brush size
+ glm::vec2 dragAnchor_{0.0f}; // DragRect: where the click landed (window pixels)
+ glm::vec3 dragAnchorHit_{0.0f};
+ float dabRadiusScale_ = 1.0f, dabStrengthScale_ = 1.0f, dabAngle_ = 0.0f; // per-dab overrides
+ bool alphaInvert_ = false;
+ std::mutex alphaMutex_;
+ std::string pendingAlphaPath_; // set by the file dialog thread
};
} // namespace sf
diff --cc src/app/PanelMasking.cpp
index fbeea803,00000000..20794a5c
mode 100644,000000..100644
--- a/src/app/PanelMasking.cpp
+++ b/src/app/PanelMasking.cpp
@@@ -1,94 -1,0 +1,95 @@@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// Masking: Ctrl mask strokes, the Ctrl + background gestures and the
+// "Masking" section of the Tools panel. The operations themselves are the
+// mask_* commands (core/Masking.cpp).
+#include "app/App.h"
+
+#include <algorithm>
+#include <cmath>
+
+namespace sf {
+
+namespace {
+
+constexpr float kMaskDragThresholdPx = 4.0f; // movement that turns a Ctrl+click into a drag
+
+bool anyMasked(const Mesh& mesh) {
+ return std::any_of(mesh.mask.begin(), mesh.mask.end(), [](float m) { return m > 0.0f; });
+}
+
+} // namespace
+
+void App::beginMaskStroke(float x, float y) {
+ // Masks are not layered, so the stroke always targets the base (its weight is never 0).
+ strokeInvert_ = (SDL_GetModState() & SDL_KMOD_ALT) != 0; // Ctrl+Alt erases
+ if (!doc_.sculptor.beginStroke(doc_.mesh, strokeInvert_ ? "Unmask" : "Mask", -1)) return;
+ strokeMask_ = true;
+ strokeBrush_ = BrushType::Standard;
+ haveLastDab_ = false;
+ drag_ = Drag::Stroke;
+ lastX_ = x;
+ lastY_ = y;
+ residual_ = 0.0f;
++ lazyMouse_.reset(glm::vec2(x, y));
+ dabAt(x, y);
+}
+
+// ZBrush convention: Ctrl+drag on the background clears the mask. With
+// nothing masked the drag zooms instead, as it did before masking existed.
+void App::maskCanvasMove(float x, float y) {
+ if (maskCanvasMoved_) return;
+ if (std::hypot(x - maskCanvasX_, y - maskCanvasY_) < kMaskDragThresholdPx) return;
+ maskCanvasMoved_ = true;
+ if (anyMasked(doc_.mesh)) runCommand("mask_clear");
+ else drag_ = Drag::Zoom;
+}
+
+void App::maskCanvasRelease() {
+ if (!maskCanvasMoved_) runCommand("mask_invert"); // Ctrl+click on the background
+}
+
+void App::drawMaskingSection() {
+ ImGui::SeparatorText("Masking");
+ ImGui::Checkbox("Show mask", &renderSettings_.showMask);
+ ImGui::SameLine();
+ ImGui::TextDisabled("(Ctrl paints, Ctrl+Alt erases)");
+ ImGui::SetNextItemWidth(-1);
+ ImGui::SliderFloat("##maskstrength", &maskStrength_, 0.01f, 1.0f, "mask strength %.2f");
+
+ const ImGuiStyle& style = ImGui::GetStyle();
+ const float third = (ImGui::GetContentRegionAvail().x - 2 * style.ItemSpacing.x) / 3.0f;
+ const float half = (ImGui::GetContentRegionAvail().x - style.ItemSpacing.x) * 0.5f;
+ if (ImGui::Button("Clear##mask", ImVec2(third, 0))) runCommand("mask_clear");
+ if (ImGui::IsItemHovered()) ImGui::SetTooltip("Unmask everything (Ctrl + drag background)");
+ ImGui::SameLine();
+ if (ImGui::Button("Invert##mask", ImVec2(third, 0))) runCommand("mask_invert");
+ if (ImGui::IsItemHovered()) ImGui::SetTooltip("Ctrl + click background");
+ ImGui::SameLine();
+ if (ImGui::Button("All##mask", ImVec2(third, 0))) runCommand("mask_all");
+
+ const Args passes = {{"iterations", double(maskIterations_)}};
+ if (ImGui::Button("Blur##mask", ImVec2(half, 0))) runCommand("mask_blur", passes);
+ ImGui::SameLine();
+ if (ImGui::Button("Sharpen##mask", ImVec2(half, 0))) runCommand("mask_sharpen", passes);
+ if (ImGui::Button("Grow##mask", ImVec2(half, 0))) runCommand("mask_grow", passes);
+ ImGui::SameLine();
+ if (ImGui::Button("Shrink##mask", ImVec2(half, 0))) runCommand("mask_shrink", passes);
+ ImGui::SetNextItemWidth(-1);
+ ImGui::SliderInt("##maskpasses", &maskIterations_, 1, 20, "passes %d");
+
+ if (ImGui::Button("By cavity", ImVec2(half, 0)))
+ runCommand("mask_by_cavity", {{"strength", double(maskStrength_)}, {"threshold", double(cavityThreshold_)}});
+ if (ImGui::IsItemHovered()) ImGui::SetTooltip("Mask creases and folds (replaces the mask; uses the mask strength)");
+ ImGui::SameLine();
+ ImGui::SetNextItemWidth(-1);
+ ImGui::SliderFloat("##cavitythreshold", &cavityThreshold_, -0.2f, 0.5f, "threshold %.2f");
+ if (ImGui::Button("By polygroup", ImVec2(half, 0))) runCommand("mask_by_polygroup", {{"index", double(maskGroup_)}});
+ if (ImGui::IsItemHovered()) ImGui::SetTooltip("Mask one polygroup (replaces the mask)");
+ ImGui::SameLine();
+ ImGui::SetNextItemWidth(-1);
+ if (ImGui::InputInt("##maskgroup", &maskGroup_)) maskGroup_ = std::max(0, maskGroup_);
+}
+
+} // namespace sf
diff --cc src/core/Sculpt.h
index ee1b7496,020d8bbd..1b37670b
--- a/src/core/Sculpt.h
+++ b/src/core/Sculpt.h
@@@ -98,11 -115,13 +115,19 @@@ private
std::vector<GrabEntry> grab_;
std::vector<uint32_t> grabVerts_;
+ // Layer brush: per-stroke height already applied to each vertex.
+ void prepareLayer(const Mesh& mesh, float height);
+ std::vector<uint32_t> layerStamp_;
+ std::vector<float> layerDone_;
+ std::vector<glm::vec3> layerDir_;
+ uint32_t layerEpoch_ = 0, layerSeenStamp_ = 0;
+ float layerHeight_ = 0.0f;
++
+public:
+ // Mask brush (Ctrl in the app; defined in Masking.cpp): raises the mask
+ // under the brush towards 1, or lowers it towards 0 when p.invert is set.
+ // Ignores the existing mask (it edits it) but skips hidden vertices.
+ void dabMask(Mesh& mesh, const BVH& bvh, const DabParams& p, Symmetry sym);
};
} // namespace sf