History

Tweak to normal computation on dual contour surfaces.

Andrzej Kapolka committed 11 years ago

Commit 82fc75b1 parent b68c8361 file · +91 −109Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 1 file). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+91−109
@@ -1020,16 +1020,37 @@ public: · 1019 unmodified lines
1020 glm::vec3 normal;1020 glm::vec3 normal;
1021 QRgb color;1021 QRgb color;
1022 char material;1022 char material;
1023 int axis;
1024};1023};
1025 1024
1026class AxisIndex {1025const int MAX_NORMALS_PER_VERTEX = 4;
1026
1027class NormalIndex {
1027public:1028public:
1028 int x, y, z;1029 int indices[MAX_NORMALS_PER_VERTEX];
1029 1030
1030 AxisIndex(int x = -1, int y = -1, int z = -1) : x(x), y(y), z(z) { }1031 int getClosestIndex(const glm::vec3& normal, QVector<VoxelPoint>& vertices) const;
1031};1032};
1032 1033
1034int NormalIndex::getClosestIndex(const glm::vec3& normal, QVector<VoxelPoint>& vertices) const {
1035 int firstIndex = indices[0];
1036 int closestIndex = firstIndex;
1037 const VoxelPoint& firstVertex = vertices.at(firstIndex);
1038 float closest = normal.x * firstVertex.normal[0] + normal.y * firstVertex.normal[1] + normal.z * firstVertex.normal[2];
1039 for (int i = 1; i < MAX_NORMALS_PER_VERTEX; i++) {
1040 int index = indices[i];
1041 if (index == firstIndex) {
1042 break;
1043 }
1044 const VoxelPoint& vertex = vertices.at(index);
1045 float product = normal.x * vertex.normal[0] + normal.y * vertex.normal[1] + normal.z * vertex.normal[2];
1046 if (product > closest) {
1047 closest = product;
1048 closestIndex = index;
1049 }
1050 }
1051 return closestIndex;
1052}
1053
1033static glm::vec3 safeNormalize(const glm::vec3& vector) {1054static glm::vec3 safeNormalize(const glm::vec3& vector) {
1034 float length = glm::length(vector);1055 float length = glm::length(vector);
1035 return (length > 0.0f) ? (vector / length) : vector;1056 return (length > 0.0f) ? (vector / length) : vector;
@@ -1075,10 +1096,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 39 unmodified lines
1075 // as we scan down the cube generating vertices between grid points, we remember the indices of the last1096 // as we scan down the cube generating vertices between grid points, we remember the indices of the last
1076 // (element, line, section--x, y, z) so that we can connect generated vertices as quads1097 // (element, line, section--x, y, z) so that we can connect generated vertices as quads
1077 int expanded = size + 1;1098 int expanded = size + 1;
1078 QVector<AxisIndex> lineIndices(expanded);1099 QVector<NormalIndex> lineIndices(expanded);
1079 QVector<AxisIndex> lastLineIndices(expanded);1100 QVector<NormalIndex> lastLineIndices(expanded);
1080 QVector<AxisIndex> planeIndices(expanded * expanded);1101 QVector<NormalIndex> planeIndices(expanded * expanded);
1081 QVector<AxisIndex> lastPlaneIndices(expanded * expanded);1102 QVector<NormalIndex> lastPlaneIndices(expanded * expanded);
1082 1103
1083 const int EDGES_PER_CUBE = 12;1104 const int EDGES_PER_CUBE = 12;
1084 EdgeCrossing crossings[EDGES_PER_CUBE];1105 EdgeCrossing crossings[EDGES_PER_CUBE];
@@ -1090,7 +1111,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 5 unmodified lines
1090 for (int z = 0; z < expanded; z++) {1111 for (int z = 0; z < expanded; z++) {
1091 const QRgb* colorY = colorZ;1112 const QRgb* colorY = colorZ;
1092 for (int y = 0; y < expanded; y++) {1113 for (int y = 0; y < expanded; y++) {
1093 AxisIndex lastIndex;1114 NormalIndex lastIndex;
1094 const QRgb* colorX = colorY;1115 const QRgb* colorX = colorY;
1095 for (int x = 0; x < expanded; x++) {1116 for (int x = 0; x < expanded; x++) {
1096 int alpha0 = colorX[0] >> ALPHA_OFFSET;1117 int alpha0 = colorX[0] >> ALPHA_OFFSET;
@@ -1165,7 +1186,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 68 unmodified lines
1165 crossing.material = materialBase ? materialBase[0] : 0;1186 crossing.material = materialBase ? materialBase[0] : 0;
1166 }1187 }
1167 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f);1188 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f);
1168 crossing.axis = 0;
1169 }1189 }
1170 if (middleY) {1190 if (middleY) {
1171 if (alpha1 != alpha3) {1191 if (alpha1 != alpha3) {
@@ -1180,7 +1200,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines
1180 crossing.material = materialBase ? materialBase[1] : 0;1200 crossing.material = materialBase ? materialBase[1] : 0;
1181 }1201 }
1182 crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);1202 crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
1183 crossing.axis = 1;
1184 }1203 }
1185 if (alpha2 != alpha3) {1204 if (alpha2 != alpha3) {
1186 QRgb hermite = hermiteBase[hermiteStride];1205 QRgb hermite = hermiteBase[hermiteStride];
@@ -1194,7 +1213,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines
1194 crossing.material = materialBase ? materialBase[size] : 0;1213 crossing.material = materialBase ? materialBase[size] : 0;
1195 }1214 }
1196 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f);1215 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f);
1197 crossing.axis = 0;
1198 }1216 }
1199 if (middleZ) {1217 if (middleZ) {
1200 if (alpha3 != alpha7) {1218 if (alpha3 != alpha7) {
@@ -1209,7 +1227,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines
1209 crossing.material = materialBase ? materialBase[offset3] : 0;1227 crossing.material = materialBase ? materialBase[offset3] : 0;
1210 }1228 }
1211 crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);1229 crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
1212 crossing.axis = 2;
1213 }1230 }
1214 if (alpha5 != alpha7) {1231 if (alpha5 != alpha7) {
1215 QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1];1232 QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1];
@@ -1223,7 +1240,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines
1223 crossing.material = materialBase ? materialBase[offset5] : 0;1240 crossing.material = materialBase ? materialBase[offset5] : 0;
1224 }1241 }
1225 crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);1242 crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
1226 crossing.axis = 1;
1227 }1243 }
1228 if (alpha6 != alpha7) {1244 if (alpha6 != alpha7) {
1229 QRgb hermite = hermiteBase[hermiteArea + hermiteStride];1245 QRgb hermite = hermiteBase[hermiteArea + hermiteStride];
@@ -1237,7 +1253,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines
1237 crossing.material = materialBase ? materialBase[offset6] : 0;1253 crossing.material = materialBase ? materialBase[offset6] : 0;
1238 }1254 }
1239 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f);1255 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f);
1240 crossing.axis = 0;
1241 }1256 }
1242 }1257 }
1243 }1258 }
@@ -1254,7 +1269,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 10 unmodified lines
1254 crossing.material = materialBase ? materialBase[1] : 0;1269 crossing.material = materialBase ? materialBase[1] : 0;
1255 }1270 }
1256 crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);1271 crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
1257 crossing.axis = 2;
1258 }1272 }
1259 if (alpha4 != alpha5) {1273 if (alpha4 != alpha5) {
1260 QRgb hermite = hermiteBase[hermiteArea];1274 QRgb hermite = hermiteBase[hermiteArea];
@@ -1268,7 +1282,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines
1268 crossing.material = materialBase ? materialBase[area] : 0;1282 crossing.material = materialBase ? materialBase[area] : 0;
1269 }1283 }
1270 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f);1284 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f);
1271 crossing.axis = 0;
1272 }1285 }
1273 }1286 }
1274 }1287 }
@@ -1285,7 +1298,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 10 unmodified lines
1285 crossing.material = materialBase ? materialBase[0] : 0;1298 crossing.material = materialBase ? materialBase[0] : 0;
1286 }1299 }
1287 crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);1300 crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
1288 crossing.axis = 1;
1289 }1301 }
1290 if (middleZ) {1302 if (middleZ) {
1291 if (alpha2 != alpha6) {1303 if (alpha2 != alpha6) {
@@ -1300,7 +1312,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines
1300 crossing.material = materialBase ? materialBase[size] : 0;1312 crossing.material = materialBase ? materialBase[size] : 0;
1301 }1313 }
1302 crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);1314 crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
1303 crossing.axis = 2;
1304 }1315 }
1305 if (alpha4 != alpha6) {1316 if (alpha4 != alpha6) {
1306 QRgb hermite = hermiteBase[hermiteArea + 1];1317 QRgb hermite = hermiteBase[hermiteArea + 1];
@@ -1314,7 +1325,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines
1314 crossing.material = materialBase ? materialBase[area] : 0;1325 crossing.material = materialBase ? materialBase[area] : 0;
1315 }1326 }
1316 crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);1327 crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
1317 crossing.axis = 1;
1318 }1328 }
1319 }1329 }
1320 }1330 }
@@ -1330,12 +1340,13 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 9 unmodified lines
1330 crossing.material = materialBase ? materialBase[0] : 0;1340 crossing.material = materialBase ? materialBase[0] : 0;
1331 }1341 }
1332 crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);1342 crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
1333 crossing.axis = 2;
1334 }1343 }
1335 // at present, we simply average the properties of each crossing as opposed to finding the vertex that1344 // at present, we simply average the properties of each crossing as opposed to finding the vertex that
1336 // minimizes the quadratic error function as described in the reference paper1345 // minimizes the quadratic error function as described in the reference paper
1337 glm::vec3 center;1346 glm::vec3 center;
1338 glm::vec3 axisNormals[3];1347 glm::vec3 normals[MAX_NORMALS_PER_VERTEX];
1348 int normalCount = 0;
1349 const float CREASE_COS_NORMAL = glm::cos(glm::radians(40.0f));
1339 const int MAX_MATERIALS_PER_VERTEX = 4;1350 const int MAX_MATERIALS_PER_VERTEX = 4;
1340 quint8 materials[] = { 0, 0, 0, 0 };1351 quint8 materials[] = { 0, 0, 0, 0 };
1341 glm::vec4 materialWeights;1352 glm::vec4 materialWeights;
@@ -1344,7 +1355,18 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 2 unmodified lines
1344 for (int i = 0; i < crossingCount; i++) {1355 for (int i = 0; i < crossingCount; i++) {
1345 const EdgeCrossing& crossing = crossings[i];1356 const EdgeCrossing& crossing = crossings[i];
1346 center += crossing.point;1357 center += crossing.point;
1347 axisNormals[crossing.axis] += crossing.normal; 1358
1359 int j = 0;
1360 for (; j < normalCount; j++) {
1361 if (glm::dot(normals[j], crossing.normal) > CREASE_COS_NORMAL) {
1362 normals[j] = safeNormalize(normals[j] + crossing.normal);
1363 break;
1364 }
1365 }
1366 if (j == normalCount) {
1367 normals[normalCount++] = crossing.normal;
1368 }
1369
1348 red += qRed(crossing.color);1370 red += qRed(crossing.color);
1349 green += qGreen(crossing.color);1371 green += qGreen(crossing.color);
1350 blue += qBlue(crossing.color);1372 blue += qBlue(crossing.color);
@@ -1359,7 +1381,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines
1359 // when assigning a material, search for its presence and, if not found,1381 // when assigning a material, search for its presence and, if not found,
1360 // place it in the first empty slot1382 // place it in the first empty slot
1361 if (crossing.material != 0) {1383 if (crossing.material != 0) {
1362 for (int j = 0; j < MAX_MATERIALS_PER_VERTEX; j++) {1384 for (j = 0; j < MAX_MATERIALS_PER_VERTEX; j++) {
1363 if (materials[j] == crossing.material) {1385 if (materials[j] == crossing.material) {
1364 materialWeights[j] += 1.0f;1386 materialWeights[j] += 1.0f;
1365 totalWeight += 1.0f;1387 totalWeight += 1.0f;
@@ -1374,18 +1396,15 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines
1374 }1396 }
1375 }1397 }
1376 }1398 }
1377 glm::vec3 normal = safeNormalize(axisNormals[0] + axisNormals[1] + axisNormals[2]);
1378 center /= crossingCount;1399 center /= crossingCount;
1379 1400
1380 // use a sequence of Givens rotations to perform a QR decomposition1401 // use a sequence of Givens rotations to perform a QR decomposition
1381 // see http://www.cs.rice.edu/~jwarren/papers/techreport02408.pdf1402 // see http://www.cs.rice.edu/~jwarren/papers/techreport02408.pdf
1382 glm::mat4 r(0.0f);1403 glm::mat4 r(0.0f);
1383 glm::vec4 bottom;1404 glm::vec4 bottom;
1384 float smallestCosNormal = 1.0f;
1385 for (int i = 0; i < crossingCount; i++) {1405 for (int i = 0; i < crossingCount; i++) {
1386 const EdgeCrossing& crossing = crossings[i];1406 const EdgeCrossing& crossing = crossings[i];
1387 bottom = glm::vec4(crossing.normal, glm::dot(crossing.normal, crossing.point - center));1407 bottom = glm::vec4(crossing.normal, glm::dot(crossing.normal, crossing.point - center));
1388 smallestCosNormal = qMin(smallestCosNormal, glm::dot(crossing.normal, normal));
1389 1408
1390 for (int j = 0; j < 4; j++) {1409 for (int j = 0; j < 4; j++) {
1391 float angle = glm::atan(-bottom[j], r[j][j]);1410 float angle = glm::atan(-bottom[j], r[j][j]);
@@ -1450,63 +1469,17 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 58 unmodified lines
1450 }1469 }
1451 VoxelPoint point = { info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) + center) * scale,1470 VoxelPoint point = { info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) + center) * scale,
1452 { (quint8)(red / crossingCount), (quint8)(green / crossingCount), (quint8)(blue / crossingCount) },1471 { (quint8)(red / crossingCount), (quint8)(green / crossingCount), (quint8)(blue / crossingCount) },
1453 { (char)(normal.x * 127.0f), (char)(normal.y * 127.0f), (char)(normal.z * 127.0f) },1472 { (char)(normals[0].x * 127.0f), (char)(normals[0].y * 127.0f), (char)(normals[0].z * 127.0f) },
1454 { materials[0], materials[1], materials[2], materials[3] },1473 { materials[0], materials[1], materials[2], materials[3] },
1455 { (quint8)materialWeights[0], (quint8)materialWeights[1], (quint8)materialWeights[2],1474 { (quint8)materialWeights[0], (quint8)materialWeights[1], (quint8)materialWeights[2],
1456 (quint8)materialWeights[3] } };1475 (quint8)materialWeights[3] } };
1457 1476
1458 // determine whether we must "crease" by generating directional normals1477 NormalIndex index = { { vertices.size(), vertices.size(), vertices.size(), vertices.size() } };
1459 const float CREASE_COS_NORMAL = glm::cos(glm::radians(40.0f));1478 vertices.append(point);
1460 AxisIndex index(vertices.size(), vertices.size(), vertices.size());1479 for (int i = 1; i < normalCount; i++) {
1461 if (smallestCosNormal > CREASE_COS_NORMAL) { 1480 index.indices[i] = vertices.size();
1481 point.setNormal(normals[i]);
1462 vertices.append(point);1482 vertices.append(point);
1463
1464 } else {
1465 axisNormals[0] = safeNormalize(axisNormals[0]);
1466 axisNormals[1] = safeNormalize(axisNormals[1]);
1467 axisNormals[2] = safeNormalize(axisNormals[2]);
1468 glm::vec3 normalXY(safeNormalize(axisNormals[0] + axisNormals[1]));
1469 glm::vec3 normalXZ(safeNormalize(axisNormals[0] + axisNormals[2]));
1470 glm::vec3 normalYZ(safeNormalize(axisNormals[1] + axisNormals[2]));
1471 if (glm::dot(axisNormals[0], normalXY) > CREASE_COS_NORMAL &&
1472 glm::dot(axisNormals[1], normalXY) > CREASE_COS_NORMAL) {
1473 point.setNormal(normalXY);
1474 vertices.append(point);
1475
1476 point.setNormal(axisNormals[2]);
1477 index.z = vertices.size();
1478 vertices.append(point);
1479
1480 } else if (glm::dot(axisNormals[0], normalXZ) > CREASE_COS_NORMAL &&
1481 glm::dot(axisNormals[2], normalXZ) > CREASE_COS_NORMAL) {
1482 point.setNormal(normalXZ);
1483 vertices.append(point);
1484
1485 point.setNormal(axisNormals[1]);
1486 index.y = vertices.size();
1487 vertices.append(point);
1488
1489 } else if (glm::dot(axisNormals[1], normalYZ) > CREASE_COS_NORMAL &&
1490 glm::dot(axisNormals[2], normalYZ) > CREASE_COS_NORMAL) {
1491 point.setNormal(normalYZ);
1492 vertices.append(point);
1493
1494 point.setNormal(axisNormals[0]);
1495 index.x = vertices.size();
1496 vertices.append(point);
1497
1498 } else {
1499 point.setNormal(axisNormals[0]);
1500 vertices.append(point);
1501
1502 point.setNormal(axisNormals[1]);
1503 index.y = vertices.size();
1504 vertices.append(point);
1505
1506 point.setNormal(axisNormals[2]);
1507 index.z = vertices.size();
1508 vertices.append(point);
1509 }
1510 }1483 }
1511 1484
1512 // the first x, y, and z are repeated for the boundary edge; past that, we consider generating1485 // the first x, y, and z are repeated for the boundary edge; past that, we consider generating
@@ -1517,19 +1490,22 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 4 unmodified lines
1517 quadIndices.insert(qRgb(x, y - 1, z), indices.size());1490 quadIndices.insert(qRgb(x, y - 1, z), indices.size());
1518 quadIndices.insert(qRgb(x, y - 1, z - 1), indices.size());1491 quadIndices.insert(qRgb(x, y - 1, z - 1), indices.size());
1519 quadIndices.insert(qRgb(x, y, z - 1), indices.size());1492 quadIndices.insert(qRgb(x, y, z - 1), indices.size());
1520 indices.append(index.x);1493
1521 int index1 = lastLineIndices.at(x).x;1494 glm::vec3 normal(1.0f, 0.0f, 0.0f);
1522 int index2 = lastPlaneIndices.at((y - 1) * expanded + x).x;1495
1523 int index3 = lastPlaneIndices.at(y * expanded + x).x;1496 const NormalIndex& index1 = lastLineIndices.at(x);
1497 const NormalIndex& index2 = lastPlaneIndices.at((y - 1) * expanded + x);
1498 const NormalIndex& index3 = lastPlaneIndices.at(y * expanded + x);
1524 if (alpha0 == 0) { // quad faces negative x1499 if (alpha0 == 0) { // quad faces negative x
1525 indices.append(index3);1500 indices.append(index3.getClosestIndex(normal = -normal, vertices));
1526 indices.append(index2);1501 indices.append(index2.getClosestIndex(normal, vertices));
1527 indices.append(index1);1502 indices.append(index1.getClosestIndex(normal, vertices));
1528 } else { // quad faces positive x1503 } else { // quad faces positive x
1529 indices.append(index1);1504 indices.append(index1.getClosestIndex(normal, vertices));
1530 indices.append(index2);1505 indices.append(index2.getClosestIndex(normal, vertices));
1531 indices.append(index3);1506 indices.append(index3.getClosestIndex(normal, vertices));
1532 }1507 }
1508 indices.append(index.getClosestIndex(normal, vertices));
1533 }1509 }
1534 1510
1535 if (alpha0 != alpha2) {1511 if (alpha0 != alpha2) {
@@ -1537,19 +1513,22 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1 unmodified line
1537 quadIndices.insert(qRgb(x - 1, y, z), indices.size());1513 quadIndices.insert(qRgb(x - 1, y, z), indices.size());
1538 quadIndices.insert(qRgb(x - 1, y, z - 1), indices.size());1514 quadIndices.insert(qRgb(x - 1, y, z - 1), indices.size());
1539 quadIndices.insert(qRgb(x, y, z - 1), indices.size());1515 quadIndices.insert(qRgb(x, y, z - 1), indices.size());
1540 indices.append(index.y);1516
1541 int index1 = lastIndex.y;1517 glm::vec3 normal(0.0f, 1.0f, 0.0f);
1542 int index2 = lastPlaneIndices.at(y * expanded + x - 1).y;1518
1543 int index3 = lastPlaneIndices.at(y * expanded + x).y;1519 const NormalIndex& index1 = lastIndex;
1520 const NormalIndex& index2 = lastPlaneIndices.at(y * expanded + x - 1);
1521 const NormalIndex& index3 = lastPlaneIndices.at(y * expanded + x);
1544 if (alpha0 == 0) { // quad faces negative y1522 if (alpha0 == 0) { // quad faces negative y
1545 indices.append(index1);1523 indices.append(index1.getClosestIndex(normal = -normal, vertices));
1546 indices.append(index2);1524 indices.append(index2.getClosestIndex(normal, vertices));
1547 indices.append(index3);1525 indices.append(index3.getClosestIndex(normal, vertices));
1548 } else { // quad faces positive y1526 } else { // quad faces positive y
1549 indices.append(index3);1527 indices.append(index3.getClosestIndex(normal, vertices));
1550 indices.append(index2);1528 indices.append(index2.getClosestIndex(normal, vertices));
1551 indices.append(index1);1529 indices.append(index1.getClosestIndex(normal, vertices));
1552 }1530 }
1531 indices.append(index.getClosestIndex(normal, vertices));
1553 }1532 }
1554 1533
1555 if (alpha0 != alpha4) {1534 if (alpha0 != alpha4) {
@@ -1557,19 +1536,22 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1 unmodified line
1557 quadIndices.insert(qRgb(x - 1, y, z), indices.size());1536 quadIndices.insert(qRgb(x - 1, y, z), indices.size());
1558 quadIndices.insert(qRgb(x - 1, y - 1, z), indices.size());1537 quadIndices.insert(qRgb(x - 1, y - 1, z), indices.size());
1559 quadIndices.insert(qRgb(x, y - 1, z), indices.size());1538 quadIndices.insert(qRgb(x, y - 1, z), indices.size());
1560 indices.append(index.z);1539
1561 int index1 = lastIndex.z;1540 glm::vec3 normal(0.0f, 0.0f, 1.0f);
1562 int index2 = lastLineIndices.at(x - 1).z;1541
1563 int index3 = lastLineIndices.at(x).z;1542 const NormalIndex& index1 = lastIndex;
1543 const NormalIndex& index2 = lastLineIndices.at(x - 1);
1544 const NormalIndex& index3 = lastLineIndices.at(x);
1564 if (alpha0 == 0) { // quad faces negative z1545 if (alpha0 == 0) { // quad faces negative z
1565 indices.append(index3);1546 indices.append(index3.getClosestIndex(normal = -normal, vertices));
1566 indices.append(index2);1547 indices.append(index2.getClosestIndex(normal, vertices));
1567 indices.append(index1);1548 indices.append(index1.getClosestIndex(normal, vertices));
1568 } else { // quad faces positive z1549 } else { // quad faces positive z
1569 indices.append(index1);1550 indices.append(index1.getClosestIndex(normal, vertices));
1570 indices.append(index2);1551 indices.append(index2.getClosestIndex(normal, vertices));
1571 indices.append(index3);1552 indices.append(index3.getClosestIndex(normal, vertices));
1572 }1553 }
1554 indices.append(index.getClosestIndex(normal, vertices));
1573 }1555 }
1574 }1556 }
1575 lastIndex = index;1557 lastIndex = index;