I'm trying to grab the vertex position data from an fbx file, for testing I'm using a simple plane, it lies in the xz plane and it's 4 vertices are (+/-1, 0, +/-1). The vertex data is confirmed in Maya, which I used to export the plane.
Here's my vertex extraction code:
void getVertices()
{
foreach (ModelMesh mesh in model.Meshes)
foreach (ModelMeshPart part in mesh.MeshParts)
{
nVerts = part.NumVertices;
Vector3[] vec = new Vector3[nVerts * 2];
part.VertexBuffer.GetData<Vector3>(vec);
Console.WriteLine("#Vertices in Model: " + nVerts);
for (int i = 0; i < vec.Length; i++)
{
Console.WriteLine(i + " " vec[i].ToString());
}
}
}
Since there are 4 vertices, I get 8 Vector3s, 1 for each vertex position and one for each vertex normal. For the plane MOST are correct (I used more complicated models at first and it was less accurate).
Here are the results: all the normals should point straight up in Y.
Points: (1,0,-1) (1,0,1) (1,0,1) (-1,0,1)
Normals (0,1,0) (0,1,0) (1,-1,0) (0,0,0)
The third point, (the same as the 2nd) and the final 2 normals are wrong. I can't figure out why I am not getting the right data. I've tried increasing the vector3 array, but it only has 8 vectors to send, so i don't think I'm missing any info.
Assuming you loaded the FBX through the content pipeline, it would have assigned it one of the frameworks standard vertex types. But there is no vertex type that has only position and normal information. Most likely there is a 3rd element that is screwing up your results. This should work:
int vertexStride = model.Meshes[0].MeshParts[0].VertexDeclaration.VertexStride;
VertexBuffer vb = model.Meshes[0].MeshParts[0].VertexBuffer;
List<Vector3> vertexPositions = new List<Vector3>();
for(int i = 0; i < vb.VertexCount; i++)
{
Vector3 vec;
vb.GetData<Vector3>(i*vertexStride, vec, i, 1, vertexStride);//3rd param should either be i or 0
vertexPositions.Add(vec);
}