From 6f01a2cb97d065dc5eb99ad40a40b43decde75cb Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 22 Oct 2024 08:12:15 -0700 Subject: [PATCH] clusterizer: Prioritize triangles with valence 2 edges When a triangle has two vertices with valence 2, it's typically advantageous to prioritize it above others even if that may require an extra vertex; after removing this triangle, we'll have between one and two isolated triangles with valence=1 vertex which we'll pick up immediately. Avoiding this triangle risks leaving the small triangle cluster alone and going in a different direction only to collect it later. This significantly reduces the number of disconnected clusters due to a better global flow; note that it's important to check for the edge, not just a single valence=2 vertex, as that results in a worse local decision that doesn't sufficiently improve global traversal. --- src/clusterizer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/clusterizer.cpp b/src/clusterizer.cpp index 6e46baa5..095877a6 100644 --- a/src/clusterizer.cpp +++ b/src/clusterizer.cpp @@ -312,8 +312,12 @@ static unsigned int getNeighborTriangle(const meshopt_Meshlet& meshlet, const Co // artificially increase the priority of dangling triangles as they're expensive to add to new meshlets else if (live_triangles[a] == 1 || live_triangles[b] == 1 || live_triangles[c] == 1) priority = 1; + // if two vertices have live count of 2, removing this triangle will make another triangle dangling which is good for overall flow + else if ((live_triangles[a] == 2) + (live_triangles[b] == 2) + (live_triangles[c] == 2) >= 2) + priority = 2; + // otherwise adjust priority to be after the above cases, 3 or 4 based on used[] count else - priority = 1 + extra; + priority = 2 + extra; // since topology-based priority is always more important than the score, we can skip scoring in some cases if (priority > best_priority)