My program receives a Mesh at runtime. The mesh can be made of over 200k vertices. I need to reverse it (inside-out). I reverse the indices, but I also need to invert the normals. So far, I used this loop:
Vector3[] newnormals=new Vector3[mesh.normals.Length];
for (int i=0;i<mesh.normals.Length;i++)
{
newnormals[i] = -mesh.normals[i];
}
revMesh.normals = newnormals;
where "mesh" is the original Mesh, and of course "revMesh" is the reversed one. I don't know why, but this loop is incredibly slow. it takes many seconds on my i7. If I substitute it with
revMesh.RecalculateNormals();
the execution time goes down to under 100 ms.…
Why is my routine so inefficient? Is there some way to speed it up?