• Advertisement
Sign in to follow this  

Calculate vertex normal of unordered triangles

This topic is 3631 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a mesh without any adjacent data, Can i calculate back all its vertex normals (as fast as possible)?

Share this post


Link to post
Share on other sites
Advertisement
Any vertex's normal is simply the addition of all the normals of the triangles that it is composed of divided by the number of normals. If you have a list of triangle objects (groups of 3 verticies), you can generate a unique vertex, index, and normal list from it.

Iterate through each triangle. For each vertex:

1) Add the vertex to the output vertex array if it is unique. Either way, add the index of the vertex to the output index list.
2) If the vertex is unique, add the normal of the triangle it came from to the normal list. It should have the same index into the index array as the unique vertex. If the vertex is not unique, lookup the normal associated with the index found in step 1 and add this triangle's normal to it, dividing by two.

In the end, you should have 3 lists. These can be rendered with GL_TRIANGLES.

Not sure if this is as fast as possible, but here are some optimizations that can be made if this function is too slow:

- store the vertex list so that looking to check if a vertex is unique requires less than a worst case O( n ) search.
- the most costly operation in this loop is the vector division. That should be as fast as possible

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement