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
AI switch (F5): Preferences > AI > Enable AI features, SF_AI=off / --no-ai, privacy line
islandmed878ce474ea53
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 16064aba..c6535486 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -85,6 +85,12 @@ All notable changes to SculptForge are listed here. The format followsview no longer jumps when the pen comes back into range elsewhere or leaves mid-drag. The active Part changes onlywith the keyboard's Alt and a quick click (not with a pen button set to Alt, a long pen press or quick pen taps),and the status bar says "Active Part: <name> (Alt+click)".+- Turn AI off: **Preferences > AI > Enable AI features** (also asked in the first-run welcome). Off hides AI Brush,+ Generate 3D and their menu, shelf and command palette entries, removes the AI commands from scripts, the CLI and+ the MCP tool list, and stops every AI network call; the MCP server and the offline Relief / Inflate / Stamp stay.+ Saved at once. Studios: `SF_AI=off` (or `--no-ai`) turns it off and locks it. About and the website now say:+ "Your art is never uploaded or used for training. AI features run only when you use them and can be turned off."+## [0.10.8] - 2026-11-02### Fixeddiff --git a/CMakeLists.txt b/CMakeLists.txtindex de49b574..08e7cae0 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -209,7 +209,7 @@ else()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+add_library(sculptforge_ai STATIC src/ai/Http.cpp src/ai/AiPolicy.cpp src/ai/BrushAssistant.cpp src/ai/Generator3D.cppsrc/ai/ImageTo3DService.cpp src/ai/GradioClient.cpp src/ai/ComfyUI.cpp src/ai/AiCommands.cpp src/ai/BrushGalleryClient.cpp src/link/Socket.cppsrc/link/UnrealLink.cpp src/ai/Process.cpp src/ai/SplatTrainer.cpp)# Lets a build run from its tree find the bundled ComfyUI workflows (integrations/comfyui/workflows).@@ -341,6 +341,7 @@ if(SCULPTFORGE_BUILD_APP)src/app/PanelProject.cppsrc/app/PanelSubTools.cppsrc/app/PanelSupport.cpp+ src/app/PanelAi.cppsrc/app/PanelSupportCard.cppsrc/app/WhatsNewPopup.cppsrc/app/PanelExtract.cppdiff --git a/docs/ai-services.md b/docs/ai-services.mdindex 3cfaaff7..98d4b0ab 100644--- a/docs/ai-services.md+++ b/docs/ai-services.md@@ -4,6 +4,17 @@ Every AI feature in SculptForge is **optional and off until you use it**. Sculpttelemetry, no account and no servers of its own. When you use an AI feature, SculptForge talks**directly** to the service you picked; nothing goes anywhere else.+**Your art is never uploaded or used for training. AI features run only when you use them and can be turned off.** Your sculpts stay on your computer; only what you hand an AI feature (a brush description,+or the picture or text you give Generate 3D) goes to the service you picked.++## Turning AI off++**Preferences > AI > Enable AI features** (also asked in the first-run welcome). Off: Brush Lab and+Generate 3D are hidden, their commands (`brush_ai`, `image_to_3d`, `text_to_3d`, `comfyui_check`)+are not registered in the app, `sculptforge-cli`, Python or the MCP tool list, and no AI request is+made. The setting is `"enabled"` in `ai.json`. `SF_AI=off` in the environment (or `--no-ai`) turns+it off and locks it, for studios; `SF_AI=on` turns it on whatever was saved.+## What is sent where| Feature | Service (your choice) | What is sent | Key |diff --git a/docs/guide/brush-lab.md b/docs/guide/brush-lab.mdindex 84f2c9b2..e7781d59 100644--- a/docs/guide/brush-lab.md+++ b/docs/guide/brush-lab.md@@ -20,7 +20,8 @@ with <kbd>Alt</kbd>, <kbd>Shift</kbd>, masks, symmetry, strokes and alphas.Click **AI Brush** on the top shelf, or **AI Brush** at the top of the **Brush** palette. Brush Lab is afloating window; it opens at the top-left corner of the canvas the first time, and you can drag it anywhere.-Click the button again, or the window's close box, to hide it.+Click the button again, or the window's close box, to hide it. Not there? AI features are off: turn them on in+**Preferences > AI** (see [Turning AI off](interface.md#turning-ai-off)).## Design a brushdiff --git a/docs/guide/generate-3d.md b/docs/guide/generate-3d.mdindex 5df4f2b4..4dca5543 100644--- a/docs/guide/generate-3d.md+++ b/docs/guide/generate-3d.md@@ -271,6 +271,8 @@ Without `service=`, commands use the settings you saved in the app. See## Privacy and model licences+- Your art is never uploaded or used for training. AI features run only when you use them and can be turned off. Off (**Preferences > AI**, or `SF_AI=off`) hides Generate 3D; Relief, Inflate and Stamp stay. See+ [Turning AI off](interface.md#turning-ai-off).- SculptForge has no servers of its own and no telemetry. A hosted service receives only the prepared image(or your text) and your key or token, if any.- The free Hugging Face option runs the model authors' own demos; SculptForge does not host or bundle anydiff --git a/docs/guide/interface.md b/docs/guide/interface.mdindex b2d5d8e9..b388ecb7 100644--- a/docs/guide/interface.md+++ b/docs/guide/interface.md@@ -68,6 +68,20 @@ changes nothing. Either way, Preferences > Interface > Look changes it later.In scripts: `ui_look look=forge scheme=tokyo_night layout=sculptforge` (or `look=classic layout=zbrush`).+## Turning AI off++Your art is never uploaded or used for training. AI features run only when you use them and can be turned off.++**Preferences > AI > Enable AI features** turns off everything AI: **AI Brush** (Brush Lab, where you describe a+brush in words) and **Generate 3D** (image or text to a model) leave the shelves, menus and the command palette,+their commands leave scripts, `sculptforge-cli` and the MCP tool list, and SculptForge makes no AI network calls.+The offline image tools (**Relief**, **Inflate**, **Stamp**) and the MCP server stay. The first-run welcome asks+the same question. The choice is saved at once; turn it back on the same way, or search the command palette for+"Enable AI".++Studios can turn it off for everyone with the environment variable `SF_AI=off` (or start with `--no-ai`); the+setting is then locked. See [Studios](studios.md#environment-variables).+## The title stripFrom left to right:diff --git a/docs/guide/studios.md b/docs/guide/studios.mdindex 6f6d9643..e748f941 100644--- a/docs/guide/studios.md+++ b/docs/guide/studios.md@@ -76,6 +76,7 @@ rez-env sculptforge -- sculptforge| Variable | Effect ||---|---|+| `SF_AI` | `off`: every AI feature off and locked (app, `sculptforge-cli`, MCP, Python); `on`: on whatever was saved. `--no-ai` does the same as `off` for one start || `SCULPTFORGE_BRUSH_PATH` | Read-only studio brush folders (`:`-separated, `;` on Windows) || `SCULPTFORGE_STUDIO_BRUSHES` | With the Rez package: appended to `SCULPTFORGE_BRUSH_PATH` || `SCULPTFORGE_BRUSH_GALLERY` | Use another community brush gallery index (a URL or a folder), for example an in-house mirror |diff --git a/docs/guide/whats-new.md b/docs/guide/whats-new.mdindex 230aea77..bcb925be 100644--- a/docs/guide/whats-new.md+++ b/docs/guide/whats-new.md@@ -79,6 +79,9 @@ action: guide:whats-new.mdand the status line tells you. Your own model choice is kept. See [Image and text to 3D](generate-3d.md).- **Generated models arrive as clean quads**: Quad Remesh is now the default, with one subdivision level holdingthe detail, so you can sculpt and subdivide straight away. Voxel remesh and Off are still in **Remesh**.+- **Turn AI off**: **Preferences > AI > Enable AI features** (the welcome asks too). Off hides AI Brush and+ Generate 3D everywhere and SculptForge makes no AI network calls. Your art is never uploaded or used for training. AI features run only when you use them and can be turned off. Studios can set `SF_AI=off`.+ See [The interface](interface.md#turning-ai-off).## Version 0.10.8diff --git a/src/ai/AiCommands.cpp b/src/ai/AiCommands.cppindex 7d4adede..e212ed9f 100644--- a/src/ai/AiCommands.cpp+++ b/src/ai/AiCommands.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: GPL-3.0-or-later#include "ai/AiCommands.h"+#include "ai/AiPolicy.h"#include "ai/BrushGalleryClient.h"#include "ai/ComfyUI.h"#include "ai/ImageTo3DService.h"@@ -66,9 +67,9 @@ CommandResult importGenerated(Document& doc, const Args& a, const GeneratorResul} // namespace-void registerAiCommands(CommandRegistry& registry, std::function<AiSettings()> settings) {+void addAiFeatureCommands(CommandRegistry& registry, std::function<AiSettings()> settings) {using T = ParamSpec::Type;- registerBrushGalleryCommands(registry); // brush_gallery_search, brush_gallery_install (BrushGalleryClient.cpp)+ removeAiFeatureCommands(registry); // never twiceregistry.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=... "@@ -189,6 +190,16 @@ void registerAiCommands(CommandRegistry& registry, std::function<AiSettings()> sif (!comfy::checkServer(url, info, err)) return {false, err};return {true, info.summary() + " at " + url};}});+}++void removeAiFeatureCommands(CommandRegistry& registry) {+ for (const std::string& name : aiCommandNames()) registry.remove(name);+}++void registerAiCommands(CommandRegistry& registry, std::function<AiSettings()> settings) {+ using T = ParamSpec::Type;+ registerBrushGalleryCommands(registry); // brush_gallery_search, brush_gallery_install (BrushGalleryClient.cpp)+ if (aiEnabled()) addAiFeatureCommands(registry, settings);registry.add({"unreal_editors", "List running Unreal Editors that SculptForge can send assets to (remote execution).",{{"network", T::Bool, "Also look on other computers (Unreal needs Multicast TTL 1 and bind address 0.0.0.0).", false}},diff --git a/src/ai/AiCommands.h b/src/ai/AiCommands.hindex 542e37a2..21bd9841 100644--- a/src/ai/AiCommands.h+++ b/src/ai/AiCommands.h@@ -13,7 +13,11 @@namespace sf::ai {-// `settings` is called on every run so the latest saved settings are used.+// `settings` is called on every run so the latest saved settings are used. The AI ones (ai/AiPolicy.h+// aiCommandNames) only while aiEnabled(); the rest (community brushes, Unreal) always.void registerAiCommands(CommandRegistry& registry, std::function<AiSettings()> settings);+// The AI switch at run time (Preferences > AI): adds or removes just the AI commands.+void addAiFeatureCommands(CommandRegistry& registry, std::function<AiSettings()> settings);+void removeAiFeatureCommands(CommandRegistry& registry);} // namespace sf::aidiff --git a/src/ai/AiPolicy.cpp b/src/ai/AiPolicy.cppnew file mode 100644index 00000000..c390d3fc--- /dev/null+++ b/src/ai/AiPolicy.cpp@@ -0,0 +1,59 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+#include "ai/AiPolicy.h"++#include <algorithm>+#include <atomic>+#include <cctype>+#include <cstdlib>++namespace sf::ai {++namespace {+std::atomic<bool> gEnabled{true};+std::atomic<bool> gForcedOff{false};+} // namespace++AiOverride aiEnvOverride() {+ const char* v = std::getenv("SF_AI");+ if (!v) return AiOverride::None;+ std::string s(v);+ std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return char(std::tolower(c)); });+ if (s == "off" || s == "0" || s == "false" || s == "no") return AiOverride::Off;+ if (s == "on" || s == "1" || s == "true" || s == "yes") return AiOverride::On;+ return AiOverride::None;+}++void setAiForcedOff(bool off) { gForcedOff = off; }++bool aiPolicyLocked() { return gForcedOff || aiEnvOverride() != AiOverride::None; }++bool aiFeaturesAllowed(bool saved) {+ if (gForcedOff) return false;+ switch (aiEnvOverride()) {+ case AiOverride::Off: return false;+ case AiOverride::On: return true;+ case AiOverride::None: break;+ }+ return saved;+}++void setAiEnabled(bool on) { gEnabled = on; }+bool aiEnabled() { return gEnabled; }++std::string aiOffError() {+ return aiPolicyLocked() ? "AI features are turned off on this computer (SF_AI=off or --no-ai)"+ : "AI features are off (Preferences > AI > Enable AI features)";+}++const std::vector<std::string>& aiCommandNames() {+ static const std::vector<std::string> names = {"brush_ai", "image_to_3d", "text_to_3d", "comfyui_check"};+ return names;+}++bool isAiCommand(std::string_view name) {+ const auto& n = aiCommandNames();+ return std::find(n.begin(), n.end(), name) != n.end();+}++} // namespace sf::aidiff --git a/src/ai/AiPolicy.h b/src/ai/AiPolicy.hnew file mode 100644index 00000000..b8518be4--- /dev/null+++ b/src/ai/AiPolicy.h@@ -0,0 +1,40 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// The AI switch (Preferences > AI > Enable AI features). Off: the AI commands+// (brush designer, image / text to 3D, ComfyUI) are not registered, so no menu,+// shelf, command palette, script or MCP tool reaches them, and every AI network+// entry point refuses before it sends anything. The rest (community brushes,+// update check, bridges, the MCP server itself) is not AI and stays.+// Studios: SF_AI=off in the environment (or --no-ai) wins over the saved choice.+#pragma once++#include <string>+#include <string_view>+#include <vector>++namespace sf::ai {++inline constexpr const char* kPrivacyLine =+ "Your art is never uploaded or used for training. AI features run only when you use them and can be turned off.";++// SF_AI: "off" / "0" / "false" / "no" = Off, "on" / "1" / "true" / "yes" = On, anything else = None.+enum class AiOverride { None, Off, On };+AiOverride aiEnvOverride();+void setAiForcedOff(bool off); // --no-ai: as SF_AI=off for this process+// True when the environment or --no-ai decides, so the saved choice can't change it.+bool aiPolicyLocked();+// The effective switch: the environment (or --no-ai) wins over the saved preference.+bool aiFeaturesAllowed(bool saved);++// The process-wide gate every AI entry point checks (default on).+void setAiEnabled(bool on);+bool aiEnabled();+// The error AI entry points return while it is off.+std::string aiOffError();++// The commands that exist only while AI is on.+const std::vector<std::string>& aiCommandNames();+bool isAiCommand(std::string_view name);++} // namespace sf::aidiff --git a/src/ai/BrushAssistant.cpp b/src/ai/BrushAssistant.cppindex fc0409d5..a4a9d911 100644--- a/src/ai/BrushAssistant.cpp+++ b/src/ai/BrushAssistant.cpp@@ -1,6 +1,7 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later#include "ai/BrushAssistant.h"+#include "ai/AiPolicy.h"#include "ai/Http.h"#include "core/BrushLibrary.h"@@ -144,6 +145,7 @@ Json AiSettings::toJson() const {j.set("comfyUrl", comfyUrl);j.set("comfyImageWorkflow", comfyImageWorkflow);j.set("comfyTextWorkflow", comfyTextWorkflow);+ j.set("enabled", enabled);return j;}@@ -182,6 +184,7 @@ AiSettings AiSettings::fromJson(const Json& j) {text("comfyUrl", s.comfyUrl);s.comfyImageWorkflow = j["comfyImageWorkflow"].asString();s.comfyTextWorkflow = j["comfyTextWorkflow"].asString();+ s.enabled = j["enabled"].asBool(true);return s;}@@ -381,6 +384,10 @@ std::string modelsUrl(const std::string& chatEndpoint) {std::vector<std::string> listModels(const AiSettings& s, std::string& error) {std::vector<std::string> out;+ if (!aiEnabled()) {+ error = aiOffError();+ return out;+ }HttpResponse r = httpRequest("GET", modelsUrl(s.endpoint), requestHeaders(s), {}, 5);if (!r.error.empty()) {error = "Nothing is answering at " + s.endpoint + " - is Ollama or LM Studio running? (" + r.error + ")";@@ -398,6 +405,10 @@ std::vector<std::string> listModels(const AiSettings& s, std::string& error) {}std::string smallestOllamaModel(std::string& error) {+ if (!aiEnabled()) {+ error = aiOffError();+ return {};+ }HttpResponse r = httpRequest("GET", "http://localhost:11434/api/tags", {}, {}, 2);Json j;if (r.status != 200 || !Json::parse(r.body, j, error)) return {};@@ -415,6 +426,11 @@ std::string smallestOllamaModel(std::string& error) {BrushSuggestion requestBrush(const AiSettings& s, const std::vector<ChatMessage>& history,std::string* rawAssistantJson) {+ if (!aiEnabled()) {+ BrushSuggestion out;+ out.error = aiOffError();+ return out;+ }if (s.provider == AiSettings::Provider::Anthropic && s.resolvedKey().empty()) {BrushSuggestion out;out.error = "No Anthropic API key - add one in AI settings or set ANTHROPIC_API_KEY, or switch to Free.";diff --git a/src/ai/BrushAssistant.h b/src/ai/BrushAssistant.hindex 118678df..67e4999d 100644--- a/src/ai/BrushAssistant.h+++ b/src/ai/BrushAssistant.h@@ -16,6 +16,8 @@namespace sf::ai {struct AiSettings {+ // Preferences > AI > Enable AI features (ai/AiPolicy.h: SF_AI=off wins over it).+ bool enabled = true;// Free: Pollinations' anonymous OpenAI-compatible endpoint (open models, no// key), falling back to a local Ollama if it is running.enum class Provider { Free, Anthropic, OpenAICompatible };diff --git a/src/ai/ComfyUI.cpp b/src/ai/ComfyUI.cppindex 58de05bb..382cf6f3 100644--- a/src/ai/ComfyUI.cpp+++ b/src/ai/ComfyUI.cpp@@ -1,6 +1,7 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later#include "ai/ComfyUI.h"+#include "ai/AiPolicy.h"#include "ai/Http.h"#include "ai/ImageTo3DService.h"@@ -249,6 +250,10 @@ bool parseSystemStats(const Json& stats, ServerInfo& info) {}bool checkServer(const std::string& url, ServerInfo& info, std::string& error, int timeoutSeconds) {+ if (!aiEnabled()) {+ error = aiOffError();+ return false;+ }const std::string base = normalizeUrl(url);HttpResponse r = httpRequest("GET", base + "/system_stats", {}, {}, timeoutSeconds);if (!r.error.empty()) {@@ -569,6 +574,7 @@ int queuePosition(const Json& queue, const std::string& promptId) {GeneratorResult run(const AiSettings& s, const std::string& workflowPath, const std::string& imagePath,const std::string& prompt, const std::string& outputStem, GenerationProgress* p,std::optional<uint64_t> seed) {+ if (!aiEnabled()) return {false, {}, aiOffError()};GeneratorResult result;const bool text = imagePath.empty();const std::string kind = text ? "text" : "image";diff --git a/src/ai/GradioClient.cpp b/src/ai/GradioClient.cppindex 6c88873a..0b3bc408 100644--- a/src/ai/GradioClient.cpp+++ b/src/ai/GradioClient.cpp@@ -2,6 +2,8 @@// SPDX-License-Identifier: GPL-3.0-or-later#include "ai/GradioClient.h"+#include "ai/AiPolicy.h"+#include "ai/Http.h"#include <chrono>@@ -46,6 +48,10 @@ std::vector<std::string> GradioClient::headers(bool json) const {}bool GradioClient::connect(const std::string& spaceUrl, const std::string& token, std::string& error) {+ if (!aiEnabled()) {+ error = aiOffError();+ return false;+ }root_ = spaceUrl;while (!root_.empty() && root_.back() == '/') root_.pop_back();token_ = token;diff --git a/src/ai/Http.cpp b/src/ai/Http.cppindex ca7e8d07..ffb2b43d 100644--- a/src/ai/Http.cpp+++ b/src/ai/Http.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: GPL-3.0-or-later#include "ai/Http.h"+#include <atomic>#include <chrono>#include <random>@@ -16,6 +17,12 @@namespace sf::ai {+namespace {+std::atomic<uint64_t> gRequests{0};+}++uint64_t httpRequestCount() { return gRequests; }+HttpResponse httpRequest(const std::string& method, const std::string& url, const std::vector<std::string>& headers,const std::string& body, int timeoutSeconds) {std::string received;@@ -68,6 +75,7 @@ struct Handle {HttpResponse httpRequestStream(const std::string& method, const std::string& url, const std::vector<std::string>& headers,const std::string& body, int timeoutSeconds,const std::function<bool(const char*, size_t)>& onData) {+ ++gRequests;HttpResponse r;std::wstring wurl = widen(url);URL_COMPONENTS uc{};@@ -151,6 +159,7 @@ size_t writeCallback(char* data, size_t size, size_t count, void* user) {HttpResponse httpRequestStream(const std::string& method, const std::string& url, const std::vector<std::string>& headers,const std::string& body, int timeoutSeconds,const std::function<bool(const char*, size_t)>& onData) {+ ++gRequests;static std::once_flag once;std::call_once(once, [] { curl_global_init(CURL_GLOBAL_DEFAULT); });@@ -190,6 +199,7 @@ HttpResponse httpRequestStream(const std::string& method, const std::string& urlHttpResponse httpRequestStream(const std::string&, const std::string&, const std::vector<std::string>&, const std::string&, int,const std::function<bool(const char*, size_t)>&) {+ ++gRequests;HttpResponse r;r.error = "This build of SculptForge has no HTTP support (libcurl was not found at build time)";return r;diff --git a/src/ai/Http.h b/src/ai/Http.hindex b6ff2d46..8607c3ff 100644--- a/src/ai/Http.h+++ b/src/ai/Http.h@@ -5,6 +5,7 @@// so no extra dependency needs to be shipped. Call from a worker thread.#pragma once+#include <cstdint>#include <functional>#include <string>#include <vector>@@ -38,6 +39,9 @@ struct MultipartField {// Builds the body; `contentTypeHeader` receives the matching "Content-Type: multipart/form-data; boundary=..." header.std::string multipartBody(const std::vector<MultipartField>& fields, std::string& contentTypeHeader);+// Every request this process started (tests: the AI switch sends nothing while it is off).+uint64_t httpRequestCount();+inline HttpResponse httpPostJson(const std::string& url, const std::vector<std::string>& headers, const std::string& body,int timeoutSeconds = 120) {return httpRequest("POST", url, headers, body, timeoutSeconds);diff --git a/src/ai/ImageTo3DService.cpp b/src/ai/ImageTo3DService.cppindex 69537cf4..5803c83b 100644--- a/src/ai/ImageTo3DService.cpp+++ b/src/ai/ImageTo3DService.cpp@@ -1,6 +1,7 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later#include "ai/ImageTo3DService.h"+#include "ai/AiPolicy.h"#include "ai/ComfyUI.h"#include "ai/GradioClient.h"@@ -525,6 +526,7 @@ std::string findModelUrl(const Json& result, std::string* extension) {GeneratorResult generate3D(const AiSettings& s, const std::string& imagePath, const std::string& outputStem,GenerationProgress* progress) {+ if (!aiEnabled()) return {false, {}, aiOffError()};if (s.generatorService == "meshy") return runMeshy(s, imagePath, outputStem, progress);if (s.generatorService == "command") {status(progress, "Running your generator...");@@ -553,6 +555,7 @@ std::string falTextBody(const std::string& prompt) {GeneratorResult generate3DFromText(const AiSettings& s, const std::string& prompt, const std::string& outputStem,GenerationProgress* progress) {+ if (!aiEnabled()) return {false, {}, aiOffError()};GeneratorResult result;if (prompt.find_first_not_of(" \t\r\n") == std::string::npos) {result.error = "Describe the model you want";diff --git a/src/app/App.cpp b/src/app/App.cppindex 276596e7..5012bf64 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -193,6 +193,8 @@ bool App::init(const AppOptions& options) {} else {io.IniFilename = nullptr;}+ // Preferences > AI: tests, renders and videos start with AI on whatever this computer chose (SF_AI still wins).+ ai::setAiEnabled(ai::aiFeaturesAllowed(headless || !options.demo.empty() || aiSettings_.enabled));ai::registerAiCommands(commands_, [this] { return aiSettings_; });registerPaintUiCommands();std::snprintf(falKey_, sizeof falKey_, "%s", aiSettings_.falKey.c_str());@@ -2105,7 +2107,10 @@ void App::openPath(const std::string& path) {std::string ext = std::filesystem::path(std::u8string(path.begin(), path.end())).extension().string();std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c) { return char(std::tolower(c)); });if (Image::isImagePath(path)) {- if (loadReferenceImage(path)) showImageTo3D_ = true;+ if (loadReferenceImage(path)) {+ if (ai::aiEnabled()) showImageTo3D_ = true;+ else status_ = "Image loaded: Relief, Inflate or Stamp it from Mesh > Generate 3D";+ }} else if (ext == ".sfbrush") {installBrushFile(path);} else if (ext == kPackExtension) { // a pack: the review screen first, nothing is installed yet@@ -2360,6 +2365,8 @@ void App::drawUi() {ImGui::Text("SculptForge %s", SCULPTFORGE_VERSION);ImGui::TextWrapped("Free and open-source digital sculpting.");ImGui::Spacing();+ ImGui::TextWrapped("%s", ai::kPrivacyLine); // also on the site (website/index.html) and in docs/ai-services.md+ ImGui::Spacing();ImGui::TextWrapped("Copyright (C) 2026 The SculptForge contributors. This program is free software: you can ""redistribute it and/or modify it under the terms of the GNU General Public License, ""version 3 or later. It comes with ABSOLUTELY NO WARRANTY.");@@ -2578,6 +2585,7 @@ void App::sendBrushRequest(const std::string& text) {scrollChat_ = true;busyTime_ = 0.0f;+ if (!ai::aiEnabled()) return; // (the Brush Lab is closed then; requestBrush refuses too)// Detached worker with its own copies, so quitting never waits on the network.auto promise = std::make_shared<std::promise<BrushReply>>();pendingBrush_ = promise->get_future();diff --git a/src/app/App.h b/src/app/App.hindex 0d871b76..897779e2 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -2,6 +2,7 @@// SPDX-License-Identifier: GPL-3.0-or-later#pragma once+#include "ai/AiPolicy.h"#include "ai/BrushAssistant.h"#include "app/Actions.h"#include "app/AssetLibrary.h"@@ -431,6 +432,11 @@ private:};DialogRequest dialogRequests_[int(FileAction::Count)];+ // Preferences > AI (PanelAi.cpp, ai/AiPolicy.h): Enable AI features. Off removes the AI commands, the Brush Lab+ // and Generate 3D entries and closes their windows; saved in ai.json at once (not in tests). SF_AI / --no-ai lock it.+ void setAiFeatures(bool on);+ void registerAiActions(); // ui.brush_lab, ui.generate3d: only while AI is on+ void drawAiPrefs(); // the Preferences > AI section and the first-run question// Brush Lab (AI brush designer)bool showBrushLab_ = false; // floating; opened from the top shelf's AI Brush or the Brush palettebool hideUi_ = false;diff --git a/src/app/LightBox.cpp b/src/app/LightBox.cppindex 9f2953bd..038d6645 100644--- a/src/app/LightBox.cpp+++ b/src/app/LightBox.cpp@@ -507,7 +507,7 @@ void LightBox::contextMenu(App& app, const AssetEntry& e) {activate(app, e, false);if (mesh && ImGui::MenuItem(tr("Append as Part"), "Shift+double-click")) activate(app, e, true);if (e.kind == AssetKind::Image) {- if (ImGui::MenuItem(tr("Generate 3D..."))) app.openPath(e.path);+ if (ai::aiEnabled() && ImGui::MenuItem(tr("Generate 3D..."))) app.openPath(e.path);if (ImGui::MenuItem(tr("Relief from image")))app.confirmDiscard([&app, p = e.path] { app.runCommand("image_relief", {{"path", p}}); });if (ImGui::MenuItem(tr("Inflate image")))@@ -924,7 +924,7 @@ void LightBox::draw(App& app, const CanvasRect& canvas) {ImGui::TextDisabled("%s", e.name.c_str());ImGui::Separator();bool done = false;- if (ImGui::MenuItem(ICON_LC_SPARKLES " Generate 3D...")) app.openPath(e.path), done = true;+ if (ai::aiEnabled() && ImGui::MenuItem(ICON_LC_SPARKLES " Generate 3D...")) app.openPath(e.path), done = true;if (ImGui::MenuItem(tr("Relief from image"))) {app.confirmDiscard([&app, p = e.path] { app.runCommand("image_relief", {{"path", p}}); });done = true;diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cppindex 48473d8e..cd380285 100644--- a/src/app/Palettes.cpp+++ b/src/app/Palettes.cpp@@ -508,9 +508,13 @@ void App::drawPalette_File() {void App::drawPalette_Generate() {const tray::Style style; // quiet check marks- actionRow(*this, {"ui.generate3d"});- hint(*this, "Image or text to a sculptable 3D model: Hugging Face (free), fal.ai, Meshy, your ComfyUI server, your own "- "command, or an offline blockout.");+ if (ai::aiEnabled()) {+ actionRow(*this, {"ui.generate3d"});+ hint(*this, "Image or text to a sculptable 3D model: Hugging Face (free), fal.ai, Meshy, your ComfyUI server, your own "+ "command, or an offline blockout.");+ } else {+ hint(*this, "AI features are off (Preferences > AI): Relief, Inflate and Stamp work offline.");+ }tray::GroupLabel(*this, "From an image");if (ImGui::Button(refImage_.empty() ? "Choose image...##generate" : "Change image...##generate", ImVec2(-1, 0))) {static const SDL_DialogFileFilter filters[] = {{"Images", "png;jpg;jpeg;bmp;tga;psd;gif"}, {"All files", "*"}};@@ -540,7 +544,7 @@ void App::drawPalette_Generate() {if (ImGui::Button(tr("Stamp"), ImVec2(third, 0))) projectImageFromView();ui::HelpText("Stamp", nullptr, "Projects the image onto the model from this view as surface detail.", "Generate");ImGui::EndDisabled();- if (subpalette("generate.ai", "AI brush provider")) {+ if (ai::aiEnabled() && subpalette("generate.ai", "AI brush provider")) {tray::Section section;drawAiSettings();}@@ -606,7 +610,11 @@ void App::drawPalette_Preferences() {}if (subpalette("preferences.ai", "AI")) {tray::Section section;- drawAiPrefsSection();+ drawAiPrefs(); // the switch (PanelAi.cpp)+ if (ai::aiEnabled()) {+ ImGui::Spacing();+ drawAiPrefsSection(); // the Hugging Face token+ }}if (subpalette("preferences.updates", "Updates")) {tray::Section section;diff --git a/src/app/PanelAi.cpp b/src/app/PanelAi.cppnew file mode 100644index 00000000..38ac5487--- /dev/null+++ b/src/app/PanelAi.cpp@@ -0,0 +1,105 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Preferences > AI > Enable AI features (ai/AiPolicy.h). Off: the AI commands (brush_ai, image_to_3d,+// text_to_3d, comfyui_check) leave the command registry, so the command palette, scripts and the console+// can't reach them; AI Brush and Generate 3D leave the shelves and menus and their windows close; and every+// AI network entry point refuses. Saved in ai.json at once, so the CLI, Python and MCP server follow it.+// SF_AI=off (or --no-ai) locks it for studios.+#include "app/App.h"+#include "app/Ui.h"++#include "ai/AiCommands.h"++#include <IconsLucide.h>+#include <imgui.h>++namespace sf {++void App::registerAiActions() {+ // The switch itself: always there, so the command palette finds "AI" to turn it back on.+ Action sw;+ sw.id = "prefs.ai_features";+ sw.label = "Enable AI features";+ sw.palette = "Preferences > AI";+ sw.description = std::string("AI Brush (describe a brush) and Generate 3D (image or text to a model). Off hides them "+ "and stops every AI network call. ") + ai::kPrivacyLine;+ sw.run = [this] { setAiFeatures(!ai::aiEnabled()); };+ sw.checked = [] { return ai::aiEnabled(); };+ sw.enabled = [] { return !ai::aiPolicyLocked(); };+ actions_.add(std::move(sw));+ commands_.remove("ai_features"); // (called again when AI is turned back on)+ commands_.add({"ai_features", "Turn the AI features on or off (Preferences > AI > Enable AI features).",+ {{"on", ParamSpec::Type::Bool, "true: on, false: off.", true}},+ [this](Document&, const Args& a) -> CommandResult {+ const bool on = argBool(a, "on", true);+ if (ai::aiPolicyLocked() && on != ai::aiEnabled()) return {false, ai::aiOffError()};+ setAiFeatures(on);+ return {true, on ? "AI features on" : "AI features off"};+ }});+ if (!ai::aiEnabled()) return;++ auto flag = [this](std::string id, std::string label, const char* icon, std::string palette, bool* value,+ std::string description) {+ Action a;+ a.id = std::move(id);+ a.label = std::move(label);+ a.icon = icon;+ a.palette = std::move(palette);+ a.description = std::move(description);+ a.run = [value] { *value = !*value; };+ a.checked = [value] { return *value; };+ actions_.add(std::move(a));+ };+ flag("ui.brush_lab", "AI Brush", ICON_LC_SPARKLES, "Brush", &showBrushLab_,+ "Brush Lab: describe a brush in words and AI builds it; tweak the recipe with sliders.");+ flag("ui.generate3d", "Generate 3D", ICON_LC_WAND_SPARKLES, "Generate", &showImageTo3D_,+ "Turn an image or a description into a sculptable model (Hugging Face, fal.ai, Meshy, ComfyUI or offline).");+}++void App::setAiFeatures(bool on) {+ if (ai::aiPolicyLocked()) {+ status_ = ai::aiOffError();+ return;+ }+ const bool changed = on != ai::aiEnabled();+ aiSettings_.enabled = on;+ ai::setAiEnabled(on);+ if (changed && on) {+ ai::addAiFeatureCommands(commands_, [this] { return aiSettings_; });+ registerAiActions();+ actions_.registerCommands( // cmd.brush_ai and the others (shortcuts someone gave them are kept)+ commands_, [this](const std::string& name) { runCommand(name); },+ [this](const std::string& name) { consolePrefill(name + " "); });+ } else if (changed) {+ ai::removeAiFeatureCommands(commands_);+ for (const std::string& name : ai::aiCommandNames()) actions_.removePrefix("cmd." + name);+ actions_.removePrefix("ui.brush_lab");+ actions_.removePrefix("ui.generate3d");+ showBrushLab_ = false;+ showImageTo3D_ = false;+ }+ std::string err;+ if (!uiConfigDeterministic_ && !aiSettingsPath_.empty() && !aiSettings_.save(aiSettingsPath_, err))+ status_ = "AI features " + std::string(on ? "on" : "off") + ", but " + err;+ else+ status_ = on ? "AI features on (Preferences > AI)" : "AI features off: nothing AI runs or connects (Preferences > AI)";+}++void App::drawAiPrefs() {+ const bool locked = ai::aiPolicyLocked();+ bool on = ai::aiEnabled();+ ImGui::BeginDisabled(locked);+ if (ImGui::Checkbox("Enable AI features##prefs.ai", &on)) setAiFeatures(on);+ ImGui::EndDisabled();+ ui::HelpAction(*this, "prefs.ai_features");+ if (locked) ImGui::TextDisabled("Set by this computer (SF_AI or --no-ai).");+ ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));+ ImGui::TextWrapped("AI Brush and Generate 3D. Off: they are hidden and SculptForge makes no AI network calls.");+ ImGui::TextWrapped("%s", ai::kPrivacyLine);+ ImGui::PopStyleColor();+ if (ImGui::SmallButton("AI services & privacy##prefs.ai"))+ SDL_OpenURL("https://github.com/islandmed/SculptForge/blob/main/docs/ai-services.md");+}++} // namespace sfdiff --git a/src/app/PanelPhone.cpp b/src/app/PanelPhone.cppindex b1fdc904..00cfe754 100644--- a/src/app/PanelPhone.cpp+++ b/src/app/PanelPhone.cpp@@ -172,6 +172,10 @@ void App::handlePhoneCapture(const link::PhoneEvent& e) {status_ = "Photo received (" + where + ") but it can't be read: " + status_;return;}+ if (!ai::aiEnabled()) { // Preferences > AI is off: the photo stays the reference image+ status_ = "Photo received (" + where + "): Relief, Inflate or Stamp it from Mesh > Generate 3D";+ return;+ }showImageTo3D_ = true;textMode_ = false;if (phoneAutoGenerate_) {diff --git a/src/app/PanelSupport.cpp b/src/app/PanelSupport.cppindex b64cb307..7af38d78 100644--- a/src/app/PanelSupport.cpp+++ b/src/app/PanelSupport.cpp@@ -172,6 +172,25 @@ void App::drawSupportUi() {if (ImGui::IsItemHovered())ImGui::SetTooltip("Bust, full body, hand, foot, ear, eye, stylised and creature heads, torso and ""bevelled primitives: Library > Tool > Starter meshes.");+ // AI (Preferences > AI changes it later; saved at once).+ ImGui::Spacing();+ ImGui::AlignTextToFramePadding();+ ImGui::TextUnformatted("AI features:");+ for (const bool choice : {true, false}) {+ ImGui::SameLine();+ const bool on = ai::aiEnabled() == choice;+ if (on) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));+ ImGui::BeginDisabled(ai::aiPolicyLocked());+ if (ImGui::Button(choice ? "On##welcome.ai" : "Off##welcome.ai")) setAiFeatures(choice);+ ImGui::EndDisabled();+ if (on) ImGui::PopStyleColor();+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))+ ImGui::SetTooltip("%s", choice ? "AI Brush (describe a brush) and Generate 3D (image or text to a model)."+ : "Hides them; SculptForge makes no AI network calls.");+ }+ ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));+ ImGui::TextWrapped("%s", ai::kPrivacyLine);+ ImGui::PopStyleColor();ImGui::Spacing();if (ImGui::Button("Open the User Guide##welcome")) {guide_.open();diff --git a/src/app/Shell.cpp b/src/app/Shell.cppindex 3e6a07dc..e3ea14e9 100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@ -452,10 +452,7 @@ void App::registerShellActions() {a.checked = [this, axis] { return symmetry_.radialAxis == axis; };actions_.add(std::move(a));}- flag("ui.brush_lab", "AI Brush", ICON_LC_SPARKLES, "Brush", "", &showBrushLab_,- "Brush Lab: describe a brush in words and AI builds it; tweak the recipe with sliders.");- flag("ui.generate3d", "Generate 3D", ICON_LC_WAND_SPARKLES, "Generate", "", &showImageTo3D_,- "Turn an image or a description into a sculptable model (Hugging Face, fal.ai, Meshy, ComfyUI or offline).");+ registerAiActions(); // AI Brush, Generate 3D: only while AI is on (PanelAi.cpp)flag("ui.brush_gallery", "Community brushes", ICON_LC_GLOBE, "Brush", "", &showBrushGallery_,"Browse, search and install brushes other sculptors shared.");diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 95179ad5..3a30f43c 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -205,6 +205,7 @@// expect_value spacemouse_connected (1 when the app opened it), spacemouse_moving (1 while it moves the view)// expect_value look (0 Classic, 1 Forge Terminal, 2 Phosphor, 3 Blueprint), shell_layout (0 ZBrush-style, 1 SculptForge)#include "app/App.h"+#include "ai/Http.h"#ifndef SDL_PEN_INPUT_IN_PROXIMITY#define SDL_PEN_INPUT_IN_PROXIMITY (1u << 31) // SDL 3.4's flag; older SDL 3 never sets it@@ -618,6 +619,8 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "subtools") return double(doc.subtoolCount());if (name == "discord_requests") return double(app_.discordRequests_); // Join the community on Discord clicksif (name == "support_requests") return double(app_.supportPageRequests_); // Support SculptForge clicks+ if (name == "ai_enabled") return ai::aiEnabled() ? 1.0 : 0.0; // Preferences > AI (PanelAi.cpp)+ if (name == "http_requests") return double(ai::httpRequestCount()); // every request this process startedif (name == "welcome_open") return app_.showWelcome_ ? 1.0 : 0.0;if (name == "new_look_card_open") return app_.newLookCard_ ? 1.0 : 0.0; // "SculptForge has a new look" (0.10.7)if (name == "support_card_open") return app_.supportCardOpen() ? 1.0 : 0.0; // the support card at launchdiff --git a/src/app/main.cpp b/src/app/main.cppindex 649d7f72..59c86c83 100644--- a/src/app/main.cpp+++ b/src/app/main.cpp@@ -4,6 +4,7 @@#include "app/Bench.h"#include "app/Calibration.h"#include "app/CrashLog.h"+#include "ai/AiPolicy.h"#include "core/Pack.h"#include <SDL3/SDL_main.h>@@ -45,6 +46,7 @@ void usage() {" --ui-test FILE.sfui Run a UI test script headless and exit (0 = pass); settings are isolated\n"" --ui-out DIR Where UI tests save screenshots\n"" --fullscreen Start filling the screen (F11 toggles)\n"+ " --no-ai Start with every AI feature off and locked (as SF_AI=off)\n"" --no-packs Safe mode: start without any installed pack (Library > Packs)\n"" --blender Load what the Blender add-on sent (it starts SculptForge this way)\n"" --bench Run the performance benchmark (with GPU upload and orbit timings) and exit\n"@@ -151,6 +153,7 @@ int main(int argc, char** argv) {else if (a == "--supersample") options.supersample = std::clamp(std::atoi(next().c_str()), 1, 4);else if (a == "--ui-test") options.uiTest = next();else if (a == "--fullscreen") options.fullscreen = true;+ else if (a == "--no-ai") sf::ai::setAiForcedOff(true); // as SF_AI=off (ai/AiPolicy.h)else if (a == "--no-packs") sf::setPacksSafeMode(true); // safe mode: no installed pack is loadedelse if (a == "--blender") options.blender = true;else if (a == "--ui-out") options.uiOutDir = next();diff --git a/src/cli/main.cpp b/src/cli/main.cppindex edfc6855..0c124aba 100644--- a/src/cli/main.cpp+++ b/src/cli/main.cpp@@ -4,6 +4,7 @@// sculptforge-cli: run SculptForge commands headless, for build farms, asset// pipelines and AI agents.#include "ai/AiCommands.h"+#include "ai/AiPolicy.h"#include "ai/SplatTrainer.h"#include "cli/McpServer.h"#include "core/Benchmark.h"@@ -33,6 +34,7 @@ void usage() {" --schema Print commands as LLM tool definitions (JSON)\n"" --mcp Run as an MCP server on stdio (Claude Code, Claude Desktop, any MCP client)\n"" -q, --quiet Only print errors\n"+ " --no-ai Leave the AI commands out (as SF_AI=off; Preferences > AI turns them off for good)\n"" --no-packs Safe mode: leave every installed pack out (pack_install still works)\n"" --bench Run the performance benchmark (CPU side; the app's --bench adds the GPU)\n"" --bench-sizes 4,16,32 Benchmark sizes in millions of triangles\n"@@ -56,7 +58,11 @@ void usage() {int main(int argc, char** argv) {sf::CommandRegistry registry;- // AI commands use the same settings file as the app (keys can also come from the environment).+ // AI commands use the same settings file as the app (keys can also come from the environment), and only+ // while AI is on there (Preferences > AI), SF_AI allows it and --no-ai isn't given (ai/AiPolicy.h).+ for (int i = 1; i < argc; ++i)+ if (std::string(argv[i]) == "--no-ai") sf::ai::setAiForcedOff(true);+ sf::ai::setAiEnabled(sf::ai::aiFeaturesAllowed(sf::ai::AiSettings::load(sf::ai::defaultAiSettingsPath()).enabled));sf::ai::registerAiCommands(registry, [] { return sf::ai::AiSettings::load(sf::ai::defaultAiSettingsPath()); });// splat_train: trains in the foreground with the app's tool settings (ai/SplatTrainer.h).sf::ai::registerSplatTrainCommands(registry, [] { return sf::ai::SplatTrainSettings::load(sf::ai::defaultSplatTrainSettingsPath()); });@@ -111,6 +117,8 @@ int main(int argc, char** argv) {return 0;} else if (sf::parseBenchArg(argc, argv, i, bench)) {// handled after the loop+ } else if (a == "--no-ai") {+ // read before the commands were registered} else if (a == "--no-packs") {sf::setPacksSafeMode(true);} else if (a == "-q" || a == "--quiet") {diff --git a/src/core/Commands.cpp b/src/core/Commands.cppindex d28e67b1..206fe2fa 100644--- a/src/core/Commands.cpp+++ b/src/core/Commands.cpp@@ -829,6 +829,11 @@ CommandRegistry::CommandRegistry() {registerProjectCommands(*this); // keep last (core/Project.cpp)}+void CommandRegistry::remove(const std::string& name) {+ commands_.erase(std::remove_if(commands_.begin(), commands_.end(), [&](const Command& c) { return c.name == name; }),+ commands_.end());+}+void CommandRegistry::add(Command cmd) {// The commands that follow the brushes' symmetry take radial and local symmetry too (#63).static const char* const kSymmetric[] = {"stroke", "vdm_stamp", "mask_rect", "mask_lasso", "hide_rect",diff --git a/src/core/Commands.h b/src/core/Commands.hindex 1357cd4a..d3401c4f 100644--- a/src/core/Commands.h+++ b/src/core/Commands.h@@ -45,6 +45,7 @@ public:CommandRegistry(); // registers the built-in commandsvoid add(Command cmd);+ void remove(const std::string& name); // every command with this name (none: nothing happens)const Command* find(const std::string& name) const;const std::vector<Command>& all() const { return commands_; }diff --git a/src/python/module.cpp b/src/python/module.cppindex 8afd9d0c..e5f3939b 100644--- a/src/python/module.cpp+++ b/src/python/module.cpp@@ -12,6 +12,7 @@// doc.mask, doc.colors, doc.polygroups # optional attributes, None when absent// doc.set_selection_set("Eyes", mask=m) # push a selection set; doc.selection_set("Eyes") pulls it#include "ai/AiCommands.h"+#include "ai/AiPolicy.h"#include "ai/SplatTrainer.h"#include "core/BrushLibrary.h"#include "core/Commands.h"@@ -34,6 +35,7 @@ namespace {const CommandRegistry& registry() {static CommandRegistry r = [] {CommandRegistry reg;+ ai::setAiEnabled(ai::aiFeaturesAllowed(ai::AiSettings::load(ai::defaultAiSettingsPath()).enabled)); // Preferences > AI, SF_AIai::registerAiCommands(reg, [] { return ai::AiSettings::load(ai::defaultAiSettingsPath()); });ai::registerSplatTrainCommands(reg, [] { return ai::SplatTrainSettings::load(ai::defaultSplatTrainSettingsPath()); });return reg;diff --git a/tests/test_ai_switch.cpp b/tests/test_ai_switch.cppnew file mode 100644index 00000000..17c1a9d3--- /dev/null+++ b/tests/test_ai_switch.cpp@@ -0,0 +1,162 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// The AI switch (ai/AiPolicy.h, Preferences > AI): off, no AI command is registered and no AI entry point+// starts a network request; SF_AI wins over the saved choice; ai.json keeps it.+#include "TestHarness.h"++#include "ai/AiCommands.h"+#include "ai/AiPolicy.h"+#include "ai/ComfyUI.h"+#include "ai/GradioClient.h"+#include "ai/Http.h"+#include "ai/ImageTo3DService.h"++#include <cstdlib>+#include <filesystem>++using namespace sf;+using namespace sf::ai;++namespace {++void setEnv(const char* name, const char* value) {+#if defined(_WIN32)+ _putenv_s(name, value ? value : "");+#else+ if (value) setenv(name, value, 1);+ else unsetenv(name);+#endif+}++// Restores the switch and SF_AI, whatever a test left.+struct AiState {+ std::string savedEnv;+ bool hadEnv = false;+ AiState() {+ if (const char* v = std::getenv("SF_AI")) savedEnv = v, hadEnv = true;+ setEnv("SF_AI", nullptr);+ }+ ~AiState() {+ setEnv("SF_AI", hadEnv ? savedEnv.c_str() : nullptr);+ setAiForcedOff(false);+ setAiEnabled(true);+ }+};++CommandRegistry registryWithAi() {+ CommandRegistry r;+ registerAiCommands(r, [] { return AiSettings::defaults(AiSettings::Provider::Free); });+ return r;+}++} // namespace++TEST(ai_switch_saved_in_ai_json) {+ CHECK(AiSettings::fromJson(Json::object()).enabled); // older ai.json files: on, as before+ AiSettings s = AiSettings::defaults(AiSettings::Provider::Free);+ CHECK(s.enabled);+ s.enabled = false;+ CHECK(!AiSettings::fromJson(s.toJson()).enabled);+ const std::string path = tempPath("sf_ai_switch_test.json");+ std::string err;+ CHECK(s.save(path, err));+ CHECK(!AiSettings::load(path).enabled);+ std::filesystem::remove(path);+}++TEST(ai_switch_environment_wins) {+ AiState restore;+ CHECK(aiFeaturesAllowed(true));+ CHECK(!aiFeaturesAllowed(false));+ CHECK(!aiPolicyLocked());+ for (const char* off : {"off", "OFF", "0", "false", "no"}) {+ setEnv("SF_AI", off);+ CHECK(!aiFeaturesAllowed(true));+ CHECK(aiPolicyLocked());+ }+ setEnv("SF_AI", "on");+ CHECK(aiFeaturesAllowed(false));+ setEnv("SF_AI", "maybe"); // unknown: the saved choice+ CHECK(aiFeaturesAllowed(true));+ CHECK(!aiFeaturesAllowed(false));+ CHECK(!aiPolicyLocked());+ setEnv("SF_AI", nullptr);+ setAiForcedOff(true); // --no-ai+ CHECK(!aiFeaturesAllowed(true));+ CHECK(aiPolicyLocked());+ CHECK(aiOffError().find("SF_AI") != std::string::npos);+}++TEST(ai_switch_off_registers_no_ai_command) {+ AiState restore;+ setAiEnabled(false);+ CommandRegistry r = registryWithAi();+ for (const std::string& name : aiCommandNames()) {+ CHECK(!r.find(name));+ CHECK(r.toolSchemaJson().find("\"" + name + "\"") == std::string::npos); // the MCP / LLM tool list+ }+ CHECK(r.find("brush_gallery_search")); // not AI: they stay+ CHECK(r.find("unreal_send"));+ Document doc;+ CHECK(!r.execute(doc, "brush_ai", {{"prompt", std::string("sharp")}}).ok);++ setAiEnabled(true); // turned back on at run time: each once+ addAiFeatureCommands(r, [] { return AiSettings::defaults(AiSettings::Provider::Free); });+ addAiFeatureCommands(r, [] { return AiSettings::defaults(AiSettings::Provider::Free); });+ for (const std::string& name : aiCommandNames()) {+ int n = 0;+ for (const Command& c : r.all()) n += c.name == name;+ CHECK(n == 1);+ }+ removeAiFeatureCommands(r);+ for (const std::string& name : aiCommandNames()) CHECK(!r.find(name));+ CHECK(r.find("unreal_send"));++ CommandRegistry on = registryWithAi();+ for (const std::string& name : aiCommandNames()) CHECK(on.find(name));+}++TEST(ai_switch_off_sends_nothing) {+ AiState restore;+ setAiEnabled(false);+ const uint64_t before = httpRequestCount();+ AiSettings s = AiSettings::defaults(AiSettings::Provider::Free);+ const std::string out = tempPath("sf_ai_switch_out");+ auto refused = [](const std::string& error) { return error.find("AI features") != std::string::npos; };++ BrushSuggestion b = requestBrush(s, {composeUserMessage("sharp wrinkles", nullptr)}, nullptr);+ CHECK(!b.ok);+ CHECK(refused(b.error));+ std::string err;+ CHECK(listModels(AiSettings::defaults(AiSettings::Provider::OpenAICompatible), err).empty());+ CHECK(refused(err));+ err.clear();+ CHECK(smallestOllamaModel(err).empty());+ CHECK(refused(err));+ for (const char* service : {"huggingface", "fal", "meshy", "command", "inflate"}) {+ s.generatorService = service;+ GeneratorResult g = generate3D(s, "missing.png", out);+ CHECK(!g.ok);+ CHECK(refused(g.error));+ }+ for (const char* service : {"huggingface", "fal", "meshy"}) {+ s.generatorService = service;+ CHECK(refused(generate3DFromText(s, "a dragon head", out).error));+ }+ CHECK(refused(comfy::run(s, {}, "missing.png", {}, out, nullptr).error));+ comfy::ServerInfo info;+ err.clear();+ CHECK(!comfy::checkServer("http://127.0.0.1:9", info, err, 1));+ CHECK(refused(err));+ GradioClient gradio;+ err.clear();+ CHECK(!gradio.connect("https://example.hf.space", {}, err));+ CHECK(refused(err));+ CHECK(httpRequestCount() == before); // nothing was sent++ setAiEnabled(true); // the counter does see requests: nothing listens on port 9+ err.clear();+ CHECK(!comfy::checkServer("http://127.0.0.1:9", info, err, 1));+ CHECK(httpRequestCount() > before);+}diff --git a/tests/ui/ai_switch.sfui b/tests/ui/ai_switch.sfuinew file mode 100644index 00000000..85144be0--- /dev/null+++ b/tests/ui/ai_switch.sfui@@ -0,0 +1,65 @@+# Preferences > AI > Enable AI features (F5): off, no AI entry point is left on the shelves, in the menus, the+# command palette or scripts, and nothing AI connects; on brings them back. The welcome asks too.+run ui_look look=classic layout=zbrush # written for the Classic look and the ZBrush-style palette bar and shelves+run new_sphere subdivisions=2+expect_value ai_enabled == 1+expect "AI Brush"+click "Preferences##palette.preferences"+click "AI##preferences.ai"+expect_text "Your art is never uploaded or used for training"+shot ai-prefs-on++click "Enable AI features##prefs.ai"+expect_value ai_enabled == 0+expect_status "AI features off"+expect_not "AI Brush"+shot ai-prefs-off+run_fails brush_ai prompt=sharp+run_fails image_to_3d path=missing.png+run_fails text_to_3d prompt=dragon+run_fails comfyui_check+expect_value http_requests == 0++# The Generate palette keeps the offline tools only.+click "Generate##palette.generate"+expect_text "AI features are off"+expect "Relief"+expect_not "Generate 3D##ui.generate3d"+shot ai-generate-off++# The command palette finds the switch, not the AI tools.+key f3+type "##Command palette" "brush ai"+expect_no_text "Design a brush"+type "##Command palette" "image to 3d"+expect_no_text "Reconstruct a full 3D model"+type "##Command palette" "enable ai"+expect_text "Preferences > AI"+key esc++# Back on: everything returns.+click "Preferences##palette.preferences" # its AI section is still open+click "Enable AI features##prefs.ai"+expect_value ai_enabled == 1+expect "AI Brush"+click "Preferences##palette.preferences" # close the popup first+click "AI Brush"+expect "Brush Lab"+click "AI Brush"++# First run: the welcome asks.+key f3+type "##Command palette" "welcome"+key enter+expect_value welcome_open == 1+expect "Off##welcome.ai"+shot ai-welcome+click "Off##welcome.ai"+expect_value ai_enabled == 0+click "On##welcome.ai"+expect_value ai_enabled == 1+run ai_features on=false+expect_value ai_enabled == 0+expect_not "AI Brush"+run ai_features on=true+expect "AI Brush"diff --git a/website/index.html b/website/index.htmlindex fddaef05..b7105493 100644--- a/website/index.html+++ b/website/index.html@@ -545,6 +545,8 @@ rez-env sculptforge -- sculptforge troll.usda \<h2>Free AI built in, or bring your own</h2><p>Two AI tools work out of the box at no cost and with no sign-up. Every AI feature is optional and talksdirectly to the service you pick. SculptForge has no servers, no account and no telemetry.</p>+ <p><strong>Your art is never uploaded or used for training. AI features run only when you use them and can be+ turned off</strong> (Preferences > AI).</p><ul class="checks"><li><strong>Brush Lab, the AI brush creator:</strong> describe a brush ("dry cracked mud", "overlappingdragon scales"), and AI builds it as a recipe with every value on a slider. Then refine it in plain