diff --git a/thirdparty/nodemesh/nodemesh/builder.cpp b/thirdparty/nodemesh/nodemesh/builder.cpp index 2f27d942..3bd7c32b 100644 --- a/thirdparty/nodemesh/nodemesh/builder.cpp +++ b/thirdparty/nodemesh/nodemesh/builder.cpp @@ -304,6 +304,7 @@ bool Builder::build() } unifyBaseNormals(); + localAverageBaseNormals(); for (const auto &nodeIndex: m_sortedNodeIndices) { if (!generateCutsForNode(nodeIndex)) @@ -318,6 +319,25 @@ bool Builder::build() return succeed; } +void Builder::localAverageBaseNormals() +{ + std::vector localAverageNormals; + for (size_t nodeIndex = 0; nodeIndex < m_nodes.size(); ++nodeIndex) { + const auto &node = m_nodes[nodeIndex]; + QVector3D sumOfNormals = node.baseNormal; + for (const auto &edgeIndex: node.edges) { + const auto &edge = m_edges[edgeIndex]; + size_t neighborIndex = edge.neiborOf(nodeIndex); + const auto &neighbor = m_nodes[neighborIndex]; + sumOfNormals += neighbor.baseNormal; + } + localAverageNormals.push_back(sumOfNormals.normalized()); + } + for (size_t nodeIndex = 0; nodeIndex < m_nodes.size(); ++nodeIndex) { + m_nodes[nodeIndex].baseNormal = localAverageNormals[nodeIndex]; + } +} + bool Builder::validateNormal(const QVector3D &normal) { if (normal.isNull()) { diff --git a/thirdparty/nodemesh/nodemesh/builder.h b/thirdparty/nodemesh/nodemesh/builder.h index abee4430..de281550 100644 --- a/thirdparty/nodemesh/nodemesh/builder.h +++ b/thirdparty/nodemesh/nodemesh/builder.h @@ -83,7 +83,7 @@ private: std::vector nodes; std::vector, QVector3D>> cuts; - size_t neiborOf(size_t nodeIndex) + size_t neiborOf(size_t nodeIndex) const { const auto &otherIndex = nodes[0]; if (otherIndex == nodeIndex) @@ -131,6 +131,7 @@ private: QVector3D revisedBaseNormalAcordingToCutNormal(const QVector3D &baseNormal, const QVector3D &cutNormal); void resolveInitialTraverseDirectionRecursively(size_t nodeIndex, const QVector3D *from, std::set *visited); void unifyBaseNormals(); + void localAverageBaseNormals(); void resolveTraverseDirection(size_t nodeIndex); bool generateCutsForNode(size_t nodeIndex); bool tryWrapMultipleBranchesForNode(size_t nodeIndex, std::vector &offsets, bool &offsetsChanged);