Mesh triagnles/surface with normals


I’m trying to get every triangle or surface of a mesh, and it’s normal.

I’m using:

Mesh m = go.GetComponent<MeshFilter>();

And then I know that I can use m.triangles to get the complete list of triangles. I know that there are 3 times less triangles than length of m.triangles, and I know why.

But then I need normals for this triangles. Is there any way to use m.normals then to get normal for each triangle correctly? And why for example m.normals length of simple Cube from Unity is 24?

m.vertices contains info about each vertex in mesh

m.triangles contains just indexes of vertices, 3 vertices for each triangles

m.normals contains (or contains no if no normals in mesh) normals for each vertex, that’s why m.normals.Length == m.vertices.Length

to get normals for triangle you just need first ti get 3 indexes of vertices in trinagle, and then based on that indexes get 3 normals from n.normals

if triangle is { 0, 1, 3 }
then vertices of this triangle is { m.vertices[0], m.vertices[1], m.vertices[3] }
and normals is { m.normals[0], m.normals[1], m.normals[3] }

cube have 24 normals cause it have 24 vertices. not 8 vertices as it looks like.

cube needs a sharp edges so in one vertex on the corner it have 3 different normals for each side. that’s why for each visual vertex (8 vertices total) cube has 3 vertices in same position with 3 different normals