Jump to content
  • Advertisement
Sign in to follow this  
link3978

Generate normals from mesh

This topic is 3123 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

Hi all, After getting help from fellow gamedev.net forum members I believe I have found my true question. I have a .obj of a person's face. It contains all the faces vertices and the indicies which form a triangle list. The verticies each have the model space position and texture coordinates (pretty standard I think). I also have the face's diffuse texture. What I don't have are the normals so I can't do any kind of lighting (diffuse, specular, etc). I know I could take the cross product of two edges on each triangle to get the normal at a vertex (this may not be 100% correct but I think it is something close). But doing it this way would make the mesh look faceted and unsmooth so not very face like. I know in 3ds max they have welding/smoothing groups that I could use to fix this but I would rather not use a 3d modeling package if I didn't have to. So I guess I am wondering if doing whatever 3ds max does when you weld/smoothing group is the best way to generate normals for a mesh. If it is, I'm sure I can find some article on the net about it. Thanks! :D

Share this post


Link to post
Share on other sites
Advertisement
What you basically do to get smooth vertex normals is to compute the face normals for every face in your mesh and after that, loop over every vertex in your mesh, sum up all face normals of all faces that share this vertex and normalize the result.

That will give you smooth normals over the whole mesh. If your mesh has different smoothing groups (as far as I remeber .obj files support them as well) you have to duplicate vertices along the edges where two groups meet and calculate a different normal for each. That normal should only use per faces normals from faces in the same smoothing group.

Share this post


Link to post
Share on other sites
Quote:
What you basically do to get smooth vertex normals is to compute the face normals for every face in your mesh and after that, loop over every vertex in your mesh, sum up all face normals of all faces that share this vertex and normalize the result.


There are easier ways than that...


setNormalArrayToZero();

for each face
{
normal = (vert0-vert1) cross (vert2-vert1);
for each vertexNormal in face
{
vertexNormal += normal;
}
}

for each vertexNormal
normalise



results are good enough most of the time. There are flaws, but it's the easiest way without worrying about smoothing groups.

Share this post


Link to post
Share on other sites
Awesome paper.

I decided I am going to implement "The "Mean Weighted by Angle" (MWA) Algorithm" that was in the "A Comparison of Algorithms for Vertex Normal Computation" paper.

Thanks again all.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!