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.

QRemesh 2: polypaint density turns the cross field with the scaled metric (pole pairs where the density changes)

islandmed7aef998d7fe5
diff --git a/src/core/QRemesh2.cpp b/src/core/QRemesh2.cpp
index 03577c02..a793bcea 100644
--- a/src/core/QRemesh2.cpp
+++ b/src/core/QRemesh2.cpp
@@ -948,8 +948,10 @@ bool remeshPieceV2(const WorkMesh& piece, int axis, double wantQuads, const QRem
for (size_t v = 0; v < s.size(); ++v) s[v] = w[v] > 0.0f ? s[v] / w[v] : 0.0f;
return s;
};
+ std::vector<float> relPaint;
auto computeRel = [&]() {
rel.assign(proxy.P.size(), 1.0f);
+ relPaint.assign(proxy.P.size(), 1.0f);
if (opt.adaptive > 0.01f) {
const std::vector<float> k = vertexAverage(curv.magnitude);
std::vector<float> sorted(k);
@@ -968,23 +970,33 @@ bool remeshPieceV2(const WorkMesh& piece, int axis, double wantQuads, const QRem
proxy.color[v] = c;
const float red = std::clamp(c.x - std::max(c.y, c.z), 0.0f, 1.0f);
const float blue = std::clamp(c.z - std::max(c.x, c.y), 0.0f, 1.0f);
- rel[v] *= std::pow(2.0f, blue - red);
+ relPaint[v] = std::pow(2.0f, blue - red);
}
}
- // Smooth the log size so it changes gradually.
+ // The size the cross field turns with (QRemesh2Field.cpp): the polypaint density, which asks for real changes
+ // of density (pole pairs where it changes). Adaptive Size only stretches the map (a noisy sculpt's curvature
+ // would otherwise ask for many pole pairs).
+ if (!piece.color.empty()) proxy.fieldSize = relPaint;
+ else proxy.fieldSize.clear();
+ for (size_t v = 0; v < rel.size(); ++v) rel[v] *= relPaint[v];
+ // Smooth the log sizes so they change gradually.
VertexFaces vf;
vf.build(proxy.P.size(), proxy.T);
- for (int it = 0; it < 10; ++it) {
- std::vector<float> lr(rel.size());
- for (size_t v = 0; v < rel.size(); ++v) {
- double s = 0.0;
- int c = 0;
- for (uint32_t k = vf.off[v]; k < vf.off[v + 1]; ++k)
- for (int j = 0; j < 3; ++j) s += std::log(double(rel[proxy.T[vf.tri[k]][j]])), ++c;
- lr[v] = c ? float(std::exp(s / double(c))) : rel[v];
+ auto smoothLog = [&](std::vector<float>& x, int rounds) {
+ for (int it = 0; it < rounds; ++it) {
+ std::vector<float> lr(x.size());
+ for (size_t v = 0; v < x.size(); ++v) {
+ double s = 0.0;
+ int c = 0;
+ for (uint32_t k = vf.off[v]; k < vf.off[v + 1]; ++k)
+ for (int j = 0; j < 3; ++j) s += std::log(double(x[proxy.T[vf.tri[k]][j]])), ++c;
+ lr[v] = c ? float(std::exp(s / double(c))) : x[v];
+ }
+ x.swap(lr);
}
- rel.swap(lr);
- }
+ };
+ smoothLog(rel, 10);
+ if (!proxy.fieldSize.empty()) smoothLog(proxy.fieldSize, 30);
};
if (adaptive) {
computeRel();
diff --git a/src/core/QRemesh2.h b/src/core/QRemesh2.h
index 2e4c55bf..2769e042 100644
--- a/src/core/QRemesh2.h
+++ b/src/core/QRemesh2.h
@@ -44,6 +44,7 @@ struct Proxy {
std::vector<uint8_t> feature; // per corner: the edge is a feature line (open edges included)
std::vector<uint8_t> sharp; // per corner: ... because it is a hard edge (Detect Edges)
std::vector<float> size; // per vertex: wanted quad edge length
+ std::vector<float> fieldSize; // per vertex: the (relative) size the cross field turns with; empty = none
std::vector<vec3> color; // per vertex polypaint (usePolypaint only)
size_t triangles() const { return T.size(); }
diff --git a/src/core/QRemesh2Field.cpp b/src/core/QRemesh2Field.cpp
index 2eaf87a8..db501bc0 100644
--- a/src/core/QRemesh2Field.cpp
+++ b/src/core/QRemesh2Field.cpp
@@ -182,7 +182,28 @@ bool solveCrossField(const Proxy& p, const Frames& f, const Curvature& curv, con
const uint32_t g = o / 3;
const vec3 e = p.P[p.T[t][(k + 1) % 3]] - p.P[p.T[t][k]];
const double at = angleIn(f, t, e), ag = angleIn(f, g, e);
- transport[c] = std::polar(1.0, 4.0 * (at - ag));
+ // Wanted quad size h: the field lives in the metric scaled by 1/h, whose connection turns by
+ // (log h_b - log h_a) times the dual / primal edge length ratio (cotangent weight) crossing into t.
+ // Without it, (1/h) X can't be a gradient and the map smears the density out.
+ double size = 0.0;
+ if (!p.fieldSize.empty()) {
+ const uint32_t a = p.T[t][k], b = p.T[t][(k + 1) % 3];
+ auto cotAt = [&](uint32_t tri, uint32_t opposite) {
+ const glm::uvec3 q = p.T[tri];
+ int j = 0;
+ while (j < 3 && q[j] != opposite) ++j;
+ const vec3 u = p.P[q[(j + 1) % 3]] - p.P[q[j]], v = p.P[q[(j + 2) % 3]] - p.P[q[j]];
+ return double(glm::dot(u, v)) / std::max(1e-20, double(glm::length(glm::cross(u, v))));
+ };
+ const uint32_t ct = p.T[t][(k + 2) % 3];
+ uint32_t cg = p.T[g][0];
+ for (int j = 0; j < 3; ++j)
+ if (p.T[g][j] != a && p.T[g][j] != b) cg = p.T[g][j];
+ const double w = std::clamp(0.5 * (cotAt(t, ct) + cotAt(g, cg)), 0.0, 5.0);
+ static const double gain = std::getenv("SF_QR2_SIZEGAIN") ? std::atof(std::getenv("SF_QR2_SIZEGAIN")) : 2.0;
+ size = gain * w * (std::log(double(p.fieldSize[b])) - std::log(double(p.fieldSize[a])));
+ }
+ transport[c] = std::polar(1.0, 4.0 * (at - ag + size));
}
// System: for free t, (deg + w) z_t - sum r z_g = w target (+ fixed neighbours).
std::vector<double> diag(nt, 1.0);