# Generating mesh along path

I'm currently trying to generate a path along an array of points (Vector3) This is the result I'm currently getting:

• The dark gray points are the given path
• The red points are the generated vertices
• And the triangles are obviously the mesh I failed to generate correctly

And from the bottom it looks like this, which is odd, because I'd expect all the missing triangles to be at the bottom. But some of them just don't exist:

here's the code i wrote that generates the path mesh

//Removed code since there's no need in showing something that doesn't work


And here's a quick example of what it looks like when I drag a path:

SOLUTION FOUND

As the accepted answer states, I was skipping triangles in my triangle for loop. Here is my new working code:

public static Mesh extrudeAlongPath(Vector3[] points, float width){
if (points.Length < 2)
return null;
Mesh m = new Mesh();
List<Vector3> verts = new List<Vector3>();
List<Vector3> norms = new List<Vector3>();

for (int i = 0; i < points.Length; i++) {
if(i != points.Length-1){
Vector3 perpendicularDirection = new Vector3(-( points[i+1].z-points[i].z ), points[i].y, points[i+1].x -points[i].x).normalized;
}else{
Vector3 perpendicularDirection = new Vector3(-( points[i].z-points[i-1].z ), points[i].y, points[i].x -points[i-1].x).normalized;
}
}
m.vertices = verts.ToArray ();
m.normals = norms.ToArray ();

List<int> tris = new List<int> ();
//Changed i+=3 to i++
for(int i = 0; i < m.vertices.Length-3; i++){
if(i%2 == 0){
}else{
}
}
m.triangles = tris.ToArray ();

m.name = "pathMesh";
m.RecalculateNormals ();
m.RecalculateBounds ();
m.Optimize ();
return m;
}

• Does anything chance when you remove m.RecalculateNormals (); or m.RecalculateBounds ();? – Static Jun 27 '15 at 8:42
• unfortunately not, the exact same result – Daniel Holst Jun 27 '15 at 8:43

Try to change the tris for loop to ++ instead of +=3:

for(int i = 0; i < m.vertices.Length-3; i++){