I am following this tutorial to generate a terrain mesh, and converting it to C#.
I am getting an error:
scene/resources/mesh.cpp:354 - Condition "index >= vc" is true. Returning: Ref<TriangleMesh>()
This happens twice upon generation.
The geometry is also completely wrong:
And here:
And finally, here is my code:
` private void generateChunk()
{
var aMesh = new ArrayMesh();
var surfTool = new SurfaceTool();
surfTool.Begin(Mesh.PrimitiveType.Triangles);
var vertexCount = 0;
for (int x = 0; x <= chunkSize; x++)
{
int y = 0;
for (int z = 0; z <= chunkSize; z++)
{
var pos = new Vector3(x, y, z);
surfTool.AddVertex(pos);
vertexCount++;
drawDebugSphere(pos);
}
}
int index = 0;
for (int x = 0; x <= chunkSize; x++)
{
int y = 0;
for (int z = 0; z <= chunkSize; z++)
{
surfTool.AddIndex(index + 0);
surfTool.AddIndex(index + 1);
surfTool.AddIndex(index + chunkSize + 1);
surfTool.AddIndex(index + chunkSize + 1);
surfTool.AddIndex(index + 1);
surfTool.AddIndex(index + chunkSize + 2);
index++;
}
//index++;
}
GD.PushWarning($"Vertex count: {vertexCount}, Index count: {index * 6}");
//surfTool.GenerateNormals();
aMesh = surfTool.Commit();
Mesh = aMesh;
}
`
Any help would be greatly appreciated!
- DrBellubins