Skip to content

Commit 20536cf

Browse files
committed
demo: Add a test for simplification along attribute seam
This test is intended mostly to track future improvements to the error behavior along the seam boundary. Right now, attribute error is not correctly computed along the seam boundary which prevents some collapses and can result in artificially inflated resulting error. We also seem to have some issues with positional errors for collapses along the seam which the test also demonstrates.
1 parent 8f368a7 commit 20536cf

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

demo/tests.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,78 @@ static void simplifyErrorAbsolute()
13381338
assert(fabsf(error - 0.85f) < 0.01f);
13391339
}
13401340

1341+
static void simplifySeam()
1342+
{
1343+
// xyz+attr
1344+
float vb[] = {
1345+
0, 0, 0, 0,
1346+
0, 1, 0, 0,
1347+
0, 1, 0, 1,
1348+
0, 2, 0, 1,
1349+
1, 0, 0, 0,
1350+
1, 1, 1, 0,
1351+
1, 1, 1, 1,
1352+
1, 2, 0, 1,
1353+
2, 0, 0, 0,
1354+
2, 1, 0, 0,
1355+
2, 1, 0, 1,
1356+
2, 2, 0, 1,
1357+
3, 0, 0, 0,
1358+
3, 1, 0, 0,
1359+
3, 1, 0, 1,
1360+
3, 2, 0, 1, // clang-format :-/
1361+
};
1362+
1363+
// 0 1-2 3
1364+
// 4 5-6 7
1365+
// 8 9-10 11
1366+
// 12 13-14 15
1367+
1368+
unsigned int ib[] = {
1369+
0, 1, 4,
1370+
4, 1, 5,
1371+
2, 3, 6,
1372+
6, 3, 7,
1373+
4, 5, 8,
1374+
8, 5, 9,
1375+
6, 7, 10,
1376+
10, 7, 11,
1377+
8, 9, 12,
1378+
12, 9, 13,
1379+
10, 11, 14,
1380+
14, 11, 15, // clang-format :-/
1381+
};
1382+
1383+
// note: vertices 1-2 and 13-14 are classified as locked, because they are on a seam & a border
1384+
// since seam->locked collapses are restriced, we only get to 3 triangles on each side as the seam is simplified to 3 vertices
1385+
1386+
// so we get this structure initially, and then one of the internal seam vertices is collapsed to the other one:
1387+
// 0 1-2 3
1388+
// 5-6
1389+
// 9-10
1390+
// 12 13-14 15
1391+
unsigned int expected[] = {
1392+
0, 1, 5,
1393+
2, 3, 6,
1394+
0, 5, 12,
1395+
12, 5, 13,
1396+
6, 3, 14,
1397+
14, 3, 15, // clang-format :-/
1398+
};
1399+
1400+
unsigned int res[36];
1401+
float error = 0.f;
1402+
1403+
assert(meshopt_simplify(res, ib, 36, vb, 16, 16, 18, 1.f, 0, &error) == 18);
1404+
assert(memcmp(res, expected, sizeof(expected)) == 0);
1405+
assert(fabsf(error - 0.22f) < 0.01f); // TODO: this is higher than normal due to border errors?
1406+
1407+
float aw = 1;
1408+
assert(meshopt_simplifyWithAttributes(res, ib, 36, vb, 16, 16, vb + 3, 16, &aw, 1, NULL, 18, 2.f, 0, &error) == 18);
1409+
assert(memcmp(res, expected, sizeof(expected)) == 0);
1410+
assert(fabsf(error - 0.49f) < 0.01f); // TODO: this is higher than normal due to merged attributes?
1411+
}
1412+
13411413
static void adjacency()
13421414
{
13431415
// 0 1/4
@@ -1556,6 +1628,7 @@ void runTests()
15561628
simplifyLockFlags();
15571629
simplifySparse();
15581630
simplifyErrorAbsolute();
1631+
simplifySeam();
15591632

15601633
adjacency();
15611634
tessellation();

0 commit comments

Comments
 (0)