Sign in to follow this  
ote

Assimp : cant' access to texCoords and faces

Recommended Posts

Hello,

I'm trying to use assimp to load some models in my project. I have succesfully installed it, I am able to load some models but I have a problem to get access to two types of data : the texCoords and the indices of faces that form a mesh. When I try to retrieve those informations, my program crash due to segmentation fault. But for all the other things (vertex position, normals, colors, ...) I can get the information without any problem. I don't understand why this is happenning.

I have read the doc, looked at the samples provided with the library and to others codes I found, I think I'm doing the same but doesn't work for me with these two cases.

Here's the lines :

[code]
bool Modele::loadGlresources(const aiScene *scene)
{
for(unsigned int i = 0; i < scene->mNumMeshes; i++)
{
aiMesh* mesh = scene->mMeshes[i];

//temp array to store data
info_vertex *attributes = (info_vertex *)malloc(mesh->mNumVertices * sizeof(info_vertex));

for(unsigned int j = 0; j < mesh->mNumVertices; j++)
{
//get the position, normal, .... without problems

//here's how I do for position :
attributes[j].position.x = mesh->mVertices[j].x;
attributes[j].position.y = mesh->mVertices[j].y;
attributes[j].position.z = mesh->mVertices[j].z;
attributes[j].position.w = 1.0f;

//but here's my problem :
if(mesh->HasTextureCoords(0))
{
attributes[j].texCoord.x = mesh->mTextureCoords[0][j].x;
attributes[j].texCoord.y = mesh->mTextureCoords[0][j].y;
}
}

//and the problem with the faces :
//again temp array
element *indices = (element *)malloc(mesh->mNumFaces * 3 * sizeof(element));

if(!mesh->HasFaces()) //add that to check where the error is, but still pass the test and crash.....
return false;

unsigned int count = 0;
for(unsigned int j = 0; j < mesh->mNumFaces; j++)
{
indices[count].element = mesh->mFaces[j].mIndices[0];
indices[count + 1].element = mesh->mFaces[j].mIndices[1];
indices[count + 2].element = mesh->mFaces[j].mIndices[2];
count += 3;
}
}
return true;
}

[/code]

I've trying for hours now to make this work, but nothing works. So if someone has an idea of what I'm doing wrong, I'd be very grateful.

Sorry for my english.

Share this post


Link to post
Share on other sites
It works now without changing a single letter of my code. The problem was that I that I get the library from svn. With the latest stable version it works. :)

I have been playing with my code for the day before looking into that...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this