• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
kolarz3

Assimp loading model

14 posts in this topic

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

7b4c677ec2005.png

1

Share this post


Link to post
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.

1

Share this post


Link to post
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).

1

Share this post


Link to post
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.

1

Share this post


Link to post
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.

1

Share this post


Link to post
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"
int Model::loadFromFileModelAndInit(char *fileName)
{
	Assimp::Importer importer;
	const aiScene *scene = importer.ReadFile(fileName,aiProcessPreset_TargetRealtime_Fast|aiProcess_GenNormals);
	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;
}
1

Share this post


Link to post
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
1

Share this post


Link to post
Share on other sites

For this flag i get

mmf5.png

 

Edit:

With aiProcess_GenNormals and when I load 2 meshes I have :

mc60.png

 

Model in blender : 

kyb.png

Edited by kolarz3
0

Share this post


Link to post
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.

0

Share this post


Link to post
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.
0

Share this post


Link to post
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 ?

0

Share this post


Link to post
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
1

Share this post


Link to post
Share on other sites

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

e1x.png

 

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
0

Share this post


Link to post
Share on other sites

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

0

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  
Followers 0