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
SubTools in the app: every SubTool in the viewport, a SubTools panel, Alt+click
islandmed9c463497f37e
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 7c1b5fe2..4e157fb6 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -123,6 +123,7 @@ if(SCULPTFORGE_BUILD_APP)src/app/PanelPolypaint.cppsrc/app/PanelGoz.cppsrc/app/PanelProject.cpp+ src/app/PanelSubTools.cppsrc/render/GL.cppsrc/render/Camera.cppsrc/render/Renderer.cppdiff --git a/src/app/App.cpp b/src/app/App.cppindex f4e50028..ae9a9e46 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -249,8 +249,8 @@ int App::renderHeadless() {settings.wireframe = options_.wireframe;settings.showPolygroups = settings.showPolygroups || options_.polygroups;settings.showMesh = !options_.hideMesh;- renderer_.sync(doc_.mesh);- renderer_.syncSplats(doc_.splats, doc_.splatsVersion);+ settings.dimInactive = false; // a beauty shot: every SubTool at full brightness+ syncScene();const std::filesystem::path out(std::u8string(options_.renderPath.begin(), options_.renderPath.end()));for (int f = 0; f < frames; ++f) {camera_.yaw = glm::radians(options_.yawDegrees + 360.0f * float(f) / float(frames));@@ -315,11 +315,7 @@ int App::runUiTest(int w, int h, int fps) {ImGui::LogFinish();ImGui::Render();- Mesh& shown = displayedMesh();- if (&shown != lastDisplayed_) shown.topologyDirty = true;- lastDisplayed_ = &shown;- renderer_.sync(shown);- renderer_.syncSplats(doc_.splats, doc_.splatsVersion);+ syncScene();++frames;const std::string shot = demo_->takeShotRequest();if (shot.empty()) continue;@@ -395,11 +391,7 @@ int App::runRecording() {demo_->drawOverlay();ImGui::Render();- Mesh& shown = displayedMesh();- if (&shown != lastDisplayed_) shown.topologyDirty = true;- lastDisplayed_ = &shown;- renderer_.sync(shown);- renderer_.syncSplats(doc_.splats, doc_.splatsVersion);+ syncScene();++frames;// While waiting on a model, keep only every Nth frame (marked on screen as sped up).if ((frames % demo_->frameStride()) != 0) continue;@@ -455,11 +447,7 @@ int App::run() {drawUi();ImGui::Render();- Mesh& shown = displayedMesh();- if (&shown != lastDisplayed_) shown.topologyDirty = true;- lastDisplayed_ = &shown;- renderer_.sync(shown);- renderer_.syncSplats(doc_.splats, doc_.splatsVersion);+ syncScene();renderer_.draw(camera_, fbW, fbH, renderSettings_);ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());SDL_GL_SwapWindow(window_);@@ -517,6 +505,7 @@ void App::handleEvent(const SDL_Event& e) {}bool App::pick(float x, float y, RayHit& hit) const {+ if (!doc_.activeSubtoolInfo().visible) return false; // you can't sculpt what you can't seeint w = 0, h = 0;SDL_GetWindowSize(window_, &w, &h);glm::vec3 origin, dir;@@ -536,6 +525,17 @@ void App::onMouseDown(float x, float y, Uint8 button) {doc_.syncBvh();if (button == SDL_BUTTON_LEFT) {if (polygroupMouseDown(x, y, mod)) return;+ // Alt+click on another SubTool selects it (ZBrush); Alt+drag stays an inverted stroke or a pan.+ if ((mod & SDL_KMOD_ALT) && !ctrlDown(mod) && !(mod & SDL_KMOD_SHIFT) && doc_.subtoolCount() > 1) {+ const int target = pickSubtool(x, y);+ if (target >= 0 && target != doc_.activeSubtool) {+ drag_ = Drag::SubToolClick;+ subtoolClickTarget_ = target;+ subtoolClickX_ = x;+ subtoolClickY_ = y;+ return;+ }+ }RayHit hit;const bool maskMod = ctrlDown(mod) && !(mod & SDL_KMOD_SHIFT);if (previewLod_ < 0 && pick(x, y, hit)) {@@ -569,6 +569,7 @@ void App::onMouseMove(float x, float y, float dx, float dy, bool fromPen) {case Drag::Pan: camera_.pan(dx, dy, float(h)); break;case Drag::Zoom: camera_.zoom(-dy * 0.05f); break;case Drag::MaskCanvas: maskCanvasMove(x, y); break;+ case Drag::SubToolClick: subtoolClickMove(x, y); break;case Drag::None: break;}}@@ -577,6 +578,7 @@ void App::onMouseUp() {if (hideRectActive_) polygroupMouseUp();if (drag_ == Drag::Stroke) endStroke();if (drag_ == Drag::MaskCanvas) maskCanvasRelease();+ if (drag_ == Drag::SubToolClick) subtoolClickRelease();drag_ = Drag::None;}@@ -828,7 +830,8 @@ void SDLCALL onFileChosen(void* userdata, const char* const* files, int) {void App::queueFile(FileAction action, std::string path) {if (action != FileAction::OpenObj && action != FileAction::LoadBrush && action != FileAction::OpenImage &&- !path.empty() && std::filesystem::path(std::u8string(path.begin(), path.end())).extension().empty())+ action != FileAction::AppendSubtool && !path.empty() &&+ std::filesystem::path(std::u8string(path.begin(), path.end())).extension().empty())path += action == FileAction::SaveObj ? ".obj": action == FileAction::SaveBrush ? ".sfbrush": action == FileAction::ExportUsd ? ".usdz"@@ -882,7 +885,8 @@ void App::saveFileDialog(FileAction action) {}AABB App::sceneBounds() const {- AABB b = doc_.mesh.bounds();+ AABB b = doc_.visibleBounds(); // every SubTool that's shown+ if (!b.valid()) b = doc_.mesh.bounds();if (!doc_.splats.empty() && renderSettings_.showSplats) b.expand(doc_.splats.bounds(0.9f));return b;}@@ -918,6 +922,10 @@ void App::processPendingFiles() {break;}case FileAction::SaveProject: saveProjectTo(f.path); break;+ case FileAction::AppendSubtool:+ runCommand("subtool_append", {{"path", f.path}});+ if (lastCommandOk_) camera_.frame(sceneBounds()); // a model can be any size, anywhere+ break;case FileAction::Count: break;}}@@ -931,6 +939,22 @@ Mesh& App::displayedMesh() {return previewLod_ >= 0 && previewLod_ < int(lods_.size()) ? lods_[previewLod_] : doc_.mesh;}+void App::syncScene() {+ // The active SubTool's slot shows the LOD being previewed instead of the sculpt.+ Mesh& shown = displayedMesh();+ if (&shown != lastDisplayed_) shown.topologyDirty = true;+ lastDisplayed_ = &shown;+ std::vector<SceneMesh> scene;+ scene.reserve(doc_.subtools.size());+ for (int i = 0; i < doc_.subtoolCount(); ++i) {+ SubTool& s = doc_.subtools[size_t(i)];+ const bool active = i == doc_.activeSubtool;+ scene.push_back({s.id, active ? &shown : &s.mesh, active, s.visible});+ }+ renderer_.syncScene(scene);+ renderer_.syncSplats(doc_.splats, doc_.splatsVersion);+}+void App::setLayerWeight(int index, float weight) {doc_.mesh.setLayerWeight(index, weight);doc_.bvhDirty = true;@@ -981,6 +1005,8 @@ void App::drawUi() {if (hideUi_) return; // demos: clean beauty shotsdrawMenuBar();drawToolPanel();+ if (showSubToolsPanel_) drawSubToolsPanel();+ drawSubToolPopups();if (showLayersPanel_) drawLayersPanel();if (showGamePanel_) drawGameExportPanel();drawSplatSection();@@ -1041,6 +1067,7 @@ void App::drawUi() {"Isolate polygroup Ctrl+Shift+click (again: invert)\n""Hide polygroup Ctrl+Shift+Alt+click\n""Show all Ctrl+Shift+click background\n"+ "Select SubTool Alt+click it\n""Hide outside rect Ctrl+Shift+drag (Alt: inside)\n""Brush size [ and ]\n""Brushes 1-9, 0\n"@@ -1104,6 +1131,7 @@ void App::drawMenuBar() {ImGui::MenuItem("Show Mask", nullptr, &renderSettings_.showMask);ImGui::MenuItem("Show Polygroups", nullptr, &renderSettings_.showPolygroups);ImGui::Separator();+ ImGui::MenuItem("SubTools Panel", nullptr, &showSubToolsPanel_);ImGui::MenuItem("Layers Panel", nullptr, &showLayersPanel_);ImGui::MenuItem("Game Ready Panel", nullptr, &showGamePanel_);ImGui::MenuItem("Gaussian Splats", nullptr, &showSplatsPanel_);diff --git a/src/app/App.h b/src/app/App.hindex 48229463..87853e24 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -56,7 +56,7 @@ public:int run(); // returns the process exit codevoid shutdown();- enum class FileAction { OpenObj, SaveObj, ExportGlb, ExportLods, SaveBrush, LoadBrush, OpenImage, ExportUsd, SaveSplats, ExportUnreal, SaveProject, Count };+ enum class FileAction { OpenObj, SaveObj, ExportGlb, ExportLods, SaveBrush, LoadBrush, OpenImage, ExportUsd, SaveSplats, ExportUnreal, SaveProject, AppendSubtool, Count };struct DialogRequest {App* app;FileAction action;@@ -65,7 +65,7 @@ public:void queueFile(FileAction action, std::string path);private:- enum class Drag { None, Stroke, Orbit, Pan, Zoom, MaskCanvas };+ enum class Drag { None, Stroke, Orbit, Pan, Zoom, MaskCanvas, SubToolClick };void handleEvent(const SDL_Event& e);void onMouseDown(float x, float y, Uint8 button);@@ -73,7 +73,7 @@ private:void onMouseUp();void onKey(SDL_Keycode key, SDL_Keymod mod);- bool pick(float x, float y, RayHit& hit) const;+ bool pick(float x, float y, RayHit& hit) const; // the active SubTool (what brushes work on)BrushType activeBrush() const;void beginStroke(float x, float y, const RayHit& hit);void strokeTo(float x, float y);@@ -92,6 +92,7 @@ private:void generateLods();void clearLods();Mesh& displayedMesh();+ void syncScene(); // uploads every SubTool (the active one as displayedMesh()) and the splats to the renderervoid drawUi();void drawToolPanel();@@ -347,6 +348,29 @@ private:uint64_t autosaveRevision_ = ~uint64_t(0);bool autosaveWritten_ = false;std::string windowTitle_;+ // SubTools (PanelSubTools.cpp): the panel, and Alt+click in the viewport to select one.+ void drawSubToolsPanel();+ void drawSubToolPopups();+ // Index of the nearest visible SubTool under the cursor (-1: none); builds stale BVHs on the way.+ int pickSubtool(float x, float y, RayHit* hit = nullptr);+ void subtoolClickMove(float x, float y); // Alt press on another SubTool: dragging turns it into a stroke+ void subtoolClickRelease(); // ... and releasing without dragging selects it+ bool showSubToolsPanel_ = true;+ int subtoolClickTarget_ = -1;+ float subtoolClickX_ = 0.0f, subtoolClickY_ = 0.0f;+ uint32_t renamingSubtool_ = 0; // SubTool id being renamed inline (0: none)+ uint32_t listedActiveSubtool_ = 0; // the list scrolls to the active SubTool when it changes+ bool focusRename_ = false;+ char renameBuffer_[128] = "";+ // Not-undoable SubTool commands wait for a confirmation popup.+ struct SubToolConfirm {+ std::string title, message, button, command;+ };+ SubToolConfirm subtoolConfirm_;+ bool openSubtoolConfirm_ = false;+ // Split by polygroups needs more than one group; counted only when the active mesh changes.+ uint64_t splitGroupsKey_ = ~uint64_t(0);+ bool splitGroupsPossible_ = false;};} // namespace sfdiff --git a/src/app/Demo.cpp b/src/app/Demo.cppindex e8e8f3f7..b0785dd5 100644--- a/src/app/Demo.cpp+++ b/src/app/Demo.cpp@@ -53,7 +53,7 @@ void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, ImGuiID id, const ImRect& bb}items().rects[id] = {bb, clip};if (id && ctx && ctx->CurrentWindow && !ctx->CurrentWindow->IDStack.empty()) {- std::string window = ctx->CurrentWindow->Name;+ std::string window = ctx->CurrentWindow->RootWindow->Name; // a child (list, table) counts as its panelif (const size_t hash = window.find("##"); hash != std::string::npos) window.resize(hash);items().frame.push_back({id, ctx->CurrentWindow->IDStack.back(), std::move(window), {bb, clip}});}@@ -63,7 +63,7 @@ void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* labauto it = items().rects.find(id);if (!label || it == items().rects.end()) return;std::string text(label);- std::string window = ctx && ctx->CurrentWindow ? ctx->CurrentWindow->Name : "";+ std::string window = ctx && ctx->CurrentWindow ? ctx->CurrentWindow->RootWindow->Name : "";if (const size_t hash = window.find("##"); hash != std::string::npos) window.resize(hash);auto add = [&](const std::string& key) {items().byLabel[key] = it->second;diff --git a/src/app/PanelSubTools.cpp b/src/app/PanelSubTools.cppnew file mode 100644index 00000000..3fb6eb86--- /dev/null+++ b/src/app/PanelSubTools.cpp@@ -0,0 +1,349 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// SubTools UI: the SubTools panel (list with visibility toggles, inline+// rename, append / duplicate / delete / reorder / solo / merge / split) and+// the ZBrush viewport gesture Alt+click to select a SubTool. Every action goes+// through the subtool_* commands (core/SubTools.cpp).+#include "app/App.h"++#include <algorithm>+#include <cmath>+#include <cstdio>+#include <string>++namespace sf {++namespace {++constexpr float kClickSlopPx = 4.0f; // movement that turns an Alt+click into a drag+constexpr int kListRows = 6; // the list scrolls beyond this many SubTools++const SDL_DialogFileFilter kAppendFilters[] = {+ {"Models and projects", "obj;fbx;glb;gltf;ply;stl;GoZ;goz;usda;usd;usdz;sfproj"}, {"All files", "*"}};++void SDLCALL onAppendChosen(void* userdata, const char* const* files, int) {+ if (!files || !files[0]) return;+ auto* req = static_cast<App::DialogRequest*>(userdata);+ req->app->queueFile(req->action, files[0]);+}++// "960", "12.3k", "1.25M": triangle counts that fit a narrow column.+std::string shortCount(size_t n) {+ char buf[32];+ if (n < 1000) std::snprintf(buf, sizeof buf, "%zu", n);+ else if (n < 100000) std::snprintf(buf, sizeof buf, "%.1fk", double(n) / 1e3);+ else if (n < 1000000) std::snprintf(buf, sizeof buf, "%.0fk", double(n) / 1e3);+ else std::snprintf(buf, sizeof buf, "%.2fM", double(n) / 1e6);+ return buf;+}++// An eye: open (almond and pupil) or closed (lower lid and lashes).+void drawEye(ImDrawList* dl, ImVec2 c, float size, bool open, ImU32 col) {+ const float w = size * 0.5f, h = size * 0.42f, t = std::max(1.0f, size * 0.09f);+ const ImVec2 l(c.x - w, c.y), r(c.x + w, c.y);+ if (open) {+ dl->AddBezierQuadratic(l, ImVec2(c.x, c.y - h * 1.6f), r, col, t);+ dl->AddBezierQuadratic(l, ImVec2(c.x, c.y + h * 1.6f), r, col, t);+ dl->AddCircleFilled(c, size * 0.2f, col);+ return;+ }+ dl->AddBezierQuadratic(l, ImVec2(c.x, c.y + h * 1.3f), r, col, t);+ for (float u : {-0.55f, 0.0f, 0.55f}) {+ const ImVec2 a(c.x + u * w, c.y + h * 0.62f * (1.0f - u * u * 0.5f));+ dl->AddLine(a, ImVec2(a.x + u * size * 0.12f, a.y + size * 0.22f), col, t);+ }+}++} // namespace++int App::pickSubtool(float x, float y, RayHit* out) {+ int w = 0, h = 0;+ SDL_GetWindowSize(window_, &w, &h);+ glm::vec3 origin, dir;+ camera_.screenRay(x, y, float(w), float(h), origin, dir);+ int best = -1;+ RayHit nearest;+ for (int i = 0; i < doc_.subtoolCount(); ++i) {+ SubTool& s = doc_.subtools[size_t(i)];+ if (!s.visible) continue;+ RayHit hit;+ bool found = false;+ if (i == doc_.activeSubtool) {+ doc_.syncBvh();+ found = doc_.bvh.raycast(doc_.mesh, origin, dir, hit);+ } else {+ if (s.bvhDirty || (s.bvh.nodeCount() == 0 && s.mesh.triangleCount())) {+ s.bvh.build(s.mesh);+ s.bvhDirty = false;+ }+ found = s.bvh.raycast(s.mesh, origin, dir, hit);+ }+ if (found && (best < 0 || hit.t < nearest.t)) {+ best = i;+ nearest = hit;+ }+ }+ if (out && best >= 0) *out = nearest;+ return best;+}++void App::subtoolClickMove(float x, float y) {+ if (std::hypot(x - subtoolClickX_, y - subtoolClickY_) < kClickSlopPx) return;+ // A drag, not a click: what an Alt+drag from here does on the active SubTool+ // (brushes ignore the others): an inverted stroke, or a pan off the model.+ drag_ = Drag::None;+ RayHit hit;+ if (previewLod_ < 0 && pick(subtoolClickX_, subtoolClickY_, hit)) {+ beginStroke(subtoolClickX_, subtoolClickY_, hit);+ if (drag_ == Drag::Stroke) strokeTo(x, y);+ } else {+ int w = 0, h = 0;+ SDL_GetWindowSize(window_, &w, &h);+ drag_ = Drag::Pan;+ camera_.pan(x - subtoolClickX_, y - subtoolClickY_, float(h));+ }+}++void App::subtoolClickRelease() {+ if (subtoolClickTarget_ >= 0 && subtoolClickTarget_ < doc_.subtoolCount())+ runCommand("subtool_select", {{"index", double(subtoolClickTarget_)}});+ subtoolClickTarget_ = -1;+}++void App::drawSubToolsPanel() {+ const float scale = uiScale_;+ const ImGuiViewport* vp = ImGui::GetMainViewport();+ // First use: top right, beside the Layers and Game Ready column.+ ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + vp->Size.x - 548 * scale, vp->Pos.y + 34 * scale), ImGuiCond_FirstUseEver);+ if (!beginPanel("SubTools", &showSubToolsPanel_, 250 * scale)) {+ ImGui::End();+ return;+ }+ const int count = doc_.subtoolCount();+ const int active = doc_.activeSubtool;+ const ImGuiStyle& style = ImGui::GetStyle();++ // The list: eye, name, triangles. Row actions run after the loop (they change the list).+ int selectIndex = -1, toggleIndex = -1, deleteIndex = -1, duplicateIndex = -1, renameIndex = -1;+ std::string renameTo;+ const ImVec2 cellPad(6.0f * scale, 4.0f * scale);+ const float rowH = ImGui::GetTextLineHeight() + 2.0f * cellPad.y;+ const float listH = rowH * float(std::min(count, kListRows)) + 2.0f;+ ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, cellPad);+ if (ImGui::BeginTable("##subtools", 3, ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter,+ ImVec2(-1, listH))) {+ const float eyeW = ImGui::GetTextLineHeight() * 1.2f;+ ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthStretch);+ ImGui::TableSetupColumn("tris", ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize("0.00M").x);+ ImGui::TableSetupColumn("eye", ImGuiTableColumnFlags_WidthFixed, eyeW);+ for (int i = 0; i < count; ++i) {+ const SubTool& s = doc_.subtools[size_t(i)];+ const bool isActive = i == active;+ ImGui::PushID(int(s.id));+ ImGui::TableNextRow(ImGuiTableRowFlags_None, rowH);+ ImGui::TableSetColumnIndex(0);+ if (renamingSubtool_ == s.id) {+ ImGui::SetNextItemWidth(-1);+ if (focusRename_) {+ ImGui::SetKeyboardFocusHere();+ focusRename_ = false;+ }+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(style.FramePadding.x, 0.0f));+ const bool enter = ImGui::InputText("##rename", renameBuffer_, sizeof renameBuffer_,+ ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll);+ ImGui::PopStyleVar();+ if (enter || (ImGui::IsItemDeactivatedAfterEdit() && !ImGui::IsKeyPressed(ImGuiKey_Escape))) {+ renameTo = renameBuffer_;+ renameIndex = i;+ renamingSubtool_ = 0;+ } else if (ImGui::IsItemDeactivated()) {+ renamingSubtool_ = 0; // Escape or clicked away without a change+ }+ } else {+ if (!s.visible) ImGui::PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]);+ if (ImGui::Selectable(s.name.c_str(), isActive,+ ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap |+ ImGuiSelectableFlags_AllowDoubleClick) &&+ !isActive)+ selectIndex = i;+ if (!s.visible) ImGui::PopStyleColor();+ if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {+ renamingSubtool_ = s.id;+ focusRename_ = true;+ std::snprintf(renameBuffer_, sizeof renameBuffer_, "%s", s.name.c_str());+ }+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal))+ ImGui::SetTooltip("%s\n%zu vertices, %zu triangles\nClick to select, double-click to rename",+ s.name.c_str(), doc_.subtoolMesh(i).vertexCount(), doc_.subtoolMesh(i).triangleCount());+ if (ImGui::BeginPopupContextItem("##row")) {+ ImGui::TextDisabled("%s", s.name.c_str());+ if (ImGui::MenuItem("Rename")) {+ renamingSubtool_ = s.id;+ focusRename_ = true;+ std::snprintf(renameBuffer_, sizeof renameBuffer_, "%s", s.name.c_str());+ }+ if (ImGui::MenuItem("Duplicate")) duplicateIndex = i;+ if (ImGui::MenuItem("Delete...", nullptr, false, count > 1)) deleteIndex = i;+ ImGui::EndPopup();+ }+ if (isActive && listedActiveSubtool_ != s.id) {+ ImGui::SetScrollHereY(0.5f); // keep the active SubTool in view after Alt+click+ listedActiveSubtool_ = s.id;+ }+ }+ ImGui::TableSetColumnIndex(1);+ const std::string tris = shortCount(doc_.subtoolMesh(i).triangleCount());+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(tris.c_str()).x);+ ImVec4 trisCol = style.Colors[isActive ? ImGuiCol_Text : ImGuiCol_TextDisabled];+ if (isActive) trisCol.w *= 0.75f; // readable on the highlight+ ImGui::TextColored(trisCol, "%s", tris.c_str());+ ImGui::TableSetColumnIndex(2);+ const ImVec2 eyePos = ImGui::GetCursorScreenPos();+ const ImVec2 eyeSize(ImGui::GetContentRegionAvail().x, ImGui::GetTextLineHeight());+ if (ImGui::InvisibleButton(("##eye " + s.name).c_str(), eyeSize)) toggleIndex = i;+ const bool eyeHovered = ImGui::IsItemHovered();+ if (eyeHovered) ImGui::SetTooltip(s.visible ? "Hide %s" : "Show %s", s.name.c_str());+ const ImU32 eyeCol = ImGui::GetColorU32(eyeHovered ? style.Colors[ImGuiCol_ButtonHovered]+ : s.visible ? style.Colors[ImGuiCol_Text]+ : style.Colors[ImGuiCol_TextDisabled]);+ drawEye(ImGui::GetWindowDrawList(), ImVec2(eyePos.x + eyeSize.x * 0.5f, eyePos.y + eyeSize.y * 0.5f),+ ImGui::GetTextLineHeight() * 0.8f, s.visible, eyeCol);+ ImGui::PopID();+ }+ ImGui::EndTable();+ }+ ImGui::PopStyleVar();++ if (renameIndex >= 0 && !renameTo.empty() && renameTo != doc_.subtools[size_t(renameIndex)].name)+ runCommand("subtool_rename", {{"index", double(renameIndex)}, {"to", renameTo}});+ if (selectIndex >= 0) {+ runCommand("subtool_select", {{"index", double(selectIndex)}});+ }+ if (toggleIndex >= 0) runCommand("subtool_visibility", {{"index", double(toggleIndex)}});+ if (duplicateIndex >= 0) runCommand("subtool_duplicate", {{"index", double(duplicateIndex)}});++ // Buttons act on the active SubTool, as in ZBrush.+ const std::string activeName = doc_.activeSubtoolInfo().name;+ int visibleCount = 0;+ for (const auto& s : doc_.subtools) visibleCount += s.visible ? 1 : 0;+ auto confirm = [this](std::string title, std::string message, std::string button, std::string command) {+ subtoolConfirm_ = {std::move(title), std::move(message), std::move(button), std::move(command)};+ openSubtoolConfirm_ = true;+ };+ if (deleteIndex >= 0) {+ if (deleteIndex != doc_.activeSubtool) runCommand("subtool_select", {{"index", double(deleteIndex)}});+ confirm("Delete SubTool?", "Delete \"" + doc_.activeSubtoolInfo().name + "\"? This can't be undone.", "Delete",+ "subtool_delete");+ }+ const float third = (ImGui::GetContentRegionAvail().x - 2 * style.ItemSpacing.x) / 3.0f;+ if (ImGui::Button("Append", ImVec2(third, 0))) ImGui::OpenPopup("##append");+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal)) ImGui::SetTooltip("Add a new SubTool beside the model");+ if (ImGui::BeginPopup("##append")) {+ if (ImGui::MenuItem("Sphere")) runCommand("subtool_append", {{"type", std::string("sphere")}});+ if (ImGui::MenuItem("Cube")) runCommand("subtool_append", {{"type", std::string("cube")}});+ if (ImGui::MenuItem("Plane")) runCommand("subtool_append", {{"type", std::string("plane")}});+ ImGui::Separator();+ if (ImGui::MenuItem("From file..."))+ SDL_ShowOpenFileDialog(onAppendChosen, &dialogRequests_[int(FileAction::AppendSubtool)], window_,+ kAppendFilters, 2, nullptr, false);+ ImGui::EndPopup();+ }+ ImGui::SameLine();+ if (ImGui::Button("Duplicate", ImVec2(third, 0))) runCommand("subtool_duplicate");+ ImGui::SameLine();+ ImGui::BeginDisabled(count < 2);+ if (ImGui::Button("Delete...", ImVec2(third, 0)))+ confirm("Delete SubTool?", "Delete \"" + activeName + "\"? This can't be undone.", "Delete", "subtool_delete");+ ImGui::EndDisabled();++ ImGui::BeginDisabled(active <= 0);+ if (ImGui::ArrowButton("##up", ImGuiDir_Up)) runCommand("subtool_move", {{"direction", std::string("up")}});+ ImGui::EndDisabled();+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))+ ImGui::SetTooltip("Move up the list");+ ImGui::SameLine();+ ImGui::BeginDisabled(active >= count - 1);+ if (ImGui::ArrowButton("##down", ImGuiDir_Down)) runCommand("subtool_move", {{"direction", std::string("down")}});+ ImGui::EndDisabled();+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))+ ImGui::SetTooltip("Move down the list");+ ImGui::SameLine();+ const float half2 = (ImGui::GetContentRegionAvail().x - style.ItemSpacing.x) * 0.5f;+ const bool solo = count > 1 && visibleCount == 1 && doc_.activeSubtoolInfo().visible;+ ImGui::BeginDisabled(count < 2);+ if (solo) ImGui::PushStyleColor(ImGuiCol_Button, style.Colors[ImGuiCol_ButtonActive]);+ if (ImGui::Button("Solo", ImVec2(half2, 0))) runCommand("subtool_solo");+ if (solo) ImGui::PopStyleColor();+ ImGui::EndDisabled();+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal))+ ImGui::SetTooltip(solo ? "Show the other SubTools again" : "Show only the active SubTool");+ ImGui::SameLine();+ ImGui::BeginDisabled(visibleCount == count);+ if (ImGui::Button("Unhide all", ImVec2(half2, 0))) runCommand("subtool_show_all");+ ImGui::EndDisabled();++ const float half = (ImGui::GetContentRegionAvail().x - style.ItemSpacing.x) * 0.5f;+ ImGui::BeginDisabled(active >= count - 1);+ if (ImGui::Button("Merge down...", ImVec2(half, 0)))+ confirm("Merge Down?",+ "Merge \"" + doc_.subtools[size_t(std::min(active + 1, count - 1))].name + "\" into \"" + activeName ++ "\"? This can't be undone,\nbut Split groups separates them again.",+ "Merge", "subtool_merge_down");+ ImGui::EndDisabled();+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))+ ImGui::SetTooltip("Merge the active SubTool with the one below it");+ ImGui::SameLine();+ ImGui::BeginDisabled(visibleCount < 2);+ if (ImGui::Button("Merge visible...", ImVec2(half, 0)))+ confirm("Merge Visible?",+ "Merge the " + std::to_string(visibleCount) + " visible SubTools into one? This can't be undone,\n"+ "but Split groups separates them again.",+ "Merge", "subtool_merge_visible");+ ImGui::EndDisabled();++ // More than one polygroup? Counted only when the active mesh changes.+ const uint64_t key = (uint64_t(doc_.activeSubtoolInfo().id) << 40) ^ (doc_.undo.revision() * 0x9E3779B97F4A7C15ull) ^+ uint64_t(doc_.mesh.triangleCount());+ if (key != splitGroupsKey_) {+ splitGroupsKey_ = key;+ const auto& g = doc_.mesh.polygroups;+ splitGroupsPossible_ = g.size() == doc_.mesh.triangleCount() &&+ std::any_of(g.begin(), g.end(), [&](uint32_t id) { return id != g.front(); });+ }+ ImGui::BeginDisabled(!splitGroupsPossible_);+ if (ImGui::Button("Split groups", ImVec2(half, 0))) runCommand("subtool_split_groups");+ ImGui::EndDisabled();+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))+ ImGui::SetTooltip("One SubTool per polygroup");+ ImGui::SameLine();+ ImGui::BeginDisabled(doc_.mesh.triangleCount() == 0);+ if (ImGui::Button("Split parts", ImVec2(half, 0))) runCommand("subtool_split_parts");+ ImGui::EndDisabled();+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))+ ImGui::SetTooltip("One SubTool per disconnected piece");+ ImGui::TextDisabled("Alt+click a SubTool to select it");+ ImGui::End();+}++void App::drawSubToolPopups() {+ const std::string popup = subtoolConfirm_.title + "###" + subtoolConfirm_.command;+ if (openSubtoolConfirm_) {+ ImGui::OpenPopup(popup.c_str());+ openSubtoolConfirm_ = false;+ }+ ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));+ if (!ImGui::BeginPopupModal(popup.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) return;+ ImGui::TextUnformatted(subtoolConfirm_.message.c_str());+ ImGui::Spacing();+ const float w = 110.0f * uiScale_;+ if (ImGui::Button(subtoolConfirm_.button.c_str(), ImVec2(w, 0)) || ImGui::IsKeyPressed(ImGuiKey_Enter)) {+ ImGui::CloseCurrentPopup();+ runCommand(subtoolConfirm_.command);+ }+ ImGui::SameLine();+ if (ImGui::Button("Cancel", ImVec2(w, 0)) || ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup();+ ImGui::EndPopup();+}++} // namespace sfdiff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex a74904e9..4d4e9c29 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -18,9 +18,13 @@// expect LABEL / expect_not LABEL// expect_text TEXT / expect_no_text TEXT any text drawn this frame contains TEXT// expect_status TEXT the status bar message contains TEXT+// click_subtool NAME [U V] left-click SubTool NAME in the viewport (with the held modifiers, e.g.+// hold alt to select it); U V: fractions of its on-screen bounds// expect_value NAME OP N triangles, vertices, layers, brushes, masked, hidden, groups, colored,-// can_undo, dirty, splats, show_polygroups, show_mask, wireframe;-// OP is == != < <= > >=+// can_undo, dirty, splats, show_polygroups, show_mask, wireframe,+// subtools (count), active_subtool (index, 0 = top), visible_subtools,+// edited_subtools (SubTools with undo history); OP is == != < <= > >=+// (mesh values are the active SubTool's)// shot NAME save a screenshot NAME.png (to --ui-out)#include "app/App.h"#include "app/Demo.h"@@ -151,6 +155,17 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "show_polygroups") return app_.renderSettings_.showPolygroups ? 1.0 : 0.0;if (name == "show_mask") return app_.renderSettings_.showMask ? 1.0 : 0.0;if (name == "wireframe") return app_.renderSettings_.wireframe ? 1.0 : 0.0;+ const Document& doc = app_.doc_;+ if (name == "subtools") return double(doc.subtoolCount());+ if (name == "active_subtool") return double(doc.activeSubtool);+ if (name == "visible_subtools")+ return double(std::count_if(doc.subtools.begin(), doc.subtools.end(), [](const SubTool& s) { return s.visible; }));+ if (name == "edited_subtools") { // SubTools with undo history (the active one's lives in doc.undo)+ int n = 0;+ for (int i = 0; i < doc.subtoolCount(); ++i)+ n += (i == doc.activeSubtool ? doc.undo.canUndo() : doc.subtools[size_t(i)].undo.canUndo()) ? 1 : 0;+ return double(n);+ }if (name == "masked") {size_t n = 0;for (float v : m.mask) n += v > 0.5f;@@ -227,6 +242,10 @@ void Demo::testClick(int line, const std::string& label, int button, bool doublevoid Demo::testKey(int line, const std::string& combo) {std::string keyName;const SDL_Keymod mods = parseMods(combo, &keyName);+ std::string lower = keyName;+ std::transform(lower.begin(), lower.end(), lower.begin(), [](unsigned char c) { return char(std::tolower(c)); });+ if (lower == "enter") keyName = "Return"; // SDL's name for it+ else if (lower == "esc") keyName = "Escape";const SDL_Keycode key = SDL_GetKeyFromName(keyName.c_str());if (key == SDLK_UNKNOWN) {run([this, line, keyName] { fail(line, "unknown key \"" + keyName + "\""); });@@ -314,6 +333,58 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& e}, seconds);run([this] { SDL_SetModState(held_); });wait(0.1f);+ } else if (verb == "click_subtool") {+ if (!need(1)) return false;+ const std::string name = w[1];+ const float u = num(2, 0.5f), v = num(3, 0.5f);+ steps_.push_back([this, line, name, u, v](float t) {+ const int index = app_.doc_.findSubtool(name);+ if (index < 0) {+ fail(line, "no SubTool named \"" + name + "\"");+ return true;+ }+ // The point of its on-screen bounds nearest (U, V) where it's the front SubTool and no panel covers it.+ const AABB b = app_.doc_.subtoolMesh(index).bounds();+ ImVec2 lo(1e9f, 1e9f), hi(-1e9f, -1e9f);+ for (int i = 0; i < 8; ++i) {+ const ImVec2 p = project(glm::vec3((i & 1) ? b.max.x : b.min.x, (i & 2) ? b.max.y : b.min.y,+ (i & 4) ? b.max.z : b.min.z));+ lo = ImVec2(std::min(lo.x, p.x), std::min(lo.y, p.y));+ hi = ImVec2(std::max(hi.x, p.x), std::max(hi.y, p.y));+ }+ const ImVec2 want(lo.x + (hi.x - lo.x) * u, lo.y + (hi.y - lo.y) * v);+ auto covered = [](ImVec2 q) {+ for (ImGuiWindow* w : ImGui::GetCurrentContext()->Windows)+ if (w->WasActive && !w->Hidden && w->Rect().Contains(q)) return true;+ return false;+ };+ ImVec2 p;+ bool found = false;+ float best = 1e30f;+ constexpr int kGrid = 16;+ for (int gy = 0; gy <= kGrid; ++gy) {+ for (int gx = 0; gx <= kGrid; ++gx) {+ const ImVec2 q(lo.x + (hi.x - lo.x) * float(gx) / kGrid, lo.y + (hi.y - lo.y) * float(gy) / kGrid);+ const float d = (q.x - want.x) * (q.x - want.x) + (q.y - want.y) * (q.y - want.y);+ if (d >= best || covered(q) || app_.pickSubtool(q.x, q.y) != index) continue;+ p = q;+ best = d;+ found = true;+ }+ }+ if (!found) {+ fail(line, "SubTool \"" + name + "\" can't be clicked (hidden, covered or off screen)");+ return true;+ }+ if (t == 0.0f) { // hover for a frame first+ mouseMotion(p.x, p.y);+ return false;+ }+ mouseButton(true, SDL_BUTTON_LEFT);+ mouseButton(false, SDL_BUTTON_LEFT);+ return true;+ });+ wait(0.1f);} else if (verb == "drag") {if (!need(4)) return false;const float x0 = num(1, 0), y0 = num(2, 0), x1 = num(3, 0), y1 = num(4, 0), seconds = num(5, 0.4f);diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cppindex 6934f8a7..cbca892b 100644--- a/src/render/Renderer.cpp+++ b/src/render/Renderer.cpp@@ -53,7 +53,12 @@ uniform int uGroups; // 0: off, 1: per-triangle ids from uGroupIds, 2: everyuniform usamplerBuffer uGroupIds;uniform int uMatcap; // 1: shade with the matcap texture instead of the studio lightsuniform sampler2D uMatcapTex; // sRGB-encoded lit sphere (core/Matcap.h)+uniform int uDim; // 1: an inactive SubTool, shown a little darker and greyerout vec4 fragColor;+vec4 finish(vec3 c) {+ if (uDim == 1) c = mix(c, vec3(dot(c, vec3(0.2126, 0.7152, 0.0722))), 0.25) * 0.72;+ return vec4(pow(c, vec3(1.0 / 2.2)), 1.0);+}// Keep in sync with sf::polygroupColor.vec3 groupColor(uint id) {uint h = id * 0x9E3779B1u;@@ -85,7 +90,7 @@ void main() {float mridge = smoothstep(0.0, 0.2, -vCurvature);vec3 c = mc * tint * (1.0 - 0.55 * mcrease) * (1.0 + 0.2 * mridge);if (uShowMask == 1) c *= 1.0 - 0.75 * clamp(vMask, 0.0, 1.0);- fragColor = vec4(pow(c, vec3(1.0 / 2.2)), 1.0);+ fragColor = finish(c);return;}vec3 key = normalize(vec3(0.45, 0.65, 0.6));@@ -106,7 +111,7 @@ void main() {c += albedo * ridge * 0.3 * diff; // ridges catch the key lightc += vec3(spec) * (1.0 - crease) + rim * vec3(0.8, 0.85, 1.0);if (uShowMask == 1) c *= 1.0 - 0.75 * clamp(vMask, 0.0, 1.0);- fragColor = vec4(pow(c, vec3(1.0 / 2.2)), 1.0);+ fragColor = finish(c);})";@@ -272,35 +277,7 @@ bool Renderer::init(std::string& error) {gl::BindVertexArray(0);gl::BindBuffer(GL_ARRAY_BUFFER, 0);- gl::GenVertexArrays(1, &vao_);gl::GenVertexArrays(1, &emptyVao_);- gl::GenBuffers(1, &posBuffer_);- gl::GenBuffers(1, &nrmBuffer_);- gl::GenBuffers(1, &indexBuffer_);-- gl::BindVertexArray(vao_);- gl::BindBuffer(GL_ARRAY_BUFFER, posBuffer_);- gl::EnableVertexAttribArray(0);- gl::VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);- gl::BindBuffer(GL_ARRAY_BUFFER, nrmBuffer_);- gl::EnableVertexAttribArray(1);- gl::VertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);- gl::GenBuffers(1, &curvBuffer_);- gl::BindBuffer(GL_ARRAY_BUFFER, curvBuffer_);- gl::EnableVertexAttribArray(2);- gl::VertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, sizeof(float), nullptr);- // Colour (3) and mask (4) arrays are only enabled while the mesh has them.- gl::GenBuffers(1, &colorBuffer_);- gl::BindBuffer(GL_ARRAY_BUFFER, colorBuffer_);- gl::VertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);- gl::GenBuffers(1, &maskBuffer_);- gl::BindBuffer(GL_ARRAY_BUFFER, maskBuffer_);- gl::VertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, sizeof(float), nullptr);- gl::BindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer_);- gl::BindVertexArray(0);- gl::BindBuffer(GL_ARRAY_BUFFER, 0);- gl::GenBuffers(1, &groupData_);- gl::GenTextures(1, &groupTexture_);// Built-in matcaps, generated once (6 x 256 KB).matcapTextures_.assign(size_t(matcapCount()), 0);@@ -324,18 +301,60 @@ GLuint Renderer::matcapTexture(int index) const {return index >= 0 && index < int(matcapTextures_.size()) ? matcapTextures_[size_t(index)] : 0;}+Renderer::MeshSlot& Renderer::slot(uint32_t id) {+ for (auto& s : slots_)+ if (s.id == id) return s;+ MeshSlot& s = slots_.emplace_back();+ s.id = id;+ gl::GenVertexArrays(1, &s.vao);+ gl::GenBuffers(1, &s.posBuffer);+ gl::GenBuffers(1, &s.nrmBuffer);+ gl::GenBuffers(1, &s.curvBuffer);+ gl::GenBuffers(1, &s.indexBuffer);+ gl::GenBuffers(1, &s.colorBuffer);+ gl::GenBuffers(1, &s.maskBuffer);+ gl::GenBuffers(1, &s.groupData);+ gl::GenTextures(1, &s.groupTexture);+ gl::BindVertexArray(s.vao);+ gl::BindBuffer(GL_ARRAY_BUFFER, s.posBuffer);+ gl::EnableVertexAttribArray(0);+ gl::VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);+ gl::BindBuffer(GL_ARRAY_BUFFER, s.nrmBuffer);+ gl::EnableVertexAttribArray(1);+ gl::VertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);+ gl::BindBuffer(GL_ARRAY_BUFFER, s.curvBuffer);+ gl::EnableVertexAttribArray(2);+ gl::VertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, sizeof(float), nullptr);+ // Colour (3) and mask (4) arrays are only enabled while the mesh has them.+ gl::BindBuffer(GL_ARRAY_BUFFER, s.colorBuffer);+ gl::VertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);+ gl::BindBuffer(GL_ARRAY_BUFFER, s.maskBuffer);+ gl::VertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, sizeof(float), nullptr);+ gl::BindBuffer(GL_ELEMENT_ARRAY_BUFFER, s.indexBuffer);+ gl::BindVertexArray(0);+ gl::BindBuffer(GL_ARRAY_BUFFER, 0);+ return s;+}++void Renderer::freeSlot(MeshSlot& s) {+ gl::DeleteBuffers(1, &s.posBuffer);+ gl::DeleteBuffers(1, &s.nrmBuffer);+ gl::DeleteBuffers(1, &s.curvBuffer);+ gl::DeleteBuffers(1, &s.indexBuffer);+ gl::DeleteBuffers(1, &s.colorBuffer);+ gl::DeleteBuffers(1, &s.maskBuffer);+ gl::DeleteBuffers(1, &s.groupData);+ gl::DeleteTextures(1, &s.groupTexture);+ gl::DeleteVertexArrays(1, &s.vao);+ s = MeshSlot();+}+void Renderer::shutdown() {- gl::DeleteBuffers(1, &posBuffer_);- gl::DeleteBuffers(1, &nrmBuffer_);- gl::DeleteBuffers(1, &curvBuffer_);- gl::DeleteBuffers(1, &colorBuffer_);- gl::DeleteBuffers(1, &maskBuffer_);- gl::DeleteBuffers(1, &groupData_);- gl::DeleteTextures(1, &groupTexture_);+ for (auto& s : slots_) freeSlot(s);+ slots_.clear();+ drawList_.clear();if (!matcapTextures_.empty()) gl::DeleteTextures(GLsizei(matcapTextures_.size()), matcapTextures_.data());matcapTextures_.clear();- gl::DeleteBuffers(1, &indexBuffer_);- gl::DeleteVertexArrays(1, &vao_);gl::DeleteVertexArrays(1, &emptyVao_);gl::DeleteProgram(meshProgram_);gl::DeleteProgram(wireProgram_);@@ -427,12 +446,12 @@ void Renderer::drawSplats(const glm::mat4& view, const glm::mat4& proj, int fbWi// Signed curvature per vertex: how far the neighbour average sits above (crease, > 0) or below// (ridge, < 0) the surface, relative to the local edge length.-void Renderer::updateCurvature(const Mesh& mesh, uint32_t begin, uint32_t end) {- curvature_.resize(mesh.vertexCount(), 0.0f);+void Renderer::updateCurvature(MeshSlot& s, const Mesh& mesh, uint32_t begin, uint32_t end) {+ s.curvature.resize(mesh.vertexCount(), 0.0f);for (uint32_t v = begin; v < end && v < mesh.vertexCount(); ++v) {const auto ring = mesh.neighbors(v);if (ring.empty()) {- curvature_[v] = 0.0f;+ s.curvature[v] = 0.0f;continue;}glm::vec3 avg(0.0f);@@ -444,13 +463,13 @@ void Renderer::updateCurvature(const Mesh& mesh, uint32_t begin, uint32_t end) {}avg /= float(ring.size());edge /= float(ring.size());- curvature_[v] = edge > 0.0f ? glm::dot(mesh.normals[v], avg - p) / edge : 0.0f;+ s.curvature[v] = edge > 0.0f ? glm::dot(mesh.normals[v], avg - p) / edge : 0.0f;}}// Index buffer without hidden triangles, plus the polygroup id of every drawn// triangle in draw order (looked up by gl_PrimitiveID).-void Renderer::uploadFaces(const Mesh& mesh) {+void Renderer::uploadFaces(MeshSlot& s, const Mesh& mesh) {const size_t nt = mesh.triangleCount();const bool hidden = mesh.hidden.size() == nt && nt > 0;const bool groups = mesh.polygroups.size() == nt && nt > 0;@@ -466,57 +485,78 @@ void Renderer::uploadFaces(const Mesh& mesh) {}tris = visibleTris_.data();drawn = visibleTris_.size();- } else {- std::vector<glm::uvec3>().swap(visibleTris_);- if (groups) visibleGroups_ = mesh.polygroups;+ } else if (groups) {+ visibleGroups_ = mesh.polygroups;}- gl::BindVertexArray(vao_);+ gl::BindVertexArray(s.vao);gl::BufferData(GL_ELEMENT_ARRAY_BUFFER, GLsizeiptr(drawn * sizeof(glm::uvec3)), tris, GL_STATIC_DRAW);gl::BindVertexArray(0);- indexCount_ = GLsizei(drawn * 3);+ s.indexCount = GLsizei(drawn * 3);GLint maxTexels = 0;gl::GetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTexels);- hasGroups_ = groups && !visibleGroups_.empty() && visibleGroups_.size() <= size_t(std::max(maxTexels, 0));- if (hasGroups_) {- gl::BindBuffer(GL_TEXTURE_BUFFER, groupData_);+ s.hasGroups = groups && !visibleGroups_.empty() && visibleGroups_.size() <= size_t(std::max(maxTexels, 0));+ if (s.hasGroups) {+ gl::BindBuffer(GL_TEXTURE_BUFFER, s.groupData);gl::BufferData(GL_TEXTURE_BUFFER, GLsizeiptr(visibleGroups_.size() * sizeof(uint32_t)), visibleGroups_.data(),GL_STATIC_DRAW);- gl::BindTexture(GL_TEXTURE_BUFFER, groupTexture_);- gl::TexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, groupData_);+ gl::BindTexture(GL_TEXTURE_BUFFER, s.groupTexture);+ gl::TexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, s.groupData);gl::BindTexture(GL_TEXTURE_BUFFER, 0);gl::BindBuffer(GL_TEXTURE_BUFFER, 0);}+ // Scratch only: don't keep a big mesh's copy around.+ if (visibleTris_.capacity() > (size_t(1) << 16)) std::vector<glm::uvec3>().swap(visibleTris_);+ if (visibleGroups_.capacity() > (size_t(1) << 16)) std::vector<uint32_t>().swap(visibleGroups_);+}++void Renderer::syncScene(const std::vector<SceneMesh>& scene) {+ // Free the slots of SubTools that are gone (deleted, merged, a new scene).+ for (size_t i = 0; i < slots_.size();) {+ const bool live = std::any_of(scene.begin(), scene.end(), [&](const SceneMesh& m) { return m.id == slots_[i].id; });+ if (live) {+ ++i;+ continue;+ }+ freeSlot(slots_[i]);+ slots_.erase(slots_.begin() + std::ptrdiff_t(i));+ }+ drawList_.clear();+ for (const SceneMesh& m : scene) {+ if (!m.visible || !m.mesh) continue; // hidden: keeps its dirty state until shown+ sync(slot(m.id), *m.mesh);+ drawList_.push_back({m.id, m.active});+ }}-void Renderer::sync(Mesh& mesh) {+void Renderer::sync(MeshSlot& s, Mesh& mesh) {const size_t nv = mesh.vertexCount();- const bool full = mesh.topologyDirty || nv != vertexCapacity_;+ const bool full = s.fresh || mesh.topologyDirty || nv != s.vertexCapacity;const bool ranged = !full && mesh.dirtyBegin < mesh.dirtyEnd && mesh.dirtyEnd <= nv;const GLintptr off3 = ranged ? GLintptr(mesh.dirtyBegin * sizeof(glm::vec3)) : 0;const GLsizeiptr size3 = ranged ? GLsizeiptr((mesh.dirtyEnd - mesh.dirtyBegin) * sizeof(glm::vec3)) : 0;const GLintptr off1 = ranged ? GLintptr(mesh.dirtyBegin * sizeof(float)) : 0;const GLsizeiptr size1 = ranged ? GLsizeiptr((mesh.dirtyEnd - mesh.dirtyBegin) * sizeof(float)) : 0;if (full) {- updateCurvature(mesh, 0, uint32_t(nv));- gl::BindBuffer(GL_ARRAY_BUFFER, posBuffer_);+ updateCurvature(s, mesh, 0, uint32_t(nv));+ gl::BindBuffer(GL_ARRAY_BUFFER, s.posBuffer);gl::BufferData(GL_ARRAY_BUFFER, GLsizeiptr(nv * sizeof(glm::vec3)), mesh.positions.data(), GL_DYNAMIC_DRAW);- gl::BindBuffer(GL_ARRAY_BUFFER, nrmBuffer_);+ gl::BindBuffer(GL_ARRAY_BUFFER, s.nrmBuffer);gl::BufferData(GL_ARRAY_BUFFER, GLsizeiptr(nv * sizeof(glm::vec3)), mesh.normals.data(), GL_DYNAMIC_DRAW);- gl::BindBuffer(GL_ARRAY_BUFFER, curvBuffer_);- gl::BufferData(GL_ARRAY_BUFFER, GLsizeiptr(nv * sizeof(float)), curvature_.data(), GL_DYNAMIC_DRAW);- uploadFaces(mesh);- vertexCapacity_ = nv;+ gl::BindBuffer(GL_ARRAY_BUFFER, s.curvBuffer);+ gl::BufferData(GL_ARRAY_BUFFER, GLsizeiptr(nv * sizeof(float)), s.curvature.data(), GL_DYNAMIC_DRAW);+ uploadFaces(s, mesh);+ s.vertexCapacity = nv;} else if (ranged) {- gl::BindBuffer(GL_ARRAY_BUFFER, posBuffer_);+ gl::BindBuffer(GL_ARRAY_BUFFER, s.posBuffer);gl::BufferSubData(GL_ARRAY_BUFFER, off3, size3, mesh.positions.data() + mesh.dirtyBegin);- gl::BindBuffer(GL_ARRAY_BUFFER, nrmBuffer_);+ gl::BindBuffer(GL_ARRAY_BUFFER, s.nrmBuffer);gl::BufferSubData(GL_ARRAY_BUFFER, off3, size3, mesh.normals.data() + mesh.dirtyBegin);- updateCurvature(mesh, mesh.dirtyBegin, mesh.dirtyEnd);- gl::BindBuffer(GL_ARRAY_BUFFER, curvBuffer_);- gl::BufferSubData(GL_ARRAY_BUFFER, off1, size1, curvature_.data() + mesh.dirtyBegin);+ updateCurvature(s, mesh, mesh.dirtyBegin, mesh.dirtyEnd);+ gl::BindBuffer(GL_ARRAY_BUFFER, s.curvBuffer);+ gl::BufferSubData(GL_ARRAY_BUFFER, off1, size1, s.curvature.data() + mesh.dirtyBegin);}- if (!full && mesh.facesDirty) uploadFaces(mesh);+ if (!full && mesh.facesDirty) uploadFaces(s, mesh);// Optional per-vertex attributes: a full upload when they appear (or the// mesh changed), the dirty range otherwise, and a disabled array when absent.@@ -531,17 +571,19 @@ void Renderer::sync(Mesh& mesh) {gl::BufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);}if (present != uploaded) {- gl::BindVertexArray(vao_);+ gl::BindVertexArray(s.vao);if (present) gl::EnableVertexAttribArray(location);else gl::DisableVertexAttribArray(location);gl::BindVertexArray(0);}uploaded = present;};- syncAttribute(colorBuffer_, 3, hasColors_, mesh.colors.data(), sizeof(glm::vec3), nv > 0 && mesh.colors.size() == nv,+ syncAttribute(s.colorBuffer, 3, s.hasColors, mesh.colors.data(), sizeof(glm::vec3), nv > 0 && mesh.colors.size() == nv,off3, size3);- syncAttribute(maskBuffer_, 4, hasMask_, mesh.mask.data(), sizeof(float), nv > 0 && mesh.mask.size() == nv, off1, size1);+ syncAttribute(s.maskBuffer, 4, s.hasMask, mesh.mask.data(), sizeof(float), nv > 0 && mesh.mask.size() == nv, off1,+ size1);gl::BindBuffer(GL_ARRAY_BUFFER, 0);+ s.fresh = false;mesh.clearDirty();}@@ -655,39 +697,36 @@ void Renderer::draw(const Camera& camera, int fbWidth, int fbHeight, const Rendeglm::mat4 view = camera.view(), proj = camera.projection();gl::Enable(GL_DEPTH_TEST);gl::DepthFunc(GL_LEQUAL);- if (indexCount_ == 0 || !settings.showMesh) {+ if (drawList_.empty() || !settings.showMesh) {if (settings.showSplats) drawSplats(view, proj, fbWidth, fbHeight, settings.splatOpacity);gl::UseProgram(0);return;}- gl::BindVertexArray(vao_);auto setMatrices = [&](GLuint prog) {gl::UseProgram(prog);gl::UniformMatrix4fv(gl::GetUniformLocation(prog, "uView"), 1, GL_FALSE, glm::value_ptr(view));gl::UniformMatrix4fv(gl::GetUniformLocation(prog, "uProj"), 1, GL_FALSE, glm::value_ptr(proj));};+ auto findSlot = [this](uint32_t id) -> const MeshSlot* {+ for (const auto& s : slots_)+ if (s.id == id) return &s;+ return nullptr;+ };setMatrices(meshProgram_);gl::Uniform3fv(gl::GetUniformLocation(meshProgram_, "uBaseColor"), 1, glm::value_ptr(settings.baseColor));- gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uPaint"), settings.showPolypaint && hasColors_ ? 1 : 0);- gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uShowMask"), settings.showMask && hasMask_ ? 1 : 0);- gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uGroups"), settings.showPolygroups ? (hasGroups_ ? 1 : 2) : 0);gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uGroupIds"), 1);const GLuint matcap = matcapTexture(settings.matcap);gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uMatcap"), matcap ? 1 : 0);gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uMatcapTex"), 2);gl::ActiveTexture(kTexture2);gl::BindTexture(GL_TEXTURE_2D, matcap);- // Constant values for the attribute arrays that are disabled.- if (!hasColors_) gl::VertexAttrib3f(3, 1.0f, 1.0f, 1.0f);- if (!hasMask_) gl::VertexAttrib1f(4, 0.0f);- gl::ActiveTexture(GL_TEXTURE1);- gl::BindTexture(GL_TEXTURE_BUFFER, hasGroups_ ? groupTexture_ : 0);gl::ActiveTexture(GL_TEXTURE0);gl::Enable(GL_POLYGON_OFFSET_FILL);gl::PolygonOffset(1.0f, 1.0f);- gl::DrawElements(GL_TRIANGLES, indexCount_, GL_UNSIGNED_INT, nullptr);+ for (const DrawItem& item : drawList_)+ if (const MeshSlot* s = findSlot(item.id); s && s->indexCount > 0) drawSlot(*s, item.active, settings);gl::Disable(GL_POLYGON_OFFSET_FILL);gl::ActiveTexture(GL_TEXTURE1);gl::BindTexture(GL_TEXTURE_BUFFER, 0);@@ -695,13 +734,18 @@ void Renderer::draw(const Camera& camera, int fbWidth, int fbHeight, const Rendegl::BindTexture(GL_TEXTURE_2D, 0);gl::ActiveTexture(GL_TEXTURE0);- if (settings.wireframe) {+ if (settings.wireframe) { // the active SubTool onlysetMatrices(wireProgram_);gl::Enable(GL_BLEND);gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);gl::DepthMask(GL_FALSE);gl::PolygonMode(GL_FRONT_AND_BACK, GL_LINE);- gl::DrawElements(GL_TRIANGLES, indexCount_, GL_UNSIGNED_INT, nullptr);+ for (const DrawItem& item : drawList_) {+ const MeshSlot* s = item.active ? findSlot(item.id) : nullptr;+ if (!s || s->indexCount == 0) continue;+ gl::BindVertexArray(s->vao);+ gl::DrawElements(GL_TRIANGLES, s->indexCount, GL_UNSIGNED_INT, nullptr);+ }gl::PolygonMode(GL_FRONT_AND_BACK, GL_FILL);gl::DepthMask(GL_TRUE);gl::Disable(GL_BLEND);@@ -711,4 +755,22 @@ void Renderer::draw(const Camera& camera, int fbWidth, int fbHeight, const Rendegl::UseProgram(0);}+// One mesh with the mesh program bound. Mask and polygroup colours are for the+// SubTool being edited; polypaint shows on all of them.+void Renderer::drawSlot(const MeshSlot& s, bool active, const RenderSettings& settings) {+ gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uPaint"), settings.showPolypaint && s.hasColors ? 1 : 0);+ gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uShowMask"), active && settings.showMask && s.hasMask ? 1 : 0);+ gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uGroups"),+ active && settings.showPolygroups ? (s.hasGroups ? 1 : 2) : 0);+ gl::Uniform1i(gl::GetUniformLocation(meshProgram_, "uDim"), !active && settings.dimInactive ? 1 : 0);+ gl::BindVertexArray(s.vao);+ // Constant values for the attribute arrays that are disabled.+ if (!s.hasColors) gl::VertexAttrib3f(3, 1.0f, 1.0f, 1.0f);+ if (!s.hasMask) gl::VertexAttrib1f(4, 0.0f);+ gl::ActiveTexture(GL_TEXTURE1);+ gl::BindTexture(GL_TEXTURE_BUFFER, s.hasGroups ? s.groupTexture : 0);+ gl::ActiveTexture(GL_TEXTURE0);+ gl::DrawElements(GL_TRIANGLES, s.indexCount, GL_UNSIGNED_INT, nullptr);+}+} // namespace sfdiff --git a/src/render/Renderer.h b/src/render/Renderer.hindex a6a44f5d..a82d21d3 100644--- a/src/render/Renderer.h+++ b/src/render/Renderer.h@@ -23,22 +23,35 @@ struct RenderSettings {bool showMesh = true;bool showSplats = true;float splatOpacity = 1.0f; // global fade for using a capture as reference+ bool dimInactive = true; // SubTools other than the active one render slightly darker (ZBrush style)+};++// One mesh of the scene for Renderer::syncScene: a SubTool, keyed by its stable id.+struct SceneMesh {+ uint32_t id = 0;+ Mesh* mesh = nullptr;+ bool active = false; // gets mask darkening, polygroup colours and wireframe; never dimmed+ bool visible = true; // hidden meshes keep their GPU slot but aren't drawn (or uploaded)};// Display colour of a polygroup id (linear RGB): a stable hash spread over// pleasant hues. The mesh shader uses the same formula.glm::vec3 polygroupColor(uint32_t id);-// Mesh drawing honours the optional Mesh attributes: colours (polypaint), mask-// (darkening), polygroups (group colours) and hidden triangles (not drawn).-// Mark changed vertices dirty for colour/mask edits and set Mesh::facesDirty-// after changing `hidden` or `polygroups`.+// Draws every visible SubTool, each from its own GPU buffers (a slot keyed by+// SubTool id). Mesh drawing honours the optional Mesh attributes: colours+// (polypaint), mask (darkening), polygroups (group colours) and hidden+// triangles (not drawn). Mark changed vertices dirty for colour/mask edits and+// set Mesh::facesDirty after changing `hidden` or `polygroups`. Only what a+// mesh marks dirty is uploaded, so inactive SubTools upload once.class Renderer {public:bool init(std::string& error);void shutdown();- // Uploads whatever the mesh marked dirty, then clears its dirty state.- void sync(Mesh& mesh);+ // Makes `scene` what draw() shows, in order: uploads whatever each visible+ // mesh marked dirty and clears its dirty state (a new slot uploads+ // everything), and frees the slots of ids no longer listed.+ void syncScene(const std::vector<SceneMesh>& scene);// Re-uploads the splats when `version` differs from the last upload.void syncSplats(const SplatCloud& splats, uint64_t version);void draw(const Camera& camera, int fbWidth, int fbHeight, const RenderSettings& settings);@@ -66,19 +79,35 @@ private:glm::mat4 lastSortView_{0.0f};GLuint captureFbo_[2] = {}, captureRb_[3] = {};int captureW_ = 0, captureH_ = 0;- GLuint vao_ = 0, emptyVao_ = 0;- void updateCurvature(const Mesh& mesh, uint32_t begin, uint32_t end);- void uploadFaces(const Mesh& mesh);- GLuint posBuffer_ = 0, nrmBuffer_ = 0, curvBuffer_ = 0, indexBuffer_ = 0;- GLuint colorBuffer_ = 0, maskBuffer_ = 0;- GLuint groupData_ = 0, groupTexture_ = 0; // polygroup id per drawn triangle (texture buffer)- bool hasColors_ = false, hasMask_ = false, hasGroups_ = false;- std::vector<float> curvature_;- std::vector<glm::uvec3> visibleTris_;+ GLuint emptyVao_ = 0;+ // The GPU copy of one mesh (one SubTool).+ struct MeshSlot {+ uint32_t id = 0;+ GLuint vao = 0;+ GLuint posBuffer = 0, nrmBuffer = 0, curvBuffer = 0, indexBuffer = 0;+ GLuint colorBuffer = 0, maskBuffer = 0;+ GLuint groupData = 0, groupTexture = 0; // polygroup id per drawn triangle (texture buffer)+ bool hasColors = false, hasMask = false, hasGroups = false;+ bool fresh = true; // nothing uploaded yet+ std::vector<float> curvature;+ GLsizei indexCount = 0;+ size_t vertexCapacity = 0;+ };+ MeshSlot& slot(uint32_t id); // created on first use+ static void freeSlot(MeshSlot& s);+ void sync(MeshSlot& s, Mesh& mesh);+ static void updateCurvature(MeshSlot& s, const Mesh& mesh, uint32_t begin, uint32_t end);+ void uploadFaces(MeshSlot& s, const Mesh& mesh);+ void drawSlot(const MeshSlot& s, bool active, const RenderSettings& settings);+ std::vector<MeshSlot> slots_;+ struct DrawItem {+ uint32_t id;+ bool active;+ };+ std::vector<DrawItem> drawList_; // visible meshes, in scene order+ std::vector<glm::uvec3> visibleTris_; // scratch for uploadFacesstd::vector<uint32_t> visibleGroups_;- GLsizei indexCount_ = 0;std::vector<GLuint> matcapTextures_; // one per built-in matcap (core/Matcap.h)- size_t vertexCapacity_ = 0;};} // namespace sfdiff --git a/tests/ui/subtools.sfui b/tests/ui/subtools.sfuinew file mode 100644index 00000000..c299466c--- /dev/null+++ b/tests/ui/subtools.sfui@@ -0,0 +1,160 @@+# SubTools: the panel, Alt+click in the viewport, sculpting and undo per SubTool,+# visibility, rename, duplicate, delete, merge and split.+run new_sphere subdivisions=4 ; subtool_rename to=Body+expect "SubTools"+expect_value subtools == 1+expect "SubTools/Body"+shot one-subtool++# Append from the panel's menu: each new SubTool becomes the active one.+click "SubTools/Append"+click "Sphere"+expect_status Appended SubTool Sphere+expect_value subtools == 2+expect_value active_subtool == 1+click "SubTools/Append"+click "Cube"+expect_value subtools == 3+expect_value active_subtool == 2+key f+shot appended++# Click rows to select.+click "SubTools/Body"+expect_value active_subtool == 0+expect_status Active SubTool: Body+click "SubTools/Sphere"+expect_value active_subtool == 1++# Alt+click in the viewport selects another SubTool without sculpting anything.+hold alt+click_subtool Cube+hold none+expect_value active_subtool == 2+expect_status Active SubTool: Cube+hold alt+click_subtool Body+hold none+expect_value active_subtool == 0+expect_value edited_subtools == 0+shot alt-click++# A stroke changes only the active SubTool; undo history is per SubTool.+click "2 Clay"+stroke 0.3 0.4 0.6 0.6+expect_value can_undo == 1+expect_value edited_subtools == 1+# Alt+drag on the active SubTool is still an inverted stroke, not a selection.+hold alt+stroke 0.4 0.3 0.5 0.7+hold none+expect_value active_subtool == 0+expect_value edited_subtools == 1+shot sculpted+click "SubTools/Cube"+expect_value can_undo == 0+key ctrl+z+expect_value edited_subtools == 1+click "SubTools/Body"+expect_value can_undo == 1+key ctrl+z+key ctrl+z+expect_value can_undo == 0+expect_value edited_subtools == 0+key ctrl+shift+z+expect_value edited_subtools == 1++# Eye toggles, Solo and Unhide all.+click "SubTools/##eye Sphere"+expect_value visible_subtools == 2+expect_status Sphere hidden+shot hidden+click "SubTools/Solo"+expect_value visible_subtools == 1+expect_status Solo: Body+shot solo+click "SubTools/Solo"+expect_value visible_subtools == 3+click "SubTools/##eye Cube"+expect_value visible_subtools == 2+click "SubTools/Unhide all"+expect_value visible_subtools == 3++# Rename: double-click the row and type.+double_click "SubTools/Cube"+type "SubTools/##rename" Helmet+key enter+expect_status Renamed to Helmet+expect "SubTools/Helmet"+expect_not "SubTools/Cube"++# Duplicate, then delete through the confirmation (Cancel first).+click "SubTools/Helmet"+click "SubTools/Duplicate"+expect_value subtools == 4+expect_value active_subtool == 3+expect "SubTools/Helmet copy"+click "SubTools/Delete..."+expect_text This can't be undone+shot confirm-delete+click "Delete SubTool?/Cancel"+expect_value subtools == 4+click "SubTools/Delete..."+click "Delete SubTool?/Delete"+expect_value subtools == 3+expect_status Deleted SubTool Helmet copy+expect_not "SubTools/Helmet copy"++# Move the active SubTool up and down the list.+click "SubTools/Sphere"+click "SubTools/##up"+expect_value active_subtool == 0+click "SubTools/##down"+expect_value active_subtool == 1++# Merge down keeps polygroups apart, so Split groups separates the pieces again.+click "SubTools/Body"+click "SubTools/Merge down..."+click "Merge Down?/Merge"+expect_value subtools == 2+expect_status Merged Sphere into Body+expect_value can_undo == 0+click "SubTools/Split groups"+expect_value subtools == 3+expect_status Split into 2 SubTools+shot split-groups+click "SubTools/Merge visible..."+click "Merge Visible?/Merge"+expect_value subtools == 1+expect "SubTools/Merged"+click "SubTools/Split parts"+expect_value subtools == 3+expect_status Split into 3 SubTools+shot split-parts++# The View menu hides and shows the panel.+click "View"+click "SubTools Panel"+expect_not "SubTools/Append"+click "View"+click "SubTools Panel"+expect "SubTools/Append"++# Wireframe, polygroup colours and the LOD preview are for the active SubTool only.+key w+expect_value wireframe == 1+click "Show polygroups"+shot active-overlays+click "Show polygroups"+key w+click "Generate LOD chain"+shot lod-preview+click "Game Ready/Sculpt"++# Past six SubTools the list scrolls; clicks scroll it like a person would.+run subtool_append ; subtool_append ; subtool_append ; subtool_append+expect_value subtools == 7+expect_value active_subtool == 6+shot many+click "SubTools/Merged 1"+expect_value active_subtool == 0