# procedural generation – Splitting the mesh of a plane into submeshes

I am struggling a bit with this. I am trying to split a plane recursively into subplanes, so that frustum culling is more efficient. I am doing that by dividing the indices into the 4 subplanes for every iteration. The Problem: I do not understand why it is working perfectly for two submeshes, but the other two are …something.

First iteration working as intended:

Second iteration only working for submeshes 2 and 4, but their no.1 and 3 submeshes are not reproducing what is seen for no. 1 and 3 of iteration 1:

Code:

Generating the plane:

``````private void GeneratePlane()
{

int indexpointer = 0;

for (int y = 0; y < resolution; y++)
{
for (int x = 0; x < resolution; x++)
{

int i = x + y * resolution;

Vector2 percent = new Vector2(x, y) / (resolution - 1);

Vector3 cubeVertex = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB;

vertices[i] = cubeVertex;

if (x != resolution - 1 && y != resolution - 1)
{
indices[indexpointer] = i;
indices[indexpointer + 1] = i + resolution + 1;
indices[indexpointer + 2] = i + resolution;

indices[indexpointer + 3] = i;
indices[indexpointer + 4] = i + 1;
indices[indexpointer + 5] = i + resolution + 1;
indexpointer += 6;
}
}
}

}
``````

Splitting the indices:

``````private void SubdividePlane(int[] indices, int subdivisionRecursions, int resolution)
{
if (subdivisionRecursions == 0 || indices.Length <= 6)
{
return;
}
else
{

List<int> sub1I = new List<int>();
List<int> sub2I = new List<int>();
List<int> sub3I = new List<int>();
List<int> sub4I = new List<int>();

int indexPointer = 0;
for (int y = 0; y < resolution-1; y++)
{
for (int x = 0; x < resolution-1; x++)
{
int pointer = x + y * resolution;

int[] vertexIndices = new int[6];
for (int i=0;i<6;i++){
vertexIndices[i] = indices[i+indexPointer];
}
indexPointer+=6;

if (x <=(resolution / 2) - 1 && y <= (resolution / 2)-1)
{

}
else if (x >= (resolution / 2)  && y <= (resolution / 2)-1 )
{

}
else if (x <= (resolution / 2)-1  && y >= (resolution / 2) )
{

}
else if (x >= (resolution / 2) && y >= (resolution / 2))
{

}
}
}

SubdividePlane(sub1I.ToArray(), subdivisionRecursions - 1, resolution / 2);
SubdividePlane(sub2I.ToArray(), subdivisionRecursions - 1, resolution / 2);
SubdividePlane(sub3I.ToArray(), subdivisionRecursions - 1, resolution / 2);
SubdividePlane(sub4I.ToArray(), subdivisionRecursions - 1, resolution / 2);
}
}
``````

Could be simply be due to the way I am setting the split-thresholds in the if-conditions?

## More To Explore

### 3 Best Reasons Why You Should Do Liveops for Your Game

By juegoadmin | Game Development | October 4th, 2021 In the past, a game’s post-release cycle followed this pattern: The game hits the stores. If