Recalculate Normals?

Is it possible to recalculate the normals dynamically for a mesh?

I'm not referring to the inspector feature to compute normals of an imported mesh.

In particular I'm interested in calculating the normals for a mesh generated by extrusion.

thanks

I'm not sure how complex your mesh is and thus how intensive this would be -- I tend to work with textured quads for 2d games -- but you can certainly directly edit the normals for a mesh via the Mesh.normals property. Whether that is feasible in your case or not without some automated recalculation is another question.

Although, actually, looking at it I see a Mesh.RecalculateNormals method, too -- have you looked into that?

Just wanted to add - I tried RecalculateNormals, but for my particular mesh, it produced some strange results. It’s too complicated to explain why right now, but I ended up recalculating them using the following method:

For each triangle (a, b, c), find the face normal by taking the cross product (Vector3.Cross(…)) of (a,b) and (a, c) or some other combination. Normalize the result.

For each vertex, find the faces that contain that vertex and average the face normals to get the vertex normal.

You can do this relatively efficiently if you code it right. I don’t know if this is actually what RecalculateNormals does, but it produced the right results for me.

This article may shed some light:
http://schemingdeveloper.com/2014/10/17/better-method-recalculate-normals-unity/