Mesh Creation out of 2 Point Arrays

I am working on a project where I create streets with the help of bezier curves.
I create a bezier curve and create a boundary on each side of it by using the normalvector of point p(i) on the bezier curve. I was able to create the alpha shape of this object but now I cant get any further…
(Alpha shape

)

I need to create a mesh out of my given point strips.
The alpha shape was created by searching for intersections on each side of the boundary. If a slope is within the street object an intersection starts and ends this slope. I didnt use delauney triangulation for it because the street is basicly nothing but a slightly modified array of normals so Iit was easier for me to use line intersection for this part of my problem.

Now i dont know how to create a mesh out of it. I tried so many approaches with my given data and extended them as far as I was able to.
My latest approach saves the vertices, a boolean information if the point is a legal point (or at least if it is appearing more than once so it can be ignored after the first time) and information about the vertex index for a possible triangle creation.
I wanted to draw lines between every 2 matching outer boundary points but this is as close i can get at this moment: (Attachement 2)

As you can see after the first curve there is an imbalance between left and right side i am not able to get away.

At the moment I am using the draw method I used to create the alpha shape in the first attachment but outcommented the draw instruction and added an instruction for saving information in my class MeshBuffer (which saves vertices, indices and boolean information)

Please have in mind that im working just in the x and z Axis. So its basicly 2D.
y is always 0.

    private MeshBuffer drawHull(Line[] lines){
       MeshBuffer buffer = new MeshBuffer ();
       int iIndex = -10;
       int jIndex = -10;
       int lastIN = 0;
       bool illegalArea = false;
       buffer.Add (lines [0].left.point, true);
       for(int i = 0; i<lines.Length; i++){
         if(!illegalArea){
           if(lines[i].intersectionIds.Count==0){
             buffer.Add(lines[i].right.point,true);
             //draw(lines[i].left.point,lines[i].right.point,lines[i].id.ToString(),0.5f);
           }
           else{
             if (lines[i].intersectionIds.Count == 1) {
               iIndex= lines[i].intersectionIds [0];
               lines[i].intersec=lines[i].intersection[0];
               jIndex=0;
               buffer.Add(lines[i].intersection[0],true);
             } else {
               int max = lines[i].intersectionIds[0];
               jIndex=0;
               for(int j = 1; j<lines[i].intersectionIds.Count; j++){
                 if(max<lines[i].intersectionIds[j]){
                   max=lines[i].intersectionIds[j];
                   jIndex=j;
                 }
               }
               iIndex= max;
             }
             illegalArea=true;
             lines[i].intersec=lines[i].intersection[jIndex];
             buffer.Add(lines[i].intersection[jIndex],true);
             //draw(lines[i].left.point,lines[i].intersection[jIndex],lines[i].id.ToString(),0.5f);
             lastIN=i;
           }
         }

         else{
           buffer.Add(lines[lastIN].intersection[jIndex],false);
         }
        
         if(iIndex==i){
           buffer.Add(lines[i].right.point,true);
           lines[i].intersec=lines[lastIN].intersection[jIndex];
           //draw(lines[lastIN].intersection[jIndex],lines[i].right.point,lines[i].id.ToString(),0.5f);
           illegalArea=false;
         }
       }
      
       return buffer;
     }

In the MeshBuffer class I had to add the extra if bracket in the Add method because the indices werent right. You can see them within the second attachement instantiated as Cubes (0,1,2,2,2,2,2,2,… represent the indices)
Cubes with the same index share the same vertex and the doubled versions can (or should) be removed later on in the process.
The cubes are generated within the Add method of this class.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MeshBuffer
{
  
   public List<Vector3> vertices = new List<Vector3>();
   public List<int> triangles = new List<int>();
   public List<bool> legal = new List<bool>();
   int vertCount = -1;
   Vector3 lastVert=Vector3.up; //vert!= Vector3.up -> vert.y = 0




   public void Add(Vector3 vert, bool l){
     if (vert == lastVert) {
     } else {
       if (l) {
         vertCount++;
       }
     }
     triangles.Add(vertCount);
     GameObject g = GameObject.CreatePrimitive(PrimitiveType.Cube);
     g.transform.position=vert;
     g.name = vertCount.ToString ();
     vertices.Add (vert);
     legal.Add (l);
     lastVert = vert;
   }

}

