- Home /
How to create a 2D mesh from a vertex array?
I have read basics of creating a mesh in run-time in Unity, however, the task I have placed before myself seems too hard for me and I'd like to have some help here.
The input is an array of 2D vertices, representing a closed concave or convex polyline. I want to create a 2D mesh (a plane one) based on those vertices.
An example of the input is displayed below:
<Vertex X="-2000" Y="-1800" />
<Vertex X="-2000" Y="1800" />
<Vertex X="-1800" Y="2000" />
<Vertex X="1800" Y="2000" />
<Vertex X="2000" Y="1800" />
<Vertex X="2000" Y="-1800" />
<Vertex X="1800" Y="-2000" />
<Vertex X="-1800" Y="-2000" />
(It is quite possible to have the last row equal to the first one here.)
Which should create a mesh with this form (click to enlarge):
![alt text][1]
[1]: http://i.snag.gy/6WjwE.jpg
Now, I have heard this thing might be called triangulation, however, I cannot find a good explanation of the algorythm involving concave polyline as well as convex one. Most mentioned Delaunay's does not cover concave triangulation.
Answer by robertbu · Aug 16, 2014 at 02:02 PM
Take a look at the Triangular script in the Unity Wiki. I think it does what you want out of the box.
If it helped you, please flag robertbu's answer as correct.