- Home /
Mesh triagnles/surface with normals
Hello,
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?
Answer by ScroodgeM · Jul 20, 2012 at 09:53 AM
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
that's a helpful explanation on why the native cube has 24 verts =]
I found this after running a native cube through my mesh-reader after trying to see if I could find the collider verts. $$anonymous$$aybe you could help? (not my question, but am curious and have given a mesh-reader script, but not sure how to read the collider)
http://answers.unity3d.com/questions/287081/box-collider-vertexes-in-world-space.html
Thanks for that. I really was grateful just for the above answer. It actually makes sense when explained why there were 24 verts, regarding normals and tangents.