Edit: TL;DR All of the objects in the picture should be spheres, but they triangles are messed up for some reason.
I’m using the UProceduralMeshComponent to create a large mass out of spheres. The way I went about it is by taking a sphere that has been imported into the engine and reading all of the vertex and index data out of it. Then I use that list of verts and indices as a template to create small spheres in specific locations, but all as one mesh. When it renders to the screen though, I get this:
Here are the code snippet for moving the vertices to where I need them:
void UModelLoader::MoveSphere(FVector& centerpoint)
{
if (uAssetSphere)
{
sphere = PROCEDURAL_SHAPE_DESCRIPTION();
for (uint32 i = 0; i < uAssetSphere->RenderData->LODResources[0].PositionVertexBuffer.GetNumVertices(); ++i)
{
sphere.vertices.Add(uAssetSphere->RenderData->LODResources[0].PositionVertexBuffer.VertexPosition(i) + centerpoint);
//sphere.UV0.Add(uAssetSphere->RenderData->LODResources[0].VertexBuffer.GetVertexUV(i, 0));
//sphere.normals.Add(uAssetSphere->RenderData->LODResources[0].VertexBuffer.VertexTangentZ(i));
//sphere.vertexColors.Add(FLinearColor(1, 1, 1, 1));
//sphere.tangents.Add(FProcMeshTangent(uAssetSphere->RenderData->LODResources[0].VertexBuffer.VertexTangentX(i).X, uAssetSphere->RenderData->LODResources[0].VertexBuffer.VertexTangentX(i).Y, uAssetSphere->RenderData->LODResources[0].VertexBuffer.VertexTangentX(i).Z));
}
for (int i = 0; i < uAssetSphere->RenderData->LODResources[0].IndexBuffer.GetNumIndices(); ++i)
{
sphere.Triangles.Add(uAssetSphere->RenderData->LODResources[0].IndexBuffer.GetArrayView()[i]);
}
}
}
This is the code snippet for creating the submesh based on my stored vert data:
for (auto iter : atomGroups->GetAtoms())
{
ATOM_MESH_DESCRIPTION thisModel;
int totalNumberOfTris = 0;
for (int i = 0; i < iter.Value.Num(); ++i)
{
//thisModel.normals += iter.Value[i].atomMesh.normals;
//thisModel.tangents += iter.Value[i].atomMesh.tangents;
thisModel.vertices += iter.Value[i].atomMesh.vertices;
//thisModel.vertexColors += iter.Value[i].atomMesh.vertexColors;
//thisModel.UV0 += iter.Value[i].atomMesh.UV0;
for (int eachTri = 0; eachTri < iter.Value[i].atomMesh.Triangles.Num(); ++eachTri)
{
thisModel.Triangles.Add(iter.Value[i].atomMesh.Triangles[eachTri] + totalNumberOfTris);
}
totalNumberOfTris = thisModel.Triangles.Num();
}
mesh->CreateMeshSection_LinearColor(counter, thisModel.vertices, thisModel.Triangles, TArray<FVector>(), TArray<FVector2D>(), TArray<FLinearColor>(), TArray<FProcMeshTangent>(), false);
mesh->SetMaterial(counter, materials[counter]);
/*if (counter != 0)
mesh->SetMeshSectionVisible(counter, false);*/
++counter;
}