modModel = Content.Load<Model>("Cube1");
foreach (ModelMesh modmModel in modModel.Meshes)
{
foreach (ModelMeshPart mmpModel in modmModel.MeshParts)
{
modelExtractor = new ModelExtractor(mmpModel, new Vector3[mmpModel.NumVertices * 2], new VertexPositionColor[mmpModel.NumVertices]);
modelExtractor.ExtractVertices();
}
}
for (int a = 0; a < modelExtractor.ArrVectors.Length; a++)
{
Console.WriteLine(modelExtractor.ArrVectors[a]);
}
vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), modelExtractor.VpcVertices.Length, BufferUsage.None);
vertexBuffer.SetData(modelExtractor.VpcVertices);
This is from the main class. This is how I converted the Model into a ModelMeshPart. I didn't make a vertex buffer until after I extracted the data from the .fbx. The for loop (and the line of code inside of it) gives you a list of the extracted vertex data by writing it to the console window.
private ModelMeshPart mmpModel;
private Vector3[] arrVectors;
private VertexPositionColor[] vpcVertices;
These are the fields of my ModelExtractor class. They are used by the following method.
public void ExtractVertices()
{
this.mmpModel.VertexBuffer.GetData<Vector3>(this.arrVectors);
for (int a = 0; a < vpcVertices.Length; a += 2)
{
this.vpcVertices[a].Position.X = arrVectors[a].X;
this.vpcVertices[a].Position.Y = arrVectors[a].Y;
this.vpcVertices[a].Position.Z = arrVectors[a].Z;
}
}
I extracted data of type "Vector3". Every vertex in the .fbx has a Vector3 for posistion and another for the normal. Only then do I move the position component by component from the array of Vector3s to an array of VertexPositionColors. Notice that the for loop increments "a" by 2 instead of 1. This is so that I can skip over the Vector3s for the normals.