From dcea86aaacc7ecd26cde0210d7ae16f58a034754 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 28 Aug 2024 10:42:43 -0700 Subject: [PATCH] indexgenerator: Clean up provoking remapping pass When all three vertices are used we don't really care which one we take to be the provoking one, as neither can be reused by future triangles anyway. This makes it possible to streamline the logic following the triangle rotation, as we *must* map the provoking vertex to the new index regardless of the case. Hopefully the comments make the flow reasonably clear to the future reader. --- src/indexgenerator.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/indexgenerator.cpp b/src/indexgenerator.cpp index da5e95ca..a36f36ed 100644 --- a/src/indexgenerator.cpp +++ b/src/indexgenerator.cpp @@ -631,27 +631,19 @@ size_t meshopt_generateProvokingIndexBuffer(unsigned int* destination, unsigned unsigned int newidx = reorder_offset; - // now remap[a] = ~0u or all three verts are old + // now remap[a] = ~0u or all three vertices are old + // recording remap[a] makes it possible to remap future references to the same index, conserving space if (remap[a] == ~0u) - { remap[a] = newidx; - reorder[reorder_offset++] = a; - destination[i + 0] = newidx; - destination[i + 1] = b; - destination[i + 2] = c; - } - else - { - // all three verts are old; we need to clone one of them - // for now clone a - // TODO: predict based on valence if above isn't enough - reorder[reorder_offset++] = a; + // we need to clone the provoking vertex to get a unique index + // if all three are used the choice is arbitrary since no future triangle will be able to reuse any of these + reorder[reorder_offset++] = a; - destination[i + 0] = newidx; - destination[i + 1] = b; - destination[i + 2] = c; - } + // note: first vertex is final, the other two will be fixed up in next pass + destination[i + 0] = newidx; + destination[i + 1] = b; + destination[i + 2] = c; // update vertex valences for corner heuristic valence[a]--;