Problems with ProceduralMeshComponent

I have been trying to import an FBX file and generate a cylinder procedurally using the following code:

int32 numberOfVertices = importedMesh->GetControlPointsCount();
int32 numberOfTriangles = importedMesh->GetPolygonCount();

int32 iteratorCount=0;
while (iteratorCount < numberOfTriangles)
{
	triangles.Add(iteratorCount);
	++iteratorCount;
}

iteratorCount=0;
while (iteratorCount < numberOfVertices)
{
       vertices.Add(FVector(fbxVector4iterator->mData[0], fbxVector4iterator->mData[1], fbxVector4iterator->mData[2]));
       vertexColors.Add(FColor(100, 100, 100, 100));
       ++iteratorCount;
}

mesh->CreateMeshSection(count, vertices, triangles, normals, UV0, vertexColors, tangents, false);
mesh->SetMobility(EComponentMobility::Movable);			
mesh->AttachTo(RootComponent);

The normals, UV0, tangents are null TArrays.

The generated mesh looks like this:

I’m not sure why this is happening. Does anyone know where I’m going wrong?

Thanks!

At a glance it looks like you’re making your triangles incorrectly. The triangles array is a list of indices related to the vertex array.

Fill the vertex array, then for each triangle you need, add each vertex’s index to the triangle array.

For instance, if you have 3 vertices in the vertex array at index 0,1,2, the triangle array would have values 0,1,2 as the first three items of its array.

You look like you’re just filling your triangle array with a series of sequential numbers…

For each triangle polygon, you’ll have three elements in your triangle array.

Yup, that was pretty a stupid mistake.
Thanks, Brandelan!