- Home /

# procedural mesh error in triangulation

Hello! I am generating a procedural system, in question everything is fine, but I find a mathematical error in the triangulation, and I can not find the solution, maybe someone with a better eye and understanding can help me ... according to the triangulation int list, it should be like this: 0,1,3 - 3,2,0 | 2,3,5 - 5,2,2 | 4.5.1 - 1.0.4. but the error is in the last row, I do not understand why it remains (4,5,7 - 7,6,4.). I attach an image.

![alt text][1]

I do not understand why it happens to 7, when it should be 1, and to 6 when it should be 0. somebody help me? public GameObject node;

```
public Material mat;
[HideInInspector]
public GameObject pointDown;
[HideInInspector]
public GameObject pointUp;
[HideInInspector]
public GameObject pointUpPos;
public GameObject[] pointsDown;
public Vector3[] vertex;
[Range(1,20)]
public float Height=3;
public int point;
public int[] triangles;
private int p1;
private int p2;
private int p3;
private int b;
private int p0;
private float LastComparator;
Ray ray;
RaycastHit hit;
public Mesh mesh;
public MeshFilter mf;
public MeshRenderer meshrend;
vertexEditor vertexEdit;
private int x;
public int n;
public float textureScale;
public bool Create=false;
public int change;
void Start () {
Height = 3;
mat = Resources.Load ("fence", typeof (Material)) as Material;
mat.mainTextureScale = new Vector2(1,1);
mesh = new Mesh ();
meshrend = this.gameObject.AddComponent<MeshRenderer> ();
meshrend.material = mat;
mf = this.gameObject.AddComponent<MeshFilter> ();
textureScale=1;
}
public void GenMesh(){
b = -4;
p1 = b + 2;
p2 = p1 + 1;
p3 = p2 + 2;
p0 = -1;
for (n = 0; n < triangles.Length; n+=change) {
b = x - 2;
p1 += 2;
p2 += 2;
p3 += 2;
triangles [n] = p1;
triangles [n + 1] = p2;
triangles [n + 2] = p3;
triangles [n + 3] = p3;
triangles [n + 4] = p3 - 1;
triangles [n + 5] = p1;
triangles [n + 6] = p3-1;
triangles [n + 7] = p3;
triangles [n + 8] = 1;
triangles [n + 9] = 1;
triangles [n + 10] = p0 +1;
triangles [n + 11] = p3-1;
mesh.triangles = triangles;
}
}
void Update () {
mesh.Clear ();
mesh.vertices = vertex;
mf.mesh = mesh;
point = pointsDown.Length;
pointsDown = GameObject.FindGameObjectsWithTag ("vertex");
vertex = new Vector3[pointsDown.Length];
for (x = 0; x < pointsDown.Length; x++) {
vertex[x] = new Vector3(pointsDown[x].transform.position.x,pointsDown[x].transform.position.y,pointsDown[x].transform.position.z);
}
if (point > 0) {
change = 3;
triangles = new int[pointsDown.Length/2*3];
}
if (point > 4) {
triangles = new int[pointsDown.Length *3];
change = 6;
GenMesh ();
}
// uvmap area.
Vector2[] uvs = new Vector2[vertex.Length];
for (int i = 0; i < vertex.Length; i++)
{
Vector3 uvpos = new Vector3(vertex[i].x, ((vertex[i].x) + (vertex[i].z)), vertex[i].z);
Vector3 direction = uvpos / uvpos.magnitude;
uvs[i] = new Vector2(((vertex[i].x * direction.x) + (vertex[i].z * direction.z)) / 1, vertex[i].y / 1);
}
mesh.uv = uvs;
}
}
```

### 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

uv map problems 0 Answers

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

Automatically generating the triangle list for a mesh 0 Answers