   [DirectX 10/Assimp] Loader is not working
  Ive made a mesh loader using assimp based on a tutorial I saw somewhere. The program compiles and run without errors, but only a triangle of the mesh is rendered...Can you take a look and see what Ive done wrong?Loader function:ID3DX10Mesh* MeshLoader::importMesh(ID3D10Device* d3dDevice, std::string &file){ID3DX10Mesh* dxMesh;Vertex* vertices;UINT numVertices;UINT numTriangles;DWORD* indices;UINT* attributeBuffer;scene = importer.ReadFile( file,    aiProcess_CalcTangentSpace  |   aiProcess_Triangulate |   aiProcess_MakeLeftHanded |   aiProcess_JoinIdenticalVertices |   aiProcess_SortByPType |   aiProcess_CalcTangentSpace |   aiProcess_JoinIdenticalVertices |   aiProcess_GenSmoothNormals |   aiProcess_LimitBoneWeights |   aiProcess_RemoveRedundantMaterials |   aiProcess_OptimizeMeshes);if(!scene){MessageBox(NULL, "There is a mesh missing. Please try again or reeinstall the game.", "Mesh missing", MB_OK);PostQuitMessage(1);}D3D10_INPUT_ELEMENT_DESC vertexDesc[] ={{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},{"TANGENT",  0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},{"NORMAL",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 36, D3D10_INPUT_PER_VERTEX_DATA, 0},};aiMesh** meshes = scene->mMeshes;aiMaterial** materials = scene->mMaterials;UINT* meshID;UINT materialID;aiNode* sceneRoot = scene->mRootNode;aiNode** children = sceneRoot->mChildren;aiNode* child;UINT i = 0;bool rootNode = true;while(i < sceneRoot->mNumChildren){if(rootNode){child = sceneRoot;rootNode = false;} else{child = children;//child = sceneRoot;i++;}if(!(child->mNumMeshes > 0))continue;meshID = child->mMeshes;numVertices = meshes[meshID[0]]->mNumVertices;numTriangles = meshes[meshID[0]]->mNumFaces;vertices = new Vertex[numVertices];for(UINT  j = 0; j < meshes[meshID[0]]->mNumVertices; ++j)   {vertices[j].pos = aiVec3ToAqVector3(meshes[meshID[0]]->mVertices[j]);vertices[j].tangent = aiVec3ToAqVector3(meshes[meshID[0]]->mTangents[j]);vertices[j].normal = aiVec3ToAqVector3(meshes[meshID[0]]->mNormals[j]);vertices[j].texC = aiVec3ToAqVector2(meshes[meshID[0]]->mTextureCoords[0][j]);}D3DX10CreateMesh(d3dDevice, vertexDesc, 4, vertexDesc[0].SemanticName, numVertices, numTriangles, D3DX10_MESH_32_BIT, &dxMesh);dxMesh->SetVertexData(0, vertices);indices = new DWORD[numTriangles*3];attributeBuffer = new UINT[numTriangles];for(UINT j = 0; j < meshes[meshID[0]]->mNumFaces; j++){indices[j*3+0] = meshes[meshID[0]]->mFaces->mIndices[0];indices[j*3+1] = meshes[meshID[0]]->mFaces->mIndices[1];indices[j*3+2] = meshes[meshID[0]]->mFaces->mIndices[2];}dxMesh->SetIndexData(indices, numTriangles*3);dxMesh->SetAttributeData(attributeBuffer);dxMesh->GenerateAdjacencyAndPointReps(0.001f);dxMesh->Optimize(D3DX10_MESHOPT_ATTR_SORT|D3DX10_MESHOPT_VERTEX_CACHE,0,0);dxMesh->CommitToDevice();}delete[] vertices;delete[] indices;delete[] attributeBuffer;return dxMesh;}AqVector3 MeshLoader::aiVec3ToAqVector3(const aiVector3D& source){AqVector3 vector;vector.x = source.x;vector.y = source.y;vector.z = source.z;return vector;}AqVector2 MeshLoader::aiVec3ToAqVector2(const aiVector3D& source){AqVector2 vector;vector.x = source.x;vector.y = source.y;return vector;}[Edited by - Aqua Costa on April 18, 2010 4:47:42 AM]
  i'v noticed that u never fill attributeBuffer u just create and pass it, try to ZeroMemory on it or sett all it's values to 0after u done that try getting attribute table from mesh, c if it's correctmaybe try drawing mesh not like mesh->DrawSubset(0) more like mesh->DrawSubset(i)   ;  is it possible that there is more than one mesh in the file? check scene->mNumMeshes, maybe..   ;  I already found out the problem...This only sets the index of one face...[source lang=cpp"]indices[j*3+0] = meshes[meshID[0]]->mFaces->mIndices[0];indices[j*3+1] = meshes[meshID[0]]->mFaces->mIndices[1];indices[j*3+2] = meshes[meshID[0]]->mFaces->mIndices[2];And modified to this and now is working:indices[j*3+0] = meshes[meshID[0]]->mFaces[j].mIndices[0];indices[j*3+1] = meshes[meshID[0]]->mFaces[j].mIndices[1];indices[j*3+2] = meshes[meshID[0]]->mFaces[j].mIndices[2];Quote:Original post by e3d_ALiVEi'v noticed that u never fill attributeBuffer u just create and pass it, try to ZeroMemory on it or sett all it's values to 0after u done that try getting attribute table from mesh, c if it's correctmaybe try drawing mesh not like mesh->DrawSubset(0) more like mesh->DrawSubset(i)Im still finishing the loader   ;  By the way...If a mesh as more than one material, Assimp automatically divides the mesh into n sub-meshes (n = nº of different materials) so each sub-mesh has only one material.How do I attach each sub-mesh so into a complete mesh with n subsets?   ;  to attach sub mesh[aka subset] to ID3DXMesh(10) u have to edit either attribute table[1 attribute is a range for 1 submesh] or edit per vertex(what vertex goes to what submesh)attribute table editing is much easyfirst you create one mesh D3DX10CreateMesh, make sure that number vertices and indices can contain all submeshes. After you done, u either have to extract atribute table from assimp or somehow guessyou should look at AssimpView program[inside it they use ID3DXMesh and maybe fill it with subsets]   