fixed vertex duplicates algorithm
This commit is contained in:
parent
7825ecd12f
commit
1b14d61bdc
@ -125,13 +125,13 @@ void MeshBuilder::mergeVertices()
|
|||||||
std::set<int, VertexComparator> vertexSet;
|
std::set<int, VertexComparator> vertexSet;
|
||||||
VertexComparator::setMesh(this);
|
VertexComparator::setMesh(this);
|
||||||
|
|
||||||
int size = positions.size();
|
int swappedOffset = positions.size() - 1;
|
||||||
|
|
||||||
for(Group &g : indiceGroups)
|
for(Group &g : indiceGroups)
|
||||||
for(int i=0; i<g.indices.size(); ++i)
|
for(int i=0; i<g.indices.size(); ++i)
|
||||||
{
|
{
|
||||||
if(g.indices[i] >= positions.size())
|
if(g.indices[i] >= positions.size())
|
||||||
g.indices[i] = swapped[size - g.indices[i]];
|
g.indices[i] = swapped[swappedOffset - g.indices[i]];
|
||||||
std::pair<std::set<int,VertexComparator>::iterator,bool> ret = vertexSet.insert(g.indices[i]);
|
std::pair<std::set<int,VertexComparator>::iterator,bool> ret = vertexSet.insert(g.indices[i]);
|
||||||
if(!ret.second) // duplicate found
|
if(!ret.second) // duplicate found
|
||||||
{
|
{
|
||||||
@ -154,13 +154,18 @@ void MeshBuilder::mergeVertices()
|
|||||||
}
|
}
|
||||||
if(hasTangents())
|
if(hasTangents())
|
||||||
{
|
{
|
||||||
|
tangents[g.indices[i]].tangent += tangents[toDelete].tangent;
|
||||||
|
tangents[g.indices[i]].binormal += tangents[toDelete].binormal;
|
||||||
tangents[toDelete] = tangents.back();
|
tangents[toDelete] = tangents.back();
|
||||||
tangents.pop_back();
|
tangents.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(Tangents &t : tangents)
|
||||||
fprintf(stdout, "found %d vertex duplicates\n", swapped.size());
|
{
|
||||||
|
t.tangent = glm::normalize(t.tangent);
|
||||||
|
t.binormal = glm::normalize(t.binormal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshBuilder::computeNormals()
|
void MeshBuilder::computeNormals()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user