Indexing directX 9中的Obj加载程序

Indexing directX 9中的Obj加载程序,indexing,directx,mesh,vertex,wavefront,Indexing,Directx,Mesh,Vertex,Wavefront,我编写了一个程序来加载directx 9中的obj文件。我所做的就是从文件中读取顶点数据和索引数据(我没有读取任何纹理或顶点法线数据)。然后我将这些数据直接插入顶点和索引缓冲区 当我运行代码时,对象被渲染,但它们不是正确的形状。网格变形。这是我的密码- D3DXCreateMeshFVF( index_size, // NumFaces vertex_size, // NumVertices D3DXMESH_MANAGED, // Options D3

我编写了一个程序来加载directx 9中的obj文件。我所做的就是从文件中读取顶点数据和索引数据(我没有读取任何纹理或顶点法线数据)。然后我将这些数据直接插入顶点和索引缓冲区

当我运行代码时,对象被渲染,但它们不是正确的形状。网格变形。这是我的密码-

D3DXCreateMeshFVF(
    index_size,  // NumFaces 
    vertex_size,  // NumVertices 
    D3DXMESH_MANAGED, // Options 
    D3DFVF_XYZ, // FVF 
    Device,  // The Device 
    &Mesh[id].MeshData);  // The Mesh 

VOID* pVertices; 
// Copy the vertices into the buffer 
Mesh[id].MeshData->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&pVertices);

memcpy( pVertices, VertexData, vertex_size*sizeof(FLOAT)*3); // VertexData is the vertex data that I obtained form the obj file

// Unlock the vertex buffer 

 Mesh[id].MeshData->UnlockVertexBuffer();

// Prepare to copy the indices into the index buffer 

VOID* IndexPtr;

// Lock the index buffer

 Mesh[id].MeshData->LockIndexBuffer( 0, &IndexPtr );

// Check to make sure the index buffer can be locked 

// Copy the indices into the buffer

 memcpy( IndexPtr, IndexData, index_size*sizeof(WORD));// IndexData is the list of indices I obtained form he obj file.

// Unlock the buffer 

Mesh[id].MeshData->UnlockIndexBuffer();
当我显示一个立方体时,它只显示它的一半,并且缺少一些面。 我想这是索引缓冲区的问题,但我不知道如何解决它

我真的需要帮助。
谢谢大家。

我现在没有时间阅读代码,但据我记忆所及,.obj文件中的索引数据不是从0开始的,而是从1开始的。我的意思是,一旦加载所有索引数据,就应该在每个索引中减去-1

如果将.OBJ与.X文件进行比较,您将看到索引数据之间的差异