I’ve been trying to pull the verices, UVs, triangles & Vertex Normals from a UStaticMesh. With mixed results. Anybody out there actively understand the layout of FStaticMeshLODResources?
Here’s what I’ve found so far:
Vertices
GetNumVertices() ← returns how many there are
PositionVertexBuffer.VertexPosition() ← returns a vertex
Thing is I get far, far, far more vertices than I would expect with many vertices duplicated many times
Normals
Engine code pulls them with .VertexBuffer.VertexTangentZ()
However if I link that call into my game I get :
error LNK2001: unresolved external symbol "__declspec(dllimport) union __m128 const GVectorPackingConstants" (__imp_?GVectorPackingConstants@@3T__m128@@B)
UVs
Seem relatively straight forward with VertexBuffer.GetVertexUV() but again, due to the duplicated vertices, I have lots of UVs. Plus I have 4 UV sets for a simple texture mapped piece of geometry.
Triangles
Engine code pulls these (FBXMainExport.cpp line 1800) with:
TArray<uint32> Indices;
for (int32 PolygonsIndex = 0; PolygonsIndex < PolygonsCount; ++PolygonsIndex)
{
FIndexArrayView RawIndices = RenderMesh.IndexBuffer.GetArrayView();
FStaticMeshSection& Polygons = RenderMesh.Sections[PolygonsIndex];
const uint32 TriangleCount = Polygons.NumTriangles;
for (uint32 TriangleIndex = 0; TriangleIndex < TriangleCount; ++TriangleIndex)
{
for (uint32 PointIndex = 0; PointIndex < 3; PointIndex++)
{
uint32 UnrealVertIndex = RawIndices[Polygons.FirstIndex + ((TriangleIndex * 3) + PointIndex)];
}
}
}
However when I run that in my code the triangle list comes out as 0,1,2,3,4,5,6,7,8. Is that why there are so many vertices because there is a vert / triangle?
I’m just wondering
- Why are there so many verts?
- Why can’t I VertexBuffer.VertexTangentZ (why is it Z?) and how do I link in GVectorPackingConstants?
- Why are there so many UVs?
- Why does a hierarchical mesh of 4 pieces seem to get welded into one single piece when I look at it in UStaticMesh?
- Why is my triangle indices increasing by 1 each time from 0, i.e. 0,1,2,3,4
- Are there any experts out there that understand this data structure and how to decypher it?