Here is the method i use to draw the lines between the vertices as shown in attachement 2

     private void generateMeshStrip(MeshBuffer left, MeshBuffer right){
       List<int> tris = new List<int> ();
       List<Vector3> vertsl = new List<Vector3> ();
       List<Vector3> vertsr = new List<Vector3> ();
       List<int> indexl = new List<int> ();
       List<int> indexr = new List<int> ();
       for(int i = 0; i<left.legal.Count-1; i++){
         if(left.legal[i]){
           indexl.Add(vertsl.Count);
           vertsl.Add(left.vertices[i]);
         }
         else{
           if(i<left.legal.Count-1){
             if(left.legal[i+1]){
               indexl.Add(vertsl.Count);              
             }
             else{
               indexl.Add(vertsl.Count-1);            
             }
           }
           else{
             indexl.Add(vertsl.Count-1);
           }
         }
         if(right.legal[i]){
           indexr.Add(vertsr.Count);
           vertsr.Add(right.vertices[i]);
         }
         else{
           if(i<left.legal.Count-1){
             if(right.legal[i+1]){
               indexr.Add(vertsr.Count);              
             }
             else{
               indexr.Add(vertsr.Count-1);            
             }
           }
           else{
             indexr.Add(vertsr.Count-1);
           }

         }
       }


       for (int j = 0; j<indexl.Count; j++) {
         draw(vertsl[indexl[j]],vertsr[indexr[j]],j.ToString());
       }
     }

I just need a method to get the lines right or a direct method to create the mesh.
Im working on this since more than a day without any result which drives me insane because mesh creation for this shouldnt be that hard i guess.
I think I need a different point of view on my approach.
PLEASE HELP ME :frowning: :frowning:

UPDATE
[EDIT] SOLVED

Got the thing with the lines right (

) but my mesh isnt displayed right ( )…

I also changed the Add method of my MeshBuffer:

  public void Add(Vector3 vert, bool l, int o){
     otherside.Add (o);
     triangles.Add(vertCount);
     GameObject g = GameObject.CreatePrimitive(PrimitiveType.Cube);
     g.transform.position=vert;
     vertices.Add (vert);

     g.name = vertCount.ToString () +" - "+ l.ToString ();

     legal.Add (l);
//NEW
     if (legal.Count > 1&&l) {
//CHANGES THE LAST OF THE FALSE VALUES TO TRUE
//(CUBES ARE DISPLAYING THEM WRONG IN THEIR NAME)
       legal [legal.Count - 2] = true;
     }
//
     if (l) {
       vertCount++;
    
     }
   }

I also made a change in my drawHull() method by deleting the Add instruction in the intersection area and an iteration of the vertCount in the i=iIndex if bracket.

vertCount which represents the amount of unique vertices is equal to the amount of true entries in the List legal of the MeshBuffer class

Vertices are added if the mapped boolean value is true;

Seeems like lot of the vertices is unasigned and at 0,0,0 tho…

    private void test(MeshBuffer l, MeshBuffer r){


       int legalR = 0;
       int legalL = 0;
       //DRAW LINES BETWEEN VERTS
       for(int k = 0; k<l.legal.Count; k++){
         draw(l.vertices[k]+Vector3.up,r.vertices[k],k.ToString()+" l: "+l.legal[k].ToString()+" r: "+r.legal[k].ToString());
         if(l.legal[k]){
           legalL++;
         }
         if(r.legal[k]){
           legalR++;
         }
       }

       Debug.Log ("#true in l.legal: " + legalL + " l.vertCount+1: " + (l.vertCount) + " #true in r.legal: " + legalR + " r.vertCount+1: " + (r.vertCount ));

       //GENERATE MESH
       int i = 0;
       List<int> tris = new List<int> ();
       Vector3[] verts = new Vector3[l.vertCount + r.vertCount];
       int offset = l.vertCount;
       int h = 0;
       int j = offset;
       while (i<l.triangles.Count-1) {
         int tri1_0 = l.triangles[i];
         int tri1_1 = l.triangles[i+1];
         int tri1_2 = r.triangles[i+1];
        
         if(tri1_0!=tri1_1){
           tris.Add(tri1_0);
           tris.Add(tri1_1);
           tris.Add(tri1_2+offset);
         }

         int tri2_0 = l.triangles[i];
         int tri2_1 = r.triangles[i+1];
         int tri2_2 = r.triangles[i];

        
         if(tri2_1!=tri2_2){
           tris.Add(tri2_0);
           tris.Add(tri2_1+offset);
           tris.Add(tri2_2+offset);
         }
         if(l.legal[i]){
           verts[h]=l.vertices[l.triangles[i]];
           h++;
         }
         if(r.legal[i]){
           verts[j]=r.vertices[r.triangles[i]];
           j++;
         }
         i++;
       }


       int[] triangles = new int[tris.Count];
       for(int k = 0; k<tris.Count; k++){
         triangles[k]=tris[k];
       }
      
       Mesh m = new Mesh();
       m.vertices=verts;
       m.triangles=triangles;
       GameObject test = new GameObject();
       test.AddComponent<MeshFilter>();
       test.AddComponent<MeshCollider>();
       test.GetComponent<MeshFilter>().mesh=m;
       test.GetComponent<MeshCollider>().sharedMesh=m;
       test.AddComponent<MeshRenderer>();

     }