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.

Forge Spheres: a new sphere near the centre line snaps onto it as one sphere with symmetry

islandmed1730aa948a34
diff --git a/changes/fix-forgesphere-midline.md b/changes/fix-forgesphere-midline.md
new file mode 100644
index 00000000..bf25749b
--- /dev/null
+++ b/changes/fix-forgesphere-midline.md
@@ -0,0 +1,8 @@
+---
+fixed: Forge Spheres with Symmetry on: a new sphere placed near the centre line (closer than its own radius) now
+ snaps onto it as one sphere instead of two overlapping twins that skinned as separate branches. Spheres growing
+ from a mirrored arm or leg still get their twin (thanks dm4nd on Discord).
+testers:
+ - Forge Spheres, Symmetry X on: Draw a sphere just off the centre line of the root: one sphere, on the line.
+ Draw one well off the line: a mirrored pair as before.
+---
diff --git a/docs/guide/forge-spheres.md b/docs/guide/forge-spheres.md
index 1ec1d3f5..a5c90faf 100644
--- a/docs/guide/forge-spheres.md
+++ b/docs/guide/forge-spheres.md
@@ -27,7 +27,8 @@ In every mode, <kbd>Alt</kbd>+click a sphere to delete it together with everythi
sphere (orange) always stays.
**Symmetry** (<kbd>X</kbd>) mirrors every edit: grow an arm on the right and the left one grows with it, move a
-leg and its twin moves too. A sphere on the centre line stays on it.
+leg and its twin moves too. A sphere on the centre line stays on it, and a new sphere placed closer to the centre
+line than its own radius snaps onto it as one sphere instead of two overlapping twins.
Every drag is one step of the Part's undo history, so <kbd>Ctrl</kbd>+<kbd>Z</kbd> takes back the last sphere
you added, moved or scaled.
diff --git a/src/core/ForgeSpheres.cpp b/src/core/ForgeSpheres.cpp
index 4d289369..dc150fab 100644
--- a/src/core/ForgeSpheres.cpp
+++ b/src/core/ForgeSpheres.cpp
@@ -257,8 +257,18 @@ int forgesphereMirror(const std::vector<ForgeSphere>& s, int i, const vec3& m) {
return best;
}
-bool forgesphereAdd(std::vector<ForgeSphere>& s, int parent, const vec3& center, float radius, Symmetry sym, int* added) {
- if (!validIndex(s, parent) || !(radius > 0.0f) || !std::isfinite(center.x + center.y + center.z)) return false;
+bool forgesphereAdd(std::vector<ForgeSphere>& s, int parent, const vec3& at, float radius, Symmetry sym, int* added) {
+ if (!validIndex(s, parent) || !(radius > 0.0f) || !std::isfinite(at.x + at.y + at.z)) return false;
+ // Near a mirror plane the copy would overlap the sphere: snap onto the plane as one sphere instead, when the
+ // parent has no separate twin across it (a sphere off the plane keeps its own mirrored child).
+ vec3 center = at;
+ const bool axes[3] = {sym.x, sym.y, sym.z};
+ for (int a = 0; a < 3; ++a) {
+ vec3 m(1.0f);
+ m[a] = -1.0f;
+ const int p = forgesphereMirror(s, parent, m);
+ if (axes[a] && std::abs(center[a]) < radius && (p < 0 || p == parent)) center[a] = 0.0f;
+ }
// Mirror parents come from the armature as it was, before the new spheres join it.
std::vector<std::pair<int, vec3>> copies;
for (const vec3& m : otherMirrors(sym)) {
diff --git a/src/core/ForgeSpheres.h b/src/core/ForgeSpheres.h
index 7794c554..349baa94 100644
--- a/src/core/ForgeSpheres.h
+++ b/src/core/ForgeSpheres.h
@@ -46,7 +46,8 @@ int forgesphereMirror(const std::vector<ForgeSphere>& spheres, int i, const glm:
// Symmetric edits (`sym`: the planes to mirror across, as the sculpt symmetry). Each returns false and leaves
// `spheres` alone when the arguments are out of range.
-// Adds a sphere growing from `parent`; `added` gets the new sphere's index (its mirror copies follow it).
+// Adds a sphere growing from `parent`; `added` gets the new sphere's index (its mirror copies follow it). With
+// symmetry, a sphere within its radius of a mirror plane snaps onto it as one sphere (unless the parent has a twin).
bool forgesphereAdd(std::vector<ForgeSphere>& spheres, int parent, const glm::vec3& center, float radius, Symmetry sym,
int* added = nullptr);
// Moves and resizes sphere `i`; a sphere on a mirror plane stays on it.
diff --git a/tests/test_forgespheres.cpp b/tests/test_forgespheres.cpp
index e09770e2..d016dae6 100644
--- a/tests/test_forgespheres.cpp
+++ b/tests/test_forgespheres.cpp
@@ -80,6 +80,20 @@ TEST(forgespheres_symmetric_edits) {
CHECK(joint == 4 && in.size() == 6 && in[2].parent == 4 && in[4].parent == 0 && in[3].parent == 5);
CHECK(glm::length(in[4].center - vec3(0.45f, 0.05f, 0)) < 1e-6f);
CHECK(forgespheresValidate(in).empty());
+
+ // Near the centre line (closer than its radius) a new sphere snaps onto it as one sphere, not two that
+ // overlap; a sphere growing from the arm stays mirrored even when it reaches the centre.
+ auto mid = s;
+ int one = -1;
+ CHECK(forgesphereAdd(mid, 0, vec3(0.08f, -0.6f, 0.1f), 0.2f, {true, false, false}, &one));
+ CHECK(one == 4 && mid.size() == 5 && mid[4].center == vec3(0.0f, -0.6f, 0.1f) && mid[4].parent == 0);
+ CHECK(forgesphereAdd(mid, 0, vec3(0.25f, -0.6f, 0.1f), 0.2f, {true, false, false}));
+ CHECK(mid.size() == 7 && std::abs(mid[6].center.x + 0.25f) < 1e-6f); // a radius off: a mirrored pair
+ CHECK(forgesphereAdd(mid, 0, vec3(0.08f, -0.6f, 0.1f), 0.2f, {false, false, false}));
+ CHECK(mid.size() == 8 && mid[7].center.x == 0.08f); // no symmetry: where it was put
+ CHECK(forgesphereAdd(mid, 2, vec3(0.1f, 0.1f, 0), 0.15f, {true, false, false}));
+ CHECK(mid.size() == 10 && mid[9].parent == 3 && std::abs(mid[9].center.x + 0.1f) < 1e-6f);
+ CHECK(forgespheresValidate(mid).empty());
}
TEST(forgespheres_validate_and_json) {