Does anyone have mesh normals calculation code?

Has anyone found some mesh-normals finding code that produces nice results in unity, as good as the recalculatenormals? Because the built-in function cannot be multi-cored, held in an array prior to writing, edited, it has bugs along seams, etc.

could you prevent me having to search around the Internet searching for and converting codes for many hours in order to find one? do you know a really good code for it in C++?

please post what you have:roll_eyes: it would be heavily of you

I’m not sure if I correctly understand your problem. . .but I think it may be a matter of averaging the normal when a vertex is shared by multiple faces. I may have C++ code lying around, I just have to look for it. Since DirectX has this I didn’t have to use my own, OpenGL on the other hand didn’t, and I did :slight_smile:

That last bit is to see if you’re following long.

Would you please post a picture of what you have.

Is this a preprocessing issue or something you are trying to do at runtime?

Why C++? Unity doesn’t use C++ for scripting.

Create two vectors based on a triangles three vertices and then take the cross product of these two vectors and normalize it.

Although the method mentioned does produce a normal, it does not account for when the same vertex is shared among multiple faces that may be oriented differently.

Take all the triangles around a vertex, do what BFGames wrote for each of and add them together. Now, normalize the result. Done.

Do a first pass with what BFGames wrote for each, so that you can get naive normals. Then take all the triangles around a vertex that are not on the opposite side of a seam edge, or have a naive normal that is over the crease angle limit, and do what Dantus wrote, and add them together scaled with the edge weights specified. Now normalize the result. Done.

Do what halley wrote, enjoy, and then go buy an ice cream!

Also remember that order matters when calculating the cross product otherwise you could have inverse normal.

a x b != b x a (not commutative).

So if winding is anti-clockwise you swap around a and b terms.