C# - How do I create a mesh between each set of 4 points in an array?

I have a method which takes in 4 vector3’s and then draws a triangulated mesh between them. I want to be able to pass in an array of vector3’s, with each set of 4 representing a separate mesh. how do I iterate through the array and create a mesh for each set of 4 points?

I assume this is what Unity does when you set a meshes triangles as that’s a single array with every 3 elements representing a triangle?

Thanks, Mike

Typed straight into this post, so completely untested, but I’d probably use something like this:

// Ensure the array consists of an equal number of 4-element sets
if (vectorArray.Length == 0 || vectorArray.Length % 4 != 0)
{
   // Invalid array length, don't pass go!
   return;
}

for (int i = 0; i < vectorArray.Length; i++)
{
   Vector3 vect1 = vectorArray[i];
   Vector3 vect2 = vectorArray[++i];
   Vector3 vect3 = vectorArray[++i];
   Vector3 vect4 = vectorArray[++i];
  // Create mesh using the above vectors...
}

So you’ve already got the function that takes 4 points and makes a mesh?

Can we assume the points in the array are in groups of four? Or is there some other way of identifying which ones should be adjacent in the mesh?

In Unity when setting meshes, you set an array of vertices, (Essentially, your vector3s are identifying the vertices.) and then the triangles are indexes of those vertices, listed in groups of three to identify which vertices should be connected in the mesh.

Cheers, that’s exactly what I was looking for :slight_smile: