I'm trying to load the improved version of the sponza model, using Assimp.
Right now I managed to load 2 models correctly ( *.obj format for now ). Once it comes to the sponza model the triangle rendering is messy, in that it seems that maybe the index buffers are wrong or I don't know what really is. I'm not sure if it's because I specified too few aiProcess_xxx to the Assimp importer.
I'll put the source code of my importer, which I think could be useful to
understand why it's not working properly and a screenshot of the wrong rendering results.
screen (I just show one mesh of the whole model for simplicity, which is represented from some arches etc.):
code:
bool importAsset( const std::string& pFile , std::vector<renderable_t*>& renderablesList ) { // Create an instance of the Importer class Assimp::Importer importer; // And have it read the given file with some example postprocessing // Usually - if speed is not the most important aspect for you - you'll // propably to request more postprocessing than we do in this example. const aiScene* scene = importer.ReadFile( pFile, aiProcess_Triangulate | aiProcess_OptimizeMeshes | aiProcess_SplitLargeMeshes | aiProcess_FindDegenerates | aiProcess_FindInvalidData | aiProcess_CalcTangentSpace | aiProcess_ImproveCacheLocality | aiProcess_FlipUVs | aiProcess_MakeLeftHanded | aiProcess_SortByPType ); // If the import failed, report it if( !scene) { //DoTheErrorLogging( importer.GetErrorString()); return false; } // Now we can access the file's contents. doTheSceneProcessing(scene,renderablesList); // We're done. Everything will be cleaned up by the importer destructor return true; } void doTheSceneProcessing( const aiScene* pScene,std::vector<renderable_t*>& renderablesList ) { //renderer interface IRenderer* pRenderer = CRenderManager::getInst().getRenderer(); MYASSERT( pRenderer ); const aiMesh* mesh = 0; //mesh const aiMaterial* material = 0; //material std::vector<WORD> indexArray; std::vector<vertexPTC0NTG_t> vertexArray; renderable_t* renderable = 0; //a renderable material_t myMaterial; //a given mesh material ZeroMemory(&myMaterial,sizeof(material_t)); myMaterial.uv_mapping[0] = 1.f; myMaterial.uv_mapping[1] = 1.f; const aiNode* rootNode = pScene->mRootNode; for(UINT c=0;c<rootNode->mNumChildren;++c) { aiNode* pChild = rootNode->mChildren[c]; if( pScene->HasMeshes() ) { for(UINT i=0;i<pChild->mNumMeshes;++i) { renderable = new renderable_t; //allocate a renderable mesh = pScene->mMeshes[pChild->mMeshes]; for(UINT j=0;j<mesh->mNumFaces;++j) //iterate through all faces and store indices { int i0 = mesh->mFaces[j].mIndices[0]; int i1 = mesh->mFaces[j].mIndices[1]; int i2 = mesh->mFaces[j].mIndices[2]; indexArray.push_back( i0 ); indexArray.push_back( i1 ); indexArray.push_back( i2 ); } vertexArray = std::vector<vertexPTC0NTG_t>(mesh->mNumVertices); for(UINT j=0;j<mesh->mNumVertices;++j) //iterate through all vertices { vertexArray[j].position = D3DXVECTOR3(&mesh->mVertices[j][0]); vertexArray[j].normal = D3DXVECTOR3(&mesh->mNormals[j][0]); if( mesh->mTangents ) vertexArray[j].tangent = D3DXVECTOR3(&mesh->mTangents[j][0]); if( mesh->mTextureCoords[0] ) vertexArray[j].uv = D3DXVECTOR2(&mesh->mTextureCoords[0][j][0]); } renderable->mIndexCount = mesh->mNumFaces*3; renderable->mVertexCount = mesh->mNumVertices; renderable->mVertexStride = sizeof(vertexPTC0NTG_t); renderable->mVertexBuffer = pRenderer->createVertexBuffer(&vertexArray[0],renderable->mVertexCount,VA_P_TC0_N_TG); renderable->mIndexBuffer = pRenderer->createIndexBuffer(&indexArray[0],renderable->mIndexCount); //get material infos aiString mtName; if( pScene->HasMaterials() ) { material = pScene->mMaterials[mesh->mMaterialIndex]; aiColor3D color; //get material name material->Get(AI_MATKEY_NAME,mtName); assimpStrToString_t(mtName,myMaterial.matName); //material colors material->Get(AI_MATKEY_SHININESS,myMaterial.ns); material->Get(AI_MATKEY_COLOR_DIFFUSE,color); myMaterial.kd = D3DXVECTOR3(&color[0]); material->Get(AI_MATKEY_COLOR_SPECULAR,color); myMaterial.ks = D3DXVECTOR3(&color[0]); material->Get(AI_MATKEY_COLOR_AMBIENT,color); myMaterial.ka = D3DXVECTOR3(&color[0]); material->Get(AI_MATKEY_COLOR_EMISSIVE,color); myMaterial.ke = D3DXVECTOR3(&color[0]); //material textures //diffuse texture myMaterial.hDiffuseMap = getTextureFromAssimpMaterial(aiTextureType_DIFFUSE,material); //normal map myMaterial.hNormalMap = getTextureFromAssimpMaterial(aiTextureType_HEIGHT,material); //specular map myMaterial.hSpecularMap = getTextureFromAssimpMaterial(aiTextureType_SPECULAR,material); //emissive map myMaterial.hEmissiveMap = getTextureFromAssimpMaterial(aiTextureType_EMISSIVE,material); //displacement map myMaterial.hHieghtMap = getTextureFromAssimpMaterial(aiTextureType_DISPLACEMENT,material); //add material to cache and set the material handle renderable->hMaterial = CMaterialManager::getInst().addMaterialToCache( myMaterial ); } //push the renderable in the list renderablesList.push_back( renderable ); } } } }
Thanks a lot in advance for any help ;)