Question answered by asker.
Mesh Creation at Runtime - Strange black artefacts
I am seeing weird artefacts on my mesh when I generate it at runtime. I build the mesh by looping through and assigning the correct vertices and triangle data, and it seems to be great mathematically. However, I then get various black lines as if I'm viewing the mesh from below, or that the bottom of the mesh is coming through the top of it (see the side on view below)!
Scene mode with game running:
Game mode with game running:
If I move the camera higher and angle the camera down I don't get it:
From the bottom, just for the record (it looks like loads of straight lines, which I thought was weird, not a direct inverse of the top of the mesh, is that normal????):
From the side, in case it helps (as you can see some of these straight lines from the below view here above the mesh, and I wonder if this is the cause????)
You can also see black areas on the edge of the mesh.
I generate the normals by running mesh.RecalculateNormals();
Here are my material settings:
And my object settings for the tilemap
And finally the code I use to create the mesh:
// Build mesh
Mesh mesh = new Mesh();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateNormals();
MeshFilter mf = GetComponent<MeshFilter> ();
MeshRenderer mr = GetComponent<MeshRenderer> ();
MeshCollider mc = GetComponent<MeshCollider> ();
mf.mesh = mesh;
mc.sharedMesh = mesh;
Any and all advice would be amazing, thanks for your help, and apologies if I'm doing something really stupid here!!!
Edit: I fixed the problem. It was an issue where I was incorrectly assigning one triangle per row with one wrong vertex. Once I fixed it, the mesh looks perfect, no jagged edges etc...
So, if anyone else sees the same issue, check your maths. It isn't a graphics issue at all, it's the assignments of vertices to the triangles. Thanks!
Follow this Question
Related Questions
Mesh wont render although there are no errors! 1 Answer
Mesh combining makes an incomplete mesh? 0 Answers
How is a Mesh Built? 1 Answer
Find the volume of an object that is underneath a mesh 0 Answers
Assigning uv's to multiple faces 1 Answer