diff --git a/src/meshbuilder.cpp b/src/meshbuilder.cpp index 66c8afc..da3f52e 100644 --- a/src/meshbuilder.cpp +++ b/src/meshbuilder.cpp @@ -125,13 +125,13 @@ void MeshBuilder::mergeVertices() std::set vertexSet; VertexComparator::setMesh(this); - int size = positions.size(); + int swappedOffset = positions.size() - 1; for(Group &g : indiceGroups) for(int i=0; i= positions.size()) - g.indices[i] = swapped[size - g.indices[i]]; + g.indices[i] = swapped[swappedOffset - g.indices[i]]; std::pair::iterator,bool> ret = vertexSet.insert(g.indices[i]); if(!ret.second) // duplicate found { @@ -154,13 +154,18 @@ void MeshBuilder::mergeVertices() } if(hasTangents()) { + tangents[g.indices[i]].tangent += tangents[toDelete].tangent; + tangents[g.indices[i]].binormal += tangents[toDelete].binormal; tangents[toDelete] = tangents.back(); tangents.pop_back(); } } } - - fprintf(stdout, "found %d vertex duplicates\n", swapped.size()); + for(Tangents &t : tangents) + { + t.tangent = glm::normalize(t.tangent); + t.binormal = glm::normalize(t.binormal); + } } void MeshBuilder::computeNormals()