I just ran into the first big problem with my current Android project.
I want to display a 3d Level that is generated from 2d data. (List of obstacles with defined corner points + a fix height stored in a json file.)
I managed to draw them onto the floor using some code I found online and the triangulation code from the wiki. Now to make them 3d I would have to move the top part (which I already have) up (that is eays :P) and then draw a border/walls around it.
The Problem is that all the triangulation code I found online is 2d only. In order to draw my walls/ borders I need a 3rd axis(up). But whenever I tried to modify my code to add 3d support Unity stopped rendering any triangles at all ![]()
Would be great If anyone could help me with this.
This is what I currently use:
private static Mesh CreateMesh(List<Vector3> verts)
{
var tris = new Triangulator(verts.Select(x => x.ToVector2xz()).ToArray());
var mesh = new Mesh();
var vertices = verts.Select(x => new Vector3(x.x, x.y, x.z)).ToList();
var indices = tris.Triangulate().ToList();
//var uv = new List<Vector2>();
var n = vertices.Count;
for (int index = 0; index < n; index++)
{
var v = vertices[index];
vertices.Add(new Vector3(v.x, v.y, v.z));
}
for (int i = 0; i < n - 1; i++)
{
indices.Add(i);
indices.Add(i + n);
indices.Add(i + n + 1);
indices.Add(i);
indices.Add(i + n + 1);
indices.Add(i + 1);
}
indices.Add(n - 1);
indices.Add(n);
indices.Add(0);
indices.Add(n - 1);
indices.Add(n + n - 1);
indices.Add(n);
mesh.vertices = vertices.ToArray();
mesh.triangles = indices.ToArray();
mesh.RecalculateNormals();
mesh.RecalculateBounds();
return mesh;
}