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.

Parts: Keep original for Split Hidden / Masked / Unmasked

islandmed967fd589b7b8
diff --git a/changes/feat-split-keep-original.md b/changes/feat-split-keep-original.md
new file mode 100644
index 00000000..e1ab2b90
--- /dev/null
+++ b/changes/feat-split-keep-original.md
@@ -0,0 +1,11 @@
+---
+whats_new: **Keep original** for **Tool > Parts > Split**: tick it and Hidden, Masked or Unmasked copy those triangles into a new Part, leaving the source Part as it is.
+added: **Keep original** checkbox under **Tool > Parts > Split** (Hidden / Masked / Unmasked; `keep=true` on
+ `part_split_hidden`, `part_split_masked`, `part_split_unmasked`): the triangles are copied into the new Part (UVs,
+ face groups, vertex paint, sculpt layers; the copy is cut at the current subdivision level) and the source Part
+ stays untouched, levels and mask included. One undo step removes the copy. Requested by _tfx on Discord.
+testers:
+ - Any OS: mask half a sphere, tick Tool > Parts > Keep original, press Split > Masked: a new "<Part> masked" Part
+ appears below with the masked half, the sphere is still whole and still masked; Ctrl+Z removes only the new Part.
+ - With Keep original off, Split > Masked still moves the triangles as before.
+---
diff --git a/docs/guide/parts.md b/docs/guide/parts.md
index dc9ae014..08e4a2cc 100644
--- a/docs/guide/parts.md
+++ b/docs/guide/parts.md
@@ -182,6 +182,7 @@ triangles back and removes the new Part.
| **Split > Hidden** | the hidden triangles; they are shown in the new Part | `part_split_hidden` |
| **Split > Masked** | the masked triangles; the new Part starts unmasked | `part_split_masked` |
| **Split > Unmasked** | the triangles that are not masked; the masked ones stay | `part_split_unmasked` |
+| **Keep original** (checkbox below) | a **copy** of those triangles; the source Part stays as it is, levels and all, and undo just removes the copy | `keep=true` on any of the three |
A triangle counts as **masked when the average mask of its three corners is above 50%**, so a soft mask edge
splits along its middle and a single masked corner doesn't take its neighbours. UVs, face groups, vertex paint and
@@ -259,7 +260,7 @@ used.
| `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 |
-| `part_split_hidden` / `part_split_masked` / `part_split_unmasked` | Split off into a new Part (undoable) |
+| `part_split_hidden` / `part_split_masked` / `part_split_unmasked` | Split off into a new Part (undoable; `keep=true` copies and leaves the source as it is) |
| `part_shading mode=flat` | Shade a Part `default` (as the scene), `smooth` or `flat` |
| `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 |
| `extract_accept` / `extract_cancel` | Keep or remove the Extract preview |
diff --git a/src/app/App.h b/src/app/App.h
index 0c088676..bb51ce68 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -1729,6 +1729,7 @@ private:
// Split by face groups needs more than one group; counted only when the active mesh changes.
uint64_t splitGroupsKey_ = ~uint64_t(0);
bool splitGroupsPossible_ = false;
+ bool splitKeepOriginal_ = false; // Split Hidden / Masked / Unmasked copy instead of move (keep=true)
// Community brushes window (PanelBrushGallery.cpp): browse, search and install shared brushes.
void drawBrushGallery(); // also finishes background downloads while the window is closed
void refreshBrushGallery();
diff --git a/src/app/I18nSimplifiedChinese.cpp b/src/app/I18nSimplifiedChinese.cpp
index 322d81e8..51da78d6 100644
--- a/src/app/I18nSimplifiedChinese.cpp
+++ b/src/app/I18nSimplifiedChinese.cpp
@@ -4445,6 +4445,8 @@ constexpr Entry kSimplifiedChinese[] = {
{"Split hidden: the hidden triangles become a new Part", "分离隐藏:隐藏的三角形成为新部件"},
{"Split masked: the masked triangles (average mask above 50%) become a new Part", "分离遮罩:遮罩的三角形(平均遮罩高于 50%)成为新部件"},
{"Split unmasked: the unmasked triangles become a new Part; the masked ones stay", "分离未遮罩:未遮罩的三角形成为新部件;遮罩的留下"},
+ {"Keep original", "保留原件"},
+ {"Split copies the triangles into the new Part and leaves this Part as it is", "分离会把三角形复制到新部件,此部件保持不变"},
{"%zu point will merge", "%zu 个点将合并"},
{"%zu points will merge", "%zu 个点将合并"},
{"Check", "检查"},
diff --git a/src/app/I18nSpanish.cpp b/src/app/I18nSpanish.cpp
index 95c0ceec..28f28144 100644
--- a/src/app/I18nSpanish.cpp
+++ b/src/app/I18nSpanish.cpp
@@ -4925,6 +4925,8 @@ constexpr Entry kSpanish[] = {
{"Split hidden: the hidden triangles become a new Part", "Separar ocultos: los triángulos ocultos pasan a una pieza nueva"},
{"Split masked: the masked triangles (average mask above 50%) become a new Part", "Separar enmascarados: los triángulos enmascarados (máscara media por encima del 50%) pasan a una pieza nueva"},
{"Split unmasked: the unmasked triangles become a new Part; the masked ones stay", "Separar sin máscara: los triángulos sin máscara pasan a una pieza nueva; los enmascarados se quedan"},
+ {"Keep original", "Conservar original"},
+ {"Split copies the triangles into the new Part and leaves this Part as it is", "Separar copia los triángulos a la pieza nueva y deja esta pieza como está"},
{"%zu point will merge", "%zu punto se fusionará"},
{"%zu points will merge", "%zu puntos se fusionarán"},
{"Check", "Comprobar"},
diff --git a/src/app/I18nTraditionalChinese.cpp b/src/app/I18nTraditionalChinese.cpp
index 76d5a4e1..aa8cff70 100644
--- a/src/app/I18nTraditionalChinese.cpp
+++ b/src/app/I18nTraditionalChinese.cpp
@@ -4443,6 +4443,8 @@ constexpr Entry kTraditionalChinese[] = {
{"Split hidden: the hidden triangles become a new Part", "分離隱藏:隱藏的三角形成為新部件"},
{"Split masked: the masked triangles (average mask above 50%) become a new Part", "分離遮罩:遮罩的三角形(平均遮罩高於 50%)成為新部件"},
{"Split unmasked: the unmasked triangles become a new Part; the masked ones stay", "分離未遮罩:未遮罩的三角形成為新部件;遮罩的留下"},
+ {"Keep original", "保留原件"},
+ {"Split copies the triangles into the new Part and leaves this Part as it is", "分離會把三角形複製到新部件,此部件保持不變"},
{"%zu point will merge", "%zu 個點將合併"},
{"%zu points will merge", "%zu 個點將合併"},
{"Check", "檢查"},
diff --git a/src/app/PanelParts.cpp b/src/app/PanelParts.cpp
index cdf68ede..697ef11c 100644
--- a/src/app/PanelParts.cpp
+++ b/src/app/PanelParts.cpp
@@ -744,7 +744,7 @@ void App::drawPartsContents() {
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))
ImGui::SetTooltip("%s", tr("One Part per disconnected piece"));
// Split off what is hidden, masked or not masked into a new Part below (one undo step each): "Split" and three
- // short buttons, so the row fits the narrowest tray.
+ // short buttons, so the row fits the narrowest tray; Keep original below them copies instead.
{
ImGui::AlignTextToFramePadding();
ImGui::TextDisabled("%s", tr("Split"));
@@ -753,7 +753,8 @@ void App::drawPartsContents() {
const bool masked = doc_.mesh.hasMask();
auto splitButton = [&](const char* label, const char* command, bool enabled, const char* tip) {
ImGui::BeginDisabled(!enabled);
- if (ImGui::Button(tr(label), ImVec2(third, 0))) runCommand(command);
+ if (ImGui::Button(tr(label), ImVec2(third, 0)))
+ runCommand(command, splitKeepOriginal_ ? Args{{"keep", true}} : Args{});
ImGui::EndDisabled();
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))
ImGui::SetTooltip("%s", tr(tip));
@@ -766,6 +767,9 @@ void App::drawPartsContents() {
ImGui::SameLine();
splitButton("Unmasked##part_split", "part_split_unmasked", masked,
"Split unmasked: the unmasked triangles become a new Part; the masked ones stay");
+ ImGui::Checkbox(tr("Keep original##part_split"), &splitKeepOriginal_);
+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal))
+ ImGui::SetTooltip("%s", tr("Split copies the triangles into the new Part and leaves this Part as it is"));
}
if (fontSmall_) ImGui::PushFont(fontSmall_);
ImGui::TextDisabled("%s", tr("Alt+click a Part to select it"));
diff --git a/src/core/Parts.cpp b/src/core/Parts.cpp
index 8cfb5b63..6aa066f6 100644
--- a/src/core/Parts.cpp
+++ b/src/core/Parts.cpp
@@ -267,15 +267,22 @@ void replaceWithPieces(Document& doc, int index, std::vector<Mesh> pieces) {
// source's old mesh and the new Part go back together. Every attribute extractTriangles keeps carries over (UVs,
// face groups, vertex paint, sculpt layers); subdivision levels can't be cut, so the source's are noted dropped
// and undo restores them. The new Part shows everything (Split Hidden) and starts unmasked (Split Masked).
-CommandResult splitOffPart(Document& doc, TriangleSet set, const char* label, const char* suffix, const char* what) {
+// With `keep` (Keep original, _tfx on Discord) the triangles are copied instead: the source stays untouched,
+// levels and all, and undo just takes the new Part away.
+CommandResult splitOffPart(Document& doc, TriangleSet set, const char* label, const char* suffix, const char* what,
+ bool keep) {
size_t n = 0;
std::vector<uint8_t> in = trianglesIn(doc.mesh, set, &n);
const std::string source = doc.activePartInfo().name;
if (n == 0) return {false, "Nothing in " + source + " is " + what};
- if (n == doc.mesh.triangleCount()) return {false, "Everything in " + source + " is " + what + ": nothing would stay"};
+ if (!keep && n == doc.mesh.triangleCount())
+ return {false, "Everything in " + source + " is " + what + ": nothing would stay"};
Mesh piece = extractTriangles(doc.mesh, in);
- for (uint8_t& k : in) k = !k;
- Mesh rest = extractTriangles(doc.mesh, in);
+ Mesh rest;
+ if (!keep) {
+ for (uint8_t& k : in) k = !k;
+ rest = extractTriangles(doc.mesh, in);
+ }
in = {};
if (set == TriangleSet::Hidden) piece.hidden.clear();
if (set == TriangleSet::Masked) piece.mask.clear();
@@ -292,12 +299,19 @@ CommandResult splitOffPart(Document& doc, TriangleSet set, const char* label, co
added.transform = place;
const uint32_t id = added.id;
const std::string name = added.name;
- doc.replaceMeshUndoable(std::move(rest), label);
- if (UndoRecord* r = doc.undo.lastUndo()) {
- r->part = std::make_shared<PartStep>();
- r->part->id = id;
- r->part->at = at;
+ auto step = std::make_shared<PartStep>();
+ step->id = id;
+ step->at = at;
+ if (keep) {
+ UndoRecord r; // undo just takes the copy away again
+ r.label = std::string(label) + " (keep original)";
+ r.part = std::move(step);
+ doc.undo.push(std::move(r));
+ doc.modified = true;
+ return {true, "Copied " + countText(n) + " into " + name + "; " + source + " is unchanged"};
}
+ doc.replaceMeshUndoable(std::move(rest), label);
+ if (UndoRecord* r = doc.undo.lastUndo()) r->part = std::move(step);
return {true, "Split " + countText(n) + " into " + name + ", " + countText(doc.mesh.triangleCount()) + " stay in " + source};
}
@@ -1026,25 +1040,33 @@ void registerPartCommands(CommandRegistry& reg) {
return {true, "Split into " + std::to_string(n) + " Parts"};
}});
- reg.add({"part_split_hidden", "Move the hidden triangles of the active Part into a new Part below it (one undo step).", {},
- [](Document& doc, const Args&) -> CommandResult {
- return splitOffPart(doc, TriangleSet::Hidden, "Split Hidden", "hidden", "hidden");
+ const ParamSpec keepParam{"keep", T::Bool,
+ "Keep original: copy the triangles into the new Part and leave the source untouched "
+ "(undo takes the copy away). Default false.",
+ false};
+ reg.add({"part_split_hidden", "Move the hidden triangles of the active Part into a new Part below it (one undo step).",
+ {keepParam},
+ [](Document& doc, const Args& a) -> CommandResult {
+ return splitOffPart(doc, TriangleSet::Hidden, "Split Hidden", "hidden", "hidden",
+ argBool(a, "keep", false));
}});
reg.add({"part_split_masked",
"Move the masked triangles of the active Part (corners' average mask above 0.5) into a new, unmasked "
"Part below it (one undo step).",
- {},
- [](Document& doc, const Args&) -> CommandResult {
- return splitOffPart(doc, TriangleSet::Masked, "Split Masked", "masked", "masked");
+ {keepParam},
+ [](Document& doc, const Args& a) -> CommandResult {
+ return splitOffPart(doc, TriangleSet::Masked, "Split Masked", "masked", "masked",
+ argBool(a, "keep", false));
}});
reg.add({"part_split_unmasked",
"Move the unmasked triangles of the active Part (corners' average mask 0.5 or less) into a new Part "
"below it; the masked ones stay (one undo step).",
- {},
- [](Document& doc, const Args&) -> CommandResult {
- return splitOffPart(doc, TriangleSet::Unmasked, "Split Unmasked", "unmasked", "unmasked");
+ {keepParam},
+ [](Document& doc, const Args& a) -> CommandResult {
+ return splitOffPart(doc, TriangleSet::Unmasked, "Split Unmasked", "unmasked", "unmasked",
+ argBool(a, "keep", false));
}});
}
diff --git a/tests/test_parts.cpp b/tests/test_parts.cpp
index b9bdf7c1..a16d1100 100644
--- a/tests/test_parts.cpp
+++ b/tests/test_parts.cpp
@@ -8,6 +8,7 @@
#include "core/Commands.h"
#include "core/FaceGroups.h"
+#include "core/Multires.h"
#include "core/Primitives.h"
#include "core/Parts.h"
#include "io/ObjIO.h"
@@ -296,6 +297,43 @@ TEST(part_split_by_selection) {
CHECK(!reg.execute(doc, "part_split_masked").ok);
}
+TEST(part_split_keep_original) {
+ // Keep original (_tfx on Discord): keep=true copies the triangles into the new Part; the source stays untouched,
+ // mask, levels and all; one undo takes the copy away.
+ Document doc;
+ CommandRegistry reg;
+ CHECK(reg.execute(doc, "new_sphere", {{"subdivisions", 2.0}}).ok);
+ CHECK(reg.execute(doc, "subdiv_divide").ok);
+ const int levels = subdivLevelCount(doc.mesh);
+ CHECK(levels == 2);
+ const size_t total = doc.mesh.triangleCount();
+ doc.mesh.mask.assign(doc.mesh.vertexCount(), 0.0f);
+ for (size_t v = 0; v < doc.mesh.vertexCount(); ++v) doc.mesh.mask[v] = doc.mesh.positions[v].x > 0.0f ? 1.0f : 0.0f;
+ doc.mesh.colors.assign(doc.mesh.vertexCount(), glm::vec3(0.7f, 0.1f, 0.3f));
+ size_t masked = 0;
+ trianglesIn(doc.mesh, TriangleSet::Masked, &masked);
+ CHECK(reg.execute(doc, "part_split_masked", {{"keep", true}}).ok);
+ CHECK(doc.partCount() == 2 && doc.activePart == 0);
+ CHECK(doc.mesh.triangleCount() == total && doc.mesh.hasMask() && subdivLevelCount(doc.mesh) == levels);
+ CHECK(doc.partMesh(1).triangleCount() == masked && !doc.partMesh(1).hasMask());
+ CHECK(doc.partMesh(1).hasColors() && doc.partMesh(1).colors[0] == glm::vec3(0.7f, 0.1f, 0.3f));
+ CHECK(doc.parts[1].name == doc.parts[0].name + " masked");
+ CHECK(reg.execute(doc, "undo").ok);
+ CHECK(doc.partCount() == 1 && doc.mesh.triangleCount() == total && doc.mesh.hasMask());
+ CHECK(reg.execute(doc, "redo").ok);
+ CHECK(doc.partCount() == 2 && doc.partMesh(1).triangleCount() == masked && doc.mesh.triangleCount() == total);
+ CHECK(reg.execute(doc, "undo").ok);
+ CHECK(reg.execute(doc, "part_split_unmasked", {{"keep", true}}).ok);
+ CHECK(doc.partMesh(1).triangleCount() == total - masked && doc.mesh.triangleCount() == total);
+ CHECK(reg.execute(doc, "undo").ok);
+ // Everything masked: a plain split refuses (nothing would stay); keep copies it all.
+ doc.mesh.mask.assign(doc.mesh.vertexCount(), 1.0f);
+ CHECK(!reg.execute(doc, "part_split_masked").ok);
+ CHECK(reg.execute(doc, "part_split_masked", {{"keep", true}}).ok);
+ CHECK(subdivLevelCount(doc.partMesh(1)) == 0 && subdivLevelCount(doc.mesh) == levels); // cut on the copy only
+ CHECK(doc.partMesh(1).triangleCount() == total && doc.mesh.triangleCount() == total);
+}
+
TEST(part_split_linked_copy) {
// Splitting a moved linked copy (#94): the new Part stays where the copy is, not at the shared mesh's place.
Document doc;
diff --git a/tests/ui/parts_split_selection.sfui b/tests/ui/parts_split_selection.sfui
index 22ad1168..08db70f8 100644
--- a/tests/ui/parts_split_selection.sfui
+++ b/tests/ui/parts_split_selection.sfui
@@ -26,6 +26,20 @@ expect "Parts/Body unmasked"
key ctrl+z
expect_value parts == 1
+# Keep original (_tfx on Discord): Split copies, Body keeps every triangle; one Ctrl+Z takes the copy away.
+click "Parts/Keep original##part_split"
+click "Parts/Masked##part_split"
+expect_value parts == 2
+expect_value active_part == 0
+expect_status Body is unchanged
+expect "Parts/Body masked"
+expect_value triangles == $all
+shot split-keep-original
+key ctrl+z
+expect_value parts == 1
+expect_value triangles == $all
+click "Parts/Keep original##part_split"
+
# Hidden: hide the left half, split it off.
run mask_clear ; hide_rect x0=0 y0=-1 x1=1 y1=1
expect_value hidden > 0