Ich habe ein Programm geschrieben, um eine obj-Datei in directx 9 zu laden. Ich lese nur die Vertex-Daten und die Indexdaten aus der Datei (ich habe keine Textur- oder Vertex-Normaldaten gelesen). Dann stecke ich diese Daten direkt in die Vertex- und Indexpuffer.Obj loader in directX 9
Wenn ich den Code ausführen, werden die Objekte gerendert, aber sie haben nicht die richtige Form. Das Netz wird verformt. Hier ist mein Code -
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();
Wenn ich einen Würfel angezeigt werden, zeigt es nur die Hälfte davon, und einige der Gesichter fehlen. Ich glaube, es ist ein Problem mit dem Index-Puffer, aber ich weiß nicht, wie es zu beheben ist.
Ich brauche wirklich Hilfe. Danke allen.