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
Dynamic topology with symmetry remeshes the mirrored side of an asymmetric mesh (#23)
islandmedd2cb8e34a302
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 754ed25e..0b1108b1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -27,6 +27,16 @@ All notable changes to SculptForge are listed here. The format followsmesh above a quarter: 78 ms a frame against 14-30), and finds them in parallel (3.7 -> 0.4 ms).- Starting a stroke no longer re-uploads the whole mesh when there are no LODs.+### Fixed+- Dynamic topology with symmetry remeshes the mirrored side of a model whose sides aren't mirrored polygon for+ polygon (#23; a QRemeshed head in the report). Splits, collapses and flips are found under the brush and done+ on the mirror images of the same edges; without images (nothing to pair the vertices with) the other side only+ moved and kept its coarse triangles: a stroke left 2,199 triangles along its path and 33 along its mirror image.+ An edge under a mirror image of the brush whose image on the brush's side is missing is now remeshed where it+ is (2,260 there). Symmetric meshes still get exactly mirrored topology (the 1M dynamic topology benchmark's times+ are unchanged). Test `dyntopo_symmetry_remeshes_both_sides_of_an_asymmetric_mesh` (a turned sphere, then+ random strokes with X and Z symmetry, valid after every dab, undone exactly).+## [0.9.6] - 2026-10-31The same evening as 0.9.5, the next batch from your reports and from askNK's review: Extract and Mirror And Weld,diff --git a/docs/guide/dynamic-topology.md b/docs/guide/dynamic-topology.mdindex 6d12cb63..c2a2c669 100644--- a/docs/guide/dynamic-topology.md+++ b/docs/guide/dynamic-topology.md@@ -39,7 +39,9 @@ and fine ones around the eyes.## What it keeps and what it doesn't- **Symmetry.** With X (or Y, Z) symmetry on, both sides are remeshed together and get mirrored triangles, not- just mirrored shapes.+ just mirrored shapes. A model whose sides aren't made of mirrored polygons (after QRemesh, or sculpted+ without symmetry) has no mirrored triangles to keep: each side then gets its own new triangles, as fine as+ the brush's side.- **Mask and visibility.** Fully masked and hidden parts are left alone. Partly masked areas are remeshed butmove less, as usual.- **Borders.** Open edges and the borders between polygroups stay where they are; their vertices only slidediff --git a/docs/guide/whats-new.md b/docs/guide/whats-new.mdindex 419858df..0e1c3fd8 100644--- a/docs/guide/whats-new.md+++ b/docs/guide/whats-new.md@@ -14,6 +14,12 @@ with a 200-pixel brush, the brush now trails the pointer by half as far, a framefirst dab appears in half the time, and lifting the pen no longer pauses for up to a second while waiting dabsare placed. See [Performance](performance.md).+### Fixes++- Dynamic topology with symmetry now adds detail on the mirrored side too when the model's two sides aren't+ built from mirrored polygons (a QRemeshed head, say): before, only the side under the brush got the new+ triangles. See [Dynamic topology](dynamic-topology.md).+## Version 0.9.6### Extractdiff --git a/src/core/Dyntopo.cpp b/src/core/Dyntopo.cppindex 3301f0b9..fccd8030 100644--- a/src/core/Dyntopo.cpp+++ b/src/core/Dyntopo.cpp@@ -451,11 +451,23 @@ bool DynamicTopology::inside(uint32_t a, uint32_t b, bool mirrored) const {return false;}-// The triangles under the brush, and the slivers under its mirror images. Operations are found on the brush's-// side and done on every side at once (orbit); the slivers are the exception, since a brush can squash a-// triangle on one side only (overlapping mirrored dabs), and they must be repaired where they are.+// Operations are found on the brush's side and done on every side at once (orbit), which needs each edge's+// mirror images. A mesh whose sides aren't mirrored (QRemesh's quads, a model edited without symmetry) has none+// to find, and its other sides were left coarse while the brush moved them too (#23): an edge under a mirror+// image of the brush whose own images are missing is remeshed where it is, as the brush's side is.+bool DynamicTopology::candidate(uint32_t a, uint32_t b) const {+ if (inside(a, b)) return true;+ if (mirrorSigns_.empty() || !inside(a, b, true)) return false;+ orbit(a, b, orbitScratch_);+ return orbitIncomplete_;+}++// The triangles under the brush and under its mirror images (for the edges candidate() takes there), and the+// slivers under all of them: a brush can squash a triangle on one side only (overlapping mirrored dabs), and+// they must be repaired where they are.void DynamicTopology::queryRegion() {bvh_->queryTriangles(*mesh_, center_, radius_, regionTris_);+ mirrorTris_.clear();slivers_.clear();const auto& p = mesh_->positions;auto addSlivers = [&](const std::vector<uint32_t>& tris) {@@ -469,7 +481,10 @@ void DynamicTopology::queryRegion() {for (const glm::vec3& s : mirrorSigns_) {bvh_->queryTriangles(*mesh_, center_ * s, radius_, more);addSlivers(more);+ mirrorTris_.insert(mirrorTris_.end(), more.begin(), more.end());}+ std::sort(mirrorTris_.begin(), mirrorTris_.end());+ mirrorTris_.erase(std::unique(mirrorTris_.begin(), mirrorTris_.end()), mirrorTris_.end());std::sort(slivers_.begin(), slivers_.end());slivers_.erase(std::unique(slivers_.begin(), slivers_.end()), slivers_.end());}@@ -746,7 +761,7 @@ uint32_t DynamicTopology::split(uint32_t a, uint32_t b) {void DynamicTopology::pushEdgesAround(uint32_t v, bool longer) {ring(v, scratch2_);for (uint32_t u : scratch2_) {- if (deadV_[u] || !inside(v, u)) continue;+ if (deadV_[u] || !candidate(v, u)) continue;const float l = len2(v, u);if (longer ? l > splitLen2_ : l < collapseLen2_) {heap_.push_back({longer ? l : -l, std::min(u, v), std::max(u, v)});@@ -826,6 +841,17 @@ void DynamicTopology::splitPass() {if (l > splitLen2_ && inside(a, b)) heap_.push_back({l, std::min(a, b), std::max(a, b)});}}+ // Under the mirror images: only edges whose image on the brush's side is missing (the others are split+ // with it, by splitOrbit).+ for (uint32_t t : mirrorTris_) {+ const glm::uvec3 tri = mesh_->triangles[t];+ for (int c = 0; c < 3; ++c) {+ const uint32_t a = tri[c], b = tri[(c + 1) % 3];+ if (a > b && edgeTriangles(a, b, tris) != 1) continue;+ const float l = len2(a, b);+ if (l > splitLen2_ && !inside(a, b) && candidate(a, b)) heap_.push_back({l, std::min(a, b), std::max(a, b)});+ }+ }auto less = [](const Edge& x, const Edge& y) {return x.len2 != y.len2 ? x.len2 < y.len2 : x.a != y.a ? x.a > y.a : x.b > y.b;};@@ -976,6 +1002,16 @@ void DynamicTopology::collapsePass() {if (l < collapseLen2_ && inside(a, b)) heap_.push_back({-l, std::min(a, b), std::max(a, b)});}}+ for (uint32_t t : mirrorTris_) { // (as in splitPass)+ if (t >= mesh_->triangleCount() || deadT_[t]) continue;+ const glm::uvec3 tri = mesh_->triangles[t];+ for (int c = 0; c < 3; ++c) {+ const uint32_t a = tri[c], b = tri[(c + 1) % 3];+ if (a > b && edgeTriangles(a, b, tris) != 1) continue;+ const float l = len2(a, b);+ if (l < collapseLen2_ && !inside(a, b) && candidate(a, b)) heap_.push_back({-l, std::min(a, b), std::max(a, b)});+ }+ }for (uint32_t t : slivers_) {if (t >= mesh_->triangleCount() || deadT_[t]) continue;const glm::uvec3 tri = mesh_->triangles[t];@@ -1111,7 +1147,7 @@ void DynamicTopology::flipPass() {const glm::uvec3& tri = mesh_->triangles[t];for (int c = 0; c < 3; ++c) {const uint32_t a = tri[c], b = tri[(c + 1) % 3];- if (a < b && inside(a, b)) candidates.emplace_back(a, b);+ if (a < b && candidate(a, b)) candidates.emplace_back(a, b);}}}diff --git a/src/core/Dyntopo.h b/src/core/Dyntopo.hindex f7e0153b..b58e2d98 100644--- a/src/core/Dyntopo.h+++ b/src/core/Dyntopo.h@@ -157,6 +157,9 @@ private:bool boundaryVertex(uint32_t v) const;float len2(uint32_t a, uint32_t b) const;bool inside(uint32_t a, uint32_t b, bool mirrored = false) const;+ // An edge to remesh: under the brush, or under a mirror image of it with no image on the brush's side (an+ // asymmetric mesh: that side is remeshed on its own).+ bool candidate(uint32_t a, uint32_t b) const;glm::vec3 faceNormalAt(uint32_t v) const;// Symmetry: the mirror images of vertex v (kNone where unknown).uint32_t mirrorOf(size_t mirror, uint32_t v) const;@@ -202,11 +205,13 @@ private:std::vector<uint8_t> deadV_, deadT_;std::vector<uint32_t> freeV_, freeT_;std::vector<uint32_t> changedV_, changedT_, regionTris_, slivers_;+ std::vector<uint32_t> mirrorTris_; // the triangles under the brush's mirror images (queryRegion)std::vector<uint8_t> changedVFlag_;std::vector<Edge> heap_;std::vector<std::pair<uint32_t, uint32_t>> moved_;std::vector<uint32_t> recordedNow_;mutable bool orbitIncomplete_ = false; // the last orbit() missed a mirror image+ mutable std::vector<std::pair<uint32_t, uint32_t>> orbitScratch_; // candidate()size_t ops_ = 0, maxOps_ = 0;mutable std::vector<uint32_t> scratch_, scratch2_, ringA_, ringB_, ringC_, lockScratch_;};diff --git a/tests/test_dyntopo.cpp b/tests/test_dyntopo.cppindex 021039e2..72f6f59c 100644--- a/tests/test_dyntopo.cpp+++ b/tests/test_dyntopo.cpp@@ -13,6 +13,8 @@#include "core/Primitives.h"#include "core/ThreadPool.h"+#include <glm/gtc/matrix_transform.hpp>+#include <algorithm>#include <cmath>#include <cstdlib>@@ -325,6 +327,92 @@ TEST(dyntopo_x_symmetry_makes_mirrored_topology) {if (map.size() == d.mesh.vertexCount()) CHECK(mirroredTopology(d.mesh, map));}+TEST(dyntopo_symmetry_remeshes_both_sides_of_an_asymmetric_mesh) {+ // #23: a symmetric shape whose triangles aren't mirrored (here a sphere turned a little; in the report a+ // QRemeshed head) found no mirror images for the remeshing, so with X symmetry the side under the brush got+ // fine triangles and the mirrored side, which the brush moves just the same, kept its coarse ones. Both+ // sides must get the detail (not the same triangles: there were none to mirror).+ Document d = sphereDoc(3);+ const glm::mat3 turn = glm::mat3(glm::rotate(glm::mat4(1.0f), 0.3f, glm::vec3(0.2f, 1.0f, 0.4f)));+ for (glm::vec3& p : d.mesh.positions) p = turn * p;+ d.mesh.recomputeAllNormals();+ d.mesh.rebuildTopology();+ d.bvh.build(d.mesh);+ d.sculptor.dyntopo.detail = 0.75f;+ const Symmetry sym{true, false, false};+ const float radius = 0.3f, target = dyntopoEdgeLength(d.sculptor.dyntopo, radius, 2.0f);+ std::vector<glm::vec3> path;+ CHECK(d.sculptor.beginStroke(d.mesh, "Standard"));+ for (int i = 0; i < 8; ++i) {+ const glm::vec3 from = glm::vec3(0.55f, 0.1f * float(i) - 0.35f, 0.9f) * 3.0f;+ RayHit hit;+ if (d.bvh.raycast(d.mesh, from, glm::normalize(-from), hit)) path.push_back(hit.position);+ CHECK(dabToward(d, from, radius, BrushType::Standard, sym));+ }+ d.undo.push(d.sculptor.endStroke());+ CHECK(invalid(d.mesh, true).empty());+ CHECK(bvhMatches(d.mesh, d.bvh));+ // Along the stroke and along its mirror image: how many triangles, and the longest edge.+ auto near = [&](float sign, size_t& count, float& longest) {+ count = 0;+ longest = 0.0f;+ for (const glm::uvec3& t : d.mesh.triangles) {+ const glm::vec3 c = (d.mesh.positions[t.x] + d.mesh.positions[t.y] + d.mesh.positions[t.z]) / 3.0f;+ bool in = false;+ for (const glm::vec3& p : path) in = in || glm::distance(c, glm::vec3(p.x * sign, p.y, p.z)) < radius * 0.6f;+ if (!in) continue;+ ++count;+ for (int k = 0; k < 3; ++k)+ longest = std::max(longest, glm::distance(d.mesh.positions[t[k]], d.mesh.positions[t[(k + 1) % 3]]));+ }+ };+ size_t brushSide = 0, mirrorSide = 0;+ float brushLongest = 0.0f, mirrorLongest = 0.0f;+ near(1.0f, brushSide, brushLongest);+ near(-1.0f, mirrorSide, mirrorLongest);+ std::printf(" brush side %zu triangles (longest edge %.3f), mirrored side %zu (%.3f), target %.3f\n", brushSide,+ brushLongest, mirrorSide, mirrorLongest, target);+ CHECK(brushSide > 200);+ CHECK(mirrorSide * 10 > brushSide * 7); // within 30%+ CHECK(mirrorLongest <= target * 4.0f / 3.0f * 1.5f);++ // Every side remeshed on its own stays a valid mesh, with X and Z symmetry (three images) and any brush,+ // and undo takes it all back exactly.+ const Mesh turned = [&] {+ Mesh m = makeIcosphere(3, 1.0f);+ for (glm::vec3& p : m.positions) p = turn * p;+ return m;+ }();+ uint32_t rng = 777;+ auto rnd = [&rng] {+ rng ^= rng << 13;+ rng ^= rng >> 17;+ rng ^= rng << 5;+ return float(rng & 0xffff) / 65535.0f;+ };+ const BrushType types[] = {BrushType::Standard, BrushType::SnakeHook, BrushType::Smooth, BrushType::Clay, BrushType::Pinch};+ bool valid = true;+ for (int stroke = 0; stroke < 10 && valid; ++stroke) {+ const BrushType type = types[stroke % 5];+ d.sculptor.dyntopo.detail = 0.4f + 0.5f * rnd();+ CHECK(d.sculptor.beginStroke(d.mesh, brushName(type)));+ const glm::vec3 dir = glm::normalize(glm::vec3(0.3f + 0.6f * rnd(), rnd() - 0.5f, 0.2f + 0.6f * rnd()));+ const glm::vec3 step = glm::normalize(glm::cross(dir, glm::vec3(0.1f, 1.0f, 0.2f))) * 0.07f;+ for (int i = 0; i < 6 && valid; ++i) {+ dabToward(d, (dir + step * float(i)) * 3.0f, 0.2f + 0.2f * rnd(), type, Symmetry{true, false, true}, 0.6f, step * 0.5f);+ const std::string why = invalid(d.mesh, true);+ if (!why.empty()) std::printf(" stroke %d dab %d: %s\n", stroke, i, why.c_str());+ valid = why.empty();+ }+ d.undo.push(d.sculptor.endStroke());+ }+ CHECK(valid);+ CHECK(bvhMatches(d.mesh, d.bvh));+ while (d.undo.canUndo()) d.undo.undo(d.mesh, d.bvh);+ CHECK(d.mesh.triangles == turned.triangles);+ CHECK(invalid(d.mesh, true).empty());+}+TEST(dyntopo_carries_attributes_and_drops_uvs) {Document d = sphereDoc(2);Mesh& m = d.mesh;