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.

Micro base path: the stroke's own base kernel in the stroke again (fused there, 120 px p99 rose 344 -> 590 ms on a 3060); only the dabs still waiting at the pen's lift go through the plain path, fused (Sculptor::microBaseFuse, set by App::endStroke), which kept the 240 px release win (2.2 -> 1.4 s)

islandmedc4771cc00dde
diff --git a/src/app/App.cpp b/src/app/App.cpp
index fc031144..ca3064e1 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -2323,7 +2323,9 @@ void App::flushGrab() {
void App::endStroke() {
flushGrab(); // (Move: the last samples' move)
if (asyncStroke_) solverWait(); // (the dabs in flight; then the solver thread is idle)
+ doc_.sculptor.microBaseFuse = true; // (big dabs on a micro level's base: these go through together)
drainStrokeDabs(0.0); // the dabs still waiting belong to this stroke
+ doc_.sculptor.microBaseFuse = false;
doc_.sculptor.flushDetailClone(doc_.mesh, doc_.bvh, symmetry_); // a Detail Clone click
kelvinFinish(); // the rest of a Kelvinlet move (PanelKelvinlet.cpp)
// (a command can end a Ctrl+click before its release: finishStrokeNow clears the mask click too)
diff --git a/src/core/Sculpt.cpp b/src/core/Sculpt.cpp
index 147da391..0d7be14a 100644
--- a/src/core/Sculpt.cpp
+++ b/src/core/Sculpt.cpp
@@ -432,6 +432,91 @@ bool Sculptor::microBaseDab(const Mesh& mesh, BrushType type, const DabParams& p
return microBase_ == 1;
}
+void Sculptor::microBaseKernel(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p, Symmetry sym) {
+ auto clock = std::chrono::steady_clock::now();
+ const MicroMesh& mm = *mesh.micro;
+ const uint32_t n = mm.n, S = mm.samples;
+ const float r = p.radius, r2 = r * r;
+ const float s = std::clamp(p.strength * std::clamp(p.pressure, 0.0f, 1.0f), 0.0f, 1.0f);
+ const float sign = p.invert ? -1.0f : 1.0f;
+ for (const SymCopy& m : copies(sym)) {
+ const glm::vec3 c = m.point(p.center), view = m.dir(p.viewDir);
+ // The corners within reach: base points whose displaced corner may be in the sphere.
+ bvh.queryVertices(mesh, c, r + float(mm.rangeMax) * mm.step, baseVerts_);
+ const size_t nv = baseVerts_.size();
+ baseFall_.assign(nv, 0.0f);
+ baseCorner_.resize(nv);
+ baseNormal_.resize(nv);
+ poolFor(nv, [&](size_t b, size_t e) {
+ for (size_t i = b; i < e; ++i) {
+ const uint32_t v = baseVerts_[i];
+ const IndexRing ring = mesh.vertexTriangles(v);
+ if (ring.empty()) continue;
+ const uint32_t t = ring[0];
+ const glm::uvec3 tr = mesh.triangles[t];
+ const int k = tr.x == v ? 0 : tr.y == v ? 1 : 2;
+ const int16_t d = mm.disp[size_t(t) * S + (k == 0 ? 0 : k == 1 ? MicroMesh::index(n, 0, n) : MicroMesh::index(0, n, n))];
+ const glm::vec3 nn = mesh.normals[v];
+ const float len = glm::length(nn);
+ const glm::vec3 un = len > 1e-20f ? nn / len : glm::vec3(0.0f, 0.0f, 1.0f);
+ const glm::vec3 q = mesh.positions[v] + un * (float(d) * mm.step);
+ const float d2 = glm::dot(q - c, q - c);
+ baseCorner_[i] = q, baseNormal_[i] = un;
+ if (d2 < r2) baseFall_[i] = brushFalloff(std::sqrt(d2), r, p.focal);
+ }
+ }, 4096);
+ // The brush plane (Standard, Clay): weighted normal and centre of the corners under the brush.
+ glm::vec3 areaNormal = -view, areaCenter = c;
+ if (type != BrushType::Inflate) {
+ glm::dvec3 nsum(0.0), csum(0.0);
+ double w = 0.0;
+ for (size_t i = 0; i < nv; ++i)
+ if (baseFall_[i] > 0.0f) {
+ nsum += glm::dvec3(baseNormal_[i] * baseFall_[i]);
+ csum += glm::dvec3(baseCorner_[i] * baseFall_[i]);
+ w += baseFall_[i];
+ }
+ if (w > 0.0) {
+ areaCenter = glm::vec3(csum / w);
+ const double len = glm::length(nsum);
+ if (len > 1e-12) areaNormal = glm::vec3(nsum / len);
+ }
+ }
+ // The plain mesh's kernels (SculptKernel.h: Standard and Clay along the plane's normal, Inflate along the
+ // vertex's): the grid's own Clay moves each point along its normal by up to 3x the gap to the plane, which on
+ // a scan's noisy normals and deep folds overshoots, dab after dab, into spikes hundreds of units long.
+ PlaneKernel plane;
+ plane.type = type;
+ plane.center = c;
+ plane.viewDir = view;
+ plane.areaNormal = areaNormal;
+ plane.areaCenter = areaCenter;
+ plane.r = r;
+ plane.s = s;
+ plane.sign = sign;
+ plane.focal = p.focal;
+ plane.invert = p.invert;
+ baseMoves_.assign(nv, glm::vec3(0.0f));
+ poolFor(nv, [&](size_t b, size_t e) {
+ for (size_t i = b; i < e; ++i) {
+ const float f = baseFall_[i];
+ if (f <= 0.0f) continue;
+ baseMoves_[i] = type == BrushType::Inflate ? baseNormal_[i] * (sign * s * r * 0.05f * f) : plane.offsetWith(baseCorner_[i], f);
+ }
+ }, 4096);
+ size_t k = 0;
+ for (size_t i = 0; i < nv; ++i)
+ if (baseMoves_[i] != glm::vec3(0.0f)) baseVerts_[k] = baseVerts_[i], baseMoves_[k++] = baseMoves_[i];
+ baseVerts_.resize(k);
+ baseMoves_.resize(k);
+ timings.kernelMs += lapMs(clock);
+ timings.vertices += k;
+ moveVertices(mesh, bvh, baseVerts_, baseMoves_); // (the undo record, normals, BVH)
+ timings.normalsMs += lapMs(clock);
+ }
+ ++timings.dabs;
+}
+
bool Sculptor::microReady(Mesh& mesh) {
if (!mesh.micro || !microMatches(mesh)) return false;
if (!micro_.active() || microMesh_ != &mesh) {
@@ -799,9 +884,14 @@ void Sculptor::dab(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p, Sym
dabKelvinlet(mesh, bvh, type, p, sym);
return;
}
- // A micro level: the grid takes the dab (core/MicroSculpt.cpp), or a big one moves the base below it through the
- // plain path below (fused batches and all), the detail riding along (microBaseDab).
- if (microReady(mesh) && !microBaseDab(mesh, type, p)) {
+ // A micro level: a big dab moves the base below it (microBaseKernel), the grid takes the rest (core/MicroSculpt.cpp).
+ if (microReady(mesh) && microBaseDab(mesh, type, p)) {
+ if (!microBaseFuse) {
+ microBaseKernel(mesh, bvh, type, p, sym);
+ return;
+ }
+ // (the dabs left at the pen's lift: on through the plain path below, fused)
+ } else if (microReady(mesh)) {
const double k0 = micro_.findMs + micro_.kernelMs, s0 = micro_.stitchMs;
const uint64_t pts = micro_.points;
for (const SymCopy& m : copies(sym))
diff --git a/src/core/Sculpt.h b/src/core/Sculpt.h
index 02f31743..17115cde 100644
--- a/src/core/Sculpt.h
+++ b/src/core/Sculpt.h
@@ -295,12 +295,15 @@ public:
bool microMoveAlongNormals = false;
// Standard, Clay and Inflate dabs whose radius spans at least this many base edges move the base vertices of a
// micro level (the detail rides along, as with Move), not its millions of grid points: a scan's micro level
- // has tiny base triangles (Lucy: 28M), where the per-patch work of the grid cost seconds a dab. They take the plain
- // mesh's path (its fused batches included). Not with a mask or hidden faces (the grid masks per point and keeps
- // hidden patches whole), an alpha, layers or dynamic topology.
+ // has tiny base triangles (Lucy: 28M), where the per-patch work of the grid cost seconds a dab. Not with a mask
+ // or hidden faces (the grid masks per point and keeps hidden patches whole) or an alpha.
// SF_MICRO_BASE=0: always the grid (A/B).
static constexpr float kMicroBaseSpan = 16.0f;
bool microBaseDabs = microBaseDefault();
+ // Set by the app while it places the dabs still waiting when the pen lifts: those big micro dabs go through the
+ // plain mesh's path, fused (SculptBatch.cpp), not one base pass each (a 240 px stroke's release on Lucy 112M:
+ // 2.2 -> 1.4 s on a 3060). In the stroke the base kernel stays (fused there, 120 px fell behind: p99 344 -> 590 ms).
+ bool microBaseFuse = false;
static bool microBaseDefault();
MicroStroke& microStroke() { return micro_; }
// Mirror sign vectors for the enabled symmetry axes (always starts with (1,1,1)); ignores radial and local.
@@ -369,6 +372,14 @@ private:
// This stroke's dabs on a micro level go to the base vertices (-1: not decided yet; microBaseDab).
int microBase_ = -1;
bool microBaseDab(const Mesh& mesh, BrushType type, const DabParams& p);
+ // The plain mesh's brush (Standard, Clay, Inflate) at the base vertices, evaluated at the micro surface's corners
+ // (base point + normal * corner height): the base moves as a plain mesh would and the patches' points follow
+ // (Phong over the corners, as N2's coarse lattice), their heights untouched.
+ void microBaseKernel(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p, Symmetry sym);
+ std::vector<uint32_t> baseVerts_;
+ std::vector<glm::vec3> baseMoves_;
+ std::vector<float> baseFall_;
+ std::vector<glm::vec3> baseCorner_, baseNormal_;
bool microReady(Mesh& mesh); // the mesh has a micro level: starts the micro stroke on first use
float strokeDiagonal_ = 0.0f;
// The last remesh (repairDab remeshes it again when the brush squashed a triangle).
diff --git a/src/core/SculptBatch.cpp b/src/core/SculptBatch.cpp
index e539fce4..5c6e0679 100644
--- a/src/core/SculptBatch.cpp
+++ b/src/core/SculptBatch.cpp
@@ -30,7 +30,7 @@
namespace sf {
bool Sculptor::batchable(const Mesh& mesh, BrushType type, const DabParams& p, const Symmetry& sym) const {
- if (!adaptiveDabs || !isPlaneKernelBrush(type) || type == BrushType::Trim || dyntopo.enabled || draft_ || (mesh.micro && microBase_ != 1))
+ if (!adaptiveDabs || !isPlaneKernelBrush(type) || type == BrushType::Trim || dyntopo.enabled || draft_ || (mesh.micro && !(microBase_ == 1 && microBaseFuse)))
return false;
if ((p.alpha && !p.alpha->empty()) || p.frontFacesOnly || p.connectedOnly || p.viewFalloff) return false;
if (mesh.normals.size() != mesh.vertexCount()) return false;
diff --git a/tests/test_micro.cpp b/tests/test_micro.cpp
index 501514e5..b12dea61 100644
--- a/tests/test_micro.cpp
+++ b/tests/test_micro.cpp
@@ -719,11 +719,13 @@ std::vector<glm::vec3> microSurface(const Mesh& m) {
TEST(micro_base_stroke_is_the_plain_brush) {
// A big Standard, Inflate or Clay brush on a micro level over a dense base (a scan's) moves the base vertices
- // (Sculptor::microBaseDab): through the plain path, exactly as the plain brush moves the same mesh without the level, the detail riding along untouched (its heights bit-identical), one undo step
+ // (Sculptor::microBaseDab): as the plain brush moves the same mesh without the level (no detail: the corners are
+ // the vertices), the detail riding along untouched (its heights bit-identical), one undo step
// bringing every vertex and height back bit-exactly, redo the stroke.
for (BrushType type : {BrushType::Standard, BrushType::Inflate, BrushType::Clay}) {
for (bool detail : {false, true}) {
Document plain = makeDoc(makeBenchSphere(200000)), base = microDoc(2, 200000);
+ plain.sculptor.adaptiveDabs = false; // (its plane from every vertex, as the base path's)
if (detail) microNoise(base.mesh, 0.002f, 60.0f, 7);
const std::vector<glm::vec3> positions = base.mesh.positions;
const std::vector<int16_t> heights = base.mesh.micro->disp;
@@ -739,7 +741,9 @@ TEST(micro_base_stroke_is_the_plain_brush) {
std::printf(" base stroke %d%s: height %.4f, off the plain brush by %.4f%% at most\n", int(type), detail ? " (detail)" : "",
height, 100.0 * worst / height);
CHECK(height > 0.005);
- CHECK(worst <= height * 1e-6); // (the plain path itself, on the same base)
+ // (within a few percent: the plain brush picks and re-normals its region its own way, dab after dab; the
+ // detail's corner heights tilt the brush plane a little more)
+ CHECK(worst <= height * (detail ? 0.08 : 0.03));
const std::vector<glm::vec3> after = microSurface(base.mesh);
CHECK(base.undo.undo(base.mesh, base.bvh));
CHECK(base.mesh.positions == positions && base.mesh.micro->disp == heights && microSurface(base.mesh) == surface);