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 branch 'brush-gallery'

islandmed4e003d4107ca
diff --cc CMakeLists.txt
index c4ca13af,3d378fcc..3a9eae53
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@@ -80,10 -82,7 +83,10 @@@ endif(
# --- Bring-your-own-AI (brush assistant). HTTPS via WinHTTP or libcurl. ---
add_library(sculptforge_ai STATIC src/ai/Http.cpp src/ai/BrushAssistant.cpp src/ai/Generator3D.cpp
- src/ai/ImageTo3DService.cpp src/ai/GradioClient.cpp src/ai/ComfyUI.cpp src/ai/AiCommands.cpp src/link/Socket.cpp
- src/ai/ImageTo3DService.cpp src/ai/GradioClient.cpp src/ai/AiCommands.cpp src/ai/BrushGalleryClient.cpp src/link/Socket.cpp src/link/UnrealLink.cpp)
++ src/ai/ImageTo3DService.cpp src/ai/GradioClient.cpp src/ai/ComfyUI.cpp src/ai/AiCommands.cpp src/ai/BrushGalleryClient.cpp src/link/Socket.cpp
+ src/link/UnrealLink.cpp)
+# Lets a build run from its tree find the bundled ComfyUI workflows (integrations/comfyui/workflows).
+target_compile_definitions(sculptforge_ai PRIVATE SF_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
find_package(Threads REQUIRED)
target_link_libraries(sculptforge_ai PUBLIC sculptforge_core Threads::Threads)
if(WIN32)
@@@ -129,7 -123,7 +132,8 @@@ if(SCULPTFORGE_BUILD_APP
src/app/PanelMasking.cpp
src/app/PanelPolygroups.cpp
src/app/PanelBrushes.cpp
+ src/app/PanelBrushLibrary.cpp
+ src/app/PanelBrushGallery.cpp
src/app/PanelPolypaint.cpp
src/app/PanelGoz.cpp
src/app/PanelProject.cpp
diff --cc src/ai/AiCommands.cpp
index 603fe218,a100d0ea..02dbf2c0
--- a/src/ai/AiCommands.cpp
+++ b/src/ai/AiCommands.cpp
@@@ -2,7 -2,7 +2,8 @@@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "ai/AiCommands.h"
+ #include "ai/BrushGalleryClient.h"
+#include "ai/ComfyUI.h"
#include "ai/ImageTo3DService.h"
#include "core/EnginePresets.h"
#include "core/Voxel.h"
@@@ -15,17 -14,9 +16,18 @@@
namespace sf::ai {
+namespace {
+
+std::optional<uint64_t> comfySeed(const Args& a) {
+ if (!a.contains("seed")) return std::nullopt;
+ return uint64_t(std::max(0.0, argNumber(a, "seed", 0.0)));
+}
+
+} // namespace
+
void registerAiCommands(CommandRegistry& registry, std::function<AiSettings()> settings) {
using T = ParamSpec::Type;
+ registerBrushGalleryCommands(registry); // brush_gallery_search, brush_gallery_install (BrushGalleryClient.cpp)
registry.add({"brush_ai",
"Design a brush from a description. Free by default (a hosted open model, no key); or "
"provider=anthropic (ANTHROPIC_API_KEY), or provider=openai-compatible endpoint=... model=... "
diff --cc src/app/App.cpp
index c1813cae,a459222f..7617ab4c
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@@ -250,8 -230,8 +250,9 @@@ bool App::init(const AppOptions& option
}
void App::shutdown() {
+ flushBrushEdits();
if (refTexture_) gl::DeleteTextures(1, &refTexture_);
+ gallery_.reset(); // its preview textures need the GL context
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();
diff --cc src/app/App.h
index 4d891540,20cc9f50..3191704c
--- a/src/app/App.h
+++ b/src/app/App.h
@@@ -429,19 -373,14 +430,27 @@@ private
// Split by polygroups needs more than one group; counted only when the active mesh changes.
uint64_t splitGroupsKey_ = ~uint64_t(0);
bool splitGroupsPossible_ = false;
+ // Community brushes window (PanelBrushGallery.cpp): browse, search and install shared brushes.
+ void drawBrushGallery(); // also finishes background downloads while the window is closed
+ void refreshBrushGallery();
+ void pollBrushGallery();
+ bool galleryBusy() const; // UI tests: wait_idle
+ static void destroyBrushGallery(struct BrushGalleryState* state);
+ bool showBrushGallery_ = false;
+ std::unique_ptr<struct BrushGalleryState, void (*)(struct BrushGalleryState*)> gallery_{nullptr, &destroyBrushGallery};
+
+ // ---- Shell (A): layout, shelves, palettes, trays, theme ----
+ UiLayout layout_ = standardLayout();
+ // ---- end Shell (A) ----
+
+ // ---- LightBox (B): LightBox, thumbnails, pickers ----
+ LightBox lightbox_;
+ ThumbnailCache thumbs_;
+ // ---- end LightBox (B) ----
+
+ // ---- Help/Console/Config (C): actions, help, command palette, console, config ----
+ ActionRegistry actions_;
+ // ---- end Help/Console/Config (C) ----
};
} // namespace sf
diff --cc src/app/Demo.h
index 041ae50c,80534376..ecb033c7
--- a/src/app/Demo.h
+++ b/src/app/Demo.h
@@@ -114,7 -114,7 +114,7 @@@ private
bool testing_ = false;
std::vector<std::string> failures_;
std::string frameText_, shotRequest_, shotDir_, scriptName_, lineText_;
- std::string scriptDir_; // relative `drop` paths start here
- std::string scriptDir_; // folder of the .sfui script ($SCRIPT_DIR in env steps)
++ std::string scriptDir_; // the .sfui script's folder: relative `drop` paths, $SCRIPT_DIR in env steps
SDL_Keymod held_ = SDL_KMOD_NONE; // modifiers held by `hold` (Ctrl to mask, Ctrl+Shift to hide...)
};
diff --cc src/app/UiTest.cpp
index c910a1c2,b1daf430..8c2e8ecb
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@@ -14,7 -14,7 +14,8 @@@
// drag X0 Y0 X1 Y1 [S] left-drag in window fractions (rectangle hide, sliders...)
// orbit DX DY right-drag on the background, in pixels
// run COMMANDS sculptforge-cli commands, e.g. run new_sphere subdivisions=4
+// drop FILE as if FILE were dropped onto the window (relative to the script's folder)
+ // env NAME VALUE set an environment variable; $SCRIPT_DIR is the script's folder
// wait SECONDS / wait_idle [TIMEOUT] (AI requests and background jobs) / wait_for LABEL [TIMEOUT]
// expect LABEL / expect_not LABEL
// expect_text TEXT / expect_no_text TEXT any text drawn this frame contains TEXT
@@@ -427,12 -411,18 +429,24 @@@ bool Demo::parseStep(int line, const st
} else if (verb == "orbit") {
if (!need(2)) return false;
orbit(num(1, 0), num(2, 0), 0.4f);
+ } else if (verb == "drop") {
+ if (!need(1)) return false;
+ auto file = std::filesystem::path(std::u8string(w[1].begin(), w[1].end()));
+ if (file.is_relative()) file = std::filesystem::path(std::u8string(scriptDir_.begin(), scriptDir_.end())) / file;
+ const auto u8 = file.lexically_normal().u8string();
+ run([this, path = std::string(u8.begin(), u8.end())] { app_.openPathConfirmed(path); });
+ } else if (verb == "env") {
+ if (!need(2)) return false;
+ std::string value = restOf(lineText_, 2);
+ for (size_t at = value.find("$SCRIPT_DIR"); at != std::string::npos; at = value.find("$SCRIPT_DIR", at))
+ value.replace(at, 11, scriptDir_);
+ run([name = w[1], value] {
+ #if defined(_WIN32)
+ _putenv_s(name.c_str(), value.c_str());
+ #else
+ setenv(name.c_str(), value.c_str(), 1);
+ #endif
+ });
} else if (verb == "run") {
if (!need(1)) return false;
std::vector<ScriptStatement> statements;
@@@ -453,7 -443,7 +467,7 @@@
const float timeout = num(1, 120.0f);
steps_.push_back([this, line, timeout](float t) {
const bool idle = !busy(app_.pendingBrush_) && !busy(app_.pendingGenerator_) && !busy(app_.pendingModels_) &&
- !busy(app_.pendingUnreal_) && !busy(app_.pendingComfyCheck_);
- !busy(app_.pendingUnreal_) && !app_.galleryBusy();
++ !busy(app_.pendingUnreal_) && !busy(app_.pendingComfyCheck_) && !app_.galleryBusy();
if (idle) return true;
SDL_Delay(10); // real work runs in real time
if (t > timeout) fail(line, "still busy after " + number(timeout) + " s");
diff --cc src/core/Commands.cpp
index 6d951e1d,7903d68c..8d259f44
--- a/src/core/Commands.cpp
+++ b/src/core/Commands.cpp
@@@ -538,8 -538,76 +539,77 @@@ CommandRegistry::CommandRegistry()
doc.activeBrush = doc.addBrush(std::move(r));
return {true, "Loaded brush '" + doc.brushes[doc.activeBrush].name + "'"};
}});
+ registerBrushLibraryCommands(*this); // brush_install, brush_code, brush_delete, ... (BrushLibrary.cpp)
registerBrushCommands(*this); // brush_set_alpha (BrushAlpha.cpp)
+
+ add({"stroke",
+ "Apply a brush along a path on the active SubTool, like dragging the cursor in the viewport (one undo "
+ "step). Each point is projected onto the surface along the view direction, so points drawn in the "
+ "camera's plane give a screen-space stroke. Used for scripted detailing and brush preview renders.",
+ {{"points", T::String,
+ "World-space path: \"x,y,z x,y,z ...\" (or separated by '|'). One point stamps a single dab.", true},
+ {"brush", T::String,
+ "Custom brush (library name) or built-in brush (Standard, Clay, Crease, Inflate, ...). Default: the "
+ "active brush.",
+ false},
+ {"view", T::String, "Direction the path is projected along, \"x,y,z\" (default 0,0,-1: front view).", false},
+ {"radius", T::Number, "Brush radius in world units (default 4% of the mesh size).", false},
+ {"strength", T::Number, "Strength 0-1 (default 0.5).", false},
+ {"pressure", T::Number, "Constant pen pressure 0-1 (default 1).", false},
+ {"invert", T::Bool, "Invert the brush (carve instead of build, like holding Alt).", false},
+ {"curve", T::Bool, "Smooth curve through the points (default true); false = straight segments.", false},
+ {"spacing", T::Number, "Dab spacing as a fraction of the radius (default: the brush's own).", false},
+ {"symmetry", T::String, "Mirror axes, e.g. \"x\" or \"xz\" (default none).", false},
+ {"seed", T::Number, "Random seed for brush jitter (default 1).", false}},
+ [](Document& doc, const Args& a) -> CommandResult {
+ PathStroke st;
+ std::string err;
+ if (!parsePathPoints(argString(a, "points"), st.points, err)) return {false, err};
+ const std::string view = argString(a, "view");
+ if (!view.empty() && !parseVec3(view, st.view)) return {false, "Bad view '" + view + "' (expected x,y,z)"};
+ st.radius = float(argNumber(a, "radius", 0.0));
+ st.strength = float(argNumber(a, "strength", 0.5));
+ st.pressure = float(argNumber(a, "pressure", 1.0));
+ st.invert = argBool(a, "invert", false);
+ st.curve = argBool(a, "curve", true);
+ st.spacing = float(argNumber(a, "spacing", -1.0));
+ st.seed = uint32_t(std::max(argNumber(a, "seed", 1.0), 0.0));
+ for (char c : argString(a, "symmetry")) {
+ const char l = char(std::tolower(static_cast<unsigned char>(c)));
+ if (l == 'x') st.symmetry.x = true;
+ else if (l == 'y') st.symmetry.y = true;
+ else if (l == 'z') st.symmetry.z = true;
+ else return {false, "symmetry takes the axes x, y and z"};
+ }
+
+ // Resolve the brush: a library recipe (exact name, then any case), then a built-in type.
+ const std::string name = argString(a, "brush");
+ auto lower = [](std::string s) {
+ std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return char(std::tolower(c)); });
+ return s;
+ };
+ const BrushRecipe* recipe = nullptr;
+ BrushType type = BrushType::Standard;
+ if (name.empty()) {
+ if (doc.activeBrush >= 0 && doc.activeBrush < int(doc.brushes.size())) recipe = &doc.brushes[doc.activeBrush];
+ } else {
+ for (const auto& b : doc.brushes)
+ if (b.name == name) recipe = &b;
+ for (const auto& b : doc.brushes)
+ if (!recipe && lower(b.name) == lower(name)) recipe = &b;
+ if (!recipe) {
+ int found = -1;
+ for (int i = 0; i < int(BrushType::Count); ++i)
+ if (lower(brushName(BrushType(i))) == lower(name)) found = i;
+ if (found < 0) return {false, "No such brush: " + name};
+ type = BrushType(found);
+ }
+ }
+ const int dabs = strokePath(doc, recipe, type, st, err);
+ if (dabs < 0) return {false, err};
+ if (dabs == 0) return {false, "The path never crosses the surface (check the points and view)"};
+ return {true, "Stroked " + std::to_string(dabs) + " dabs with " + (recipe ? recipe->name : brushName(type))};
+ }});
add({"splat_info", "Report the loaded Gaussian splats.", {},
[](Document& doc, const Args&) -> CommandResult {