How to disable smooth lighting on procedural mesh

Hello, I made a terrain generator script which generate a grid and (temporarily) set random height to the vertices.

The problem is that it looks very smooth :
But i’d like to make it looks “flat” and show the edges.

It actually like the “Smooth” shading of Blender :

But i want it to look like the “Flat” shading :

So I needto set this appearance only with code. Thanks !

90049-capture.pngYou will have to duplicate the vertices of the edges.

When you call mesh.RecalculateNormals() it calculates an average normal of adjacent faces.
The normals are used to calculate the amount of light a face gets, averaging the normal makes that smooth lighting effect.

I’ve looked into this for a while, there is an option to do this on an imported mesh, but nothing for a runtime generated mesh.
This is because imported meshes actually have the triangles separate under the hood.
You just have to duplicate the vertices of every edge, and that should work.