MDX: Accessing the vertices/indices from a Mesh

Recommended Posts

I know you're supposed to use Mesh.LockVertexBuffer() and Mesh.LockIndexBuffer() but they are both returning nothing, even though the mesh is loaded correctly.
Mesh X = Mesh.FromFile( @"C:\car.x", MeshFlags.Dynamic, Device );
if( X != null )
{
Vertex[] Vertices = (Vertex[])X.LockVertexBuffer( typeof(Vertex), LockFlags.None, 0 );
ushort[] Indices = (ushort[])X.LockIndexBuffer( typeof(ushort), LockFlags.None, 0 );
}

What am I doing wrong?

Share on other sites
Gage64    1235
Are you sure that the vertex format of the mesh's vertices is the same as the Vertex struct? Also, are you sure you can pass zero for the third parameter (I ask because I don't quite understand how it's used from the documentation)?

Does it work if you use the overload that returns a GraphicsStream?

Share on other sites
The vertex and index formats were both correct, but in any case I just now tried the GraphicsStream method instead, and it works correctly.