【问题标题】:Obj loader in directX 9directX 9 中的对象加载器
【发布时间】:2012-04-26 21:36:05
【问题描述】:

我写了一个程序来在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();

当我显示一个立方体时,它只显示了一半,并且缺少一些面。 我怀疑是索引缓冲区有问题,但我不知道如何解决。

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

【问题讨论】:

    标签: indexing directx mesh vertex wavefront


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      相关资源
      最近更新 更多