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.
This commit is contained in:
Arseny Kapoulkine
2024-10-22 08:12:15 -07:00
parent f0b98e359f
commit 6f01a2cb97
+5 -1
View File
@@ -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)