So,I'm trying to load a model with assimp,but the resulting model is messed up really bad.
Keep in mind that right now all I use is a vertex position and a vertex normal(no texture coords)
This is the code that creates the vertex/index buffers and fills them.
void testt::build(){
const aiScene* scene;
scene = aiImportFile("C:\\Program Files (x86)\\Microsoft DirectX SDK (June 2010)\\Samples\\Media\\Dwarf\\Dwarf.x", aiProcess_MakeLeftHanded |
aiProcess_FlipWindingOrder);
total_vertices = 0;
total_indices = 0;
for (long long i = 0; i < scene->mNumMeshes; i++){
total_vertices += scene->mMeshes[i]->mNumVertices;
total_indices += scene->mMeshes[i]->mNumFaces * 3;
}
Devil_Room::Brain::pDevice->CreateVertexBuffer(total_vertices * sizeof(Devil_Room::Vertex), D3DUSAGE_WRITEONLY, D3DFVF_XYZ | D3DFVF_NORMAL, D3DPOOL_DEFAULT, &vb, NULL);
Devil_Room::Brain::pDevice->CreateIndexBuffer(sizeof(DWORD32)* total_indices, D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT,
&ib, NULL);
int nr_meshes;
int nr_textures;
long long nr_ofAddedvertices = 0;
long long nr_ofAddedindices = 0;
nr_meshes = scene->mNumMeshes;
for (long long i = 0; i < nr_meshes; i++){
Vertex* vertices = new Vertex[scene->mMeshes[i]->mNumVertices];
for (long long x = 0; x < scene->mMeshes[i]->mNumVertices; x++){
const aiVector3D* pPos = &(scene->mMeshes[i]->mVertices[x]);
const aiVector3D* pNormal = &(scene->mMeshes[i]->mNormals[x]);
vertices[x].x = pPos->x;
vertices[x].y = pPos->y;
vertices[x].z = pPos->z;
vertices[x].Normal.x = pNormal->x;
vertices[x].Normal.y = pNormal->y;
vertices[x].Normal.z = pNormal->z;
}
Vertex* vt;
vb->Lock(nr_ofAddedvertices * sizeof(Vertex),
(total_vertices - nr_ofAddedvertices) * sizeof(Vertex),
reinterpret_cast<void**>(&vt), 0);
for (long long x = 0; x < scene->mMeshes[i]->mNumVertices; x++){
vt[x] = vertices[x];
}
nr_ofAddedvertices += scene->mMeshes[i]->mNumVertices;
vb->Unlock();
DWORD32 * indices = new DWORD32[scene->mMeshes[i]->mNumFaces * 3];
long long pos_ind = 0;
for (long long z = 0;z < scene->mMeshes[i]->mNumFaces; z++) {
const aiFace& Face = scene->mMeshes[i]->mFaces[z];
indices[pos_ind++] = Face.mIndices[0];
indices[pos_ind++] = Face.mIndices[1];
indices[pos_ind++] = Face.mIndices[2];
}
unsigned long* vtt;
ib->Lock(nr_ofAddedindices * sizeof(DWORD32),
total_indices - nr_ofAddedindices * sizeof(DWORD32),
reinterpret_cast<void**>(&vtt), 0);
for (int x = 0; x < scene->mMeshes[i]->mNumFaces * 3; x++){
vtt[x] = indices[x];
}
nr_ofAddedindices += scene->mMeshes[i]->mNumFaces * 3;
ib->Unlock();
delete[] vertices;
delete[] indices;
}
}