- Home /
Calculating normals manually
Hi,
I would like to calculate normals for a model I created but I don't want to use "RecalculateNormals()" method.
So my first question is, what is the size of Mesh.normal[] ? Is it Mesh.triangles.Length /3 ?
Given vertices of a triangle t to be a(Xa,Ya,Za) , b(Xb,Yb,Zb) and c(Xc,Yc,Zc),
also assume Vab (Xb-Xa,Yb-Ya,Zb-Za) and Vbc (xc-xb,yc-yb,zc-zb) two vertices, does the following calculate the normal vector correctly:
Cross product of Vab X Vbc
Thanks.
$$anonymous$$y untested assumptions (I'm away form my desktop):
Normals are vertex attributes, not triangle attributes, so the normals array will be the same size as the vertices array.
A normal is the average of the normals of the triangles that share a particular vertex. If vertices are not shared, all three vertices of a triangle will have the same normal.
Your math looks fine as long as you are walking in a clockwise direction around the triangle...which should happen if a,b,c are in the order of the triangles array.
Dumping the data from a couple of simple meshes should verify. Note the triangles array contains indexes into the vertices array.