Filling the space between bezier curves with a texture,

I want to dynamically draw 2D road segments in Unity with scripts. Each segment is defined by 4 points and the required control points to draw bezier curves. This means a segments outer shape consists of 2 “ends” wich are just simple lines, and 2 bezier curves.

I am using this GitHub - dbrizov/NaughtyBezierCurves: Bezier Curve Game Object for Unity to create the bezier curves. This results into an outer shape of a segment like this:

Creating the outer shape of a segment is pretty simple. Now I want to fill the segment with a texture. I dont know how I can create planes or a mesh with the same shape as the outer shape of the segment. This is what I want to achive:


I first thought about going along the bezier curves and creating slim splanes all along the curve, but this would lead to overlapping or gaps between them. Plus, I dont know how to orient the planes towards the other curve.

Maybe someone has a simple solution how I can add a texture to the road with a script.

,

[151214-ddd.png*_|151214]

Discretize your curves into two point lists. Build the mesh like this (Not tested but should not be too wrong):

// Discretize the curves
// You have verticesOnCurve1[n] and verticesOnCurve2[n]
// float width is your road's width

//// Vertices ////
List<Vector3> vertexBuffer = new List<Vector3>();
for (int i = 0; i < n; i++) {
    vertexBuffer.Add(verticesOnCurve1*); // Top points*

}
for (int i = 0; i < n; i++) {
vertexBuffer.Add(verticesOnCurve2*); // Bottom points*
}

//// Indices ////
List indexBuffer = new List();
for (int i = 0; i < n - 1; i++) {
indexBuffer.Add(i);
indexBuffer.Add(i + 1);
indexBuffer.Add(n + i);
indexBuffer.Add(n + i);
indexBuffer.Add(i + 1);
indexBuffer.Add(n + i + 1);
}

//// UVs ////
List pointMileages = new List(); // Mileages are calculated from the top curve
pointMileages.Add(0); // Starting point
for (int i = 1; i < n; i++) {
var distance = (verticesOnCurve1 - verticesOnCurve1[i - 1]).magnitude;
pointMileages.Add(pointMileages[i - 1] + distance); // Other points
}
List uvs = new List();
for (int i = 0; i < n; i++) {
uvs.Add(new Vector2(pointMileages / width, 0)); // Top points
}
for (int i = 0; i < n; i++) {
uvs.Add(new Vector2(pointMileages / width, 1)); // Bottom points
}
_*