I go through all the faces and check if their indicies are part of multiple smoothing groups. If so I mark what index was part of a separate smoothing group. Then I go through again and duplicate that vertex and update the faces array to use that new vertex.
I hope that makes sense.
Here is a screenshot of two chess pieces. In it you can see the knight and the rook have certain areas that are smoothing nicely and others that you can clearly see the polygons. I feel like I am duplicating vertices too many times if they are part of too many faces but I can't seem to fix it. If anyone has any idea what I am doing wrong I would greatly appreciate it. Code is below the picture. Thanks for the help.
Here is the code for finding shared vertices and the how I duplicate them.
It probably looks confusing and is.... so if you want me to explain it more I can. Thanks for the help.
void ObjFileReader::findSharedVertices(int numberOfObjects, int sizeOfVerts, QVector<int> *faces, QVector<int> *repeatedIndices, QVector<int> *repeatsInsideFaces, QVector<int> *smoothingGroups){
QVector<int> *smooths = new QVector<int>[numberOfObjects];
for(int i = 0; i < numberOfObjects; i++){
repeatedIndices.resize(sizeOfVerts);
smooths.resize(sizeOfVerts);
for(int j = 0; j < faces.size(); j++){
repeatedIndices[faces[j]]++;
if(repeatedIndices[faces[j]] > 1){
if(smooths[faces[j]] == smoothingGroups[j]){
repeatedIndices[faces[j]]--;
} else {
repeatsInsideFaces.append(j);
}
} else {
smooths[faces[j]] = smoothingGroups[j];
}
}
}
}
void ObjFileReader::duplicateSharedVertices(int numberOfObjects, QVector<int> *smoothingGroupIndices, QVector<int> *faces, QVector<Point3d> *m_points, QVector<int> *uvCoordinateIndexing, QVector<int> *repeatedIndices, QVector<int> *repeatsInsideFaces){
int total = 0;
for(int i = 0; i < numberOfObjects; i++){
for(int j = 0; j < repeatsInsideFaces.size(); j++){
m_points->append((*m_points)[faces[repeatsInsideFaces[j]]]);
faces[repeatsInsideFaces[j]] = m_points->size()-1;
}
}
}