Add local average base normals
The base normal of each node will be averaged by sum of all the neighbors' base normal.master
parent
fd7dbb2024
commit
3e82ee597e
|
@ -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<QVector3D> 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()) {
|
||||
|
|
|
@ -83,7 +83,7 @@ private:
|
|||
std::vector<size_t> nodes;
|
||||
std::vector<std::pair<std::vector<size_t>, 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<size_t> *visited);
|
||||
void unifyBaseNormals();
|
||||
void localAverageBaseNormals();
|
||||
void resolveTraverseDirection(size_t nodeIndex);
|
||||
bool generateCutsForNode(size_t nodeIndex);
|
||||
bool tryWrapMultipleBranchesForNode(size_t nodeIndex, std::vector<float> &offsets, bool &offsetsChanged);
|
||||
|
|
Loading…
Reference in New Issue