Duplicating vertices when reading .obj files

jkpie
2013-09-17
2013-09-18
  • jkpie
    jkpie
    2013-09-17

    Hi,

    I am new user of Assimp. I try to load mesh from .obj file (quads) and triangulate it.

    I've tried to do this this way:

    const aiScene * pScene = importer.ReadFile( path, aiProcess_Triangulate | aiProcess_JoinIdenticalVertices );

    and also:

    const aiScene * pScene = importer.ReadFile( path, aiProcessPreset_TargetRealtime_Quality );

    I don't understand, why I have different number of vertices in loaded mesh, then in original file (14174 in obj file and 14420 in loaded data). I noticed, that some vertices are duplicated. Moreover the indexes of vertices are different than in original file (for example the vertex at position (0,0,0) had index 5 and after triangulation has index 432).

    Is there any way to read mesh consisting of quads and triangulate it, without duplicating vertices and changing it's numbers?

    I'll be very grateful for help.

    J.

     
  • Kim Kulling
    Kim Kulling
    2013-09-18

    The obj-fileformat is optimized for unique data. Unfortunately if you want to rendr the mesh thigs are a little bit different. Normally a vertex layout consists more than only the position. It also contains colors, normal, texture coordinates etc. .
    So when assimp imports the data it looks for the given layout and generates vertices for this layout. And sometimes you can have different texture coordinates at one position for instance.

    This is the reason for the more data.

    Hopefully this helps a little bit.

    Kimmi

     
  • jkpie
    jkpie
    2013-09-18

    Thank you Kimmi for the explanation. However I think, there is something wrong. For example after load and triangulation I have two vertices at the same positions with different indexes. So when I render the scene everything looks good, however when I try to move the vertex with certain index then I can see, that he consists of two vertices, where one is connected for example with triangles on the left and the second with triangles on the right side. So in fact after movement of such vertex I have a visible hole in my mesh.
    J

     
  • Then compare the texture coordinates, normals and colors for those two vertices. The vertices will differ at least at one of these vertex components, or otherwise Assimp wouldn't have had to split them up. If you want to edit a mesh after loading, convert it to a suitable data representation or move all vertices at one position together.