Created
January 30, 2018 15:53
-
-
Save yoeven/9ff65c9edbe74b904c1a829edbe24215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The following code is based of this thread: https://answers.unity.com/questions/798510/flat-shading.html | |
* | |
* This function flat shades any mesh. | |
* | |
*/ | |
using UnityEngine; | |
public static class FlatShader | |
{ | |
public static void flatShade(this Mesh mesh) | |
{ | |
Vector3[] oldVerts = mesh.vertices; | |
int[] triangles = mesh.triangles; | |
Vector3[] vertices = new Vector3[triangles.Length]; | |
for (int i = 0; i < triangles.Length; i++) | |
{ | |
vertices[i] = oldVerts[triangles[i]]; | |
triangles[i] = i; | |
} | |
mesh.vertices = vertices; | |
mesh.triangles = triangles; | |
mesh.RecalculateBounds(); | |
mesh.RecalculateNormals(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment