Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Part folders (#96): group Parts in the Parts list; drag in and out, fold, rename, hide/show and move a folder at once

islandmedec43333f8bb5
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ffe7a2e6..5ce21085 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -916,6 +916,8 @@ if(SCULPTFORGE_BUILD_TESTS)
sculptforge_ui_test(right_tray_looks_720 right_tray_looks --size 1280x720)
sculptforge_ui_test(windows_dpi_2560 windows_dpi --size 2560x1600)
sculptforge_ui_test(windows_dpi_2160 windows_dpi --size 2160x1350)
+ # Part folders (#96) at 200 % on a 3200x1800 screen (tests/ui/hidpi/: scripts only run at their HiDPI size).
+ sculptforge_ui_test(part_folders_hidpi hidpi/part_folders --size 3200x1800)
set_tests_properties(ui_right_tray_looks_720 ui_windows_dpi_2560 ui_windows_dpi_2160 PROPERTIES LABELS "ui;dpi" TIMEOUT 300)
sculptforge_ui_test(user_guide_1080 user_guide --size 1920x1080)
# A crash leaves a note in the log file (#16). Needs no window.
diff --git a/changes/feat-part-folders.md b/changes/feat-part-folders.md
new file mode 100644
index 00000000..6a8baf0b
--- /dev/null
+++ b/changes/feat-part-folders.md
@@ -0,0 +1,8 @@
+---
+whats_new: **Part folders**: in **Tool > Parts**, group Parts in folders (drag them in and out), fold, rename, hide or move a whole folder at once.
+added: **Part folders** (#96, thanks @ebarranco): folders in the Parts list; drag Parts in and out, fold, rename, hide and
+ show, and move a whole folder with the gizmo's new **Folder** option. Saved in projects; older versions open them without folders.
+testers:
+ - Tool > Parts: append two spheres, click the folder button, drag the other sphere onto the folder; hide it with its eye; right-click > Move with the gizmo.
+ - Save, open again: the folder is back. Open the file in 0.11.7: it opens, without folders.
+---
diff --git a/docs/guide/gizmo.md b/docs/guide/gizmo.md
index 1facca39..4df87413 100644
--- a/docs/guide/gizmo.md
+++ b/docs/guide/gizmo.md
@@ -101,6 +101,9 @@ example to turn a whole character with its eyes, teeth and clothes. The pivot is
Part gets its own undo step: undo goes back in the active Part, and selecting another Part undoes its
part.
+**Folder**, beside it, moves the visible Parts in the active Part's [folder](parts.md#folders) together, for
+example both eyes. Right-click a folder's header in the Parts list > **Move with the gizmo** turns it on for you.
+
## What a transform keeps
A transform only changes where the vertices are. Face Groups, quads, UVs, vertex paint, textures, the mask and
diff --git a/docs/guide/parts.md b/docs/guide/parts.md
index 599d1183..a0351ab4 100644
--- a/docs/guide/parts.md
+++ b/docs/guide/parts.md
@@ -91,6 +91,29 @@ Hidden Parts aren't drawn, can't be selected with <kbd>Alt</kbd>+click, and are
> **Note:** Part visibility is different from hiding part of a mesh with face groups or a rectangle. That hides
> faces inside one Part; see [Face Groups and visibility](face-groups.md).
+## Folders
+
+Folders group Parts in the list, for example the eyes and teeth of a head, so you can hide, show and move them
+together.
+
+| To | Do this |
+|---|---|
+| Make a folder | Click the folder button under the list: a new folder holds the active Part; type its name and press <kbd>Enter</kbd> |
+| Put a Part in a folder | Drag its row onto the folder's header (or onto a Part already in it), or right-click the row > **Folder** > the folder's name |
+| Take a Part out | Drag it onto a Part outside folders, or right-click it > **Folder** > **Out of the folder** |
+| Fold or open a folder | Click its header |
+| Rename it | Double-click the header (or right-click > **Rename**) |
+| Hide or show all its Parts | Click the eye on the header |
+| Move, turn or scale it | Right-click the header > **Move with the gizmo** |
+| Remove it | Right-click the header > **Remove folder (keep its Parts)** |
+
+A Part that joins a folder moves to just below the folder's last Part, so a folder's Parts stay together. When the
+folder holding the active Part is folded, its header shows the accent bar. **Move with the gizmo** makes one of
+the folder's Parts active and turns on the gizmo's **Folder** option, so every visible Part in the folder moves
+together; see [All Parts and Folder](gizmo.md#all-parts). Duplicates and the pieces of a split stay in their
+Part's folder. Folders are saved in the project; older versions of SculptForge open the file and simply show no
+folders.
+
## Reorder Parts
The up and down arrow buttons under the list move the active Part one place up or down. The order matters for
@@ -157,7 +180,7 @@ delete can't be undone.
| Format | What happens to Parts |
|---|---|
-| Project (`.sfproj`) | Every Part is saved with its name, visibility, attributes, layers and active layer |
+| Project (`.sfproj`) | Every Part is saved with its name, visibility, folder, attributes, layers and active layer |
| OBJ | Each visible Part is an `o` object; on import, `o` objects become Parts and `g` groups become face groups |
| glTF / GLB | One node and mesh per visible Part, both ways |
| FBX | One model per visible Part (with LODs, an LOD group each), both ways |
@@ -185,6 +208,11 @@ used.
| `part_visibility visible=false` | Show or hide (toggles when `visible` is left out) |
| `part_solo` / `part_show_all` | Solo the active Part / show every Part |
| `part_move direction=up` | Move a Part up or down the list |
+| `part_folder_new folder=Eyes` | Make a folder holding a Part (`empty=true`: an empty one) |
+| `part_set_folder name=EyeL folder=Eyes` | Put a Part into a folder (`folder=` empty: out of its folder) |
+| `part_folder_visibility folder=Eyes` | Hide or show a folder's Parts (toggles when `visible` is left out) |
+| `part_folder_collapse` / `part_folder_rename` / `part_folder_delete` | Fold or open, rename, remove a folder (`folder=`) |
+| `transform translate=0,0.1,0 folder=true` | Transform the visible Parts in the active Part's folder |
| `part_merge_down` / `part_merge_visible` | Merge |
| `part_split_groups` / `part_split_parts` | Split |
| `extract thickness=0.02 smooth=5 double=false` | Preview an Extract shell from the mask; `tcorne` / `tborder` for a triangle rim; `accept=true` keeps it at once |
diff --git a/src/app/App.h b/src/app/App.h
index 0dcea562..dea8618a 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -1496,6 +1496,7 @@ private:
bool jobWaitsForStroke() const;
Uint64 clickClockNs() const; // the status bar names the new active Part and how it was chosen
uint32_t renamingPart_ = 0; // Part id being renamed inline (0: none)
+ uint32_t renamingFolder_ = 0; // Part folder id being renamed inline (0: none; #96)
uint32_t listedActivePart_ = 0; // the list scrolls to the active Part when it changes
// Part thumbnails (#43): rendered from each Part's GPU buffers while the Parts panel shows, one per frame
// at most, a change once it has settled (PartThumbnails.h); GL textures by Part id.
@@ -1634,6 +1635,16 @@ private:
float microSlider_ = 4.0f; // Tool > Geometry > Micro: the micro level the next Divide to micro makes
bool sdivHeld_ = false;
void drawPartsContents();
+ // Parts list folders (#96): what a frame's folder rows asked for, run after the list (by folder name).
+ struct PartFolderActions {
+ std::string toggle, collapse, remove, gizmo, rename, renameTo;
+ int part = -1; // a Part put into folder partTo ("" = out of its folder)
+ std::string partTo;
+ };
+ void drawPartFolderRow(int folder, float rowH, ImVec2 cellPad, PartFolderActions& fa);
+ void partDropTarget(const std::string& folder, PartFolderActions& fa);
+ std::string partFolderName(uint32_t id) const;
+ void startFolderRename(); // the folder just made: its name ready to type
// PanelExtract.cpp: Tool > Part > Extract, Tool > Geometry > Modify Topology (Mirror And Weld) and
// Tool > Deformation (Mirror).
void drawExtractContents();
@@ -1861,7 +1872,7 @@ private:
bool pivotPlaced = false; // Alt+drag, snap or a drag moved it: stop following the centre
bool orientSurface = false; // axes from the surface the pivot was snapped to (else world)
glm::mat3 frame{1.0f}; // the surface axes (turn with rotations)
- bool useMask = true, all = false;
+ bool useMask = true, all = false, folder = false; // folder: the active Part's folder moves together (#96)
float falloff = 0.0f; // fraction of the size (core/MeshTransform.h)
bool snapNext = false; // "Pivot to Surface": the next click on the model places the pivot
uint64_t centreKey = ~uint64_t(0), maskKey = 0;
diff --git a/src/app/Gizmo.cpp b/src/app/Gizmo.cpp
index 2598f6f8..07ca6c39 100644
--- a/src/app/Gizmo.cpp
+++ b/src/app/Gizmo.cpp
@@ -175,6 +175,10 @@ void App::registerGizmoActions() {
add("gizmo.all", "All Parts", ICON_LC_LAYERS, kPath, "", [this] { gizmo_.all = !gizmo_.all; },
[this] { return gizmo_.all; },
"Transform every visible Part together. Each Part gets its own undo step.");
+ add("gizmo.folder", "Folder", ICON_LC_FOLDER, kPath, "", [this] { gizmo_.folder = !gizmo_.folder; },
+ [this] { return gizmo_.folder; },
+ "Transform the visible Parts in the active Part's folder together (Parts list folders). Each Part gets its "
+ "own undo step.");
}
void App::setGizmoMode(GizmoMode mode) {
@@ -198,9 +202,11 @@ void App::setGizmoMode(GizmoMode mode) {
std::vector<int> App::gizmoTargets() const {
std::vector<int> out;
+ const uint32_t folder = doc_.activePartInfo().folder;
for (int i = 0; i < doc_.partCount(); ++i) {
const bool visible = doc_.parts[size_t(i)].visible;
- if (i == doc_.activePart ? visible : gizmo_.all && visible) out.push_back(i);
+ const bool together = gizmo_.all || (gizmo_.folder && folder && doc_.parts[size_t(i)].folder == folder);
+ if (i == doc_.activePart ? visible : together && visible) out.push_back(i);
}
return out;
}
@@ -209,8 +215,9 @@ void App::updateGizmoPivot() {
// Recomputed only when the scene changes: a new undo step, another Part, the options.
uint64_t key = uint64_t(doc_.activePartInfo().id) * 1000003u ^ doc_.undo.revision() * 7919u ^
doc_.mesh.vertexCount() * 31u ^ (gizmo_.all ? 2u : 0u) ^ (gizmo_.useMask ? 4u : 0u) ^
+ (gizmo_.folder ? 8u + uint64_t(doc_.activePartInfo().folder) * 16u : 0u) ^
uint64_t(doc_.partCount()) << 48;
- if (gizmo_.all)
+ if (gizmo_.all || gizmo_.folder)
for (const Part& s : doc_.parts) key = key * 1099511628211ull ^ s.undo.revision() ^ (s.visible ? 1u : 0u);
if (key == gizmo_.centreKey) return;
gizmo_.centreKey = key;
@@ -653,6 +660,7 @@ void App::gizmoRelease() {
if (symmetry_.z) sym += 'z';
if (!sym.empty() && doc_.mesh.hasMask() && gizmo_.useMask) args["symmetry"] = sym;
if (gizmo_.all) args["all"] = true;
+ else if (gizmo_.folder && doc_.activePartInfo().folder) args["folder"] = true;
status_ = std::string(label) + " " + readout + ": " + std::to_string(moved) + " vertices";
consoleEcho("transform", args, {true, status_});
updateTitle();
@@ -713,6 +721,7 @@ void App::applyGizmoNumbers() {
if (symmetry_.z) sym += 'z';
if (!sym.empty()) args["symmetry"] = sym;
if (gizmo_.all) args["all"] = true;
+ else if (gizmo_.folder && doc_.activePartInfo().folder) args["folder"] = true;
const glm::vec3 pivot = gizmo_.pivot;
const glm::mat3 frameBefore = gizmo_.frame;
const bool surfaceBefore = gizmo_.orientSurface;
@@ -909,7 +918,7 @@ void App::drawGizmoContents(bool compact) {
kPath);
ui::Segmented(*this, {"gizmo.reset_pivot", "gizmo.snap_pivot"});
ui::Segmented(*this, {"gizmo.orient_world", "gizmo.orient_surface"});
- ui::Segmented(*this, {"gizmo.use_mask", "gizmo.all"});
+ ui::Segmented(*this, {"gizmo.use_mask", "gizmo.folder", "gizmo.all"});
float pct = gizmo_.falloff * 100.0f;
ImGui::SetNextItemWidth(-1.0f);
if (ui::SliderInside("##gizmo_falloff", &pct, 0.0f, 50.0f, "Falloff %.0f%%")) gizmo_.falloff = pct / 100.0f;
diff --git a/src/app/PanelParts.cpp b/src/app/PanelParts.cpp
index 8f06dc9e..6514e026 100644
--- a/src/app/PanelParts.cpp
+++ b/src/app/PanelParts.cpp
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Parts UI: the Parts panel (list with visibility toggles, inline
-// rename, append / duplicate / delete / reorder / solo / merge / split) and
+// rename, folders (#96), append / duplicate / delete / reorder / solo / merge / split) and
// the classic viewport gesture Alt+click to select a Part. Every action goes
// through the part_* commands (core/Parts.cpp).
#include "app/App.h"
@@ -13,7 +13,9 @@
#include "core/Multires.h"
#include "render/GL.h"
+#include <IconsLucide.h>
#include <cctype>
+#include <cstring>
#include <imgui_internal.h>
#include <algorithm>
@@ -229,12 +231,42 @@ void App::drawPartsContents() {
// 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;
+ // Folders (#96): pending actions on one, by name; a Part put into a folder ("" = out of its folder).
+ PartFolderActions fa;
+ int newFolderPart = -1;
+ // What the list shows, top to bottom: each folder's header where its first Part is, then (open) its Parts;
+ // empty folders last.
+ struct Row {
+ int part = -1, folder = -1; // folder: the header (part < 0) or the folder this Part is in
+ };
+ std::vector<Row> rows;
+ {
+ std::vector<char> listed(doc_.partFolders.size(), 0);
+ for (int i = 0; i < count; ++i) {
+ const int f = doc_.partFolderIndex(doc_.parts[size_t(i)].folder);
+ if (f < 0) {
+ rows.push_back({i, -1});
+ continue;
+ }
+ if (listed[size_t(f)]) continue;
+ listed[size_t(f)] = 1;
+ rows.push_back({-1, f});
+ if (doc_.partFolders[size_t(f)].collapsed) continue;
+ for (int k = i; k < count; ++k)
+ if (doc_.parts[size_t(k)].folder == doc_.partFolders[size_t(f)].id) rows.push_back({k, f});
+ }
+ for (size_t f = 0; f < listed.size(); ++f)
+ if (!listed[f]) rows.push_back({-1, int(f)});
+ }
const ImVec2 cellPad(6.0f * scale, 4.0f * scale);
// Each row starts with the Part's thumbnail (#43); the text is centred on its height.
const float thumb = 30.0f * scale, lineH = ImGui::GetTextLineHeight();
const float innerH = std::max(lineH, thumb), textDy = (innerH - lineH) * 0.5f;
const float rowH = innerH + 2.0f * cellPad.y;
- const float listH = rowH * float(std::min(count, kListRows)) + 2.0f;
+ const float folderH = lineH + 2.0f * cellPad.y + 2.0f * scale;
+ const float indent = 14.0f * scale; // a folder's Parts, under its header
+ float listH = 2.0f;
+ for (size_t r = 0; r < rows.size() && r < size_t(kListRows); ++r) listH += rows[r].part < 0 ? folderH : rowH;
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, cellPad);
// The list sits in a recessed well, no outline. The active row is a lighter neutral with the accent only as the
// 2 px bar at its left edge (docs/ui-design.md §10), so it doesn't read as a dimmed orange fill.
@@ -255,12 +287,19 @@ void App::drawPartsContents() {
ImGui::TableSetupColumn("sdiv", ImGuiTableColumnFlags_WidthFixed, anyLevels ? ImGui::CalcTextSize("SDiv 8/8").x : 0.0f);
ImGui::TableSetupColumn("tris", ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize("0.00M").x);
ImGui::TableSetupColumn("eye", ImGuiTableColumnFlags_WidthFixed, eyeW);
- for (int i = 0; i < count; ++i) {
+ // A Part dropped on a row: into that folder, or (on a Part outside folders) out of its folder.
+ for (const Row& row : rows) {
+ if (row.part < 0) {
+ drawPartFolderRow(row.folder, folderH, cellPad, fa);
+ continue;
+ }
+ const int i = row.part;
const Part& s = doc_.parts[size_t(i)];
const bool isActive = i == active;
ImGui::PushID(int(s.id));
ImGui::TableNextRow(ImGuiTableRowFlags_None, rowH);
ImGui::TableSetColumnIndex(0);
+ if (row.folder >= 0) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + indent);
const ImVec2 thumbAt = ImGui::GetCursorScreenPos();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + thumb + 6.0f * scale);
if (renamingPart_ == s.id) {
@@ -292,6 +331,15 @@ void App::drawPartsContents() {
selectIndex = i;
ImGui::PopStyleVar();
if (!s.visible) ImGui::PopStyleColor();
+ if (ImGui::BeginDragDropSource()) { // #96: drag a Part onto a folder (or onto a Part outside folders)
+ ImGui::SetDragDropPayload("SF_PART", &s.id, sizeof s.id);
+ ImGui::Text(tr("Move %s"), s.name.c_str());
+ ImGui::EndDragDropSource();
+ }
+ {
+ const int f = doc_.partFolderIndex(s.folder);
+ partDropTarget(f >= 0 ? doc_.partFolders[size_t(f)].name : std::string(), fa);
+ }
if (isActive) {
const ImVec2 r0 = ImGui::GetItemRectMin(), r1 = ImGui::GetItemRectMax();
const float x = ImGui::TableGetCellBgRect(ImGui::GetCurrentTable(), 0).Min.x;
@@ -316,6 +364,23 @@ void App::drawPartsContents() {
std::snprintf(renameBuffer_, sizeof renameBuffer_, "%s", s.name.c_str());
}
if (ImGui::MenuItem(tr("Duplicate"), actions_.shortcutText("part.duplicate").c_str())) duplicateIndex = i;
+ if (ImGui::BeginMenu(tr("Folder"))) {
+ if (ImGui::MenuItem(tr("New folder"))) newFolderPart = i;
+ if (!doc_.partFolders.empty()) ImGui::Separator();
+ for (const PartFolder& f : doc_.partFolders)
+ if (ImGui::MenuItem((f.name + "##to folder").c_str(), nullptr, s.folder == f.id) && s.folder != f.id) {
+ fa.part = i;
+ fa.partTo = f.name;
+ }
+ if (s.folder) {
+ ImGui::Separator();
+ if (ImGui::MenuItem(tr("Out of the folder"))) {
+ fa.part = i;
+ fa.partTo.clear();
+ }
+ }
+ ImGui::EndMenu();
+ }
if (ImGui::MenuItem(tr("Delete..."), nullptr, false, count > 1)) deleteIndex = i;
ImGui::EndPopup();
}
@@ -378,6 +443,30 @@ void App::drawPartsContents() {
}
if (toggleIndex >= 0) runCommand("part_visibility", {{"index", double(toggleIndex)}});
if (duplicateIndex >= 0) runCommand("part_duplicate", {{"index", double(duplicateIndex)}});
+ if (newFolderPart >= 0) {
+ runCommand("part_folder_new", {{"index", double(newFolderPart)}});
+ startFolderRename();
+ }
+ if (fa.part >= 0 && fa.partTo != partFolderName(doc_.parts[size_t(fa.part)].folder))
+ runCommand("part_set_folder", {{"index", double(fa.part)}, {"folder", fa.partTo}});
+ if (!fa.toggle.empty()) runCommand("part_folder_visibility", {{"folder", fa.toggle}});
+ if (!fa.collapse.empty()) runCommand("part_folder_collapse", {{"folder", fa.collapse}});
+ if (!fa.rename.empty() && !fa.renameTo.empty() && fa.renameTo != fa.rename)
+ runCommand("part_folder_rename", {{"folder", fa.rename}, {"to", fa.renameTo}});
+ if (!fa.remove.empty()) runCommand("part_folder_delete", {{"folder", fa.remove}});
+ if (!fa.gizmo.empty()) {
+ // Move the whole folder: one of its Parts active, the gizmo's Folder option on, Move.
+ const int f = doc_.findPartFolder(fa.gizmo);
+ if (f >= 0 && doc_.activePartInfo().folder != doc_.partFolders[size_t(f)].id)
+ for (int i = 0; i < doc_.partCount(); ++i)
+ if (doc_.parts[size_t(i)].folder == doc_.partFolders[size_t(f)].id) {
+ runCommand("part_select", {{"index", double(i)}});
+ break;
+ }
+ gizmo_.folder = true;
+ setGizmoMode(GizmoMode::Move);
+ status_ = "Move " + fa.gizmo + ": drag the gizmo (its visible Parts move together; W again: back to Draw)";
+ }
// Buttons act on the active Part.
const std::string activeName = doc_.activePartInfo().name;
@@ -467,9 +556,17 @@ void App::drawPartsContents() {
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))
ImGui::SetTooltip("%s", tr("Move down the list"));
ImGui::SameLine();
+ if (ImGui::Button(ICON_LC_FOLDER_PLUS "###part_folder_new", ImVec2(arrowW, 0))) {
+ runCommand("part_folder_new");
+ startFolderRename();
+ }
+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal))
+ ImGui::SetTooltip("%s", tr("New folder with the active Part (drag Parts onto a folder to add them)"));
+ ImGui::SameLine();
// Solo and X-Ray side by side (#80), then Unhide all.
- const float rest = ImGui::GetContentRegionAvail().x - 2.0f * (arrowW + style.ItemSpacing.x) - 2.0f * style.ItemSpacing.x;
- const float soloW = std::floor(rest * 0.3f), xrayW = std::floor(rest * 0.32f);
+ // Solo and X-Ray as wide as their words (never clipped, at any UI scale); Unhide all takes the rest.
+ const float pad = 2.0f * style.FramePadding.x + 4.0f * uiScale_;
+ const float soloW = std::ceil(ImGui::CalcTextSize(tr("Solo")).x + pad), xrayW = std::ceil(ImGui::CalcTextSize(tr("X-Ray")).x + pad);
const bool solo = count > 1 && visibleCount == 1 && doc_.activePartInfo().visible;
ImGui::BeginDisabled(count < 2);
if (solo) ImGui::PushStyleColor(ImGuiCol_Button, style.Colors[ImGuiCol_ButtonActive]);
@@ -534,6 +631,143 @@ void App::drawPartsContents() {
if (fontSmall_) ImGui::PopFont();
}
+std::string App::partFolderName(uint32_t id) const {
+ const int f = doc_.partFolderIndex(id);
+ return f >= 0 ? doc_.partFolders[size_t(f)].name : std::string();
+}
+
+void App::startFolderRename() {
+ if (!lastCommandOk_ || doc_.partFolders.empty()) return;
+ const PartFolder& f = doc_.partFolders.back(); // (the one just made)
+ renamingFolder_ = f.id;
+ focusRename_ = true;
+ std::snprintf(renameBuffer_, sizeof renameBuffer_, "%s", f.name.c_str());
+}
+
+// A folder's header row (#96): chevron, folder, name, its triangles and an eye for all its Parts. Click folds or
+// opens it, double-click renames, right-click for the rest; actions come back by the folder's name.
+void App::partDropTarget(const std::string& folder, PartFolderActions& fa) {
+ if (!ImGui::BeginDragDropTarget()) return;
+ if (const ImGuiPayload* p = ImGui::AcceptDragDropPayload("SF_PART"); p && p->DataSize == sizeof(uint32_t)) {
+ uint32_t id = 0;
+ std::memcpy(&id, p->Data, sizeof id);
+ fa.part = doc_.partIndex(id);
+ fa.partTo = folder;
+ }
+ ImGui::EndDragDropTarget();
+}
+
+void App::drawPartFolderRow(int fi, float rowH, ImVec2 cellPad, PartFolderActions& fa) {
+ const PartFolder& f = doc_.partFolders[size_t(fi)];
+ const ImGuiStyle& style = ImGui::GetStyle();
+ const float scale = uiScale_;
+ int members = 0, shown = 0;
+ bool hasActive = false;
+ size_t tris = 0;
+ for (int i = 0; i < doc_.partCount(); ++i) {
+ if (doc_.parts[size_t(i)].folder != f.id) continue;
+ ++members;
+ shown += doc_.parts[size_t(i)].visible ? 1 : 0;
+ hasActive |= i == doc_.activePart;
+ tris += doc_.partMesh(i).triangleCount();
+ }
+ const bool visible = shown > 0;
+ const float textDy = (rowH - 2.0f * cellPad.y - ImGui::GetTextLineHeight()) * 0.5f;
+ ImGui::PushID(int(f.id) ^ 0x46000000);
+ ImGui::TableNextRow(ImGuiTableRowFlags_None, rowH);
+ ImGui::TableSetColumnIndex(0);
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textDy);
+ const ImVec2 at = ImGui::GetCursorScreenPos();
+ const float iconW = ImGui::CalcTextSize(ICON_LC_FOLDER).x;
+ const float textX = iconW * 2.0f + 8.0f * scale; // chevron, folder, then the name
+ if (renamingFolder_ == f.id) {
+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + textX);
+ 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 folder", renameBuffer_, sizeof renameBuffer_,
+ ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll);
+ ImGui::PopStyleVar();
+ if (enter || (ImGui::IsItemDeactivatedAfterEdit() && !ImGui::IsKeyPressed(ImGuiKey_Escape))) {
+ fa.rename = f.name;
+ fa.renameTo = renameBuffer_;
+ renamingFolder_ = 0;
+ } else if (ImGui::IsItemDeactivated()) {
+ renamingFolder_ = 0;
+ }
+ } else {
+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + textX);
+ if (!visible) ImGui::PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]);
+ if (ImGui::Selectable((f.name + "##folder").c_str(), false,
+ ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap |
+ ImGuiSelectableFlags_AllowDoubleClick | ImGuiSelectableFlags_NoAutoClosePopups)) {
+ fa.collapse = f.name; // (a double-click's second click folds it back)
+ if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { // the header's own (not its eye's)
+ renamingFolder_ = f.id;
+ focusRename_ = true;
+ std::snprintf(renameBuffer_, sizeof renameBuffer_, "%s", f.name.c_str());
+ }
+ }
+ if (!visible) ImGui::PopStyleColor();
+ partDropTarget(f.name, fa);
+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal))
+ ImGui::SetTooltip(tr("Folder %s: %d Part%s\nClick to %s, double-click to rename, drag Parts onto it"),
+ f.name.c_str(), members, members == 1 ? "" : "s", f.collapsed ? "open" : "fold");
+ if (ImGui::BeginPopupContextItem("##folder row")) {
+ ImGui::TextDisabled("%s", f.name.c_str());
+ if (ImGui::MenuItem(tr("Rename"))) {
+ renamingFolder_ = f.id;
+ focusRename_ = true;
+ std::snprintf(renameBuffer_, sizeof renameBuffer_, "%s", f.name.c_str());
+ }
+ if (ImGui::MenuItem(visible ? tr("Hide its Parts") : tr("Show its Parts"), nullptr, false, members > 0))
+ fa.toggle = f.name;
+ if (ImGui::MenuItem(tr("Move with the gizmo"), nullptr, false, shown > 0)) fa.gizmo = f.name;
+ ImGui::Separator();
+ if (ImGui::MenuItem(tr("Remove folder (keep its Parts)"))) fa.remove = f.name;
+ ImGui::EndPopup();
+ }
+ if (hasActive && f.collapsed) { // the active Part is folded away in here: the accent bar says so
+ const ImVec2 r0 = ImGui::GetItemRectMin(), r1 = ImGui::GetItemRectMax();
+ const float x = ImGui::TableGetCellBgRect(ImGui::GetCurrentTable(), 0).Min.x;
+ ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(x, r0.y), ImVec2(x + 2.0f * scale, r1.y), theme::u32(theme::accent));
+ }
+ }
+ {
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const ImU32 dim = ImGui::GetColorU32(style.Colors[ImGuiCol_TextDisabled]);
+ const ImU32 text = ImGui::GetColorU32(style.Colors[visible ? ImGuiCol_Text : ImGuiCol_TextDisabled]);
+ dl->AddText(at, dim, f.collapsed ? ICON_LC_CHEVRON_RIGHT : ICON_LC_CHEVRON_DOWN);
+ dl->AddText(ImVec2(at.x + iconW + 4.0f * scale, at.y), text, f.collapsed ? ICON_LC_FOLDER : ICON_LC_FOLDER_OPEN);
+ }
+ ImGui::TableSetColumnIndex(2);
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textDy);
+ if (members) {
+ const std::string t = shortCount(tris);
+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(t.c_str()).x);
+ ImGui::TextDisabled("%s", t.c_str());
+ }
+ ImGui::TableSetColumnIndex(3);
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textDy);
+ const ImVec2 eyePos = ImGui::GetCursorScreenPos();
+ const ImVec2 eyeSize(ImGui::GetContentRegionAvail().x, ImGui::GetTextLineHeight());
+ ImGui::BeginDisabled(members == 0);
+ if (ImGui::InvisibleButton(("##eye folder " + f.name).c_str(), eyeSize)) fa.toggle = f.name;
+ ImGui::EndDisabled();
+ const bool eyeHovered = ImGui::IsItemHovered();
+ if (eyeHovered) ImGui::SetTooltip(visible ? "Hide the Parts in %s" : "Show the Parts in %s", f.name.c_str());
+ const ImU32 eyeCol = ImGui::GetColorU32(eyeHovered ? style.Colors[ImGuiCol_ButtonHovered]
+ : visible ? style.Colors[ImGuiCol_Text]
+ : style.Colors[ImGuiCol_TextDisabled]);
+ if (members)
+ drawEye(ImGui::GetWindowDrawList(), ImVec2(eyePos.x + eyeSize.x * 0.5f, eyePos.y + eyeSize.y * 0.5f),
+ ImGui::GetTextLineHeight() * 0.8f, visible, eyeCol);
+ ImGui::PopID();
+}
+
void App::drawPartPopups() {
const std::string popup = partConfirm_.title + "###" + partConfirm_.command;
if (openPartConfirm_) {
diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cpp
index 8b72cbaa..edd2ad41 100644
--- a/src/app/PanelProject.cpp
+++ b/src/app/PanelProject.cpp
@@ -423,6 +423,7 @@ void App::storeProjectSettings() {
gizmo.set("axis_y", vec3Json(gizmo_.frame[1]));
gizmo.set("use_mask", gizmo_.useMask);
gizmo.set("all_parts", gizmo_.all);
+ gizmo.set("folder_parts", gizmo_.folder);
gizmo.set("falloff", double(gizmo_.falloff));
s.set("gizmo", std::move(gizmo));
@@ -602,6 +603,7 @@ void App::applyProjectSettings() {
}
readBool(g, "use_mask", gizmo_.useMask);
readBool(g, "all_parts", gizmo_.all);
+ readBool(g, "folder_parts", gizmo_.folder);
readFloat(g, "falloff", gizmo_.falloff);
gizmo_.falloff = std::clamp(gizmo_.falloff, 0.0f, 1.0f);
if (!gizmo_.pivotPlaced) updateGizmoPivot();
diff --git a/src/core/Document.cpp b/src/core/Document.cpp
index 10cac296..6681b284 100644
--- a/src/core/Document.cpp
+++ b/src/core/Document.cpp
@@ -27,6 +27,7 @@ void Document::setMesh(Mesh m, std::string name, BVH* built) {
bvhDirty = false;
bridgeName.clear();
qremeshGuides.clear();
+ partFolders.clear();
parts.clear();
parts.emplace_back();
parts.back().id = nextPartId_++;
@@ -173,6 +174,61 @@ std::string Document::uniquePartName(const std::string& wanted) const {
}
}
+uint32_t Document::addPartFolder(const std::string& name) {
+ PartFolder f;
+ f.id = nextFolderId_++;
+ f.name = uniqueFolderName(name.empty() ? "Folder" : name);
+ partFolders.push_back(std::move(f));
+ modified = true;
+ return partFolders.back().id;
+}
+
+int Document::partFolderIndex(uint32_t id) const {
+ for (size_t i = 0; i < partFolders.size(); ++i)
+ if (partFolders[i].id == id) return int(i);
+ return -1;
+}
+
+int Document::findPartFolder(const std::string& name) const {
+ for (size_t i = 0; i < partFolders.size(); ++i)
+ if (partFolders[i].name == name) return int(i);
+ return -1;
+}
+
+void Document::removePartFolder(uint32_t id) {
+ const int f = partFolderIndex(id);
+ if (f < 0) return;
+ for (Part& s : parts)
+ if (s.folder == id) s.folder = 0;
+ partFolders.erase(partFolders.begin() + f);
+ modified = true;
+}
+
+int Document::setPartFolder(int i, uint32_t id) {
+ if (i < 0 || i >= partCount() || (id && partFolderIndex(id) < 0)) return i;
+ if (parts[size_t(i)].folder == id) return i;
+ parts[size_t(i)].folder = id;
+ modified = true;
+ int last = -1; // the folder's last other Part
+ for (int k = 0; k < partCount(); ++k)
+ if (k != i && id && parts[size_t(k)].folder == id) last = k;
+ if (last < 0) return i;
+ const uint32_t activeId = activePartInfo().id;
+ const int to = last < i ? last + 1 : last; // where it lands once taken out
+ if (to < i) std::rotate(parts.begin() + to, parts.begin() + i, parts.begin() + i + 1);
+ else if (to > i) std::rotate(parts.begin() + i, parts.begin() + i + 1, parts.begin() + to + 1);
+ activePart = partIndex(activeId);
+ return to;
+}
+
+std::string Document::uniqueFolderName(const std::string& wanted) const {
+ if (findPartFolder(wanted) < 0) return wanted;
+ for (int n = 2;; ++n) {
+ std::string candidate = wanted + " " + std::to_string(n);
+ if (findPartFolder(candidate) < 0) return candidate;
+ }
+}
+
AABB Document::visibleBounds() const {
AABB b;
for (int i = 0; i < partCount(); ++i)
diff --git a/src/core/Document.h b/src/core/Document.h
index bc85db1d..940a6a02 100644
--- a/src/core/Document.h
+++ b/src/core/Document.h
@@ -37,6 +37,7 @@ struct Part {
std::string name;
bool visible = true;
Shading shading = Shading::Default; // per-Part override of the scene's shading
+ uint32_t folder = 0; // the PartFolder it's in (its id), 0 = none
// Inactive Parts only (empty while active).
Mesh mesh;
BVH bvh;
@@ -48,6 +49,14 @@ struct Part {
std::vector<QRemeshGuide> qremeshGuides; // QRemesh Guides (core/QRemeshGuides.h)
};
+// A folder in the Parts list (#96): a name the list groups its Parts under, so they hide, show and move
+// together. Display and organisation only; saved in projects (optional keys, older versions ignore them).
+struct PartFolder {
+ uint32_t id = 0; // stable for the session; Part::folder points here
+ std::string name;
+ bool collapsed = false; // the list shows only its header
+};
+
// An undo step that added Part `id` at list position `at` (UndoRecord::part): `stashed` holds the Part
// while it's undone.
struct PartStep {
@@ -166,6 +175,21 @@ struct Document {
// Removes the preview Part (if any); `staleOnly`: only when it's no longer current.
void dropExtractPreview(bool staleOnly = false);
+ // --- Part folders (#96). Not undoable either; changes set `modified`.
+ std::vector<PartFolder> partFolders;
+ // Adds a folder (its name made unique) and returns its id.
+ uint32_t addPartFolder(const std::string& name);
+ // Index of the folder with this id / name (exact match), or -1.
+ int partFolderIndex(uint32_t id) const;
+ int findPartFolder(const std::string& name) const;
+ // Removes a folder; its Parts stay, outside any folder.
+ void removePartFolder(uint32_t id);
+ // Puts Part `i` into folder `id` (0 = out of any folder). Joining a folder moves the Part to just below the
+ // folder's last Part, so a folder's Parts stay together in the list; returns the Part's new index.
+ int setPartFolder(int i, uint32_t id);
+ // A folder name not used yet ("Folder", "Folder 2", ...).
+ std::string uniqueFolderName(const std::string& wanted) const;
+
// A name not used by any Part yet ("Eye", "Eye 2", ...).
std::string uniquePartName(const std::string& wanted) const;
// Bounds of every visible Part.
@@ -185,6 +209,7 @@ struct Document {
private:
uint64_t cleanRevision_ = 0, cleanSplatsVersion_ = 0;
uint32_t nextPartId_ = 2;
+ uint32_t nextFolderId_ = 1;
};
} // namespace sf
diff --git a/src/core/Parts.cpp b/src/core/Parts.cpp
index 59563684..5b0a1f8e 100644
--- a/src/core/Parts.cpp
+++ b/src/core/Parts.cpp
@@ -187,14 +187,21 @@ CommandResult notFound(const Args& a) {
return {false, a.contains("name") ? "No Part named '" + argString(a, "name") + "'" : std::string("No such Part")};
}
+// The folder named by folder= (#96), or -1.
+int targetFolder(const Document& doc, const Args& a) { return doc.findPartFolder(argString(a, "folder")); }
+
+CommandResult folderNotFound(const Args& a) { return {false, "No folder named '" + argString(a, "folder") + "'"}; }
+
// Replaces Part `index` by `pieces`, named after it ("Body 1", "Body 2", ...); the first piece is selected.
void replaceWithPieces(Document& doc, int index, std::vector<Mesh> pieces) {
notePartLevelsDropped(doc, index); // the pieces are cut from the current level
const std::string base = doc.parts[size_t(index)].name;
const bool visible = doc.parts[size_t(index)].visible;
+ const uint32_t folder = doc.parts[size_t(index)].folder;
for (size_t k = 0; k < pieces.size(); ++k) {
const int at = doc.addPart(std::move(pieces[k]), base + " " + std::to_string(k + 1), false, index + 1 + int(k));
doc.parts[size_t(at)].visible = visible;
+ doc.parts[size_t(at)].folder = folder;
}
doc.selectPart(index + 1);
doc.removePart(index);
@@ -321,8 +328,15 @@ void registerPartCommands(CommandRegistry& reg) {
if (subdivLevelCount(doc.partMesh(i))) out += ", " + subdivLevelText(doc.partMesh(i));
if (i == doc.activePart) out += ", active";
if (!s.visible) out += ", hidden";
+ if (const int f = doc.partFolderIndex(s.folder); f >= 0) out += ", in " + doc.partFolders[size_t(f)].name;
out += ")";
}
+ for (const PartFolder& f : doc.partFolders) {
+ int n = 0;
+ for (const Part& s : doc.parts) n += s.folder == f.id ? 1 : 0;
+ out += "\nFolder " + f.name + " (" + std::to_string(n) + " Part" + (n == 1 ? "" : "s") +
+ (f.collapsed ? ", collapsed" : "") + ")";
+ }
return {true, out};
}});
@@ -477,8 +491,10 @@ void registerPartCommands(CommandRegistry& reg) {
if (i < 0) return notFound(a);
Mesh copy = doc.partMesh(i);
const Shading shading = doc.parts[size_t(i)].shading;
+ const uint32_t folder = doc.parts[size_t(i)].folder;
const int added = doc.addPart(std::move(copy), doc.parts[size_t(i)].name + " copy", true, i + 1);
doc.parts[size_t(added)].shading = shading;
+ doc.parts[size_t(added)].folder = folder; // (right below it: the folder stays together)
return {true, "Duplicated as " + doc.parts[size_t(added)].name};
}});
@@ -532,6 +548,90 @@ void registerPartCommands(CommandRegistry& reg) {
return {true, s.name + " shading: " + shadingName(mode)};
}});
+ // Folders (#96): group Parts in the list; hide, show and move (transform folder=true) a folder at once.
+ const ParamSpec folderParam{"folder", T::String, "Folder name.", true};
+ reg.add({"part_folder_new", "Make a folder in the Parts list and put a Part in it (the active one by default).",
+ {{"folder", T::String, "Its name (default Folder; made unique).", false},
+ {"empty", T::Bool, "Make it empty instead. Default false.", false}, indexParam, nameParam},
+ [](Document& doc, const Args& a) -> CommandResult {
+ const int i = targetPart(doc, a);
+ if (i < 0) return notFound(a);
+ const uint32_t id = doc.addPartFolder(argString(a, "folder", "Folder"));
+ const std::string& folder = doc.partFolders.back().name;
+ if (argBool(a, "empty", false)) return {true, "Made folder " + folder};
+ const int at = doc.setPartFolder(i, id);
+ return {true, "Made folder " + folder + " with " + doc.parts[size_t(at)].name};
+ }});
+
+ reg.add({"part_set_folder", "Put a Part into a folder, or take it out (folder empty).",
+ {{"folder", T::String, "Folder name; empty = out of its folder.", true}, indexParam, nameParam},
+ [](Document& doc, const Args& a) -> CommandResult {
+ const int i = targetPart(doc, a);
+ if (i < 0) return notFound(a);
+ const std::string name = doc.parts[size_t(i)].name;
+ if (argString(a, "folder").empty()) {
+ doc.setPartFolder(i, 0);
+ return {true, name + " is out of its folder"};
+ }
+ const int f = targetFolder(doc, a);
+ if (f < 0) return folderNotFound(a);
+ doc.setPartFolder(i, doc.partFolders[size_t(f)].id);
+ return {true, name + " is in " + doc.partFolders[size_t(f)].name};
+ }});
+
+ reg.add({"part_folder_rename", "Rename a Part folder.",
+ {folderParam, {"to", T::String, "The new name.", true}},
+ [](Document& doc, const Args& a) -> CommandResult {
+ const int f = targetFolder(doc, a);
+ if (f < 0) return folderNotFound(a);
+ std::string to = argString(a, "to");
+ if (to.empty()) return {false, "The name can't be empty"};
+ PartFolder& folder = doc.partFolders[size_t(f)];
+ if (folder.name != to) to = doc.uniqueFolderName(to);
+ folder.name = to;
+ doc.modified = true;
+ return {true, "Folder renamed to " + to};
+ }});
+
+ reg.add({"part_folder_visibility", "Show or hide every Part in a folder.",
+ {folderParam, {"visible", T::Bool, "true to show, false to hide. Default: hide if any is shown, else show.", false}},
+ [](Document& doc, const Args& a) -> CommandResult {
+ const int f = targetFolder(doc, a);
+ if (f < 0) return folderNotFound(a);
+ const PartFolder& folder = doc.partFolders[size_t(f)];
+ bool anyShown = false;
+ for (const Part& s : doc.parts) anyShown |= s.folder == folder.id && s.visible;
+ const bool show = argBool(a, "visible", !anyShown);
+ int n = 0;
+ for (Part& s : doc.parts)
+ if (s.folder == folder.id) {
+ s.visible = show;
+ ++n;
+ }
+ if (n == 0) return {false, folder.name + " has no Parts"};
+ doc.modified = true;
+ return {true, folder.name + (show ? " shown" : " hidden")};
+ }});
+
+ reg.add({"part_folder_collapse", "Fold a Part folder in the list (only its header shows), or open it.",
+ {folderParam, {"collapsed", T::Bool, "true to fold, false to open. Default: toggle.", false}},
+ [](Document& doc, const Args& a) -> CommandResult {
+ const int f = targetFolder(doc, a);
+ if (f < 0) return folderNotFound(a);
+ PartFolder& folder = doc.partFolders[size_t(f)];
+ folder.collapsed = argBool(a, "collapsed", !folder.collapsed); // (a view state: not an unsaved change)
+ return {true, folder.name + (folder.collapsed ? " folded" : " opened")};
+ }});
+
+ reg.add({"part_folder_delete", "Remove a Part folder. Its Parts stay, outside any folder.", {folderParam},
+ [](Document& doc, const Args& a) -> CommandResult {
+ const int f = targetFolder(doc, a);
+ if (f < 0) return folderNotFound(a);
+ const std::string name = doc.partFolders[size_t(f)].name;
+ doc.removePartFolder(doc.partFolders[size_t(f)].id);
+ return {true, "Removed folder " + name + " (its Parts stay)"};
+ }});
+
reg.add({"part_solo", "Show only the active Part, or (when it already is the only one shown) show all again.", {},
[](Document& doc, const Args&) -> CommandResult {
bool othersShown = false;
diff --git a/src/core/Project.cpp b/src/core/Project.cpp
index 8cca7f0c..683b4a75 100644
--- a/src/core/Project.cpp
+++ b/src/core/Project.cpp
@@ -55,7 +55,7 @@ ProjectThumbnailProvider& thumbnailProvider() {
// version 1); every other key belongs to
// Document::projectSettings (camera, render, brush, symmetry, ...).
const char* const kCoreKeys[] = {"format", "version", "app_version", "mesh", "layers", "active_layer",
- "parts", "active_part", "brushes", "active_brush", "splats", "attachments"};
+ "parts", "active_part", "part_folders", "brushes", "active_brush", "splats", "attachments"};
std::filesystem::path fsPath(const std::string& p) { return std::filesystem::path(std::u8string(p.begin(), p.end())); }
@@ -849,6 +849,7 @@ struct LoadedPart {
std::vector<QRemeshGuide> qremeshGuides;
bool visible = true;
Shading shading = Shading::Default;
+ int folder = -1; // index into the manifest's part_folders (#96)
int activeLayer = -1;
Mesh mesh;
// A big mesh's BVH is built on its own thread once the positions and triangles are read (they don't change
@@ -898,6 +899,7 @@ bool saveProject(const std::string& path, const Document& doc, std::string& erro
st.set("name", s.name);
st.set("visible", s.visible);
if (s.shading != Shading::Default) st.set("shading", shadingName(s.shading)); // (no format change: optional)
+ if (const int f = doc.partFolderIndex(s.folder); f >= 0) st.set("folder", f); // (#96: optional, as shading)
writeMesh(w, "parts/" + std::to_string(i) + "/", doc.partMesh(i), st);
st.set("active_layer", active ? doc.activeLayer : s.activeLayer);
if (hasPaintLayers(doc.partMesh(i)))
@@ -937,6 +939,16 @@ bool saveProject(const std::string& path, const Document& doc, std::string& erro
}
manifest.set("parts", std::move(parts));
manifest.set("active_part", doc.activePart);
+ if (!doc.partFolders.empty()) { // Parts list folders (#96); no format change: older readers ignore them
+ Json folders = Json::array();
+ for (const PartFolder& f : doc.partFolders) {
+ Json fj = Json::object();
+ fj.set("name", f.name);
+ if (f.collapsed) fj.set("collapsed", true);
+ folders.push(std::move(fj));
+ }
+ manifest.set("part_folders", std::move(folders));
+ }
Json brushes = Json::array();
for (const auto& b : doc.brushes) brushes.push(b.toJson());
@@ -1054,6 +1066,7 @@ bool loadProject(const std::string& path, Document& doc, std::string& error) {
if (s.name.empty()) s.name = "Part";
s.visible = sj["visible"].asBool(true);
if (sj["shading"].isString()) parseShading(sj["shading"].asString(), s.shading); // unknown: Default
+ s.folder = int(sj["folder"].asNumber(-1));
s.bridgeName = sj["bridge_name"].asString();
s.qremeshGuides = qremeshGuidesFromJson(sj["qremesh_guides"]);
if (!readMesh(r, sj["mesh"], sj["layers"], s.mesh, error, false, false)) return false;
@@ -1160,6 +1173,16 @@ bool loadProject(const std::string& path, Document& doc, std::string& error) {
s.bridgeName = parts[i].bridgeName;
s.qremeshGuides = std::move(parts[i].qremeshGuides);
}
+ // Folders (#96): a Part pointing at a folder that isn't there is simply outside any folder.
+ if (const Json& folders = manifest["part_folders"]; folders.isArray() && folders.size() <= kMaxProjectParts) {
+ std::vector<uint32_t> ids;
+ for (const Json& fj : folders.items()) {
+ ids.push_back(doc.addPartFolder(fj["name"].isString() ? fj["name"].asString() : std::string("Folder")));
+ doc.partFolders.back().collapsed = fj["collapsed"].asBool(false);
+ }
+ for (size_t i = 0; i < parts.size(); ++i)
+ if (parts[i].folder >= 0 && parts[i].folder < int(ids.size())) doc.parts[i].folder = ids[size_t(parts[i].folder)];
+ }
doc.selectPart(activePart);
doc.splats = std::move(splats);
doc.splatsChanged();
diff --git a/src/core/TransformCommands.cpp b/src/core/TransformCommands.cpp
index 3049ff69..58a027b2 100644
--- a/src/core/TransformCommands.cpp
+++ b/src/core/TransformCommands.cpp
@@ -65,6 +65,7 @@ CommandResult runTransform(Document& doc, const Args& a) {
const bool useMask = argBool(a, "masked", true);
const float falloff = std::clamp(float(argNumber(a, "falloff", 0)), 0.0f, 1.0f);
const bool all = argBool(a, "all", false);
+ const uint32_t folder = argBool(a, "folder", false) ? doc.activePartInfo().folder : 0; // #96
Symmetry sym{false, false, false};
for (char c : lower(argString(a, "symmetry"))) {
if (c == 'x') sym.x = true;
@@ -75,7 +76,8 @@ CommandResult runTransform(Document& doc, const Args& a) {
std::vector<int> targets;
for (int i = 0; i < doc.partCount(); ++i)
- if (all ? doc.parts[size_t(i)].visible || i == doc.activePart : i == doc.activePart) targets.push_back(i);
+ if (i == doc.activePart || (doc.parts[size_t(i)].visible && (all || (folder && doc.parts[size_t(i)].folder == folder))))
+ targets.push_back(i);
MeshTransform t;
t.translate = translate;
@@ -137,7 +139,9 @@ void registerTransformCommands(CommandRegistry& reg) {
"Mirror a masked transform across these planes through the origin, e.g. x: the unmasked part on the "
"other side of the plane takes the mirrored transform (both arms pose together).",
false},
- {"all", T::Bool, "Transform every visible Part. Default false.", false}},
+ {"all", T::Bool, "Transform every visible Part. Default false.", false},
+ {"folder", T::Bool, "Transform the visible Parts in the active Part's folder together. Default false.",
+ false}},
runTransform});
}
diff --git a/tests/test_part_io.cpp b/tests/test_part_io.cpp
index e2b46c62..d2295933 100644
--- a/tests/test_part_io.cpp
+++ b/tests/test_part_io.cpp
@@ -192,6 +192,60 @@ TEST(part_project_v2_round_trip) {
std::filesystem::remove(path);
}
+TEST(part_project_folders) {
+ // #96: folders and which Parts are in them come back; no format change (older versions ignore the keys).
+ Document doc = makeScene();
+ const uint32_t gear = doc.addPartFolder("Gear");
+ doc.addPartFolder("Empty");
+ doc.partFolders[0].collapsed = true;
+ doc.setPartFolder(2, gear); // Sword
+ doc.setPartFolder(1, gear); // Eye (active): moves below the Sword
+ CHECK(doc.parts[1].name == "Sword" && doc.parts[2].name == "Eye" && doc.activePart == 2);
+ const std::string path = tempPath("sf_part_folders.sfproj");
+ std::string err;
+ CHECK(saveProject(path, doc, err));
+
+ Document back;
+ CHECK(loadProject(path, back, err));
+ CHECK(back.partFolders.size() == 2 && back.partFolders[0].name == "Gear" && back.partFolders[0].collapsed);
+ CHECK(back.partFolders[1].name == "Empty" && !back.partFolders[1].collapsed);
+ CHECK(back.parts[0].folder == 0 && back.parts[1].folder == back.partFolders[0].id &&
+ back.parts[2].folder == back.partFolders[0].id);
+ CHECK(back.activePart == 2 && !back.dirty());
+
+ std::vector<ZipEntry> entries;
+ CHECK(readStoredZip(path, entries, err));
+ Json manifest;
+ CHECK(!entries.empty() && Json::parse(std::string(entries[0].data.begin(), entries[0].data.end()), manifest, err));
+ CHECK(manifest["version"].asNumber() == kProjectBaseWriteVersion); // what a scene without folders writes
+ CHECK(manifest["part_folders"].size() == 2 && manifest["parts"][1]["folder"].asNumber() == 0);
+ CHECK(!manifest["parts"][0].has("folder"));
+
+ // Saved again (by this version or one that kept the key but not the Parts' folder= index): nothing doubles,
+ // and a Part pointing at a folder that isn't there is outside any folder.
+ CHECK(saveProject(path, back, err));
+ CHECK(editManifest(path, [](Json& j) {
+ Json list = Json::array();
+ for (size_t i = 0; i < j["parts"].size(); ++i) {
+ Json st = j["parts"][i];
+ if (i == 1) st.set("folder", 7.0);
+ list.push(std::move(st));
+ }
+ j.set("parts", std::move(list));
+ }));
+ Document again;
+ CHECK(loadProject(path, again, err));
+ CHECK(again.partFolders.size() == 2 && again.parts[1].folder == 0 && again.parts[2].folder == again.partFolders[0].id);
+ CHECK(!again.projectSettings.has("part_folders"));
+
+ // A project without folders (every earlier version's) opens with none.
+ Document plain = makeScene();
+ CHECK(saveProject(path, plain, err));
+ CHECK(loadProject(path, again, err) && again.partFolders.empty());
+ for (const Part& s : again.parts) CHECK(s.folder == 0);
+ std::filesystem::remove(path);
+}
+
TEST(part_project_version1_still_loads) {
// Write a single-Part project, then turn its manifest into the version 1 layout.
Document doc = makeDoc(makeIcosphere(2));
diff --git a/tests/test_parts.cpp b/tests/test_parts.cpp
index 0044ecf3..ff183ec6 100644
--- a/tests/test_parts.cpp
+++ b/tests/test_parts.cpp
@@ -186,3 +186,60 @@ TEST(part_append_file) {
CHECK(!reg.execute(doc, "part_append", {{"type", std::string("teapot")}}).ok);
std::filesystem::remove(path);
}
+
+TEST(part_folders) {
+ // #96: folders group Parts in the list; hide, show and move them together.
+ Document doc;
+ CommandRegistry reg;
+ CHECK(reg.execute(doc, "new_sphere", {{"subdivisions", 2.0}}).ok);
+ CHECK(reg.execute(doc, "part_rename", {{"to", std::string("Head")}}).ok);
+ for (const char* name : {"Eye L", "Body", "Eye R"}) {
+ CHECK(reg.execute(doc, "part_append", {{"type", std::string("sphere")}}).ok);
+ CHECK(reg.execute(doc, "part_rename", {{"to", std::string(name)}}).ok);
+ }
+ doc.markClean();
+ // A new folder takes the active Part (Eye R); a Part joining it goes right below the folder's last Part.
+ CommandResult r = reg.execute(doc, "part_folder_new", {{"folder", std::string("Eyes")}});
+ CHECK(r.ok && doc.partFolders.size() == 1 && doc.partFolders[0].name == "Eyes");
+ CHECK(doc.activePartInfo().name == "Eye R" && doc.activePartInfo().folder == doc.partFolders[0].id);
+ CHECK(doc.dirty());
+ CHECK(reg.execute(doc, "part_set_folder", {{"name", std::string("Eye L")}, {"folder", std::string("Eyes")}}).ok);
+ CHECK(doc.parts[0].name == "Head" && doc.parts[1].name == "Body" && doc.parts[2].name == "Eye R" &&
+ doc.parts[3].name == "Eye L");
+ CHECK(doc.activePartInfo().name == "Eye R"); // the active Part follows the move
+ CHECK(!reg.execute(doc, "part_set_folder", {{"index", 0.0}, {"folder", std::string("Nope")}}).ok);
+ // Names stay unique.
+ CHECK(reg.execute(doc, "part_folder_new", {{"folder", std::string("Eyes")}, {"empty", true}}).ok);
+ CHECK(doc.partFolders.size() == 2 && doc.partFolders[1].name == "Eyes 2");
+ CHECK(reg.execute(doc, "part_folder_rename", {{"folder", std::string("Eyes 2")}, {"to", std::string("Props")}}).ok);
+ CHECK(doc.partFolders[1].name == "Props");
+ CHECK(reg.execute(doc, "part_list").message.find("Eye L (") != std::string::npos);
+ CHECK(reg.execute(doc, "part_list").message.find("in Eyes") != std::string::npos);
+ CHECK(reg.execute(doc, "part_list").message.find("Folder Eyes (2 Parts)") != std::string::npos);
+
+ // Hide and show the whole folder.
+ CHECK(reg.execute(doc, "part_folder_visibility", {{"folder", std::string("Eyes")}}).ok);
+ CHECK(!doc.parts[2].visible && !doc.parts[3].visible && doc.parts[0].visible && doc.parts[1].visible);
+ CHECK(reg.execute(doc, "part_folder_visibility", {{"folder", std::string("Eyes")}}).ok);
+ CHECK(doc.parts[2].visible && doc.parts[3].visible);
+ CHECK(!reg.execute(doc, "part_folder_visibility", {{"folder", std::string("Props")}}).ok); // empty
+ CHECK(reg.execute(doc, "part_folder_collapse", {{"folder", std::string("Eyes")}}).ok && doc.partFolders[0].collapsed);
+
+ // transform folder=true moves the folder's visible Parts, nothing else.
+ const glm::vec3 head = doc.partMesh(0).bounds().center(), eyeL = doc.partMesh(3).bounds().center();
+ const glm::vec3 eyeR = doc.mesh.bounds().center();
+ r = reg.execute(doc, "transform", {{"translate", std::string("0,1,0")}, {"folder", true}});
+ CHECK(r.ok && r.message.find("in 2 Parts") != std::string::npos);
+ CHECK(std::abs(doc.mesh.bounds().center().y - eyeR.y - 1.0f) < 1e-4f);
+ CHECK(std::abs(doc.partMesh(3).bounds().center().y - eyeL.y - 1.0f) < 1e-4f);
+ CHECK(glm::length(doc.partMesh(0).bounds().center() - head) < 1e-6f);
+
+ // Duplicates and split pieces stay in the folder; out of it, and removing the folder keeps the Parts.
+ CHECK(reg.execute(doc, "part_duplicate").ok && doc.activePartInfo().folder == doc.partFolders[0].id);
+ CHECK(reg.execute(doc, "part_set_folder", {{"folder", std::string()}}).ok && doc.activePartInfo().folder == 0);
+ CHECK(reg.execute(doc, "part_folder_delete", {{"folder", std::string("Eyes")}}).ok);
+ CHECK(doc.partFolders.size() == 1 && doc.partCount() == 5);
+ for (const Part& s : doc.parts) CHECK(s.folder == 0);
+ // A new scene has no folders.
+ CHECK(reg.execute(doc, "new_sphere").ok && doc.partFolders.empty());
+}
diff --git a/tests/ui/hidpi/part_folders.sfui b/tests/ui/hidpi/part_folders.sfui
new file mode 100644
index 00000000..7d516643
--- /dev/null
+++ b/tests/ui/hidpi/part_folders.sfui
@@ -0,0 +1,24 @@
+# Part folders (#96) on a HiDPI screen (CMake: 3200x1800 at 200 %): the header, its menu, folded, the header's menu, a Part's Folder menu.
+ui_scale 200
+run new_sphere subdivisions=4 ; part_rename to=Head
+run part_append type=sphere ; part_rename to="Left eye" ; transform scale=0.25 pivot=origin translate=-0.65,0.3,0.85
+run part_append type=cube ; part_rename to=Body ; transform translate=0,-1.6,0
+run part_append type=sphere ; part_rename to="Right eye" ; transform scale=0.25 pivot=origin translate=-0.05,0.3,0.85
+run part_folder_new folder=Eyes ; part_set_folder name="Left eye" folder=Eyes
+key f
+expect "Parts/Eyes##folder"
+expect "Parts/Left eye"
+shot folders
+run part_folder_collapse folder=Eyes
+expect_not "Parts/Left eye"
+shot folded
+run part_folder_collapse folder=Eyes
+right_click "Parts/Eyes##folder"
+expect "Move with the gizmo"
+shot folder-menu
+key escape
+wait 0.5
+right_click "Parts/Body"
+click "Folder"
+expect "Eyes##to folder"
+shot part-folder-menu
diff --git a/tests/ui/part_folders.sfui b/tests/ui/part_folders.sfui
new file mode 100644
index 00000000..bfb64248
--- /dev/null
+++ b/tests/ui/part_folders.sfui
@@ -0,0 +1,77 @@
+# Part folders (#96): make one from the active Part, drag Parts in and out, fold and open it, hide and show it,
+# rename it, move the whole folder with the gizmo; projects keep the folders. Shots at 1x (HiDPI: part_folders_hidpi).
+run new_sphere subdivisions=4 ; part_rename to=Head
+run part_append type=sphere ; part_rename to="Left eye" ; transform scale=0.25 pivot=origin translate=-0.65,0.3,0.85
+run part_append type=cube ; part_rename to=Body ; transform translate=0,-1.6,0
+run part_append type=sphere ; part_rename to="Right eye" ; transform scale=0.25 pivot=origin translate=-0.05,0.3,0.85
+key f
+expect_value parts == 4
+expect_value active_part == 3
+
+# The folder button makes a folder holding the active Part, its name ready to type.
+click "Parts/###part_folder_new"
+expect_status Made folder Folder with Right eye
+type "Parts/##rename folder" Eyes
+key enter
+expect_status Folder renamed to Eyes
+expect "Parts/Eyes##folder"
+shot new-folder
+
+# Drag the left eye onto the folder's header: it joins and moves below the right eye.
+drag_item "Parts/Left eye" 0 70
+expect_status Left eye is in Eyes
+expect_value active_part == 2
+shot dragged-in
+
+# The folder's eye hides and shows both eyes; the Body stays.
+click "Parts/##eye folder Eyes"
+expect_status Eyes hidden
+expect_value visible_parts == 2
+shot folder-hidden
+click "Parts/##eye folder Eyes"
+expect_value visible_parts == 4
+
+# Click the header to fold it (the accent bar says the active Part is inside), again to open it.
+click "Parts/Eyes##folder"
+expect_status Eyes folded
+expect_not "Parts/Left eye"
+shot folded
+wait 0.5
+click "Parts/Eyes##folder"
+expect_status Eyes opened
+expect "Parts/Left eye"
+wait 0.5
+
+# Move with the gizmo: both eyes move, nothing else.
+click "Parts/Left eye"
+remember center_y left0
+click "Parts/Body"
+remember center_y body0
+right_click "Parts/Eyes##folder"
+click "Move with the gizmo"
+expect_value gizmo_mode == 1
+expect_status Move Eyes
+gizmo_drag move_y 0 -40
+shot gizmo-moved
+key w
+click "Parts/Left eye"
+expect_value center_y > $left0
+click "Parts/Body"
+expect_value center_y == $body0
+
+# Right-click a Part > Folder > Out of the folder.
+wait 0.5
+right_click "Parts/Right eye"
+click "Folder"
+click "Out of the folder"
+expect_status Right eye is out of its folder
+shot out-of-folder
+
+# Saved and opened again: the folder and its Part come back.
+run save_project path=sf_ui_part_folders.sfproj
+run new_sphere
+expect_not "Parts/Eyes##folder"
+run open_project path=sf_ui_part_folders.sfproj
+expect "Parts/Eyes##folder"
+expect "Parts/Left eye"
+