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
QRemesh 2: untangle folded quads, symmetry-plane vertices back onto the sculpt; help texts, notices and header for the two methods
islandmed9d6af27dc9a8
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.mdindex 77147a07..cc45bdfe 100644--- a/THIRD_PARTY_NOTICES.md+++ b/THIRD_PARTY_NOTICES.md@@ -16,6 +16,7 @@ licenses require.| [MikkTSpace](https://github.com/mmikk/MikkTSpace) | commit 3e895b4 | zlib License | Tangent frames for baked tangent-space normal maps (Tool > Bake), matching Blender, Unreal, Unity and Godot. Vendored in third_party/mikktspace. || [tinyexr](https://github.com/syoyo/tinyexr) | 1.0.13 | BSD 3-Clause License (includes OpenEXR code under the OpenEXR BSD licence) | OpenEXR reading and writing for vector displacement maps (Brush > Vector Displacement). Vendored in third_party/tinyexr; uses stb's zlib. || [Instant Meshes](https://github.com/wjakob/instant-meshes) | formulas only, nothing vendored | BSD 3-Clause License | QRemesh (Tool > Geometry): the field formulas in src/core/QRemesh.cpp (extrinsic 4-RoSy orientation / position compatibility, the middle point of two tangent planes, lattice rounding) follow its reference code. The rest of QRemesh is our own. |+| QRemesh 2 (published methods, no third-party code) | — | — | The default QRemesh method (src/core/QRemesh2*.cpp) is our own implementation of published techniques: integer-grid maps / mixed-integer quadrangulation (Bommes, Zimmer & Kobbelt 2009; Bommes, Campen, Ebke, Alliez & Kobbelt 2013), N-RoSy fields as complex powers and the smoothest field by inverse power iteration (Ray, Vallet, Li & Lévy 2008; Knöppel, Crane, Pinkall & Schröder 2013), the dihedral curvature tensor (Cohen-Steiner & Morvan 2003), isotropic remeshing (Botsch & Kobbelt 2004) and smoothed aggregation multigrid. No code from QuadWild (GPL-3), libigl (MPL-2.0), CoMISo or Instant Meshes is included. || [Inter typeface](https://github.com/rsms/inter) | 4.1 | SIL Open Font License 1.1 | User interface font, embedded in the desktop app. Vendored in assets/fonts. || [ICT-FaceKit](https://github.com/ICT-VGL/ICT-FaceKit) (ICT Face Model Light) | commit on master, 2020 | MIT License | The template head of Generate Facial Shapes (Tool > Facial Shapes): its neutral skin, mouth and eye sockets and its 53 ARKit-style expression shapes, converted by tools/face/build_ict_template.py into assets/face/ict-arkit.sfface (embedded). Not the separately licensed full ICT Face Model. || [libcurl](https://curl.se) | system library | curl License (MIT/X derivate) | HTTPS for optional AI features on Linux and macOS. Linked dynamically from the operating system; Windows uses the built-in WinHTTP instead. |diff --git a/docs/guide/retopology.md b/docs/guide/retopology.mdindex d0e214dc..a6f93c1a 100644--- a/docs/guide/retopology.md+++ b/docs/guide/retopology.md@@ -36,7 +36,7 @@ Both steps are single undo steps (<kbd>Ctrl</kbd>+<kbd>Z</kbd>).| **Half / Same / Double** | Set the target to half, the same as or twice the SubTool's current polygon count || **Adaptive Size** | 0 makes quads all about the same size. Higher values make smaller quads where the surface curves and bigger ones on flat areas, for the same total || **Keep Groups** | Edge loops run exactly along the polygroup borders, and the result keeps the polygroups |-| **Detect Edges** | Hard edges, where faces meet at more than 50 degrees, get an edge loop, so boxes and bevels stay crisp (on by default) |+| **Detect Edges** | Hard edges get an edge loop, so boxes and bevels stay crisp (on by default). QRemesh 2 takes faces meeting at more than about 60 degrees along a line at least a few quads long (a scan's or a sculpt's deep creases are left to the flow); the legacy method any edge over 50 degrees || **Use Polypaint** | Paint where you want density: red areas get up to four times the quads, blue areas down to a quarter, white areas are unchanged || **Symmetry** | Remesh one half and mirror it, welded on the seam, for exactly symmetric topology (on by default). It mirrors on the axis chosen in the **Transform** palette (X if none), across the model's own middle plane: the world's centre plane when the model is symmetric about it, otherwise the plane through the model's middle, so a model moved away from the centre works too. A model that isn't mirror-symmetric is remeshed whole instead, and the status line says "Symmetry off: the model isn't mirror-symmetric"; one that is nearly symmetric (a bump on one side) gets mirrored topology that follows each side's own surface || **Keep Original** | Keep the SubTool as it was, hidden, below the new one, ready for ProjectAll. Off: the SubTool is replaced, as in ZBrush (undo brings it back) |diff --git a/src/app/PanelRetopo.cpp b/src/app/PanelRetopo.cppindex bb0b2f9d..4eb53654 100644--- a/src/app/PanelRetopo.cpp+++ b/src/app/PanelRetopo.cpp@@ -334,7 +334,7 @@ void App::drawQRemeshContents() {ImGui::SameLine();ImGui::SetCursorPosX(x0 + half + style.ItemSpacing.x); // the right column, inside the section indentImGui::Checkbox("Detect Edges", &retopo_.detectEdges);- ui::HelpText("Detect Edges", nullptr, "Hard edges (faces meeting at more than 50 degrees) get an edge loop, so they stay sharp.",+ ui::HelpText("Detect Edges", nullptr, "Hard edges get an edge loop, so they stay sharp (QRemesh 2: faces meeting at more than about 60 degrees along a line at least a few quads long; legacy: more than 50 degrees).",kQRemeshPath);ImGui::Checkbox("Use Polypaint", &retopo_.usePolypaint);ui::HelpText("Use Polypaint", nullptr,diff --git a/src/core/QRemesh.h b/src/core/QRemesh.hindex 24e21ffb..1273f74b 100644--- a/src/core/QRemesh.h+++ b/src/core/QRemesh.h@@ -1,7 +1,9 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later//-// QRemesh (Geometry > QRemesh, like ZBrush's ZRemesher): automatic quad retopology. A field-aligned method+// QRemesh (Tool > Remesh / Tool > Geometry > QRemesh, like ZBrush's ZRemesher): automatic quad retopology. Two+// methods: QRemesh 2, the default (an integer-grid map, core/QRemesh2.cpp), and the legacy one described here,+// which shares the steps around it (symmetry, guides, pieces, attributes). The legacy method is a field-aligned method// after Instant Field-Aligned Meshes (Jakob, Tarini, Panozzo, Sorkine-Hornung, SIGGRAPH Asia 2015; the// reference code is BSD-3, this is a fresh implementation of the parts we need)://diff --git a/src/core/QRemesh2.cpp b/src/core/QRemesh2.cppindex ff261b61..fac07c8d 100644--- a/src/core/QRemesh2.cpp+++ b/src/core/QRemesh2.cpp@@ -1594,7 +1594,58 @@ bool remeshPieceOnce(const WorkMesh& piece, int axis, double wantQuads, const QR}}relaxLoops(qp, quads, rt, std::max(opt.smoothIterations, 0), feat);- for (uint32_t v : planeVerts) qp[v][axis] = 0.0f;+ // Untangle: a quad turned against its neighbours (a fold left by a repair) gets its vertices moved to their+ // neighbours' average and back onto the sculpt.+ {+ const size_t nv = qp.size();+ std::vector<std::vector<uint32_t>> nbq(nv), vq(nv);+ for (uint32_t f = 0; f < quads.size(); ++f)+ for (int k = 0; k < 4; ++k) {+ vq[quads[f][k]].push_back(f);+ nbq[quads[f][k]].push_back(quads[f][(k + 1) % 4]);+ nbq[quads[f][k]].push_back(quads[f][(k + 3) % 4]);+ }+ std::vector<uint8_t> isFeat(nv, 0);+ for (size_t v = 0; v < nv && v < feat.size(); ++v) isFeat[v] = feat[v];+ for (uint32_t v : planeVerts) isFeat[v] = 1;+ size_t untangled = 0;+ for (int it = 0; it < 8; ++it) {+ std::vector<vec3> qn(quads.size());+ for (uint32_t f = 0; f < quads.size(); ++f) {+ const glm::uvec4 q = quads[f];+ qn[f] = safeNormalize(glm::cross(qp[q.z] - qp[q.x], qp[q.w] - qp[q.y]), vec3(0.0f));+ }+ std::vector<uint32_t> bad;+ for (uint32_t f = 0; f < quads.size(); ++f) {+ vec3 around(0.0f);+ for (int k = 0; k < 4; ++k)+ for (uint32_t g : vq[quads[f][k]]) around += qn[g];+ if (glm::dot(qn[f], around - 4.0f * qn[f]) < 0.0f)+ for (int k = 0; k < 4; ++k) bad.push_back(quads[f][k]);+ }+ if (bad.empty()) break;+ std::sort(bad.begin(), bad.end());+ bad.erase(std::unique(bad.begin(), bad.end()), bad.end());+ for (uint32_t v : bad) {+ if (isFeat[v] || nbq[v].empty()) continue;+ vec3 c(0.0f);+ for (uint32_t u : nbq[v]) c += qp[u];+ c /= float(nbq[v].size());+ SurfaceHit hit;+ qp[v] = surface.closestPoint(c, 2.0f * h0, hit) ? hit.position : c;+ ++untangled;+ }+ }+ if (timing && untangled) std::fprintf(stderr, " v2 untangled %zu vertex moves\n", untangled);+ }+ for (uint32_t v : planeVerts) { // onto the sculpt, then exactly onto the plane (a symmetric sculpt meets it there)+ for (int it = 0; it < 3; ++it) {+ qp[v][axis] = 0.0f;+ SurfaceHit hit;+ if (surface.closestPoint(qp[v], 2.0f * h0, hit)) qp[v] = hit.position;+ }+ qp[v][axis] = 0.0f;+ }mark("relax");out.mesh.P = std::move(qp);diff --git a/src/core/QRemesh2Param.cpp b/src/core/QRemesh2Param.cppindex 483246e7..cf89fd4f 100644--- a/src/core/QRemesh2Param.cpp+++ b/src/core/QRemesh2Param.cpp@@ -431,15 +431,6 @@ bool solveGridMap(const Proxy& p, const Frames& f, CrossField& field, GridMap& ofor (uint32_t v = 0; v < el.size(); ++v)if (el.eliminated(v)) maxLen = std::max(maxLen, el.expr(v).size()), total += el.expr(v).size();std::fprintf(stderr, " grid map: expressions max %zu terms, %zu in all\n", maxLen, total);- for (uint32_t v = 0; v < el.size(); ++v)- if (el.eliminated(v) && el.expr(v).size() == maxLen) {- int kinds[4] = {};- for (const Term& t : el.expr(v)) ++kinds[el.kind(t.var)];- std::fprintf(stderr, " var %u kind %d: terms real %d seam %d feature %d sing %d, first coefs %g %g %g\n", v,- el.kind(v), kinds[0], kinds[1], kinds[2], kinds[3], el.expr(v)[0].a, el.expr(v)[1].a,- el.expr(v)[2].a);- break;- }}// 4. Free unknowns. The reduced system C^T K C y = C^T (b - K d) (x = C y + d) is applied without forming it:// the cut tree makes C fill in (a transition is the composition of everything below it), C^T K C would not fit.diff --git a/src/core/RetopoCommands.cpp b/src/core/RetopoCommands.cppindex 5737ba80..fdb49c8c 100644--- a/src/core/RetopoCommands.cpp+++ b/src/core/RetopoCommands.cpp@@ -96,8 +96,8 @@ void registerRetopoCommands(CommandRegistry& reg) {{"adaptive", T::Number, "Adaptive Size 0-1: 0 = even quads, 1 = small quads in curved areas, big ""ones on flat areas. Default 0.5.", false},{"keep_groups", T::Bool, "Keep Groups: edge loops follow the polygroup borders and the groups are kept.", false},- {"detect_edges", T::Bool, "Detect Edges: hard edges (faces meeting at more than 50 degrees) get an edge "- "loop. Default true.", false},+ {"detect_edges", T::Bool, "Detect Edges: hard edges get an edge loop (v2: faces meeting at more than about "+ "60 degrees along a line a few quads long; legacy: over 50 degrees). Default true.", false},{"use_polypaint", T::Bool, "Use the polypaint as a density guide: red areas get up to 4x the quads, blue ""areas down to a quarter.", false},{"symmetry", T::String, "Mirror the topology across x, y or z. The mirror plane is found from the model (the "@@ -107,7 +107,8 @@ void registerRetopoCommands(CommandRegistry& reg) {"for the world's centre).", false},{"keep_original", T::Bool, "Keep the original as a hidden SubTool below (for project_all). Default false.", false},{"smooth", T::Number, "Relaxation passes on the surface (0-30). Default 6.", false},- {"seed", T::Number, "Random start of the direction field (results are repeatable per seed).", false},+ {"seed", T::Number, "Legacy method: random start of the direction field (results are repeatable per seed). "+ "QRemesh 2 has no random start.", false},{"keep_texture", T::Bool, "Keep a painted texture: Auto UV the result and project the texture onto it. ""Default true.", false},{"guides", T::Bool, "Follow the SubTool's QRemesh Guides (curves drawn with qremesh_guide): an edge loop "