Skip to content

Commit 6176b20

Browse files
committed
demo: Add a unit test for sparse meshlets
This is something that we don't normally hit during meshlet processing outside of Nanite workflows.
1 parent c623543 commit 6176b20

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

demo/tests.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,28 @@ static void clusterBoundsDegenerate()
10401040
assert(bounds2.center[2] - bounds2.radius <= 0 && bounds2.center[2] + bounds2.radius >= 1);
10411041
}
10421042

1043+
static void meshletsSparse()
1044+
{
1045+
const float vbd[16 * 3] = {};
1046+
const unsigned int ibd[6] = {0, 7, 15, 15, 7, 3};
1047+
1048+
meshopt_Meshlet ml[1];
1049+
unsigned int mv[4];
1050+
unsigned char mt[8];
1051+
size_t mc = meshopt_buildMeshlets(ml, mv, mt, ibd, 6, vbd, 16, sizeof(float) * 3, 64, 64, 0.f);
1052+
1053+
assert(mc == 1);
1054+
assert(ml[0].triangle_count == 2);
1055+
assert(ml[0].vertex_count == 4);
1056+
1057+
unsigned int tri0[3] = {mv[mt[0]], mv[mt[1]], mv[mt[2]]};
1058+
unsigned int tri1[3] = {mv[mt[3]], mv[mt[4]], mv[mt[5]]};
1059+
1060+
// technically triangles could also be flipped in the meshlet but for now just assume they aren't
1061+
assert(memcmp(tri0, ibd + 0, 3 * sizeof(unsigned int)) == 0);
1062+
assert(memcmp(tri1, ibd + 3, 3 * sizeof(unsigned int)) == 0);
1063+
}
1064+
10431065
static size_t allocCount;
10441066
static size_t freeCount;
10451067

@@ -2094,6 +2116,7 @@ void runTests()
20942116
encodeFilterExpClamp();
20952117

20962118
clusterBoundsDegenerate();
2119+
meshletsSparse();
20972120

20982121
customAllocator();
20992122

0 commit comments

Comments
 (0)