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
VDM brush in the app: Brush > Vector Displacement (maps, Load VDM, New VDM Plane, Create VDM, Export EXR), DragDot stroke, VDM in the alpha slot and picker, thumbnails, F3 actions, UI test
islandmed17b1434f1998
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 0957d738..b2a49b92 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -180,6 +180,7 @@ if(SCULPTFORGE_BUILD_APP)src/app/PanelPolygroups.cppsrc/app/Selection.cppsrc/app/PanelBrushes.cpp+ src/app/PanelVdm.cppsrc/app/PanelBrushLibrary.cppsrc/app/PanelBrushGallery.cppsrc/app/PanelPolypaint.cppdiff --git a/src/app/App.cpp b/src/app/App.cppindex 51952133..6bffe22f 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -873,6 +873,10 @@ void App::beginStroke(float x, float y, const RayHit& hit) {dragAnchorHit_ = hit.position;return; // the stamp appears once the drag gives it a size}+ if (strokeType_ == StrokeType::DragDot) {+ dragDotTo(x, y); // one stamp under the cursor, which follows it until release (PanelVdm.cpp)+ return;+ }firstDab(x, y);}@@ -903,6 +907,10 @@ void App::strokeTo(float x, float y) {dragRectTo(x, y);return;}+ if (strokeType_ == StrokeType::DragDot && !strokeMask_) {+ dragDotTo(x, y);+ return;+ }if (strokeType_ == StrokeType::LazyMouse) {const glm::vec2 lazy = lazyMouse_.follow(glm::vec2(x, y));x = lazy.x;@@ -992,6 +1000,7 @@ void App::dabAt(float x, float y, float pressure) {}p.alpha = &doc_.brushAlpha;p.alphaUp = screenUpVector(dabAngle_);+ p.vdm = doc_.brushVdm.get();p.strokeDelta = haveLastDab_ ? hit.position - lastDabHit_ : glm::vec3(0.0f);lastDabHit_ = hit.position;haveLastDab_ = true;@@ -1055,6 +1064,7 @@ void App::runCommand(const std::string& name, const Args& args) {if (r.ok && (name == "subtool_append" || name == "subtool_duplicate") && !onScreen(doc_.mesh.bounds()))camera_.frame(sceneBounds());afterCommand(name, args, r);+ afterVdmCommand(name, r); // the VDM brush after vdm_set / vdm_capture, the top view after vdm_new_planewatchActiveBrush();updateTitle();consoleEcho(name, args, r); // the console shows every command as a script line@@ -1100,6 +1110,9 @@ void App::openPath(const std::string& path) {if (loadReferenceImage(path)) showImageTo3D_ = true;} else if (ext == ".sfbrush") {installBrushFile(path);+ } else if (ext == ".exr" || ext == ".sfvdm") { // a vector displacement map for the VDM brush+ runCommand("vdm_set", {{"path", path}, {"swap_yz", vdmImport_.swapYZ}, {"flip_x", vdmImport_.flipX},+ {"flip_y", vdmImport_.flipY}, {"flip_z", vdmImport_.flipZ}, {"scale", double(vdmImport_.scale)}});} else {runCommand("open", {{"path", path}});}@@ -1272,6 +1285,7 @@ void App::drawUi() {drawBrushGallery();if (showImageTo3D_) drawImageTo3D();pollAlphaFile();+ pollVdm();if (previewLod_ >= 0) {const CanvasRect c = canvasRect();std::string banner = "Previewing LOD" + std::to_string(previewLod_) + " - " +diff --git a/src/app/App.h b/src/app/App.hindex 60a85ca9..37705759 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -357,6 +357,25 @@ private:bool alphaInvert_ = false;std::mutex alphaMutex_;std::string pendingAlphaPath_; // set by the file dialog thread+ // Vector displacement brushes (PanelVdm.cpp, core/Vdm.h): the Brush palette's Vector Displacement section,+ // its file dialogs and actions, DragDot, and the DragRect stroke the VDM brush brings along (as ZBrush's do).+ void dragDotTo(float x, float y);+ bool vdmBrushActive() const { return brush_ == BrushType::Vdm && doc_.activeBrush < 0 && !paintMode_; }+ void drawVdmSection();+ void registerVdmActions();+ void pollVdm(); // every frame: file dialog results, and the stroke follows the brush+ void afterVdmCommand(const std::string& name, const CommandResult& r);+ static void SDLCALL onVdmChosen(void* userdata, const char* const* files, int filter);+ static void SDLCALL onVdmExportChosen(void* userdata, const char* const* files, int filter);+ friend void drawVdmGrid(App&, GridMode);+ std::mutex vdmMutex_;+ std::string pendingVdmPath_, pendingVdmExport_; // set by the file dialog threads+ VdmImportOptions vdmImport_;+ int vdmPlaneRes_ = 256, vdmCaptureSize_ = 256;+ char vdmName_[64] = "My VDM";+ bool vdmStrokeAuto_ = false; // the VDM brush switched the stroke to DragRect+ StrokeType vdmSavedStroke_ = StrokeType::Dots;+ bool vdmWasActive_ = false;// Persistent brush library (PanelBrushLibrary.cpp, core/BrushLibrary.h): the Custom brushes list// with its right-click menu, paste (Ctrl+V), and saving Brush Lab edits a moment after the last change.void initBrushLibrary();diff --git a/src/app/Config.cpp b/src/app/Config.cppindex 73590b9d..2e3c568c 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -358,6 +358,7 @@ void App::initActions() {registerGizmoActions(); // Q W E R: Draw, and the Gizmo 3D's Move, Scale, Rotate (Gizmo.cpp)registerBakeUiActions(); // Tool > Bake (PanelBake.cpp)registerRetopoUiActions(); // Geometry > QRemesh, SubTool > ProjectAll (PanelRetopo.cpp)+ registerVdmActions(); // Brush > Vector Displacement (PanelVdm.cpp)registerPerformanceUiActions(); // Preferences > Performance (PanelPerformance.cpp)registerInputActions(); // ZBrush keys: U I O, Space, L, V, Ctrl+A / I / H / W..., the input style (Input.cpp)diff --git a/src/app/LightBox.cpp b/src/app/LightBox.cppindex e8fc8000..291fa82f 100644--- a/src/app/LightBox.cpp+++ b/src/app/LightBox.cpp@@ -983,7 +983,7 @@ void App::initLightBox() {"(B S T = Standard).",[] { openPicker(Picker::Brush, ImVec2(-1, -1)); });add("ui.picker.stroke", "Stroke picker", ICON_LC_SPLINE, "Stroke", "",- "Pop up the stroke types: Dots, DragRect, Spray and LazyMouse.",+ "Pop up the stroke types: Dots, DragRect, DragDot, Spray and LazyMouse.",[] { openPicker(Picker::Stroke, ImVec2(-1, -1)); });add("ui.picker.alpha", "Alpha picker", ICON_LC_CIRCLE_DASHED, "Alpha", "","Pop up the brush alphas: built-in stamps and images from your library.",diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cppindex 94206887..09ea6c74 100644--- a/src/app/Palettes.cpp+++ b/src/app/Palettes.cpp@@ -165,6 +165,7 @@ void App::drawPalette_Brush() {}}}+ if (subpalette("brush.vdm", "Vector Displacement")) drawVdmSection(); // PanelVdm.cppdrawBrushGrid(*this, GridMode::Palette);}diff --git a/src/app/PanelBrushes.cpp b/src/app/PanelBrushes.cppindex d7631cd6..b0eee034 100644--- a/src/app/PanelBrushes.cpp+++ b/src/app/PanelBrushes.cpp@@ -129,6 +129,7 @@ void App::dragRectTo(float x, float y) {p.focal = focalShift_;p.alpha = &doc_.brushAlpha;p.alphaUp = glm::normalize(q * glm::vec3(drag.x, -drag.y, 0.0f)); // the alpha's top follows the drag+ p.vdm = doc_.brushVdm.get();if (strokePaint_) paintAt(p); // restoreStroke reverted the previous stamp's colours tooif (!strokeSculpt_) return;const BrushRecipe* recipe = strokeRecipe();diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cppindex cf0eda16..54142221 100644--- a/src/app/PanelProject.cpp+++ b/src/app/PanelProject.cpp@@ -231,6 +231,7 @@ void App::storeProjectSettings() {brush.set("pressure_strength", pressureStrength_);brush.set("pressure_size", pressureSize_);brush.set("paint_color", vec3Json(doc_.paintColor));+ brush.set("vdm", doc_.brushVdm ? doc_.brushVdm->name : std::string()); // by name: the map stays in the librarys.set("brush", std::move(brush));Json sym = Json::object();@@ -297,6 +298,8 @@ void App::applyProjectSettings() {readBool(b, "pressure_strength", pressureStrength_);readVec3(b["paint_color"], doc_.paintColor);readBool(b, "pressure_size", pressureSize_);+ if (const int vdm = b["vdm"].isString() ? findVdm(doc_, b["vdm"].asString()) : -1; vdm >= 0)+ doc_.brushVdm = doc_.vdms[size_t(vdm)];}if (const Json& sym = s["symmetry"]; sym.isObject()) {readBool(sym, "x", symmetry_.x);@@ -358,7 +361,7 @@ void App::openPathConfirmed(const std::string& path) {// Images go to the Image to 3D panel and brushes into the library: no scene change.std::string ext = fsPath(path).extension().string();for (auto& c : ext) c = char(std::tolower(static_cast<unsigned char>(c)));- if (Image::isImagePath(path) || ext == ".sfbrush") openPath(path);+ if (Image::isImagePath(path) || ext == ".sfbrush" || ext == ".exr" || ext == ".sfvdm") openPath(path);else confirmDiscard([this, path] { openPath(path); });}diff --git a/src/app/PanelVdm.cpp b/src/app/PanelVdm.cppnew file mode 100644index 00000000..0e03c2b3--- /dev/null+++ b/src/app/PanelVdm.cpp@@ -0,0 +1,229 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Vector displacement brushes (core/Vdm.h) in the app: Brush > Vector Displacement (the maps, loading EXRs,+// the VDM plane and Create VDM, Export EXR), their F3 actions, the DragDot stroke, and the DragRect stroke the+// VDM brush brings along while it is the brush (ZBrush's VDM brushes come set to DragRect).+#include "app/App.h"+#include "app/Ui.h"++#include <IconsLucide.h>++#include <algorithm>+#include <cmath>+#include <filesystem>++namespace sf {++namespace {++const SDL_DialogFileFilter kVdmFilters[] = {{"Vector displacement maps", "exr;sfvdm"}, {"All files", "*"}};+const SDL_DialogFileFilter kExrFilters[] = {{"OpenEXR", "exr"}};++void hint(const char* text) {+ ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));+ ImGui::TextWrapped("%s", text);+ ImGui::PopStyleColor();+}++void actionButton(App& app, const char* id, float width = -1.0f) {+ ui::ActionButton(app, id, ImVec2(width < 0.0f ? ImGui::GetContentRegionAvail().x : width, 0));+}++} // namespace++void SDLCALL App::onVdmChosen(void* userdata, const char* const* files, int) {+ if (!files || !files[0]) return;+ auto* app = static_cast<App*>(userdata);+ std::lock_guard lock(app->vdmMutex_);+ app->pendingVdmPath_ = files[0];+}++void SDLCALL App::onVdmExportChosen(void* userdata, const char* const* files, int) {+ if (!files || !files[0]) return;+ auto* app = static_cast<App*>(userdata);+ std::lock_guard lock(app->vdmMutex_);+ app->pendingVdmExport_ = files[0];+}++void App::registerVdmActions() {+ auto add = [this](const char* id, const char* label, const char* icon, std::function<void()> run,+ std::function<bool()> enabled, const char* description, const char* command) {+ Action a;+ a.id = id;+ a.label = label;+ a.icon = icon;+ a.palette = "Brush > Vector Displacement";+ a.run = std::move(run);+ a.enabled = std::move(enabled);+ a.description = description;+ a.command = command;+ actions_.add(std::move(a));+ };+ add("vdm.load", "Load VDM...", ICON_LC_FOLDER_OPEN,+ [this] { SDL_ShowOpenFileDialog(onVdmChosen, this, window_, kVdmFilters, 2, nullptr, false); }, nullptr,+ "Load a vector displacement map for the VDM brush: a 32- or 16-bit OpenEXR from Blender's VDM Brush Baker (or "+ "any EXR whose RGB are X right, Y up, Z out of the surface, in brush radii) or a .sfvdm. It is kept in your "+ "brush library. You can also drop an .exr on the window.",+ "vdm_set");+ add("vdm.new_plane", "New VDM Plane", ICON_LC_GRID_3X3,+ [this] { runCommand("vdm_new_plane", {{"resolution", double(vdmPlaneRes_)}}); }, nullptr,+ "Add a flat VDM plane to sculpt a new brush on (ZBrush's VDM plane template): seen from the top, its border "+ "masked so it stays put; the other SubTools are hidden. Sculpt anything (overhangs welcome), then Create VDM.",+ "vdm_new_plane");+ add("vdm.create", "Create VDM", ICON_LC_STAMP,+ [this] {+ runCommand("vdm_capture", {{"name", std::string(vdmName_)}, {"resolution", double(vdmCaptureSize_)}});+ },+ [this] { return doc_.mesh.hasUvs(); },+ "Turn the sculpted VDM plane into a vector displacement brush: how far every point moved from the flat grid "+ "becomes the map, saved in your brush library and picked as the VDM brush's map (ZBrush: Create brush from "+ "the VDM plane). Needs the VDM plane (its UVs record where each point started).",+ "vdm_capture");+ add("vdm.export", "Export EXR...", ICON_LC_DOWNLOAD,+ [this] { SDL_ShowSaveFileDialog(onVdmExportChosen, this, window_, kExrFilters, 1, nullptr); },+ [this] { return doc_.brushVdm != nullptr; },+ "Save the VDM brush's map as a 32-bit float OpenEXR, for Blender: add it as the texture of a Draw brush with "+ "Area Plane mapping and Vector Displacement on (Help > User Guide > Sculpting > Vector displacement brushes).",+ "vdm_export");+}++void App::pollVdm() {+ std::string load, save;+ {+ std::lock_guard lock(vdmMutex_);+ load.swap(pendingVdmPath_);+ save.swap(pendingVdmExport_);+ }+ if (!load.empty()) openPath(load); // vdm_set with the import options (App.cpp)+ if (!save.empty()) {+ if (std::filesystem::path(std::u8string(save.begin(), save.end())).extension().empty()) save += ".exr";+ runCommand("vdm_export", {{"path", save}});+ }+ // The VDM brush stamps with DragRect (or DragDot); the stroke picked before comes back with the next brush.+ const bool active = vdmBrushActive();+ if (active && !vdmWasActive_ && strokeType_ != StrokeType::DragRect && strokeType_ != StrokeType::DragDot) {+ vdmSavedStroke_ = strokeType_;+ strokeType_ = StrokeType::DragRect;+ vdmStrokeAuto_ = true;+ } else if (!active && vdmWasActive_) {+ if (vdmStrokeAuto_ && strokeType_ == StrokeType::DragRect) strokeType_ = vdmSavedStroke_;+ vdmStrokeAuto_ = false;+ }+ vdmWasActive_ = active;+}++void App::afterVdmCommand(const std::string& name, const CommandResult& r) {+ if (!r.ok) return;+ if (name == "vdm_set" || name == "vdm_capture") { // a new map: sculpt with it+ brush_ = BrushType::Vdm;+ doc_.activeBrush = -1;+ paintMode_ = false;+ } else if (name == "vdm_new_plane") { // sculpt it from the top, like the map sees it+ camera_.setOrientation(glm::angleAxis(-1.5707963f, glm::vec3(1.0f, 0.0f, 0.0f)));+ camera_.frame(doc_.mesh.bounds());+ }+}++// DragDot: one stamp of the Draw Size under the cursor; dragging slides it over the surface, and it stays where+// the button comes up.+void App::dragDotTo(float x, float y) {+ doc_.sculptor.restoreStroke(doc_.mesh, doc_.bvh);+ RayHit hit;+ if (!pick(x, y, hit)) return;+ const float pressure = strokePressure();+ DabParams p;+ p.center = hit.position;+ p.viewDir = camera_.forward();+ p.radius = radiusPx_ * (pressureSize_ ? std::max(pressure, 0.05f) : 1.0f) *+ camera_.worldPerPixel(hit.position, canvasHeight());+ p.strength = strokeBrush_ == BrushType::Smooth ? smoothStrength_ : strength_;+ p.pressure = pressureStrength_ ? pressure : 1.0f;+ p.invert = strokeInvert_;+ p.frontFacesOnly = frontFacesOnly_;+ p.focal = focalShift_;+ p.alpha = &doc_.brushAlpha;+ p.alphaUp = screenUpVector(0.0f);+ p.vdm = doc_.brushVdm.get();+ lastDabScreen_ = glm::vec2(x, y);+ if (strokePaint_) paintAt(p); // restoreStroke reverted the previous stamp's colours too+ if (!strokeSculpt_) return;+ if (const BrushRecipe* recipe = strokeRecipe()) doc_.sculptor.dabRecipe(doc_.mesh, doc_.bvh, *recipe, p, symmetry_);+ else doc_.sculptor.dab(doc_.mesh, doc_.bvh, strokeBrush_, p, symmetry_);+}++// Brush > Vector Displacement.+void App::drawVdmSection() {+ const float s = uiScale_;+ const std::shared_ptr<const VectorDisplacement>& vdm = doc_.brushVdm;+ // The brush's map, large, with its name and size.+ const float big = std::min(128.0f * s, ImGui::GetContentRegionAvail().x);+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetContentRegionAvail().x - big) * 0.5f);+ const ImVec2 p0 = ImGui::GetCursorScreenPos();+ ImGui::Dummy(ImVec2(big, big));+ ImDrawList* dl = ImGui::GetWindowDrawList();+ dl->AddRectFilled(p0, ImVec2(p0.x + big, p0.y + big), IM_COL32(42, 42, 46, 255), 4.0f * s);+ if (ImTextureID tex = thumbs_.vdm(vdm)) dl->AddImageRounded(tex, p0, ImVec2(p0.x + big, p0.y + big), ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, 4.0f * s);+ if (vdmBrushActive()) dl->AddRect(p0, ImVec2(p0.x + big, p0.y + big), ui::color::accent, 4.0f * s, 0, 2.0f * s);+ if (vdm) {+ const std::string info = vdm->name + " (" + std::to_string(vdm->width) + " px)";+ const ImVec2 size = ImGui::CalcTextSize(info.c_str());+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetContentRegionAvail().x - size.x) * 0.5f);+ ImGui::TextUnformatted(info.c_str());+ }+ if (!vdmBrushActive()) {+ actionButton(*this, "brush.vdm");+ }+ drawVdmGrid(*this, GridMode::Palette);++ ImGui::SeparatorText("Load");+ actionButton(*this, "vdm.load");+ ImGui::Checkbox("Swap Y/Z##vdm", &vdmImport_.swapYZ);+ ui::HelpText("Swap Y/Z", nullptr,+ "For maps that store the surface normal in G instead of B (Y-up apps). Blender's maps and ours need "+ "nothing; ZBrush maps depend on its Vector Displacement Flip options, so try this if a stamp comes "+ "out lying on its side.",+ "Brush > Vector Displacement");+ ImGui::SameLine();+ ImGui::Checkbox("Flip X##vdm", &vdmImport_.flipX);+ ui::HelpText("Flip X", nullptr, "Mirror the map's sideways (R) channel when loading: for a stamp that comes out mirrored.",+ "Brush > Vector Displacement");+ ImGui::SameLine();+ ImGui::Checkbox("Flip Y##vdm", &vdmImport_.flipY);+ ui::HelpText("Flip Y", nullptr, "Mirror the map's up (G) channel when loading: for a stamp that leans the wrong way.",+ "Brush > Vector Displacement");+ ImGui::Checkbox("Flip Z##vdm", &vdmImport_.flipZ);+ ui::HelpText("Flip Z", nullptr, "Negate the map's height (B) when loading: for a map that digs in where it should rise.",+ "Brush > Vector Displacement");+ ImGui::SameLine();+ ImGui::SetNextItemWidth(-1);+ ImGui::SliderFloat("##vdmscale", &vdmImport_.scale, 0.1f, 10.0f, "Scale %.2f", ImGuiSliderFlags_Logarithmic);+ ui::HelpText("Scale", nullptr,+ "Multiply a loaded map's vectors: for maps saved in other units than the brush radius (1 = as stored).",+ "Brush > Vector Displacement");++ ImGui::SeparatorText("Create");+ ImGui::SetNextItemWidth(-1);+ ImGui::SliderInt("##vdmplane", &vdmPlaneRes_, 64, 1024, "Plane Res %d");+ ui::HelpText("Plane Res", nullptr,+ "Quads per side of a new VDM plane. 256 is a good start; divide it (Ctrl+D) for finer detail.",+ "Brush > Vector Displacement");+ actionButton(*this, "vdm.new_plane");+ ImGui::SetNextItemWidth(-1);+ ImGui::InputTextWithHint("##vdmname", "Name of the new VDM", vdmName_, sizeof vdmName_);+ ui::HelpText("VDM name", nullptr, "What Create VDM calls the new map (a map of the same name is replaced).",+ "Brush > Vector Displacement");+ ImGui::SetNextItemWidth(-1);+ ImGui::SliderInt("##vdmsize", &vdmCaptureSize_, 64, 1024, "Map Size %d px");+ ui::HelpText("Map Size", nullptr,+ "Pixels a side of the map Create VDM makes. 256 holds most shapes; 512 for fine detail (Blender suggests "+ "512 or less).",+ "Brush > Vector Displacement");+ actionButton(*this, "vdm.create");+ actionButton(*this, "vdm.export");+ hint("Stamp with DragRect (drag sets size and turn) or DragDot. Z Intensity 50 presses the map at its own size; "+ "Alt digs it in. A VDM moves points sideways, so it needs a dense mesh: divide first, and stamp at the "+ "highest subdivision level.");+}++} // namespace sfdiff --git a/src/app/Pickers.cpp b/src/app/Pickers.cppindex a6eff97c..cb692d04 100644--- a/src/app/Pickers.cpp+++ b/src/app/Pickers.cpp@@ -354,6 +354,9 @@ const char* brushTypeDescription(int type) {return "Raises the surface to one fixed height per stroke; overlapping passes never stack.";case BrushType::Nudge:return "Slides the surface sideways along the stroke without changing its height.";+ case BrushType::Vdm:+ return "Vector displacement: drag out one stamp of a whole 3D shape, overhangs and all (a horn, an ear, "+ "scales). Choose the map in Brush > Vector Displacement or the Alpha picker. Works best on dense meshes.";default:return "";}@@ -690,11 +693,12 @@ void drawBrushGrid(App& app, GridMode mode) {void drawStrokeGrid(App& app, GridMode mode) {const float tile = 64.0f * app.uiScale_;- static const char* const glyphs[] = {ICON_LC_ELLIPSIS, ICON_LC_SQUARE_DASHED_MOUSE_POINTER, ICON_LC_SPRAY_CAN,- ICON_LC_SPLINE_POINTER};+ static const char* const glyphs[] = {ICON_LC_ELLIPSIS, ICON_LC_SQUARE_DASHED_MOUSE_POINTER, ICON_LC_MOUSE_POINTER_2,+ ICON_LC_SPRAY_CAN, ICON_LC_SPLINE_POINTER};static const char* const help[] = {"Even dabs along the path: the classic brush stroke.","Click and drag one stamp: the drag length sets its size and its direction the rotation (great with alphas).",+ "Click and drag one stamp of the brush's Draw Size around the surface; it lands where you let go (great for VDMs).","Scattered dabs of random size and strength, for organic texture.","The brush trails the cursor on a string, for smooth, steady lines.",};@@ -724,7 +728,44 @@ void drawStrokeGrid(App& app, GridMode mode) {}}+void drawVdmGrid(App& app, GridMode mode) {+ const float tile = 64.0f * app.uiScale_;+ const int columns = columnsFor(tile, mode);+ sectionHeader("Vector displacement");+ int column = 0;+ for (size_t i = 0; i < app.doc_.vdms.size(); ++i) {+ const std::shared_ptr<const VectorDisplacement> v = app.doc_.vdms[i];+ tileGrid(column, columns);+ const bool on = app.vdmBrushActive() && app.doc_.brushVdm == v;+ const ImTextureID tex = app.thumbs_.vdm(v);+ const std::string id = v->name + "##vdm" + std::to_string(i);+ if (AssetTile(id.c_str(), tex, ICON_LC_STAMP, v->name, tile, on)) {+ app.doc_.brushVdm = v;+ app.brush_ = BrushType::Vdm;+ app.doc_.activeBrush = -1;+ app.paintMode_ = false;+ app.status_ = "VDM: " + v->name;+ if (mode == GridMode::Popup) closePicker();+ }+ const std::string text = v->builtin ? "Built-in vector displacement map (CC0)." : "Vector displacement map from your library.";+ quickInfo(tex, ICON_LC_STAMP, v->name, text, v->path.empty() ? std::string() : v->path);+ ui::HelpText(v->name.c_str(), nullptr, "Stamp this vector displacement map with the VDM brush (DragRect).",+ "Brush > Vector Displacement");+ if (!v->builtin && ImGui::BeginPopupContextItem()) {+ ImGui::TextDisabled("%s", v->name.c_str());+ ImGui::Separator();+ if (ImGui::MenuItem("Delete##vdm")) app.runCommand("vdm_delete", {{"name", v->name}});+ ImGui::EndPopup();+ }+ }+ AssetTileHoverGlow();+}+void drawAlphaGrid(App& app, GridMode mode) {+ if (app.vdmBrushActive()) {+ drawVdmGrid(app, mode);+ ImGui::Dummy(ImVec2(0, 4));+ }const float tile = 64.0f * app.uiScale_;const int columns = columnsFor(tile, mode);const BrushAlpha& current = app.doc_.brushAlpha;diff --git a/src/app/Pickers.h b/src/app/Pickers.hindex 7b312211..98df8c83 100644--- a/src/app/Pickers.h+++ b/src/app/Pickers.h@@ -31,6 +31,9 @@ void drawBrushGrid(App& app, GridMode mode);void drawAlphaGrid(App& app, GridMode mode);void drawMaterialGrid(App& app, GridMode mode);void drawStrokeGrid(App& app, GridMode mode);+// The VDM brush's maps (built-in and library), reused by Brush > Vector Displacement; picking one makes the VDM+// brush the brush. The Alpha picker shows them first while the VDM brush is the brush.+void drawVdmGrid(App& app, GridMode mode);// One brush of the picker, the LightBox Brush tab and the shelves.struct BrushItem {diff --git a/src/app/Shell.cpp b/src/app/Shell.cppindex 4053a63a..2cf8438b 100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@ -275,6 +275,8 @@ void App::registerShellActions() {"Trim Dynamic: shaves away everything above a plane.","Raises the surface to one fixed height per stroke; overlaps never stack.","Slides the surface sideways along the stroke.",+ "Vector displacement: one DragRect stamps a whole shape with overhangs (horn, ear curl, scales, nostril, or "+ "your own from a VDM plane). Pick the map under Brush > Vector Displacement.",};static_assert(std::size(kBrushHelp) == size_t(BrushType::Count));for (int i = 0; i < int(BrushType::Count); ++i) {@@ -1460,6 +1462,11 @@ void App::drawStrokeTile(const char* id, ImVec2 size) {dl->AddLine(at(0.3f, 0.66f), at(0.7f, 0.34f), col, 1.5f * s);dl->AddTriangleFilled(at(0.7f, 0.34f), at(0.6f, 0.36f), at(0.67f, 0.44f), col);break;+ case StrokeType::DragDot: // one dot slid along a path+ dl->AddCircleFilled(at(0.66f, 0.38f), 6.0f * s, col);+ dl->AddLine(at(0.24f, 0.70f), at(0.58f, 0.44f), IM_COL32(235, 235, 235, 120), 1.2f * s);+ dl->AddCircle(at(0.24f, 0.70f), 4.0f * s, IM_COL32(235, 235, 235, 120), 0, 1.2f * s);+ break;case StrokeType::Spray: {uint32_t seed = 7;for (int i = 0; i < 26; ++i) {@@ -1487,13 +1494,22 @@ void App::drawStrokeTile(const char* id, ImVec2 size) {default: break;}if (clicked) openPicker(Picker::Stroke, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));- ui::HelpText("Stroke", nullptr, "How dabs follow the cursor: Dots, DragRect, Spray or LazyMouse. Click to choose.",+ ui::HelpText("Stroke", nullptr, "How dabs follow the cursor: Dots, DragRect, DragDot, Spray or LazyMouse. Click to choose.","Left shelf");}void App::drawAlphaTile(const char* id, ImVec2 size) {const float s = uiScale_;ImVec2 a, b;+ if (vdmBrushActive() && doc_.brushVdm) { // the VDM brush's 3D alpha (ZBrush shows VDMs in the alpha slot)+ const bool clicked = tileFrame(id, size, fontSmall_, doc_.brushVdm->name, s, a, b);+ if (ImTextureID tex = thumbs_.vdm(doc_.brushVdm))+ ImGui::GetWindowDrawList()->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s),+ ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, 4.0f * s);+ if (clicked) openPicker(Picker::Alpha, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));+ ui::HelpText("VDM", nullptr, "The VDM brush's vector displacement map. Click to pick another.", "Left shelf");+ return;+ }const bool clicked = tileFrame(id, size, fontSmall_, doc_.brushAlpha.name, s, a, b);ImDrawList* dl = ImGui::GetWindowDrawList();ImTextureID tex = thumbs_.alpha(doc_.brushAlpha);diff --git a/src/app/Thumbnails.cpp b/src/app/Thumbnails.cppindex 881bfce5..f626aea4 100644--- a/src/app/Thumbnails.cpp+++ b/src/app/Thumbnails.cpp@@ -167,6 +167,9 @@ std::unique_ptr<Mesh> sculptBrushPreview(const BrushRecipe* recipe, int type, flcase BrushType::Layer:stroke(d, nullptr, bt, planeCurve(), down, 0.34f, 1.0f); // its height scales with the radiusbreak;+ case BrushType::Vdm: // one stamp of the built-in Horn+ stroke(d, nullptr, bt, {glm::vec3(0.0f, 1.0f, 0.1f)}, down, 0.5f, 0.5f, false);+ break;default:stroke(d, nullptr, bt, planeCurve(), down, r, 1.0f);break;@@ -280,6 +283,35 @@ ImTextureID ThumbnailCache::recipe(const BrushRecipe& recipe) {true);}+ImTextureID ThumbnailCache::vdm(const std::shared_ptr<const VectorDisplacement>& vdm) {+ if (!vdm || vdm->empty()) return ImTextureID(0);+ // Name, size and a sparse sample of the vectors (as alpha() does): cheap enough every frame.+ uint64_t h = fnv1a64("vdm|" + vdm->name + "|" + std::to_string(vdm->width) + "x" + std::to_string(vdm->height));+ const size_t n = vdm->vectors.size();+ for (size_t i = 0; i < 97; ++i) {+ const glm::vec3 v = vdm->vectors[i * n / 97];+ h = fnv1a64(std::string_view(reinterpret_cast<const char*>(&v), sizeof v), h);+ }+ return request(+ "vdm|" + hex64(h) + "|" + std::to_string(kThumbnailVersion),+ [vdm] {+ // One stamp on a fine plane, seen from above at an angle (the stamp's top is away from the camera).+ Result r;+ Document d;+ d.setMesh(makePlane(200, 2.6f));+ d.brushVdm = vdm;+ stroke(d, nullptr, BrushType::Vdm, {glm::vec3(0.0f, 1.0f, 0.0f)}, glm::vec3(0.0f, -1.0f, 0.0f), 0.62f,+ 0.5f, false);+ r.mesh = sceneMesh(d);+ r.pitch = -40.0f;+ r.yaw = 20.0f;+ r.distance = 2.3f;+ r.label = "vdm " + vdm->name;+ return r;+ },+ false);+}+ImTextureID ThumbnailCache::alpha(const BrushAlpha& alpha) {// Name, size and a sparse sample of the values: cheap enough to compute every frame.uint64_t h = fnv1a64(alpha.name + "|" + std::to_string(alpha.width) + "x" + std::to_string(alpha.height));diff --git a/src/app/Thumbnails.h b/src/app/Thumbnails.hindex aed2c35c..07907a02 100644--- a/src/app/Thumbnails.h+++ b/src/app/Thumbnails.h@@ -15,6 +15,7 @@#include "core/BrushRecipe.h"#include "core/Image.h"#include "core/Mesh.h"+#include "core/Vdm.h"#include <imgui.h>@@ -44,6 +45,7 @@ public:ImTextureID brush(int brushType); // BrushType, or kPaintBrush (AssetLibrary.h)ImTextureID recipe(const BrushRecipe& recipe);ImTextureID alpha(const BrushAlpha& alpha);+ ImTextureID vdm(const std::shared_ptr<const VectorDisplacement>& vdm); // one stamp of the map on a planeImTextureID material(int matcap); // -1 = StudioImTextureID primitive(int primitive); // Primitive (AssetLibrary.h)// Projects (their embedded thumbnail.png, else rendered once), meshes and images.diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 19e3146f..557801e4 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -68,7 +68,8 @@// 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),-// last_stroke_dabs (dabs of the last finished stroke)+// last_stroke_dabs (dabs of the last finished stroke), stroke_type (0 Dots, 1 DragRect,+// 2 DragDot, 3 Spray, 4 LazyMouse), vdms (VDM brush maps), vdm_files (.sfvdm in the library)// z_intensity, smooth_intensity, rgb_intensity (0-100), focal_shift (-100..100), draw_size,// quickmenu_open, lazy_mouse, input_style (0 ZBrush, 1 SculptForge), brush_type (BrushType// index, -1 for a custom brush or Paint), last_dab_x / last_dab_y (window pixels), paint_r@@ -277,6 +278,8 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "draw_size") return std::round(app_.radiusPx_);if (name == "quickmenu_open") return app_.quickMenu_.open ? 1.0 : 0.0;if (name == "lazy_mouse") return app_.strokeType_ == StrokeType::LazyMouse ? 1.0 : 0.0;+ 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 == "brush_type") return app_.doc_.activeBrush >= 0 || app_.paintMode_ ? -1.0 : double(int(app_.brush_));if (name == "last_dab_x") return app_.lastDabScreen_.x;@@ -329,14 +332,15 @@ double Demo::query(const std::string& name, bool& known) const {}if (name == "user_brushes")return double(std::count_if(doc.brushes.begin(), doc.brushes.end(), [](const BrushRecipe& b) { return isUserLibraryBrush(b); }));- if (name == "library_files") {+ if (name == "library_files" || name == "vdm_files") { // .sfbrush / .sfvdm files in the user library+ const char* ext = name == "vdm_files" ? ".sfvdm" : ".sfbrush";const std::string& dir = brushLibraryPaths().userDir;std::error_code ec;size_t n = 0;if (!dir.empty())for (std::filesystem::directory_iterator it(std::filesystem::path(std::u8string(dir.begin(), dir.end())), ec), end;!ec && it != end; it.increment(ec))- n += it->path().extension() == ".sfbrush";+ n += it->path().extension() == ext;return double(n);}if (name == "masked") {diff --git a/src/core/Stroke.cpp b/src/core/Stroke.cppindex b3d0e22f..47ff2168 100644--- a/src/core/Stroke.cpp+++ b/src/core/Stroke.cpp@@ -11,6 +11,7 @@ const char* strokeTypeName(StrokeType type) {switch (type) {case StrokeType::Dots: return "Dots";case StrokeType::DragRect: return "DragRect";+ case StrokeType::DragDot: return "DragDot";case StrokeType::Spray: return "Spray";case StrokeType::LazyMouse: return "LazyMouse";default: return "?";diff --git a/src/core/Stroke.h b/src/core/Stroke.hindex c2aa377b..5c3cc531 100644--- a/src/core/Stroke.h+++ b/src/core/Stroke.h@@ -15,6 +15,7 @@ namespace sf {enum class StrokeType {Dots, // evenly spaced dabs along the cursor pathDragRect, // click-drag stamps one dab: drag length = size, drag direction = alpha rotation+ DragDot, // click-drag slides one dab of the brush's Draw Size over the surface until releaseSpray, // scattered dabs with random size, strength and rotationLazyMouse, // dabs follow a point dragged behind the cursor on a string (smooth lines)Countdiff --git a/tests/ui/vdm.sfui b/tests/ui/vdm.sfuinew file mode 100644index 00000000..f881d815--- /dev/null+++ b/tests/ui/vdm.sfui@@ -0,0 +1,115 @@+# Vector displacement brushes (Brush > Vector Displacement): pick a built-in VDM, stamp it with DragRect (the drag+# sets size and turn) and DragDot, Alt digs in, undo; the stroke comes back with the next brush; then sculpt a VDM+# plane, Create VDM (saved to the library) and stamp the new brush on the sphere.+expect_value vdm_files == 0+expect_value vdms == 4+run new_sphere subdivisions=6+click "Brush##palette.brush"+click "Brush/##totray"+wait 0.3+click "Vector Displacement##brush.vdm"+expect "Horn##vdm0"+expect "Ear Curl##vdm1"+expect "Scales##vdm2"+expect "Nostril##vdm3"+expect "Load VDM...##vdm.load"+expect "New VDM Plane##vdm.new_plane"+wait_idle 30+shot palette++# Ctrl-hover help on the new controls.+hold ctrl+hover "Swap Y/Z##vdm"+expect_help G instead of B+hover "Create VDM##vdm.create"+expect_help VDM plane+hold none++# Picking a map makes the VDM brush the brush, with DragRect.+expect_value stroke_type == 0+click "Horn##vdm0"+expect_value brush_type == 14+expect_value stroke_type == 1+expect_status VDM: Horn+snapshot+stroke 0.72 0.5 0.8 0.36+expect_value moved > 300+expect_value moved_out > 0+expect_value can_undo == 1+wait_idle 30+shot horn+key ctrl+z+expect_value moved == 0++# The Nostril digs in; Alt turns the Horn into a hole.+click "Nostril##vdm3"+snapshot+stroke 0.7 0.45 0.78 0.45+expect_value moved_out < 0+shot nostril+key ctrl+z+click "Horn##vdm0"+hold alt+stroke 0.7 0.45 0.78 0.45+hold none+expect_value moved_out < 0+key ctrl+z++# DragDot: the stamp has the Draw Size and lands where the drag ends.+click "Scales##vdm2"+expect_status VDM: Scales+click "Stroke##palette.stroke"+click "DragDot##stroke"+key escape+expect_value stroke_type == 2+snapshot+stroke 0.3 0.4 0.62 0.55+expect_value moved > 300+remember last_dab_x dotx+expect_value last_dab_x > 0+shot dragdot+key ctrl+z++# Another brush brings the stroke that was picked before the VDM brush back (DragDot was picked by hand: it stays).+click "Clay##brush.clay"+expect_value stroke_type == 2+click "Stroke##palette.stroke"+click "Dots##stroke"+key escape+click "Horn##vdm0"+expect_value stroke_type == 1+click "Clay##brush.clay"+expect_value stroke_type == 0++# Create VDM: a VDM plane (the sphere is hidden), sculpt it, capture it into the library.+type "##vdmname" "Bump Spike"+click "New VDM Plane##vdm.new_plane"+expect_value subtools == 2+expect_value visible_subtools == 1+expect_value uvs == 1+expect_value masked > 100+expect_value camera_aligned == 1+click "Inflate##brush.inflate"+stroke 0.4 0.45 0.6 0.55+stroke 0.45 0.55 0.6 0.45+wait_idle 30+shot vdm-plane+click "Create VDM##vdm.create"+expect_status Created VDM 'Bump Spike'+expect_value vdm_files == 1+expect_value vdms == 5+expect_value brush_type == 14+expect "Bump Spike##vdm4"+wait_idle 30+shot created++# Stamp it on the sphere.+run subtool_select index=0+run subtool_visibility index=0 visible=true+run subtool_visibility index=1 visible=false+expect_value active_subtool == 0+snapshot+stroke 0.5 0.5 0.62 0.4+expect_value moved > 100+wait_idle 30+shot stamped