I had to do this myself recently and there wasn’t any decent answer online so I’m going to post my findings here for future reference, although you probably moved on and hopefully had a solution.
There is two different set of vertices you can obtain from the UStaticMesh class. One is from the the RenderData class which Rama explains here. The problem with this, is that I found extra vertices on the mesh when compared to the model is loaded in Maya; which I believe is explained here.
The second way is through the FRawMesh struct, which stores the mesh data as it was from Maya or whatever modelling software you use. The FRawMesh and equally important FRawMeshBulkData are both in the RawMesh.h header file and are apart of the RAWMESH api so you will need to include RAWMESH in your module dependencies.
Here’s code of the function I needed the raw mesh data for as an example of it in use. I probably do a few stupid things in here so please correct me if something is not optimal.
#if WITH_EDITORONLY_DATA
void ExtractMeshInfo(UStaticMesh *_mesh, UCurveLinearColor *_curve) // I dump the info into a Linear Color Curve because the Vector curve contains the Minimal_API macro, hopefully I'll find a use for the extra float.
{
// Check that the mesh passed in is a valid mesh, valid meaning contains no junk data that would cause a crash
if (!_mesh->IsValidLowLevel())
return;
if (&_mesh->SourceModels[0] == nullptr)
return;
// Load up and access information from the SourceModel used for LOD0
FStaticMeshSourceModel *sourceModel = &_mesh->SourceModels[0]; // The index corresponds to the LOD group
FRawMesh rawMesh;
sourceModel->RawMeshBulkData->LoadRawMesh(rawMesh); // This function loads bulk data into rawMesh and makes the data nice and accessible
// Will store vertex information in these variables
FVector vertPos;
uint32 vertices = rawMesh.VertexPositions.Num();
if (vertices > 0)
{
// Clear out any previously store data in the curve
_curve->FloatCurves[0].Reset();
_curve->FloatCurves[1].Reset();
_curve->FloatCurves[2].Reset();
_curve->FloatCurves[3].Reset();
for (uint32 ii = 0; ii < vertices; ++ii)
{
vertPos = rawMesh.VertexPositions[ii];
// Add the vertex information to the curve at a time which corresponds to the vertex's index
_curve->FloatCurves[0].AddKey(ii, vertPos.X);
_curve->FloatCurves[1].AddKey(ii, vertPos.Y);
_curve->FloatCurves[2].AddKey(ii, vertPos.Z);
}
}
}
#endif
edit: Just found this, which uses the same concept and helped me optimize this code.