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

## Recommended Posts

I try to load with assimp simple box. But assimp return wrong number of vertex. I try several formats(didnt help). This is my model :

xof 0303txt 0032

Frame Root {
FrameTransformMatrix {
1.000000, 0.000000, 0.000000, 0.000000,
0.000000,-0.000000, 1.000000, 0.000000,
0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000;;
}
Frame Cube {
FrameTransformMatrix {
1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 0.000000, 1.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000;;
}
Mesh { // Cube mesh
8;
1.000000; 1.000000;-1.000000;,
1.000000;-1.000000;-1.000000;,
-1.000000;-1.000000;-1.000000;,
-1.000000; 1.000000;-1.000000;,
1.000000; 0.999999; 1.000000;,
0.999999;-1.000001; 1.000000;,
-1.000000;-1.000000; 1.000000;,
-1.000000; 1.000000; 1.000000;;
12;
3;3,1,0,,
3;5,7,4,,
3;1,4,0,,
3;6,5,1,,
3;7,6,2,,
3;3,0,4,,
3;3,2,1,,
3;5,6,7,,
3;6,1,2,,
3;7,2,3,,
3;3,4,7,,
3;1,5,4,;
MeshNormals { // Cube normals
12;
0.000000; 0.000000;-1.000000;,
-0.000000;-0.000000; 1.000000;,
1.000000; 0.000000;-0.000000;,
-0.000000;-1.000000;-0.000000;,
-1.000000; 0.000000;-0.000000;,
0.000000; 1.000000; 0.000000;,
0.000000;-0.000000;-1.000000;,
0.000000;-0.000000; 1.000000;,
-0.000000;-1.000000; 0.000000;,
-1.000000; 0.000000;-0.000000;,
0.000000; 1.000000; 0.000000;,
1.000000;-0.000001; 0.000000;;
12;
3;0,0,0,,
3;1,1,1,,
3;2,2,2,,
3;3,3,3,,
3;4,4,4,,
3;5,5,5,,
3;6,6,6,,
3;7,7,7,,
3;8,8,8,,
3;9,9,9,,
3;10,10,10,,
3;11,11,11,;
} // End of Cube normals
MeshMaterialList { // Cube material list
1;
12;
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0;;
Material Material {
0.640000; 0.640000; 0.640000; 1.000000;;
96.078431;
0.500000; 0.500000; 0.500000;;
0.000000; 0.000000; 0.000000;;
}
} // End of Cube material list
} // End of Cube mesh
} // End of Cube
} // End of Root



Model have 8 Vertex, when I call mesh->mNumVertices I get 24. This code loading vertex :

	for (unsigned int i = 0 ; i < mesh->mNumVertices ; i++)
{
Vert.push_back(Vertex( mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z,mesh->mTextureCoords[0][i].x,mesh->mTextureCoords[0][i].y,mesh->mNormals[i].x,mesh->mNormals[i].y,mesh->mNormals[i].z));
}


##### Share on other sites

Does MeshNormals define normals for each triangle? If yes, then you simply have vertices that have same position, but different normal. Therefore 6 faces, each 4 vertices = 24.

##### Share on other sites

How can i get real number of vertex ?

##### Share on other sites

What do you mean? You actually have 24 vertices.

If you want to have only 8 you need to define normals for vertices, not triangles, however your model won't be shaded correctly (in this case).

##### Share on other sites

Now I have model with 2676 vertex and 892 indi. Normals are per vertex. Assimp return that i have only 554 vertex.

##### Share on other sites

Did you count in all vertices? They might be split into several meshes.

There's also chance of duplicate vertices (depends on your exporter), Assimp removes duplicate vertices.

##### Share on other sites

Maybe i dont known how to generate corectly normals in blender. Now I generate normals in assimp. But I have still problem. This is my model http://pastebin.com/MQ5pWACz . This have 176 vertex and 348 indi. I noticed strange behaviour of assimp. He split my model into 2 meshes. First have 488 vert and 54 indi, second have 120 vert and 294 indi. Sum of indi is 348 and is correct, but sum of vertex is 608. Still I have strange mix of triangle. This is my full code of loading mesh :

#include "Model.h"
{
Assimp::Importer importer;
aiMesh *mesh = scene->mMeshes[0];
for(unsigned int i=0;i<mesh->mNumFaces;i++)
{
const aiFace& face = mesh->mFaces[i];
Indi.push_back(face.mIndices[0]);
Indi.push_back(face.mIndices[1]);
Indi.push_back(face.mIndices[2]);
}
numIndi=mesh->mNumFaces;
for (unsigned int i = 0 ; i < mesh->mNumVertices ; i++)
{
Vert.push_back(Vertex( mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z,1.0,1.0,mesh->mNormals[i].x,mesh->mNormals[i].y,mesh->mNormals[i].z));
}
numVert=mesh->mNumVertices;
sizeVert=sizeof(Vertex);
return 1;
}


