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
Lit Spheres: rename, move to folder, folder headings, drop on Library Material tab, 'material capture' aliases (#124)
islandmed4d88a74f798f
diff --git a/changes/feat-litsphere-manage.md b/changes/feat-litsphere-manage.mdnew file mode 100644index 00000000..aef70554--- /dev/null+++ b/changes/feat-litsphere-manage.md@@ -0,0 +1,22 @@+---+whats_new: **Organise your Lit Spheres**: right-click one of your own in the material picker, **Render > Materials** or+ the Library and choose **Rename...** or **Move to folder**; sub-folders of the Lit Spheres folder show as headings.+ Drop an image onto the Library's Material tab to load it. Search for "material capture" finds them too.+added: **Rename and organise your Lit Spheres** (#124, thanks Pumaman101): **Rename...** and **Move to folder**+ (existing folders, **New folder...**) in the right-click menu of the material picker, **Render > Materials** and the+ Library's Material tab rename or move the image in the Lit Spheres folder; a name in use is refused, nothing is+ overwritten, and projects that use a renamed one still find it (by its pixels). Sub-folders of the Lit Spheres+ folder (one level) are headings in all three lists. Pack, studio-folder and project-only Lit Spheres show the items+ greyed out with the reason. Scripts: `rename_litsphere`, `move_litsphere`.+added: Dropping an image onto the Library's Material tab loads it as a Lit Sphere (#124); dropped on the canvas it+ does what it did before.+changed: The command search and the Library filter also find Lit Spheres by "material capture" and "material image".+testers:+ - Any OS: Render > Materials > Load Lit Sphere... a PNG; right-click it > Rename..., type a name another material+ has: a red message, nothing changes; type a new name + Enter: the list and the file in Documents/SculptForge/Lit+ Spheres show the new name; reopen a project saved with it: same look, no duplicate in the list.+ - Right-click > Move to folder > New folder... "Metals" + Enter: a Metals heading in the picker (M), the palette and+ the Library's Material tab; the file is in Lit Spheres/Metals.+ - Windows: drag a JPG from Explorer onto the Library's Material tab: it loads and becomes the material.+---+Issue #124 (Pumaman101). Brief: BRIEF.md (not committed).diff --git a/docs/guide/vertex-paint.md b/docs/guide/vertex-paint.mdindex ac7bba26..da08085d 100644--- a/docs/guide/vertex-paint.md+++ b/docs/guide/vertex-paint.md@@ -150,7 +150,8 @@ way round, so a stroke with **Rgb** on can sculpt into the "Smile" layer and pai## Materials (Lit Spheres)-Materials change only how the model is shaded in the viewport. They aren't exported and don't change vertex paint.+The materials are material capture (lit sphere) images: each one is a picture of a lit sphere that shades the whole+model. They change only how the model is shaded in the viewport. They aren't exported and don't change vertex paint.| Material | Look ||---|---|@@ -187,8 +188,8 @@ PBR shading uses the material channels and is not tinted. Saved with the project### Your own Lit Spheres-A Lit Sphere is a picture of a lit sphere (Sloan and others, 2001): the view colours each point of the model with the sphere's colour where its-surface faces the same way. Any lit-sphere image works: a square PNG, JPG or EXR+Your own Lit Spheres are material capture (lit sphere) images too (Sloan and others, 2001): the view colours each point+of the model with the sphere's colour where its surface faces the same way. Any lit-sphere image works: a square PNG, JPG or EXRwith the sphere filling it (a non-square image is cropped to its centre; big ones are scaled to 1024 pixels).- **Render > Materials > Load Lit Sphere...** picks an image. It joins the material list under its file name, the view uses@@ -198,7 +199,18 @@ with the sphere filling it (a non-square image is cropped to its centre; big one**Render > Materials** or the Library's Material tab, no restart needed. Studios can share a read-only folder bylisting it in the `SCULPTFORGE_LITSPHERE_PATH` environment variable (separated by `:`, `;` on Windows); those loadwhen SculptForge starts.-- To remove one, right-click it in the material picker or palette and choose **Remove**. An image from your+- **Drop an image onto the Library's Material tab** to load it the same way (dropped on the canvas, an image keeps+ its usual meaning).+- **Rename** one: right-click it in the material picker, **Render > Materials** or the Library's Material tab and choose+ **Rename...**, type the name and press <kbd>Enter</kbd>. Its file in the Lit Spheres folder is renamed too. A name+ another Lit Sphere already has is refused, so nothing is overwritten. Projects that use it keep their look: they find+ it by its pixels, not its name.+- **Organise** them in folders: each sub-folder of the Lit Spheres folder (one level) is a heading in the lists.+ Right-click a Lit Sphere and choose **Move to folder** for an existing folder, **New folder...** to make one, or+ **Lit Spheres (no folder)** to take it out again. You can also make the folders in your file manager.+- Lit Spheres from a pack, from a studio folder or carried only by the open project have no file of yours to change:+ Rename and Move to folder are greyed out, and pointing at them says why.+- To remove one, right-click it and choose **Remove**. An image from yourLit Spheres folder goes to the trash (the Recycle Bin on Windows), so you can still get it back. On macOS it isonly hidden until you restart, and the message says where its file is so you can delete it yourself.Built-in materials can't be removed.@@ -206,7 +218,7 @@ with the sphere filling it (a non-square image is cropped to its centre; big oneYour Lit Spheres appear in the material picker (<kbd>M</kbd>), **Render > Materials** and the Library, after the-built-in ones. A project that uses one carries a copy of the image, so it opens with the same look on another+built-in ones, those in folders under their folder's name. A project that uses one carries a copy of the image, so it opens with the same look on anothercomputer (or after you delete the file). Loading an image with the same name again replaces it. EXR images areread as linear light, so very bright highlights clip to white.@@ -230,8 +242,6 @@ your preferred shading. The scene's shading you choose is also the preference foitself). Smooth and Flat have no default shortcut, so noclassic key changes meaning; assign one under **Edit > Preferences > Hotkeys** if you switch often.-> **Not yet:** loading your own Lit Sphere images, and physically based materials or BPR-style renders.-## Scripting| Command | What it does |@@ -249,6 +259,8 @@ classic key changes meaning; assign one under **Edit > Preferences > Hotkeys** i| `paint_layer_list` | List the layers, top first (`*` marks the active one) || `set_material name=Chrome` | Viewport material: a Lit Sphere name (`Soft Clay` is the default, your own Lit Spheres included) or `studio` (desktop app only) || `load_litsphere path=gold.png` | Load a Lit Sphere image and use it; `keep=false` doesn't copy it into the Lit Spheres folder (desktop app only) |+| `rename_litsphere name=Gold to="Old Gold"` | Rename one of your Lit Spheres and its image in the Lit Spheres folder; a name in use is refused (desktop app only) |+| `move_litsphere name=Gold folder=Metals` | Move one of your Lit Spheres into a sub-folder of the Lit Spheres folder (made if needed; `folder=""` moves it back) (desktop app only) || `remove_litsphere name=Gold` | Remove one of your Lit Spheres; its image in the Lit Spheres folder goes to the trash (desktop app only) || `set_background mode=flat color=60,70,80` | The view's background: `gradient` (the default) or `flat` with a colour (`#rrggbb`, `r,g,b` or a name); see [The background](interface.md#the-background) (desktop app only) || `set_shading mode=flat` | The scene's shading: `smooth` (the default) or `flat` (desktop app only) |diff --git a/src/app/App.cpp b/src/app/App.cppindex 73a534a2..adf455df 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -1409,7 +1409,7 @@ void App::dispatchEvent(const SDL_Event& event) {strokePopupKeyUp(e.key.key); // the stroke popup's held key: pick the item pointed atbreak;case SDL_EVENT_DROP_FILE:- if (e.drop.data) openPathConfirmed(e.drop.data);+ if (e.drop.data && !libraryBrowser_.takeDrop(*this, e.drop.x, e.drop.y, e.drop.data)) openPathConfirmed(e.drop.data);break;default:break;diff --git a/src/app/App.h b/src/app/App.hindex 5763097d..38fcb822 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -894,6 +894,9 @@ private:void loadLitSphereDialog(); // Material > Load Lit Sphere...void rescanLitSphereFolder(); // loads new / changed images in lit sphereFolder(), drops deleted onesvoid materialListShown(); // a material list is on screen: rescans when it has just opened+ std::vector<std::string> litsphereSubfolders() const; // sub-folders of litsphereFolder() (one level), sorted+ std::string litsphereLocked(int index) const; // why Rename / Move can't touch it ("" = they can)+ bool moveLitSphereFile(int index, const std::string& to, const std::string& group, std::string& error);std::map<std::string, std::pair<uintmax_t, int64_t>> litsphereFolderSeen_; // path -> size, time at the last scanstd::set<std::string> hiddenLitSphereFiles_; // removed Lit Spheres whose file couldn't go to the trashint materialListFrame_ = -10;@@ -1583,6 +1586,7 @@ private:friend struct PickerUi;friend void drawAlphaGrid(App&, GridMode);friend void drawMaterialGrid(App&, GridMode);+ friend void litsphereMenu(App&, int, const std::function<void()>&);friend void drawStrokeGrid(App&, GridMode);void initLibraryBrowser(); // end of init(): library folders, thumbnail cache, actions, project thumbnailsvoid showStarterMeshes(); // the Library at Tool > Starter meshes (File > New from Starter Mesh, the welcome)diff --git a/src/app/LibraryBrowser.cpp b/src/app/LibraryBrowser.cppindex 5d08dfe7..7a7553f5 100644--- a/src/app/LibraryBrowser.cpp+++ b/src/app/LibraryBrowser.cpp@@ -5,6 +5,7 @@#include "app/App.h"#include "app/Pickers.h"+#include "app/SearchAliases.h"#include "app/Ui.h"#include "app/I18n.h"#include "core/ListSort.h"@@ -29,6 +30,12 @@ namespace sf {namespace {+// The sub-folder of the Lit Spheres folder a Material tile is in ("" for others): a heading in the strip (#124).+std::string materialGroup(const AssetEntry& e) {+ const CustomLitSphere* c = e.kind == AssetKind::Material ? customLitSphere(e.index) : nullptr;+ return c ? c->group : std::string();+}+namespace fs = std::filesystem;constexpr const char* kStarterFolder = "Starter meshes"; // the Tool tab's folder of core/StarterMeshes.h@@ -285,6 +292,16 @@ void LibraryBrowser::rootEntries(App& app, std::vector<AssetEntry>& out) {e.name = i < 0 ? "Studio" : litsphereName(i);out.push_back(std::move(e));}+ { // grouped like the pickers (#124): ungrouped first, then each sub-folder of the Lit Spheres folder+ const std::vector<std::string> groups = litsphereGroups();+ std::stable_sort(out.begin(), out.end(), [&](const AssetEntry& a, const AssetEntry& b) {+ const auto rank = [&](const AssetEntry& e) {+ const std::string g = materialGroup(e);+ return g.empty() ? 0 : int(std::find(groups.begin(), groups.end(), g) - groups.begin()) + 1;+ };+ return rank(a) < rank(b);+ });+ }break;case LibraryTab::Image:case LibraryTab::Splats: {@@ -377,9 +394,14 @@ std::vector<AssetEntry> LibraryBrowser::entries(App& app) {}if (filter_[0]) {const std::string f = lower(filter_);+ // A Lit Sphere also answers to its plain words (SearchAliases.h: "material capture", "material image").+ std::string litsphereWords = "lit sphere";+ for (const std::string& w : searchAliasesIn("Lit Sphere")) litsphereWords += ", " + lower(w);out.erase(std::remove_if(out.begin(), out.end(),[&](const AssetEntry& e) {- return e.kind != AssetKind::Up && lower(e.name).find(f) == std::string::npos;+ if (e.kind == AssetKind::Up || lower(e.name).find(f) != std::string::npos) return false;+ return !(e.kind == AssetKind::Material && e.index >= 0 &&+ litsphereWords.find(f) != std::string::npos);}),out.end());}@@ -513,6 +535,10 @@ void LibraryBrowser::activate(App& app, const AssetEntry& e, bool append) {}void LibraryBrowser::contextMenu(App& app, const AssetEntry& e) {+ if (e.kind == AssetKind::Material && isCustomLitSphere(e.index)) { // as in the pickers (#124)+ litsphereMenu(app, e.index);+ return;+ }ImGui::TextDisabled("%s", e.name.c_str());ImGui::Separator();const bool mesh = e.kind == AssetKind::Mesh || e.kind == AssetKind::Project || e.kind == AssetKind::Primitive;@@ -813,6 +839,7 @@ void LibraryBrowser::draw(App& app, const CanvasRect& canvas) {if (open_ && ImGui::IsKeyPressed(ImGuiKey_Escape, false) && !ImGui::GetIO().WantCaptureKeyboard &&!ImGui::IsAnyItemActive() && !ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel))open_ = false;+ shownMin_ = shownMax_ = ImVec2(0, 0);if (!open_) {pressing_ = tileDrag_ = false;return;@@ -840,6 +867,8 @@ void LibraryBrowser::draw(App& app, const CanvasRect& canvas) {}ImDrawList* wdl = ImGui::GetWindowDrawList();const ImVec2 wp = ImGui::GetWindowPos(), ws = ImGui::GetWindowSize();+ shownMin_ = wp;+ shownMax_ = ImVec2(wp.x + ws.x, wp.y + ws.y);// 1 px edge toward the canvas.const float edge = layout.libraryBottom ? wp.y : wp.y + ws.y - 1.0f;wdl->AddLine(ImVec2(wp.x, edge), ImVec2(wp.x + ws.x, edge), IM_COL32(14, 14, 16, 255));@@ -854,8 +883,31 @@ void LibraryBrowser::draw(App& app, const CanvasRect& canvas) {const std::vector<AssetEntry> items = entries(app);const float tile = kTile * scale, rowH = (kTile + kLabel + 4.0f) * scale, gap = kGap * scale;- const int columns = int((items.size() + size_t(rows) - 1) / size_t(rows));- const float contentW = float(columns) * (tile + gap);+ // Column-major tiles; a Lit Sphere group (#124) starts a new column after a heading column with its name.+ std::vector<ImVec2> at(items.size()); // each tile's place in the strip (x, row)+ struct Heading {+ float x, w;+ std::string text;+ };+ std::vector<Heading> headings;+ float contentW = 0.0f;+ {+ float x = 0.0f;+ int row = 0;+ std::string group;+ for (size_t i = 0; i < items.size(); ++i) {+ if (const std::string g = materialGroup(items[i]); g != group) {+ group = g;+ if (row > 0) x += tile + gap, row = 0;+ const float w = std::min(ImGui::CalcTextSize(g.c_str()).x, tile * 1.5f) + 10.0f * scale;+ headings.push_back({x, w, g});+ x += w + gap;+ }+ at[i] = ImVec2(x, float(row));+ if (++row == rows) x += tile + gap, row = 0;+ }+ contentW = x + (row > 0 ? tile + gap : 0.0f);+ }ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 6.0f * scale);ImGui::SetNextWindowContentSize(ImVec2(contentW, float(rows) * rowH));@@ -898,8 +950,8 @@ void LibraryBrowser::draw(App& app, const CanvasRect& canvas) {const ImVec2 base = ImGui::GetCursorScreenPos();for (size_t i = 0; i < items.size(); ++i) {const AssetEntry& e = items[i];- const int col = int(i) / rows, row = int(i) % rows;- const float x = float(col) * (tile + gap);+ const float x = at[i].x;+ const int row = int(at[i].y);if (x + tile < scrollX - tile || x > scrollX + viewW + tile) continue; // off screen: no thumbnail workImGui::SetCursorScreenPos(ImVec2(base.x + x, base.y + float(row) * rowH + 4.0f * scale));const ImTextureID tex = thumbnail(app, e);@@ -938,6 +990,16 @@ void LibraryBrowser::draw(App& app, const CanvasRect& canvas) {ImGui::EndPopup();}}+ for (const Heading& h : headings) { // an accent rule down the rows, the folder's name at the top+ if (h.x + h.w < scrollX - tile || h.x > scrollX + viewW + tile) continue;+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const float x0 = base.x + h.x, y0 = base.y + 4.0f * scale;+ dl->AddLine(ImVec2(x0 + 1.0f, y0), ImVec2(x0 + 1.0f, y0 + float(rows) * rowH - 8.0f * scale), kAccent, 2.0f * scale);+ const ImVec2 t(x0 + 7.0f * scale, y0);+ dl->PushClipRect(t, ImVec2(x0 + h.w, y0 + float(rows) * rowH), true);+ dl->AddText(t, ImGui::GetColorU32(ImGuiCol_Text), h.text.c_str());+ dl->PopClipRect();+ }// Only folders (or nothing): say how things get here.const bool onlyFolders = std::all_of(items.begin(), items.end(), [](const AssetEntry& e) {return e.kind == AssetKind::Folder || e.kind == AssetKind::Up;@@ -956,7 +1018,7 @@ void LibraryBrowser::draw(App& app, const CanvasRect& canvas) {: "Nothing here yet.";const float x =base.x +- (items.empty() ? 8.0f : float((items.size() + size_t(rows) - 1) / size_t(rows)) * (tile + gap) + 12.0f);+ (items.empty() ? 8.0f : contentW + 12.0f);ImGui::SetCursorScreenPos(ImVec2(x, base.y + 4.0f * scale + tile * 0.5f - ImGui::GetTextLineHeight() * 0.5f));if (hint)ImGui::TextDisabled("%s", tr(hint));@@ -1014,6 +1076,13 @@ void LibraryBrowser::draw(App& app, const CanvasRect& canvas) {}}+bool LibraryBrowser::takeDrop(App& app, float x, float y, const std::string& path) {+ if (!open_ || place_.tab != LibraryTab::Material || !isLitSphereFile(path)) return false;+ if (x < shownMin_.x || y < shownMin_.y || x >= shownMax_.x || y >= shownMax_.y) return false;+ app.runCommand("load_litsphere", {{"path", path}}); // the loader Load Lit Sphere... uses, nothing new+ return true;+}+void LibraryBrowser::drawPreferences(App& app) {UiLayout& layout = app.layout_;ImGui::Checkbox(tr("Show at startup##library"), &showAtStartup);diff --git a/src/app/LibraryBrowser.h b/src/app/LibraryBrowser.hindex a4df8af9..95c16de2 100644--- a/src/app/LibraryBrowser.h+++ b/src/app/LibraryBrowser.h@@ -38,6 +38,11 @@ public:// Height the strip takes over the canvas at `rows` rows (logical px x scale).static float height(int rows, float scale);+ // A file dropped at (x, y) (window coordinates): an image dropped on the Material tab loads as a Lit Sphere (#124).+ // False when the Library doesn't take it (the canvas does what it always does).+ bool takeDrop(App& app, float x, float y, const std::string& path);+ ImVec2 shownCentre() const { return ImVec2((shownMin_.x + shownMax_.x) * 0.5f, (shownMin_.y + shownMax_.y) * 0.5f); }+// Thread-safe: the folder dialog's callback ("Open folder..." adds a library root).void folderChosen(const std::string& path);@@ -60,6 +65,7 @@ private:std::string folderLabel(const App& app, const std::string& folder) const;bool open_ = false;+ ImVec2 shownMin_{0, 0}, shownMax_{0, 0}; // the strip's window as last drawn (empty: not shown)Place place_;std::vector<Place> back_, forward_;char filter_[64] = "";diff --git a/src/app/PanelVertexPaint.cpp b/src/app/PanelVertexPaint.cppindex 0e373baa..4d6553ca 100644--- a/src/app/PanelVertexPaint.cpp+++ b/src/app/PanelVertexPaint.cpp@@ -55,23 +55,34 @@ void App::rescanLitSphereFolder() {if (dir.empty()) return;namespace fs = std::filesystem;std::map<std::string, std::pair<uintmax_t, int64_t>> now;- std::error_code ec;- for (fs::directory_iterator it(u8path(dir), ec), end; !ec && it != end; it.increment(ec)) {- std::error_code fileEc;- const std::string path = u8string(it->path());- if (!isLitSphereFile(path) || !it->is_regular_file(fileEc)) continue;- const auto size = it->file_size(fileEc);- const auto time = it->last_write_time(fileEc).time_since_epoch().count();- now[path] = {size, int64_t(time)};- }+ std::map<std::string, std::string> groupOf; // path -> its sub-folder ("" = the folder itself)+ // The folder and its sub-folders, one level deep (#124): each sub-folder is a heading in the lists.+ const auto list = [&](const fs::path& folder, const std::string& group) {+ std::error_code ec;+ for (fs::directory_iterator it(folder, ec), end; !ec && it != end; it.increment(ec)) {+ std::error_code fileEc;+ const std::string path = u8string(it->path());+ if (!isLitSphereFile(path) || !it->is_regular_file(fileEc)) continue;+ const auto size = it->file_size(fileEc);+ const auto time = it->last_write_time(fileEc).time_since_epoch().count();+ now[path] = {size, int64_t(time)};+ groupOf[path] = group;+ }+ };+ list(u8path(dir), "");+ for (const std::string& sub : litsphereSubfolders()) list(u8path(dir) / u8path(sub), sub);for (const auto& [path, stamp] : now) {if (hiddenLitSphereFiles_.count(path)) continue;const auto seen = litsphereFolderSeen_.find(path);if (seen != litsphereFolderSeen_.end() && seen->second == stamp) continue;CustomLitSphere m;std::string err;- if (readLitSphereImage(path, m, err)) addCustomLitSphere(std::move(m));- else SDL_Log("Lit Spheres: skipped %s", err.c_str());+ if (readLitSphereImage(path, m, err)) {+ m.group = groupOf[path];+ addCustomLitSphere(std::move(m));+ } else {+ SDL_Log("Lit Spheres: skipped %s", err.c_str());+ }}for (const auto& [path, stamp] : litsphereFolderSeen_)if (!now.count(path))@@ -79,6 +90,72 @@ void App::rescanLitSphereFolder() {litsphereFolderSeen_ = std::move(now);}+std::vector<std::string> App::litsphereSubfolders() const {+ std::vector<std::string> subs;+ const std::string dir = litsphereFolder();+ if (dir.empty()) return subs;+ namespace fs = std::filesystem;+ std::error_code ec;+ for (fs::directory_iterator it(u8path(dir), ec), end; !ec && it != end; it.increment(ec)) {+ std::error_code dirEc;+ const std::string name = u8string(it->path().filename());+ if (!name.empty() && name[0] != '.' && it->is_directory(dirEc)) subs.push_back(name);+ }+ std::sort(subs.begin(), subs.end());+ return subs;+}++// Why Rename / Move to folder can't change this Lit Sphere's file, or "" when they can: only images in the library's+// Lit Spheres folder (or a sub-folder of it) that SculptForge may write are ours to rename.+std::string App::litsphereLocked(int index) const {+ const CustomLitSphere* c = customLitSphere(index);+ if (!c) return "Built-in Lit Spheres can't be renamed or moved.";+ if (std::find(packs_.litspheres.begin(), packs_.litspheres.end(), index) != packs_.litspheres.end())+ return "This Lit Sphere comes from a pack, which stays as it was installed.";+ if (c->path.empty())+ return "This Lit Sphere came with the open project and has no file of its own. Load Lit Sphere... with its image "+ "to keep it in your library.";+ namespace fs = std::filesystem;+ std::error_code ec;+ const fs::path file = u8path(c->path), parent = file.parent_path();+ const bool ours = !litsphereFolder().empty() && (fs::equivalent(parent, u8path(litsphereFolder()), ec) ||+ fs::equivalent(parent.parent_path(), u8path(litsphereFolder()), ec));+ if (!ours) {+ for (const std::string& d : studioLitSphereDirs())+ if (fs::equivalent(parent, u8path(d), ec))+ return "This Lit Sphere comes from a studio folder (SCULPTFORGE_LITSPHERE_PATH), which SculptForge only reads.";+ return "Only Lit Spheres in your library's Lit Spheres folder can be renamed or moved.";+ }+ const fs::perms p = fs::status(file, ec).permissions();+ if (!ec && (p & fs::perms::owner_write) == fs::perms::none) return "Its file is read-only.";+ return {};+}++// Moves the image of a custom Lit Sphere in the Lit Spheres folder to `to` (no overwrite) and keeps the lists in step.+bool App::moveLitSphereFile(int index, const std::string& to, const std::string& group, std::string& error) {+ namespace fs = std::filesystem;+ const std::string from = customLitSphere(index)->path;+ std::error_code ec;+ if (fs::exists(u8path(to), ec) && !fs::equivalent(u8path(from), u8path(to), ec)) { // (equivalent: only the case changes)+ error = u8string(u8path(to).filename()) + " is already there";+ return false;+ }+ fs::create_directories(u8path(to).parent_path(), ec);+ ec.clear();+ fs::rename(u8path(from), u8path(to), ec);+ if (ec) {+ error = "Couldn't move " + from + ": " + ec.message();+ return false;+ }+ relocateCustomLitSphere(index, to, group);+ if (const auto seen = litsphereFolderSeen_.find(from); seen != litsphereFolderSeen_.end()) { // not new on the next scan+ const auto stamp = seen->second;+ litsphereFolderSeen_.erase(seen);+ litsphereFolderSeen_[to] = stamp;+ }+ return true;+}+// Material lists (palette, picker, Library) call this every frame they show: the first frame after a gap rescans.void App::materialListShown() {const int frame = ImGui::GetFrameCount();@@ -167,6 +244,55 @@ void App::registerPaintUiCommands() {return {true, "Removed " + shown + " for this session; delete " + path +" to remove it for good (" + err + ")"};}});+ commands_.add({"rename_litsphere",+ "Rename one of your Lit Spheres (#124): its image in the library's Lit Spheres folder is renamed too. "+ "Projects that use it still find it (they match its pixels). Built-in, studio-folder, pack and "+ "project-only Lit Spheres can't be renamed; a name another Lit Sphere has is refused.",+ {{"name", ParamSpec::Type::String, "The Lit Sphere's name.", true},+ {"to", ParamSpec::Type::String, "The new name (also the file name, without its extension).", true}},+ [this](Document&, const Args& a) -> CommandResult {+ const std::string name = argString(a, "name"), to = argString(a, "to");+ const int index = findLitSphere(name);+ if (index < 0) return {false, "No Lit Sphere called '" + name + "'"};+ if (const std::string why = litsphereLocked(index); !why.empty()) return {false, why};+ const std::string old = litsphereName(index);+ if (to == old) return {true, "Unchanged: " + old};+ std::string err;+ if (!checkLitSphereFileName(to, err)) return {false, err};+ if (const int other = findLitSphere(to); other >= 0 && other != index)+ return {false, std::string("There is already a Lit Sphere called ") + litsphereName(other)};+ namespace fs = std::filesystem;+ const CustomLitSphere* c = customLitSphere(index);+ const fs::path from = u8path(c->path);+ const std::string dest = u8string(from.parent_path() / u8path(to + u8string(from.extension())));+ if (!moveLitSphereFile(index, dest, c->group, err) || !renameCustomLitSphere(index, to, err))+ return {false, err};+ return {true, "Renamed " + old + " to " + to};+ }});+ commands_.add({"move_litsphere",+ "Move one of your Lit Spheres into a sub-folder of the library's Lit Spheres folder (#124), which the "+ "material lists show as a heading; the folder is made if it isn't there. An empty folder moves it "+ "back to the Lit Spheres folder itself.",+ {{"name", ParamSpec::Type::String, "The Lit Sphere's name.", true},+ {"folder", ParamSpec::Type::String, "The sub-folder's name (one level; empty: none).", true}},+ [this](Document&, const Args& a) -> CommandResult {+ const std::string name = argString(a, "name"), folder = argString(a, "folder");+ const int index = findLitSphere(name);+ if (index < 0) return {false, "No Lit Sphere called '" + name + "'"};+ if (const std::string why = litsphereLocked(index); !why.empty()) return {false, why};+ std::string err;+ if (!folder.empty() && !checkLitSphereFileName(folder, err)) return {false, "Folder: " + err};+ namespace fs = std::filesystem;+ const CustomLitSphere* c = customLitSphere(index);+ if (c->group == folder) return {true, std::string(litsphereName(index)) + " is already there"};+ fs::path dir = u8path(litsphereFolder());+ if (!folder.empty()) dir /= u8path(folder);+ if (!moveLitSphereFile(index, u8string(dir / u8path(c->path).filename()), folder, err))+ return {false, err};+ ++materialListFrame_; // (nothing else to redo: the lists group by the registry)+ return {true, std::string("Moved ") + litsphereName(index) + " to " ++ (folder.empty() ? std::string("Lit Spheres") : folder)};+ }});// Viewport shading: Lit Sphere or PBR (render/Renderer.h RenderSettings, core/EnvironmentMath.h).commands_.add({"viewport_shading","Viewport shading: lit_sphere (the material sphere or studio lights, the default) or pbr (the "diff --git a/src/app/Pickers.cpp b/src/app/Pickers.cppindex 6bcee1fa..46c064c9 100644--- a/src/app/Pickers.cpp+++ b/src/app/Pickers.cpp@@ -1037,6 +1037,90 @@ void drawAlphaGrid(App& app, GridMode mode) {AssetTileHoverGlow();}+void litsphereMenu(App& app, int index, const std::function<void()>& beforeRemove) {+ // One rename or new-folder field at a time, kept while the menu stays open.+ static int editing = -1; // the Lit Sphere whose field shows+ static bool folderField = false; // the field is Move to folder > New folder... (else Rename)+ static bool focus = false;+ static char buffer[128] = {};+ static std::string error;+ if (ImGui::IsWindowAppearing()) editing = -1, error.clear();+ const std::string name = litsphereName(index); // a copy: a rename changes it+ ImGui::TextDisabled("%s", name.c_str());+ const CustomLitSphere* c = customLitSphere(index);+ if (c && !c->path.empty()) { // the file name (and its folder); the whole path is long+ const std::filesystem::path p(std::u8string(c->path.begin(), c->path.end()));+ const std::u8string file = (c->group.empty() ? p.filename() : p.parent_path().filename() / p.filename()).u8string();+ ImGui::TextDisabled("%s", reinterpret_cast<const char*>(file.c_str()));+ }+ ImGui::Separator();+ const std::string locked = app.litsphereLocked(index);+ const auto lockedTip = [&] {+ if (!locked.empty() && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) ImGui::SetTooltip("%s", locked.c_str());+ };+ // The inline field: Enter applies, Escape cancels; a refusal (a name clash...) shows under it and keeps it open.+ const auto field = [&](const char* id, bool forFolder) {+ if (editing != index || folderField != forFolder) return;+ if (focus) {+ ImGui::SetKeyboardFocusHere();+ focus = false;+ }+ ImGui::SetNextItemWidth(180.0f * app.uiScale_);+ if (ImGui::InputText(id, buffer, sizeof buffer, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {+ if (forFolder) app.runCommand("move_litsphere", {{"name", name}, {"folder", std::string(buffer)}});+ else app.runCommand("rename_litsphere", {{"name", name}, {"to", std::string(buffer)}});+ if (app.lastCommandOk_) {+ editing = -1;+ error.clear();+ ImGui::CloseCurrentPopup();+ } else {+ error = app.status_;+ focus = true;+ }+ }+ if (!error.empty()) {+ ImGui::PushStyleColor(ImGuiCol_Text, theme::danger);+ ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + 240.0f * app.uiScale_);+ ImGui::TextUnformatted(error.c_str());+ ImGui::PopTextWrapPos();+ ImGui::PopStyleColor();+ }+ };+ const auto openField = [&](bool forFolder) {+ editing = index;+ folderField = forFolder;+ focus = true;+ error.clear();+ std::snprintf(buffer, sizeof buffer, "%s", forFolder ? "" : name.c_str());+ };+ ImGui::BeginDisabled(!locked.empty());+ if (ImGui::Selectable("Rename...##litsphere", false, ImGuiSelectableFlags_NoAutoClosePopups)) openField(false);+ ImGui::EndDisabled();+ lockedTip();+ field("##litsphererename", false);+ ImGui::BeginDisabled(!locked.empty());+ const bool moveMenu = ImGui::BeginMenu("Move to folder##litsphere");+ ImGui::EndDisabled();+ lockedTip();+ if (moveMenu) {+ const std::string group = c ? c->group : std::string();+ if (ImGui::MenuItem("Lit Spheres (no folder)##litspheremove", nullptr, group.empty(), !group.empty()))+ app.runCommand("move_litsphere", {{"name", name}, {"folder", std::string()}});+ for (const std::string& sub : app.litsphereSubfolders())+ if (ImGui::MenuItem((sub + "##litspheremove").c_str(), nullptr, sub == group, sub != group))+ app.runCommand("move_litsphere", {{"name", name}, {"folder", sub}});+ ImGui::Separator();+ if (ImGui::Selectable("New folder...##litsphere", false, ImGuiSelectableFlags_NoAutoClosePopups)) openField(true);+ field("##litspherefolder", true);+ ImGui::EndMenu();+ }+ ImGui::Separator();+ if (ImGui::MenuItem("Remove##litsphere")) {+ if (beforeRemove) beforeRemove();+ app.runCommand("remove_litsphere", {{"name", name}});+ }+}+void drawMaterialGrid(App& app, GridMode mode) {State& s = st();const bool popup = mode == GridMode::Popup;@@ -1055,8 +1139,23 @@ void drawMaterialGrid(App& app, GridMode mode) {list.push_back(i);keys.push_back({i < 0 ? "Studio" : litsphereName(i), "", recentRank(s.recentMaterials, std::to_string(i))});}- for (size_t o : listSortOrder(keys, listSortFromId(app.uiPrefs_.materialSort))) {+ // The chosen order, then grouped (#124): ungrouped first, then each sub-folder of the Lit Spheres folder under its heading.+ std::vector<size_t> order = listSortOrder(keys, listSortFromId(app.uiPrefs_.materialSort));+ const std::vector<std::string> groups = litsphereGroups();+ const auto groupRank = [&](size_t o) {+ const CustomLitSphere* c = customLitSphere(list[o]);+ if (!c || c->group.empty()) return 0;+ return int(std::find(groups.begin(), groups.end(), c->group) - groups.begin()) + 1;+ };+ std::stable_sort(order.begin(), order.end(), [&](size_t a, size_t b) { return groupRank(a) < groupRank(b); });+ int shownGroup = 0;+ for (size_t o : order) {const int i = list[o];+ if (const int g = groupRank(o); g != shownGroup) {+ shownGroup = g;+ sectionHeader(groups[size_t(g - 1)].c_str());+ column = 0;+ }tileGrid(column, columns);const char* name = i < 0 ? "Studio" : litsphereName(i);const ImTextureID tex = app.thumbs_.material(i);@@ -1073,23 +1172,16 @@ void drawMaterialGrid(App& app, GridMode mode) {"rim, so strokes read without glare.": i == 0 ? "Made for sculpting: a strong key light, crisp highlights and deep cavities so ""every stroke reads."- : isCustomLitSphere(i) ? "Your own Lit Sphere. Right-click to remove it."+ : isCustomLitSphere(i) ? "Your own Lit Sphere. Right-click to rename it, move it to a folder or remove it.": "Lit Sphere material: the whole lit look in one image.","Material");if (isCustomLitSphere(i) && ImGui::BeginPopupContextItem()) {- ImGui::TextDisabled("%s", name);- if (const CustomLitSphere* c = customLitSphere(i); c && !c->path.empty()) { // the file name; the folder is long- const std::u8string file = std::filesystem::path(std::u8string(c->path.begin(), c->path.end())).filename().u8string();- ImGui::TextDisabled("%s", reinterpret_cast<const char*>(file.c_str()));- }- ImGui::Separator();- if (ImGui::MenuItem("Remove##litsphere")) {+ litsphereMenu(app, i, [&] {if (popup && s.previewing) { // put the real material back before it can goapp.renderSettings_.litsphere = s.savedLitSphere;s.previewing = false;}- app.runCommand("remove_litsphere", {{"name", std::string(name)}});- }+ });ImGui::EndPopup();}}diff --git a/src/app/Pickers.h b/src/app/Pickers.hindex 54820eef..895933b5 100644--- a/src/app/Pickers.h+++ b/src/app/Pickers.h@@ -8,6 +8,7 @@#include <imgui.h>+#include <functional>#include <string>#include <vector>@@ -31,6 +32,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 right-click menu of a custom Lit Sphere (#124), inside an open pop-up: Rename..., Move to folder, Remove.+// `beforeRemove` runs just before it is removed (the picker puts its hover preview back).+void litsphereMenu(App& app, int index, const std::function<void()>& beforeRemove = {});// 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);diff --git a/src/app/SearchAliases.h b/src/app/SearchAliases.hindex f8ec4d9b..f217d320 100644--- a/src/app/SearchAliases.h+++ b/src/app/SearchAliases.h@@ -37,7 +37,7 @@ inline constexpr SearchAlias kSearchAliases[] = {{"Append", "insert, kitbash, add mesh, import mesh", true},{"Library", "assets, browser", false},{"Forge Sphere", "armature, skeleton, base mesh", false},- {"Lit Sphere", "sphere material, shader", false},+ {"Lit Sphere", "sphere material, shader, material capture, material image", false},{"Close Holes", "fill holes, cap, watertight", false},{"Snapshot", "checkpoint, backup", false},{"Steady Stroke", "stabilizer, smoothing", false},diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 3390e1db..c018dc32 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -49,6 +49,7 @@// camera_distance D put the camera D model units from the point it looks at (extreme zoom)// run COMMANDS sculptforge-cli commands, e.g. run new_sphere subdivisions=4 ($SCRIPT_DIR: the script's folder)// drop FILE as if FILE were dropped onto the window (relative to the script's folder)+// drop_library FILE as if FILE were dropped onto the middle of the Library strip (an SDL drop event there)// restart [FILE] as quitting and starting again, for the preferences, shortcuts and layout: ui.json// is saved (what waits), the defaults come back, then ui.json is read as at the start;// FILE (beside the script) replaces ui.json first (an older version's settings)@@ -707,6 +708,17 @@ double Demo::query(const std::string& name, bool& known) const {n += isLitSphereFile(it->path().string()) ? 1 : 0;return double(n);}+ if (name == "litsphere_folder_files") { // images in the Lit Spheres folder's sub-folders (#124)+ int n = 0;+ for (const std::string& sub : app_.litsphereSubfolders()) {+ const std::string dir = app_.litsphereFolder() + "/" + sub;+ std::error_code ec;+ for (std::filesystem::directory_iterator it(std::filesystem::path(std::u8string(dir.begin(), dir.end())), ec), end;+ !ec && it != end; it.increment(ec))+ n += isLitSphereFile(it->path().string()) ? 1 : 0;+ }+ return double(n);+ }if (name == "flat_shading") return app_.renderSettings_.flatShading ? 1.0 : 0.0;if (name == "gradient_background") return app_.renderSettings_.gradientBackground ? 1.0 : 0.0;if (name == "background_r" || name == "background_g" || name == "background_b") // 0-255, display values@@ -1560,6 +1572,21 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& eif (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 == "drop_library") { // drop_library FILE: the file dropped on the middle of the Library strip+ 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())] {+ const ImVec2 at = app_.libraryBrowser_.shownCentre();+ SDL_Event e{};+ e.type = SDL_EVENT_DROP_FILE;+ e.drop.windowID = SDL_GetWindowID(app_.window_);+ e.drop.x = at.x;+ e.drop.y = at.y;+ e.drop.data = path.c_str();+ app_.handleEvent(e);+ });} else if (verb == "choose_file" && w.size() > 2 && w[1] == "maya_folder") {// choose_file maya_folder <folder>: what File > Maya > Exchange folder's dialog would answer (relative to the// working directory, like copy's destination).diff --git a/src/core/LitSphere.cpp b/src/core/LitSphere.cppindex 19d3c2c2..a47f6ae3 100644--- a/src/core/LitSphere.cpp+++ b/src/core/LitSphere.cpp@@ -278,6 +278,55 @@ bool removeCustomLitSphere(int index) {return true;}+bool checkLitSphereFileName(const std::string& name, std::string& error) {+ if (name.empty()) error = "The name is empty";+ else if (name.size() > 100) error = "The name is too long";+ else if (name[0] == '.') error = "The name can't start with a dot";+ else if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') error = "The name can't start or end with a space or end with a dot";+ else if (name.find_first_of("/\\:*?\"<>|") != std::string::npos) error = "The name can't contain / \\ : * ? \" < > |";+ else if (std::any_of(name.begin(), name.end(), [](char c) { return static_cast<unsigned char>(c) < 32; }))+ error = "The name can't contain control characters";+ else return true;+ return false;+}++bool renameCustomLitSphere(int index, const std::string& name, std::string& error) {+ if (!isLitSphereListed(index) || !isCustomLitSphere(index)) {+ error = "Only your own Lit Spheres can be renamed";+ return false;+ }+ if (!checkLitSphereFileName(name, error)) return false;+ if (const int other = findLitSphere(name); other >= 0 && other != index) {+ error = std::string("There is already a Lit Sphere called ") + litsphereName(other);+ return false;+ }+ // A removed one with this name would come back over the renamed one if its file were loaded again: it keeps its+ // index under a name no list shows.+ for (size_t i = 0; i < customs().size(); ++i)+ if (customs()[i].removed && squash(customs()[i].name) == squash(name)) customs()[i].name += " (removed)";+ customs()[size_t(index - kStyleCount)].name = name;+ ++g_revision; // the lists and thumbnail keys show the name+ return true;+}++bool relocateCustomLitSphere(int index, const std::string& path, const std::string& group) {+ if (!isCustomLitSphere(index)) return false;+ CustomLitSphere& c = customs()[size_t(index - kStyleCount)];+ c.path = path;+ c.group = group;+ return true;+}++std::vector<std::string> litsphereGroups() {+ std::vector<std::string> groups;+ for (const CustomLitSphere& c : customs())+ if (!c.removed && !c.group.empty() &&+ std::none_of(groups.begin(), groups.end(), [&](const std::string& g) { return squash(g) == squash(c.group); }))+ groups.push_back(c.group);+ std::sort(groups.begin(), groups.end(), [](const std::string& a, const std::string& b) { return squash(a) < squash(b); });+ return groups;+}+int findLitSphereByHash(uint64_t hash) {for (size_t i = 0; i < customs().size(); ++i)if (!customs()[i].removed && customs()[i].hash == hash) return kStyleCount + int(i);diff --git a/src/core/LitSphere.h b/src/core/LitSphere.hindex 1424376b..aaa3ad81 100644--- a/src/core/LitSphere.h+++ b/src/core/LitSphere.h@@ -45,6 +45,7 @@ struct CustomLitSphere {int size = 0; // size x size pixelsstd::vector<uint8_t> rgba; // sRGB RGBA8, rows bottom-up, as generateLit Sphereuint64_t hash = 0; // of the pixels (thumbnail keys, finding a project's Lit Sphere again)+ std::string group; // the sub-folder of the library's Lit Spheres folder it is in ("" = none): a list headingbool removed = false; // removeCustomLit Sphere: kept so indices stay put, but listed and found no more};constexpr int kMaxLitSphereSide = 1024; // bigger images are scaled down@@ -74,6 +75,17 @@ int addCustomLitSphere(CustomLitSphere m);// Takes a custom Lit Sphere out of the lists and name lookups for the rest of the session (its file is the caller's// business). False for built-ins and bad indices.bool removeCustomLitSphere(int index);+// Renames a listed custom Lit Sphere (#124; its file is the caller's business). False, with `error`, for built-ins, a+// name that isn't a valid file name (checkLitSphereFileName) or one another listed Lit Sphere has (case-insensitive).+bool renameCustomLitSphere(int index, const std::string& name, std::string& error);+// Where a custom Lit Sphere's image is now (after a rename or a move to another folder); bumps no revision (the pixels+// are the same). False for built-ins.+bool relocateCustomLitSphere(int index, const std::string& path, const std::string& group);+// A Lit Sphere or folder name that is also a portable file name: not empty, no / \ : * ? " < > |, no control+// characters, not "." or ".." or starting with a dot, no trailing dot or space, at most 100 bytes.+bool checkLitSphereFileName(const std::string& name, std::string& error);+// The groups the listed custom Lit Spheres are in, sorted case-insensitively ("" not included).+std::vector<std::string> litsphereGroups();// The listed custom Lit Sphere read from `path` (exact path), or -1.int findLitSphereByPath(const std::string& path);// The index of a custom Lit Sphere with exactly these pixels, or -1.diff --git a/tests/test_vertexpaint.cpp b/tests/test_vertexpaint.cppindex 4579fde5..336e19fd 100644--- a/tests/test_vertexpaint.cpp+++ b/tests/test_vertexpaint.cpp@@ -458,6 +458,48 @@ TEST(litsphere_remove_and_trash) {#endif}+TEST(litsphere_rename_move_and_hash) {+ // #124: renaming keeps the index and the pixels, so a project that carries the image (matched by its pixel hash)+ // still finds it under the new name; a name clash or a name that can't be a file name is refused.+ CustomLitSphere m;+ m.name = "Rename Me";+ m.size = 16;+ m.rgba.assign(16 * 16 * 4, 91);+ m.path = "/lib/Lit Spheres/Rename Me.png";+ const int i = addCustomLitSphere(m);+ CustomLitSphere other = m;+ other.name = "Taken Name";+ other.rgba.assign(16 * 16 * 4, 92);+ other.hash = 0;+ const int j = addCustomLitSphere(other);+ const uint64_t hash = customLitSphere(i)->hash, revision = litsphereRevision();+ std::string err;+ CHECK(renameCustomLitSphere(i, "Brass Polished", err) && litsphereRevision() != revision);+ CHECK(std::string(litsphereName(i)) == "Brass Polished" && findLitSphere("brass polished") == i && findLitSphere("Rename Me") == -1);+ CHECK(findLitSphereByHash(hash) == i && customLitSphere(i)->hash == hash && litsphereKey(i).find("Brass Polished#") == 0);+ CHECK(!renameCustomLitSphere(i, "taken name", err) && err.find("Taken Name") != std::string::npos && findLitSphere("Taken Name") == j);+ CHECK(!renameCustomLitSphere(i, "Chrome", err) && std::string(litsphereName(i)) == "Brass Polished"); // a built-in's+ CHECK(!renameCustomLitSphere(0, "Anything", err)); // built-ins stay+ for (const char* bad : {"", "a/b", "a\\b", "x:y", ".hidden", "trail.", "who?", "pipe|", " lead"})+ CHECK(!checkLitSphereFileName(bad, err) && !renameCustomLitSphere(i, bad, err));+ CHECK(checkLitSphereFileName("Gold Leaf (old) 2", err) && checkLitSphereFileName("Grès émaillé", err));+ // A removed one of the wanted name doesn't block it, and can't take it back later.+ CHECK(removeCustomLitSphere(j) && renameCustomLitSphere(i, "Taken Name", err) && findLitSphere("Taken Name") == i);+ const int k = addCustomLitSphere(m); // "Rename Me" again: a new one+ CHECK(k != i && findLitSphere("Taken Name") == i && removeCustomLitSphere(k));++ // Moving to a sub-folder: the path and the group change, nothing else; the lists' headings follow the groups.+ CHECK(relocateCustomLitSphere(i, "/lib/Lit Spheres/Metals/Taken Name.png", "Metals") && !relocateCustomLitSphere(0, "x", "y"));+ CHECK(customLitSphere(i)->group == "Metals" && findLitSphereByHash(hash) == i);+ const std::vector<std::string> groups = litsphereGroups();+ CHECK(std::find(groups.begin(), groups.end(), "Metals") != groups.end() &&+ std::find(groups.begin(), groups.end(), "") == groups.end());+ CHECK(relocateCustomLitSphere(i, m.path, ""));+ const std::vector<std::string> after = litsphereGroups();+ CHECK(std::find(after.begin(), after.end(), "Metals") == after.end());+ removeCustomLitSphere(i);+}+TEST(vertexpaint_restore_stroke_marks_colors_dirty) {// DragRect re-stamps by restoring the stroke first: the reverted colours must reach the GPU.Document doc = makeDoc(makeIcosphere(3));diff --git a/tests/ui/litsphere_manage.sfui b/tests/ui/litsphere_manage.sfuinew file mode 100644index 00000000..b18e4d26--- /dev/null+++ b/tests/ui/litsphere_manage.sfui@@ -0,0 +1,91 @@+# Your own Lit Spheres, organised (#124): Rename and Move to folder in the right-click menu, sub-folders of the Lit+# Spheres folder as headings, a dropped image on the Library's Material tab, and projects that keep finding a renamed one.+run ui_look look=classic layout=classic # written for the Classic look and the classic palette bar and shelves+run new_sphere subdivisions=4+run load_litsphere path=$SCRIPT_DIR/data/Gold.png+run load_litsphere path=$SCRIPT_DIR/data/Rose.png+expect_value custom_litspheres == 2+expect_value litsphere_files == 2+run set_material name=gold+run save_project path=sf_ui_litsphere_manage.sfproj++# Rename from the palette's material list: a name another Lit Sphere has is refused in place, nothing overwritten.+click "Material##palette.material"+wait_idle 20+right_click "Material/Gold"+expect "Rename...##litsphere"+expect "Move to folder##litsphere"+click "Rename...##litsphere"+type "##litsphererename" rose+key enter+expect_text "There is already a Lit Sphere called Rose"+expect_value litsphere_files == 2+shot rename-clash+type "##litsphererename" Old Gold+key enter+expect_status "Renamed Gold to Old Gold"+expect_value custom_litspheres == 2+expect_value litsphere_files == 2+expect_value material_custom == 1+key escape+click "Material##palette.material"+wait_idle 20+expect "Material/Old Gold"+expect_not "Material/Gold"+key escape++# The project saved with Gold opens with it: matched by its pixels, not added again under the old name.+run set_material name=studio+run open path=sf_ui_litsphere_manage.sfproj+expect_value material_custom == 1+expect_value custom_litspheres == 2++# Move to folder: the sub-folder is made and becomes a heading in the lists; moving it back takes the heading away.+run move_litsphere name="old gold" folder=Metals+expect_status "Moved Old Gold to Metals"+expect_value litsphere_files == 1+expect_value litsphere_folder_files == 1+run_fails move_litsphere name=rose folder=../escape+run_fails rename_litsphere name=rose to=a/b+run_fails rename_litsphere name=chrome to=Shiny+click "Material##palette.material"+wait_idle 20+expect_text "Metals"+expect "Material/Old Gold"+shot grouped-palette+right_click "Material/Rose"+hover "Move to folder##litsphere"+wait 0.3+expect "Metals##litspheremove"+shot move-menu+click "Metals##litspheremove"+expect_status "Moved Rose to Metals"+expect_value litsphere_folder_files == 2+key escape++# A folder the app didn't make, made outside it: its images show under its heading on the next look.+copy data/Gold.png "$LIBRARY/Lit Spheres/Warm/Amber.png"+key ,+click "Library/Material"+wait_idle 20+expect "Library/Old Gold"+shot library-groups+type "##lbfilter" amb+wait_idle 20+expect "Library/Amber"+right_click "Library/Amber"+expect "Rename...##litsphere"+key escape+# The filter also finds Lit Spheres by their plain words (aliases, not names in the UI).+type "##lbfilter" material capture+expect "Library/Chrome"+expect "Library/Amber"+type "##lbfilter" chrome+expect_not "Library/Amber"++# An image dropped on the Material tab loads as a Lit Sphere (dropped on the canvas it keeps its usual meaning).+drop_library data/Gold.png+expect_status "Material: Gold"+expect_value custom_litspheres == 4+run move_litsphere name="old gold" folder=""+expect_value litsphere_folder_files == 2diff --git a/tools/guide/shots.sfui b/tools/guide/shots.sfuiindex b34cefc8..bf63f416 100644--- a/tools/guide/shots.sfui+++ b/tools/guide/shots.sfui@@ -371,6 +371,19 @@ wait_idle 20wait 0.2shot custom-lit-sphereskey escape+# ... organised in a folder (#124): its heading, and the right-click menu's Move to folder.+run load_litsphere path=tests/ui/data/Rose.png+run move_litsphere name=Gold folder=Metals+click "Render##menu.render"+click "Materials##section.material"+wait_idle 20+right_click "Material/Rose"+hover "Move to folder##litsphere"+wait 0.3+shot lit-sphere-folders+key escape+key escape+run move_litsphere name=Gold folder=""run set_material name="Soft Clay"# Extract (parts.md): a cap made from the masked top of a sphere, shown with its face groups (outer, inner, rim).diff --git a/website/index.html b/website/index.htmlindex 137ac55a..1f087fcc 100644--- a/website/index.html+++ b/website/index.html@@ -142,7 +142,8 @@<article class="card"><h3>Vertex paint, layers and lit spheres</h3><p>Paint colour straight onto the sculpt in layers with blend modes, tint the cavities, and judge forms- under the Sculpt, Red Wax, Clay, Skin, Bronze, Chrome or White materials.</p>+ under the Sculpt, Red Wax, Clay, Skin, Bronze, Chrome or White materials, or load your own material capture+ (lit sphere) images and keep them in folders.</p></article><article class="card" id="blender"><h3>Works with Blender</h3>