Exporting OBJ file at runtime

Currently, I’m working on a plugin and part of this plugin is a standalone OBJ exporter that reads data from UStaticMesh or USkeletalMesh at runtime and save them to a file using FFileHelper::SaveStringToFile.

I’m reading the triangles indices like this:

//StaticMesh
FRawStaticIndexBuffer* indexBuffer = &staticMesh->RenderData->LODResources[0].IndexBuffer;
       TArray<int32> indices;
       for ( int32 i = 0; i < indexBuffer->GetNumIndices(); i++ )
        	indices.Add(  indexBuffer->GetArrayView()[i]  );

//SkeletalMesh
TArray<uint32> indices;
skeletalMeshComponent->GetSkeletalMeshResource()->LODModels[0].MultiSizeIndexContainer.GetIndexBuffer( indices );

The exporter is almost done but I still cannot figure out how to get the proper material name/index for each triangle:

usemtl **MaterialName1**      //??
f 1/1 5281/2 5283/3 5282/4
f 5281/2 1321/5 1763/6 5283/3
f .....
.
.
.
usemtl **MaterialName2**     //??
f 121/12 1773/26 5287/27 1766/13
f 1773/26 445/28 1774/29 5287/27
f .....

FStaticMeshSection and FSkelMeshSection have MaterialIndex but they don’t have any data about the triangles that have been included in the section. There are also some interesting variables like BaseIndex, TriangleSorting, NumTriangles but I have no idea how to get the triangle indices from them.

Any help would be greatly appreciated.

I’m finding myself in the same position, did you make any progress on this?