Find vertex normal of unordered triangles on a mesh

Started by
4 comments, last by vic2005 16 years ago
I have a mesh without any adjacent data (Index buffer), Can i find all its vertex normals (with Index buffer)? Also , can i have some examples or websites for this kind of thing? thx
Advertisement
Hi,

the algorithm for calculating smooth vertex normals for a given triangle list looks like this (Pseudocode!):

for each triangle (v1,v2,v3) in mesh   face_normal = (v2-v1) cross (v3-v1)   normalize face_normal   for all points in triangle      store face_normal    endendfor each vertex v1 in mesh   vertex_normal = 0;   counter = 0;   for each vertex v2 in mesh      if position of v1 equals position of v2         vertex_normal += normal of v2         counter += 1      end if   end   vertex_normal /= counter;   normalize vertex_normal   store vertex_normal in v1end


However this can be optimized heavily. Don't forget to use a reliable epsilon to check vertex position differences against. If you have an Indexbuffer, simply access the Vertexbuffer indirectly by iterating through the index data.
Hope this helps you!

Best regards,
Porthos
The method i tend to use is this:
Essentialy, you have all vertex normals initialised to 0, you then loop through all triangles calculating the triangle normal, and add this to each of the vertice's normals for that triangle.

You then loop through all vertices normalising their normals.


vertex normals initialised to 0

for each triangle
calculate triangle normal
add triangle normal to each vertice's normal in triangle

for each vertex
normalise normal
wt is the difference between Porthos's method and luca-deltodesco's method?
which one is faster?
i just reread the topic starters post and realised that ofcourse, mine is not suitable for his needs as it assumes that vertices are shared between triangles properly.
Quote:Original post by Porthos
Hi,

the algorithm for calculating smooth vertex normals for a given triangle list looks like this (Pseudocode!):

for each triangle (v1,v2,v3) in mesh   face_normal = (v2-v1) cross (v3-v1)   normalize face_normal   for all points in triangle      store face_normal    endendfor each vertex v1 in mesh   vertex_normal = 0;   counter = 0;   for each vertex v2 in mesh      if position of v1 equals position of v2         vertex_normal += normal of v2         counter += 1      end if   end   vertex_normal /= counter;   normalize vertex_normal   store vertex_normal in v1end


However this can be optimized heavily. Don't forget to use a reliable epsilon to check vertex position differences against. If you have an Indexbuffer, simply access the Vertexbuffer indirectly by iterating through the index data.
Hope this helps you!

Best regards,
Porthos


I also have this kind of problem.
how to optimized it?

The second part need to process each point ,and each loop search from the begin to the end , it will be quite slow.

will it be faster when i create a index buffer for it?
But...How?

This topic is closed to new replies.

Advertisement