• Create Account

## Normals for smoothing groups issue

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1paulg568  Members

100
Like
0Likes
Like

Posted 22 January 2012 - 11:31 PM

I have been creating an obj loader. I have pretty much everything working except for smoothing groups. They partially work.

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[i].resize(sizeOfVerts);
smooths[i].resize(sizeOfVerts);
for(int j = 0; j < faces[i].size(); j++){
repeatedIndices[i][faces[i][j]]++;
if(repeatedIndices[i][faces[i][j]] > 1){
if(smooths[i][faces[i][j]] == smoothingGroups[i][j]){
repeatedIndices[i][faces[i][j]]--;
} else {
repeatsInsideFaces[i].append(j);
}
} else {
smooths[i][faces[i][j]] = smoothingGroups[i][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[i].size(); j++){
m_points->append((*m_points)[faces[i][repeatsInsideFaces[i][j]]]);
faces[i][repeatsInsideFaces[i][j]] = m_points->size()-1;
}
}
}


### #2Ashaman73  Members

13651
Like
0Likes
Like

Posted 23 January 2012 - 07:17 AM

I do it the other way around. First I give every tri its own copy of its 3 vertices. Then I compare all vertex pairs at the same position (considering a small tolerance threshold) and merge them, when they meet some criteria like
- same texture and texture coord
- same normal
- same smoothing group
...

Ashaman

2053
Like
0Likes
Like

Posted 23 January 2012 - 09:51 AM

I do it by hand when I make the model. Any non-smooth parts I specifically separate and then put them back together as one model. You might want to try doing that as it might be easier and is visually driven rather than behind the scenes in code.

### #4paulg568  Members

100
Like
0Likes
Like

Posted 23 January 2012 - 11:23 AM

Well I want the obj reader to be able to handle objects from maya, max, blender and what ever else, so handling just my models won't be good enough( I downloaded the chess pieces from turbosquid.com ). I am trying to follow the format for the obj file spec so maybe I will try generating my normals the other way around like ashman.

Thanks everyone I'll let you know my progress.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.