MDX: Accessing the vertices/indices from a Mesh

Started by
1 comment, last by CGameProgrammer 16 years, 8 months ago
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?
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
Advertisement
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?
The vertex and index formats were both correct, but in any case I just now tried the GraphicsStream method instead, and it works correctly.
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement