Make mesh triangles have a single normal vector to make them stay triangles??

Hello guys!
So here’s my problem:
My general idea was to make an endless low poly world generator but i can figure something out, in order for the terrain to be low poly i need each triangle of the mesh to have only one vector facing toward the normal vector of the triangle, but i don’t know how to do that, Is there a way to give/apply a mesh’s triangles a single vector (In my case its the normal vector of that triangle)? or alternitavely prevent the unity engine from caculating the avarage vectors of the triangle apon rnadering the mesh and just leave them as triangles?

Thanks in advance, any help much appreciated!

I think you want to explicitly assign normals to the Mesh.normals array.
One normal per your vertex. So for 1 triangle you would have 3 vertices and 3 normals

yes, you will have to work with MeshFilter.mesh or .sharedMesh

you can point it at a new instance of Mesh, for example,

    Mesh sharpCornersMesh = new Mesh();
    sharpCornersMesh.normals = new Vector3[]{ normalDir, normalDir, normalDir }; /make sure normalDir is .normalized
    sharpCornersMesh.vertices  = new Vector3[]{ coordA, coordB, coordC }
sharpCornersMesh.triangles = new int[]{0, 1, 2}

myMeshFilter.sharedMesh = sharpCornersMesh;

you could compute normalDir per each triangle as a normalDir = Cross(coordA-CoordB, coordA-coordC).normalized;
depending on the order in which you supply coordA, coordB, coordC into your mesh you may wish to swap the order of arguments in the Cross() function, else your normals will point in the opposite direction

Also, make sure to save your mesh as an asset, else you will loose it the next time you open Unity; just google about it

Thank you very much! I’ll take a look at this :slight_smile: