@@ -1114,6 +1114,65 @@ static void meshletsSparse()
11141114 assert (memcmp (tri1, ibd + 3 , 3 * sizeof (unsigned int )) == 0 );
11151115}
11161116
1117+ static void meshletsFlex ()
1118+ {
1119+ // two tetrahedrons far apart
1120+ float vb[2 * 4 * 3 ] = {
1121+ 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 ,
1122+ 10 , 0 , 0 , 11 , 0 , 0 , 10 , 1 , 0 , 10 , 0 , 1 , // clang-format :-/
1123+ };
1124+
1125+ unsigned int ib[2 * 4 * 3 ] = {
1126+ 0 , 1 , 2 , 0 , 2 , 3 , 0 , 3 , 1 , 1 , 3 , 2 ,
1127+ 4 , 5 , 6 , 4 , 6 , 7 , 4 , 7 , 5 , 5 , 7 , 6 , // clang-format :-/
1128+ };
1129+
1130+ // up to 2 meshlets with min_triangles=4
1131+ assert (meshopt_buildMeshletsBound (2 * 4 * 3 , 16 , 4 ) == 2 );
1132+
1133+ meshopt_Meshlet ml[2 ];
1134+ unsigned int mv[2 * 16 ];
1135+ unsigned char mt[2 * 8 * 3 ]; // 2 meshlets with up to 8 triangles
1136+
1137+ // with regular function, we should get one meshlet (maxt=8) or two (maxt=4)
1138+ assert (meshopt_buildMeshlets (ml, mv, mt, ib, sizeof (ib) / sizeof (ib[0 ]), vb, 8 , sizeof (float ) * 3 , 16 , 8 , 0 .f ) == 1 );
1139+ assert (ml[0 ].triangle_count == 8 );
1140+ assert (ml[0 ].vertex_count == 8 );
1141+
1142+ assert (meshopt_buildMeshlets (ml, mv, mt, ib, sizeof (ib) / sizeof (ib[0 ]), vb, 8 , sizeof (float ) * 3 , 16 , 4 , 0 .f ) == 2 );
1143+ assert (ml[0 ].triangle_count == 4 );
1144+ assert (ml[0 ].vertex_count == 4 );
1145+ assert (ml[1 ].triangle_count == 4 );
1146+ assert (ml[1 ].vertex_count == 4 );
1147+
1148+ // with flex function and mint=4 maxt=8 we should get one meshlet if split_factor is zero, or large enough to accomodate both
1149+ assert (meshopt_buildMeshletsFlex (ml, mv, mt, ib, sizeof (ib) / sizeof (ib[0 ]), vb, 8 , sizeof (float ) * 3 , 16 , 4 , 8 , 0 .f , 0 .f ) == 1 );
1150+ assert (ml[0 ].triangle_count == 8 );
1151+ assert (ml[0 ].vertex_count == 8 );
1152+
1153+ assert (meshopt_buildMeshletsFlex (ml, mv, mt, ib, sizeof (ib) / sizeof (ib[0 ]), vb, 8 , sizeof (float ) * 3 , 16 , 4 , 8 , 0 .f , 10 .f ) == 1 );
1154+ assert (ml[0 ].triangle_count == 8 );
1155+ assert (ml[0 ].vertex_count == 8 );
1156+
1157+ // however, with a smaller split factor we should get two meshlets
1158+ assert (meshopt_buildMeshletsFlex (ml, mv, mt, ib, sizeof (ib) / sizeof (ib[0 ]), vb, 8 , sizeof (float ) * 3 , 16 , 4 , 8 , 0 .f , 1 .f ) == 2 );
1159+ assert (ml[0 ].triangle_count == 4 );
1160+ assert (ml[0 ].vertex_count == 4 );
1161+ assert (ml[1 ].triangle_count == 4 );
1162+ assert (ml[1 ].vertex_count == 4 );
1163+
1164+ // this should hold when using axis-aligned metric as well (negative cone weight)
1165+ assert (meshopt_buildMeshletsFlex (ml, mv, mt, ib, sizeof (ib) / sizeof (ib[0 ]), vb, 8 , sizeof (float ) * 3 , 16 , 4 , 8 , -1 .f , 10 .f ) == 1 );
1166+ assert (ml[0 ].triangle_count == 8 );
1167+ assert (ml[0 ].vertex_count == 8 );
1168+
1169+ assert (meshopt_buildMeshletsFlex (ml, mv, mt, ib, sizeof (ib) / sizeof (ib[0 ]), vb, 8 , sizeof (float ) * 3 , 16 , 4 , 8 , -1 .f , 1 .f ) == 2 );
1170+ assert (ml[0 ].triangle_count == 4 );
1171+ assert (ml[0 ].vertex_count == 4 );
1172+ assert (ml[1 ].triangle_count == 4 );
1173+ assert (ml[1 ].vertex_count == 4 );
1174+ }
1175+
11171176static void partitionBasic ()
11181177{
11191178 // 0 1 2
@@ -2201,6 +2260,7 @@ void runTests()
22012260 meshletsEmpty ();
22022261 meshletsDense ();
22032262 meshletsSparse ();
2263+ meshletsFlex ();
22042264
22052265 partitionBasic ();
22062266
0 commit comments