History

Further improvement to normals.

Andrzej Kapolka committed 11 years ago

Commit fa122b51 parent 82fc75b1 file · +15 −6Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+15−6
@@ -1491,11 +1491,14 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1490 unmodified lines
14911491 quadIndices.insert(qRgb(x, y - 1, z - 1), indices.size());
14921492 quadIndices.insert(qRgb(x, y, z - 1), indices.size());
14931493
1494− glm::vec3 normal(1.0f, 0.0f, 0.0f);
1495−
14961494 const NormalIndex& index1 = lastLineIndices.at(x);
14971495 const NormalIndex& index2 = lastPlaneIndices.at((y - 1) * expanded + x);
14981496 const NormalIndex& index3 = lastPlaneIndices.at(y * expanded + x);
1497+
1498+ const glm::vec3& first = vertices.at(index.indices[0]).vertex;
1499+ glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first,
1500+ vertices.at(index3.indices[0]).vertex - first);
1501+
14991502 if (alpha0 == 0) { // quad faces negative x
15001503 indices.append(index3.getClosestIndex(normal = -normal, vertices));
15011504 indices.append(index2.getClosestIndex(normal, vertices));
@@ -1514,11 +1517,14 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 12 unmodified lines
15141517 quadIndices.insert(qRgb(x - 1, y, z - 1), indices.size());
15151518 quadIndices.insert(qRgb(x, y, z - 1), indices.size());
15161519
1517− glm::vec3 normal(0.0f, 1.0f, 0.0f);
1518−
15191520 const NormalIndex& index1 = lastIndex;
15201521 const NormalIndex& index2 = lastPlaneIndices.at(y * expanded + x - 1);
15211522 const NormalIndex& index3 = lastPlaneIndices.at(y * expanded + x);
1523+
1524+ const glm::vec3& first = vertices.at(index.indices[0]).vertex;
1525+ glm::vec3 normal = glm::cross(vertices.at(index3.indices[0]).vertex - first,
1526+ vertices.at(index1.indices[0]).vertex - first);
1527+
15221528 if (alpha0 == 0) { // quad faces negative y
15231529 indices.append(index1.getClosestIndex(normal = -normal, vertices));
15241530 indices.append(index2.getClosestIndex(normal, vertices));
@@ -1537,11 +1543,14 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 12 unmodified lines
15371543 quadIndices.insert(qRgb(x - 1, y - 1, z), indices.size());
15381544 quadIndices.insert(qRgb(x, y - 1, z), indices.size());
15391545
1540− glm::vec3 normal(0.0f, 0.0f, 1.0f);
1541−
15421546 const NormalIndex& index1 = lastIndex;
15431547 const NormalIndex& index2 = lastLineIndices.at(x - 1);
15441548 const NormalIndex& index3 = lastLineIndices.at(x);
1549+
1550+ const glm::vec3& first = vertices.at(index.indices[0]).vertex;
1551+ glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first,
1552+ vertices.at(index3.indices[0]).vertex - first);
1553+
15451554 if (alpha0 == 0) { // quad faces negative z
15461555 indices.append(index3.getClosestIndex(normal = -normal, vertices));
15471556 indices.append(index2.getClosestIndex(normal, vertices));