- Home /

# Automatically generating the triangle list for a mesh

Hello

Is there a way or algorithm for automatically specifying how a list of vertices should be connected?

For example lets say I have this (in 2D for simplicity):

```
*(0,0) *(2,0)
```

*(-1,-1) *(1,-1)

So I add the vertices in the order (-1,-1),(0,0),(1,-1),(2,0) and then to the triangle list I add the indices 0,1,2 and 2,1,3 and this should generate a mesh with two triangles.

However, as the number of vertices get larger the process of defining the triangles get more tedious, unless of course I add the vertices in a sort of sorted order so that I can keep track of which triangle i'm and just add an offset each time (which I don't want to do).

Where i'm going with this is this (again in 2D for simplicity): I want to define an array, say:

[0 , 0 , 1 , 0 , 1 , 0]

[0 , 0 , 0 , 0 , 0 , 0]

[0 , 1 , 0 , 1 , 0 , 0]

which would represent the xy-plane and points in that array are vertices (1) or contain nothing (0). And so, array[0,0] would be x=0, y=0 (nothing) and array[2,1] (a vertex) would be x=1, y=2. Using this, I'd then like to generate a mesh.

I know there's a triangulate script for 2D but that doesn't work for 3D?

Is this possible? Any help would be appreciated.

Thanks

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Triangulating a 2D polygon with only hull vertices. 1 Answer

Procedurally Generated Mesh Texturing 0 Answers

Holes in procedural mesh 0 Answers