##### Share on other sites
I'm not familiar with that particular mesh format but it seems to contain at least two different materials. In general that would force Assimp to split the mesh into two submeshes.

Furthermore, if you use Assimp to generate normals, how exactly do you do it? What does the documentation tell you about it? The simplest way to generate normals would be to do it per-face. Of course that will increase the number of vertices.

Edit: According to the documentation:

Generates normals for all faces of all meshes.

This is ignored if normals are already there at the time this flag is evaluated. Model importers try to load them from the source file, so they're usually already there. Face normals are shared between all points of a single face, so a single point can have multiple normals, which forces the library to duplicate vertices in some cases. #aiProcess_JoinIdenticalVertices is *senseless* then.

This flag may not be specified together with #aiProcess_GenSmoothNormals.

So having a much higher vertex count than the number of vertex positions stored in the file would be the expected case.

Edit 2: and have you tried aiProcess_GenSmoothNormals? Edited by BitMaster

##### Share on other sites

For this flag i get

Edit:

With aiProcess_GenNormals and when I load 2 meshes I have :

Model in blender :

Edited by kolarz3

##### Share on other sites

Model formats favour file size over what the actual runtime data looks like in the editor you are using. Runtime data is often bigger then the data in the file itself you can't compare the two to make sure the model is loaded correctly. The only thing you can do is check that the data in all of the vertices is the same as the vertex data in the file.

I found that Assimp doesn't read the .blend format well so export to .dea (collada format) and it generally works a lot better in assimp.

##### Share on other sites
1. Your problem is at aiMesh *mesh = scene->mMeshes[0];, you're loading only one mesh, if you have multiple materials it'll be split up, that's why you might be missing vertices.
2. Your loop assumes all faces have 3 indices, if you didn't specify flags to remove points, remove lines and triangulate surfaces then it might result in the mess you're receiving.
3. numIndi=mesh->mNumFaces;, looks like you forgot to multiply by 3.

##### Share on other sites

Can you somone tell me why blender dupicate several timer one vertex. Model that have 18 000 vertex blender save(x. format) with 52 000 vertex ?

##### Share on other sites

Assume you have a simple cube. In the most basic case that means 8 vertices and 6 faces. If you want to render it using either OpenGL or Direct3D using canonical lighting you will usually need to create a mesh with 24 vertices and 12 faces. You could also end up with 36 vertices and 12 faces (more vertices but we don't need an index buffer - might actually be a good idea for such a simple mesh).

Depending on the file format you chose any of these numbers up there could be stored in the file. None of them are wrong for our little cube.

Without knowing anything about the mesh you have, how you generated normals (and similar vertex attributes like texture coordinates) for it and which file format you chose there is really not much more than "looks about okay" anyone can say.

That said, I strongly suggest you stick to simple meshes while learning. There is no big difference in getting a 10000 vertices bullet or a 8 vertices cube to load and render correctly. But it makes a huge difference when you can just look at values in the debugger and immediately see whether they are sensible or not.

Edited by BitMaster

##### Share on other sites

Again i try to load model. This is my result :

This should be cube. I write to txt. file indi and vert and they look good.

0. 0 3 2
1. 2 1 0
2. 4 7 6
3. 6 5 4
4. 8 11 10
5. 10 9 8
6. 12 15 14
7. 14 13 12
8. 16 19 18
9. 18 17 16
10. 20 23 22
11. 22 21 20

0. -1 1 1
1. -1 -1 1
2. 1 -1 1
3. 1 1 1
4. 0.999999 -1 -1
5. -1 -1 -1
6. -1 1 -1
7. 1 0.999999 -1
8. 1 -1 1
9. 0.999999 -1 -1
10. 1 0.999999 -1
11. 1 1 1
12. -1 -1 1
13. -1 -1 -1
14. 0.999999 -1 -1
15. 1 -1 1
16. -1 1 1
17. -1 1 -1
18. -1 -1 -1
19. -1 -1 1
20. -1 1 -1
21. -1 1 1
22. 1 1 1
23. 1 0.999999 -1


Edited by kolarz3

##### Share on other sites

I find answer. I have problem because i have diffrent definition of Vertex structure