I am updating a project that is running on Unity 3.5.7f6 to 5.1.0f3. The one aspect of this project I cannot seem to figure out is with the mesh I create in code for the game dirt. This project heavily relies on dirt simulation, that is why the mesh is created and managed via C#.
The issue I am having with the ground at this moment is the mesh creation. When porting this project over to Unity 5, I was given the error that SetTriangleStrip was obsolete and I got the error Type UnityEngine.Mesh’ does not contain a definition for SetTriangleStrip. So I changed it to SetTriangles and the compile error was gone. But something had broken my mesh. Below I have pictures to show what the ground mesh should look like as well as a broken version.
This is what the ground should look like. A simple triangular plane.
This second image is what I get when I update the project to Unity 5 and change SetTriangleStrip to SetTriangles.
If I create and add a 2 sided material, I get a similar result to the 2nd image, except that there are 2 triangles that form diamond shapes. There are still large empty holes where other missing triangles should be.
Does SetTriangles work very differently from SetTriangleStrip? I have looked for more in depth documentation and have not found anything very useful. One guess I have is that SetTriangles has changed the winding order of the verticies I am passing in. Here is a small snippet of code so you can see what I mean.
private GameObject CreatePatch()
{
GameObject patch = new GameObject();
patch.AddComponent<MeshRenderer>();
patch.AddComponent<MeshFilter>();
patch.GetComponent<MeshRenderer>().sharedMaterial = DirtMaterial;
patch.transform.parent = Parent.transform;
Mesh mesh = new Mesh();
mesh.vertices = GeneratePatchVertices();
mesh.uv = GeneratePatchUVs();
mesh.normals = GeneratePatchNormals();
mesh.tangents = GeneratePatchTangents();
mesh.SetTriangles(GeneratePatchTriangleStrip(), 0);
DynamicMesh dynamicMesh = patch.AddComponent<DynamicMesh>();
dynamicMesh.Mesh = mesh;
patch.GetComponent<MeshFilter>().sharedMesh = mesh;
return patch;
}
Any help would be very appreciated.