Jump to content

  • Log In with Google      Sign In   
  • Create Account

Mesh loaded with Assimp not showing up


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 05 October 2012 - 05:55 PM

I've been trying to load an md5 file with Assimp for a while with no luck. I've used some example code that loads a simple .obj file without assimp to make sure my directx 11 code for creating vertex/index buffers, shaders and textures works. It seems like the problem is in the LoadModel method somewhere. I've removed the DirectX 11 specific code, since I got this to work with the example I found.

I'm not that experienced with 3d programming yet, so maybe there's a simple solution to my problem. Maybe it's rendered far away somewhere outside my frustum even. The model I'm trying to render is simple, and has one aiMesh and 24 vertices.

My shaders take pos, texCoord, normal and tangents. I also have a light that illuminates the whole texture. The shader is rendered with DrawIndexed(indexCount, 0, 0). I can provide some more code if necessary.

Any ideas?

This is the code is use for loading the model with Assimp:
[source lang="cpp"]struct VertexType{ XMFLOAT3 position; XMFLOAT2 texture; XMFLOAT3 normal;};struct Mesh{ ID3D11Buffer* vertexBuffer; ID3D11Buffer* indexBuffer; Texture* texture; int indexCount;};bool Model::LoadModel(ID3D11Device* device, std::string filename){ HRESULT result;Assimp::Importer importer;const aiScene* scene = importer.ReadFile(filename, aiProcess_Triangulate | aiProcess_MakeLeftHanded | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices | aiProcess_GenSmoothNormals | aiProcess_LimitBoneWeights | aiProcess_RemoveRedundantMaterials | aiProcess_OptimizeMeshes | aiProcess_GenUVCoords | aiProcess_TransformUVCoords);if(!scene){ MessageBoxA(nullptr, importer.GetErrorString(), "Error", MB_OK); return false;}meshes.reserve(scene->mNumMeshes);for( unsigned int m=0; m<scene->mNumMeshes; ++m ){ aiMesh* aiMesh = scene->mMeshes[m]; if(!aiMesh->HasNormals() || !aiMesh->HasTextureCoords(0)) { MessageBox(NULL, L"Model is missing normals or texture coordinates.", L"Error", MB_OK); return false; } Mesh mesh; D3D11_SUBRESOURCE_DATA vertexData, indexData; int vertexCount = aiMesh->mNumVertices; vector<VertexType> vertices(vertexCount); for(unsigned int i=0;i < (unsigned)vertexCount;++i) { vertices[i].position = XMFLOAT3(aiMesh->mVertices->x, aiMesh->mVertices->y, aiMesh->mVertices->z); vertices[i].normal = XMFLOAT3(aiMesh->mNormals->x, aiMesh->mNormals->y, aiMesh->mNormals->z); vertices[i].texture = XMFLOAT2(aiMesh->mTextureCoords[0][i].x, aiMesh->mTextureCoords[0][i].y); } mesh.indexCount = aiMesh->mNumFaces*3; vector<unsigned int> indices(aiMesh->mNumFaces); for (unsigned int i = 0; i < aiMesh->mNumFaces;++i) { const aiFace& Face = aiMesh->mFaces[i]; assert(Face.mNumIndices == 3); indices.push_back(Face.mIndices[0]); indices.push_back(Face.mIndices[1]); indices.push_back(Face.mIndices[2]); } int materialid = aiMesh->mMaterialIndex; aiMaterial* mat = scene->mMaterials[materialid]; aiString szPath; char diffuseName[150]; //diffuse texture if(AI_SUCCESS == aiGetMaterialString(mat, AI_MATKEY_TEXTURE_DIFFUSE(0), &szPath)) { strcpy(diffuseName, "../../Media/md5/"); strcat(diffuseName, szPath.data); } else { strcpy(diffuseName, "DEFAULTTEX"); } if(!(mesh.texture = LoadTexture(device, diffuseName))) { MessageBox(NULL, L"Could not load texture", L"Error", MB_OK); return false; }// Directx 11 code for creating vertex and index buffers etc[/source]
Edit: Removed tangents and some other code that was just there for testing.

Edited by Corvwyn, 08 October 2012 - 04:43 AM.


Sponsor:

#2 Ralara   Members   -  Reputation: 310

Like
0Likes
Like

Posted 06 October 2012 - 07:27 AM

This for loop looks a little strange to me:

for(unsigned int i=0;imVertices->x, aiMesh->mVertices->y, aiMesh->mVertices->z);


The semi-colon at the end of the loop means it won't actually loop through the code, it will only process it once, and what is 'imVertices'.

But the reason I don't think you're seeing anything on the screen is you aren't getting the vertex positions when loading (I'm wondering whether there is a mis-copy with the aforementioned for-loop, because you do use aiMesh->mVertices->x / y/ z). If the for-loop has been mis-copied then the following advice won't help and its possible something is going wrong when you are rendering, otherwise the loading code I use for assimp is as follows:
[source lang="cpp"]for (UINT i=0; i < numVertices; i++){ const aiVector3D* pos = &(inMesh->mVertices[i]); const aiVector3D* normal = &(inMesh->mNormals[i]); const aiVector3D* texCoord; if (inMesh->HasTextureCoords(0)) texCoord = &(inMesh->mTextureCoords[0][i]); else texCoord = new aiVector3D(0.0f, 0.0f, 0.0f); Vertex v; v.mPos = XMFLOAT3(pos->x, pos->y, pos->z); v.mNormal = XMFLOAT3(normal->x, normal->y, normal->z); v.mTexCoord = XMFLOAT2(texCoord->x, texCoord->y); vertices.push_back(v);}[/source]

Ralara

Edited by Ralara, 06 October 2012 - 07:28 AM.


#3 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 06 October 2012 - 07:48 AM

Thanks for the pointer. It seems like there's a bug with the code formatter when I don't have a space between i<something. I've updated my code.

I've checked the vertices after loading the model, and they seem correct. They're adjusted for weight or something, which I assume is correct according to the documentation.

Edited by Corvwyn, 06 October 2012 - 07:58 AM.


#4 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 08 October 2012 - 02:22 AM

I have now been able to load obj models without problems with multiple code examples, and using the same code to create buffers etc.

I just don't get why the data I got from Assimp won't render. I've tested the same files in both AssImp and code examples I've found. What am I missing...

I'm considering using some code I found for obj and md5 exporters and try to optimize them instead, since I can't get AssImp to work. I'd much rather use a well-tested library like AssImp though.

#5 Ralara   Members   -  Reputation: 310

Like
0Likes
Like

Posted 08 October 2012 - 03:36 AM

This does sound odd. I'm not sure what the problem could be. If you could link to the model that you are using I can try and see if my loader works when I get home from work. I seem to be doing something very similar to you at the moment because I've just finished writing the loading part of my engine/framework and I'm moving onto making games!

#6 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 08 October 2012 - 04:26 AM

Thanks.

My problem isn't really restricted to certain model. I haven't gotten any of them to work with assimp. Maybe I need to do some kind of transformation for the model to show up where my camera is. I haven't had this issue with the other model loaders I've been trying though.

I'm using the bob.md5mesh model that's included with assimp. You can find it here:
https://assimp.svn.s...dels-nonbsd/MD5

I'm looking forward to working with other parts of the engine. I've been stuck at getting model loading to work for too long now. I could just settle for a simple loader, but I want to get it right.

Edited by Corvwyn, 08 October 2012 - 04:28 AM.


#7 Ralara   Members   -  Reputation: 310

Like
2Likes
Like

Posted 08 October 2012 - 11:27 AM

Good news and bad news....

Good news is I can load the models using my loader (I tried the Bob.md5mesh and the BoarMan.md5mesh) so it is possible using Assimp. Odd thing about the BoarMan mesh is that there is not texture listed in the file (that I could see) so that model appears just black until you go far enough away to see it against the background:

http://www.adamsmith-demos.co.uk/wp-content/uploads/2012/10/BoarMan_Full.png

When the Bob mesh first loads because of its size it appears like this:

http://www.adamsmith-demos.co.uk/wp-content/uploads/2012/10/Bob_Loaded.png

and once I've moved around it looks like this:

http://www.adamsmith-demos.co.uk/wp-content/uploads/2012/10/Bob_Full.png

Bad news being that it doesn't make it any clearer as to what you're problem is...

The difference between our code that I can tell is that you load the meshes that aiScene provides (which in the case of Bob.md5mesh is one) whereas I set a hierarchy of sub-meshes up using the aiScene's root node. This way I get 6 meshes for the individual bits of Bob.

I don't think just loading the one mesh from aiScene would make it not appear, I think it would just make the first mesh in the file appear which is his body so you should get at least that....

Only thing I can think is that maybe you're not loading the texture properly and the mesh is covering the whole screen and appearing black?

<shameless_plug>
You can see the way I do my loading at http://www.adamsmith-demos.co.uk/
</shameless_plug>

Hope this helps!

#8 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 08 October 2012 - 12:07 PM

Thanks for the Info. I am loading all the meshes by looping through mMeshes, so they're all getting loaded.

I'll check out your code and see if it helps to load all the child nodes from aiNode.

#9 Ralara   Members   -  Reputation: 310

Like
0Likes
Like

Posted 08 October 2012 - 12:38 PM

I was just about to explain why I thought you were only loading one because I could have sworn I'd seen when debugging that the aiScene only had a single mesh, but I just ran it again and it had 6... going mad I think!

#10 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 08 October 2012 - 01:13 PM

Hehe

#11 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 10 October 2012 - 06:37 AM

I tried using nodes etc. to get it working, but I still can't get the model to load. I don't need to use childNode->mTransformation to get anything to show, do I?

Do you think it would be possible to get some of your code for loading/rendering the model, in case I've missed something?

Edited by Corvwyn, 10 October 2012 - 06:37 AM.


#12 Ralara   Members   -  Reputation: 310

Like
0Likes
Like

Posted 11 October 2012 - 02:02 AM

The transformation matrices are just to work out how one sub-mesh is relative to its parent mesh so its not essential and you should at least be seeing something on screen. I'm at work at the moment, but when I get home tonight I'll edit this post with the code I am using / a link of where to download it from.

[edit] - The current version of the source code I am using can be found at http://www.adamsmith-demos.co.uk/wp-content/uploads/downloads/2012/10/Source.rar. This is only the code, if you want you can build it to debug it but its a directX11 project so you'll need the sdk and an 11 card.

If you want you can link to your code and we can both see if we can spot the problem?

Edited by Ralara, 11 October 2012 - 11:10 AM.


#13 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 11 October 2012 - 04:40 AM

Yeah. That's what I figured the matrices were used for. They will be useful when I get this working.

Thanks for your help.

Didn't see your edit there to begin with. I'll check out your code soon. My code is a mess at the moment, since I've been refactoring and testing a lot. I'll see what I can do. Nice structure in your code though.

Edited by Corvwyn, 12 October 2012 - 07:31 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS