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
Symmetric dabs: one normal update for every mirror's vertices (once where the mirrors overlap)
islandmede4bb0577391d
diff --git a/src/core/Sculpt.cpp b/src/core/Sculpt.cppindex 6ceacedf..f1830d14 100644--- a/src/core/Sculpt.cpp+++ b/src/core/Sculpt.cpp@@ -289,6 +289,7 @@ UndoRecord Sculptor::endStroke() {void Sculptor::dab(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p, Symmetry sym) {if (!active_) return;+ dabVerts_.clear();for (const glm::vec3& m : mirrors(sym)) {DabParams mp = p;mp.center *= m;@@ -297,6 +298,7 @@ void Sculptor::dab(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p, Symmp.alphaUp *= m;dabSingle(mesh, bvh, type, mp);}+ updateDabNormals(mesh);}void Sculptor::dabSingle(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p) {@@ -461,21 +463,25 @@ void Sculptor::dabSingle(Mesh& mesh, BVH& bvh, BrushType type, const DabParams&});displaceAll(mesh, verts_, scratch_);- finishDab(mesh, bvh, verts_, clock, true);+ finishDab(mesh, bvh, clock);}-// Normals and BVH after a dab moved `verts`, with the time each takes (the kernel ran since `clock`).-// `queried`: verts are (some of) what the BVH's last vertex query returned.-void Sculptor::finishDab(Mesh& mesh, BVH& bvh, std::span<const uint32_t> verts, std::chrono::steady_clock::time_point clock,- bool queried) {+// The BVH after a mirror's dab moved (some of) the vertices its query returned, verts_ (the kernel ran since+// `clock`). The next mirror's query needs the new boxes; normals wait until every mirror moved its vertices+// (updateDabNormals), so where mirrors overlap they are updated once.+void Sculptor::finishDab(Mesh& mesh, BVH& bvh, std::chrono::steady_clock::time_point clock) {timings.kernelMs += lapMs(clock);- mesh.updateNormals(verts);- timings.normalsMs += lapMs(clock);- if (queried) bvh.refitQueried(mesh);- else bvh.refit(mesh, verts);+ bvh.refitQueried(mesh);timings.bvhMs += lapMs(clock);++timings.dabs;- timings.vertices += verts.size();+ timings.vertices += verts_.size();+ dabVerts_.insert(dabVerts_.end(), verts_.begin(), verts_.end()); // a vertex twice is fine: updateNormals dedups+}++void Sculptor::updateDabNormals(Mesh& mesh) {+ auto clock = std::chrono::steady_clock::now();+ mesh.updateNormals(dabVerts_);+ timings.normalsMs += lapMs(clock);}void Sculptor::dabRecipe(Mesh& mesh, BVH& bvh, const BrushRecipe& recipe, const DabParams& p, Symmetry sym) {@@ -483,6 +489,7 @@ void Sculptor::dabRecipe(Mesh& mesh, BVH& bvh, const BrushRecipe& recipe, constDabParams base = p;base.pressure = std::pow(std::clamp(p.pressure, 0.0f, 1.0f), recipe.pressureCurve);base.frontFacesOnly = p.frontFacesOnly || recipe.frontFacesOnly;+ dabVerts_.clear();for (const glm::vec3& m : mirrors(sym)) {DabParams mp = base;mp.center *= m;@@ -491,6 +498,7 @@ void Sculptor::dabRecipe(Mesh& mesh, BVH& bvh, const BrushRecipe& recipe, constmp.alphaUp *= m;dabRecipeSingle(mesh, bvh, recipe, mp);}+ updateDabNormals(mesh);}void Sculptor::dabRecipeSingle(Mesh& mesh, BVH& bvh, const BrushRecipe& r, const DabParams& p) {@@ -617,7 +625,7 @@ void Sculptor::dabRecipeSingle(Mesh& mesh, BVH& bvh, const BrushRecipe& r, const});displaceAll(mesh, verts_, scratch_);}- finishDab(mesh, bvh, verts_, clock, true);+ finishDab(mesh, bvh, clock);}void Sculptor::beginGrab(Mesh& mesh, BVH& bvh, const DabParams& p, Symmetry sym) {diff --git a/src/core/Sculpt.h b/src/core/Sculpt.hindex 72930394..f20ddf10 100644--- a/src/core/Sculpt.h+++ b/src/core/Sculpt.h@@ -110,8 +110,8 @@ public:private:void dabSingle(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p);void dabRecipeSingle(Mesh& mesh, BVH& bvh, const BrushRecipe& r, const DabParams& p);- void finishDab(Mesh& mesh, BVH& bvh, std::span<const uint32_t> verts, std::chrono::steady_clock::time_point clock,- bool queried = false);+ void finishDab(Mesh& mesh, BVH& bvh, std::chrono::steady_clock::time_point clock);+ void updateDabNormals(Mesh& mesh);void touch(Mesh& mesh, uint32_t v);// The one place brushes move vertices: scales `d` by vertexInfluence().void displace(Mesh& mesh, uint32_t v, const glm::vec3& d);@@ -125,7 +125,7 @@ private:uint64_t strokeId_ = 0;void clearRecorded();- std::vector<uint32_t> verts_;+ std::vector<uint32_t> verts_, dabVerts_; // one mirror's vertices; every mirror's (for the normals)std::vector<glm::vec3> scratch_;std::vector<float> weights_, influence_;std::vector<uint8_t> firstTouch_;