Jump to content
  • Advertisement
Sign in to follow this  
MegaPixel

Sponza Loading issues (Assimp)

This topic is 2899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

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 ;)

Share this post


Link to post
Share on other sites
Advertisement

I've now verified that it loads perfectly the old version of the sponza model (the Marko Dabrovic version). Therefore I think the crytek model is corrupt in some ways ? I load the *.obj version:



Share this post


Link to post
Share on other sites
Quote:
Original post by MegaPixel

I've now verified that it loads perfectly the old version of the sponza model (the Marko Dabrovic version). Therefore I think the crytek model is corrupt in some ways ? I load the *.obj version:



Errata: It doesn't load correctly ... strangely some triangles are not

there ... and I don't know why. If I load the model in the assimp viewer it

loads perfectly, so I guess the model is correct.

I added a VIDEO of the sponza model ( the old version )



Thanks all

[/quote]



Share this post


Link to post
Share on other sites
Quote:
Original post by MegaPixel

I've now verified that it loads perfectly the old version of the sponza model (the Marko Dabrovic version). Therefore I think the crytek model is corrupt in some ways ? I load the *.obj version:




Errata: It doesn't load correctly ... strangely some triangles are not

there ... and I don't know why. If I load the model in the assimp viewer it

loads perfectly, so I guess the model is correct.

I added a VIDEO of the sponza model ( the old version )

http://img43.imageshack.us/img43/2049/sponzarenderingissues.mp4

Thanks all

Share this post


Link to post
Share on other sites
Quote:
Original post by Pragma
Post some sample faces from the two different obj files (lines beginning with f). There are different ways that obj files use to store faces and I suspect your code is handling one of them wrong. That would explain why one file loads just fine, but the other one has its indices screwed up.


Hi Guys,

I managed to fix it. There was a bug in the importer. I was forgetting to delete the memory allocated for the vertex/index arrays after that I used it to create the d3d index/vertex buffer ... I replaced the code with a :

delete[] vertexArray;
delete[] indexArray;

and everything works just fine ! Obviously with a small model made by just a mesh I wasn't able to realise the bug.

Damn ME !!!! :D

But Thanks to both of you guys !

Here is the correct rendered sponza model ( the crytek one, which seems that the texture gi_flag.tga is missing ... ). It's a deferred renderer that I'm developing. Any suggestion/critic is welcome.

video:

http://img571.imageshack.us/img571/9463/sponzacrytekfirstrender.mp4



Share this post


Link to post
Share on other sites
Good luck with your deferred shader, I got to know the sponza model quite well when I was using it for my rendering module this year :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Darg
Good luck with your deferred shader, I got to know the sponza model quite well when I was using it for my rendering module this year :)



Thanks Darg,

It's just me or some of the sponza textures are missing ? Plus I noticed you do not render the centra curtain (which is the one without that require the missing texture :) )! The one in the center of the sponza model ...

I think I should check the materials and so on !

Btw I watched the video, very very good job ;) ! I have to start converting the lights in volume lights ! I still use the classic attenuation for the point light like c+x+x*x. But I would use the point light radius to model the fall off ...
Have you used light volumes concept as well ?

Thanks a lot


Share this post


Link to post
Share on other sites
No light volumes or anything that fancy there. That's just my old HDR forward renderer. Nothing great just thrown together in a month of two.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!