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();
立方体を表示すると、半分しか表示されず、一部の面が表示されません。インデックスバッファに問題があると思われますが、修正方法がわかりません。
本当に助けが必要です。皆さんありがとう。