I am trying to write a custom importer which will create and add a bounding box to a model at load time. I am having difficulty converting all the original Model BoundingBox code over to ModelContent.
Specifically, this part:
foreach (ModelMeshPart meshPart in mesh.MeshParts)
{
// Vertex buffer parameters
int vertexStride = meshPart.VertexBuffer.VertexDeclaration.VertexStride;
int vertexBufferSize = meshPart.NumVertices * vertexStride;
// Get vertex data as float
float[] vertexData = new float[vertexBufferSize / sizeof(float)];
meshPart.VertexBuffer.GetData<float>(vertexData);
// Iterate through vertices (possibly) growing bounding box, all calculations are done in world space
for (int i = 0; i < vertexBufferSize / sizeof(float); i += vertexStride / sizeof(float))
{
Vector3 vertexVector = new Vector3(vertexData[i], vertexData[i + 1], vertexData[i + 2]);
min = Vector3.Min(min, Vector3.Transform(vertexVector, _boneTransforms[mesh.ParentBone.Index]));
max = Vector3.Max(max, Vector3.Transform(vertexVector, _boneTransforms[mesh.ParentBone.Index]));
}
}
How do I convert the VertexData[byte] from a ModelMeshPartContent (from the pipeline) into a VertexData[float] which is what we normally get from a ModelMeshPart?
Do I assume every 4 bytes in the VertexData byte array is 1 float?
Thanks!