- Home /
Question by
cakyman · Aug 27, 2015 at 09:32 AM ·
meshgenerationprocedural meshseams
Prevent seams on a generated mesh with split edges.
I've got a script that generates a procedural mesh and then splits the edges to make it flat shaded, but there's a problem when viewing it.
There are these seams that are visible at the edges, and when viewed from a distance, cluster together to make a white/yellow hue on the entire mesh.
Here are some pictures:
Here is the code:
Mesh mesh = meshFilter.mesh;
Vector3[] vertices = mesh.vertices;
for (int i = 0; i < vertices.Length; i++) {
float xCoord = Mathf.Abs((transform.position.x + vertices[i].x) * scale)-5000;
float yCoord = Mathf.Abs((transform.position.z + vertices[i].z) * scale)-5000;
vertices[i].y = (Mathf.PerlinNoise (xCoord, yCoord) - 0.5f) * power;
}
meshFilter.mesh.vertices = vertices;
meshFilter.mesh.RecalculateBounds ();
meshFilter.mesh.RecalculateNormals ();
// split edges
Vector3[] oldVerts = vertices;
int[] triangles = mesh.triangles;
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();
meshFilter.mesh = mesh;
meshCollider.sharedMesh = mesh;
Comment
Your answer
Follow this Question
Related Questions
Procedural Mesh Generation: Creating a spherical sector 2 Answers
Why does Frame Selected toggle between position and bounds for procedural and imported meshes? 1 Answer
How do I combine normals on procedural mesh with multiple tiles? 2 Answers
Mesh generated from bezier curve loop going outside loop 0 Answers