Twinklebear / tobj

Tiny OBJ Loader in Rust
MIT License
233 stars 47 forks source link

.positions is generated with repeated vertices. #31

Closed Mautar55 closed 3 years ago

Mautar55 commented 3 years ago

To my understanding, positions is a vector which lenght should be the ammount of vertices*3. That doesn't happen with this mesh (attached). Instead of having 6036 positions, it has 6333. The integrity of the file is ok, since blender and online model viewers handle it correctly. I printed a list and searched the file, some positions are repeated for some reason.

The file contains the model, source code of the program which i used to read it and the list of printed positions.

issue.zip

arrayJY commented 3 years ago

They are not actually "repeated". The same vertex may have different texture coordinates when they sharing by different surfaces. Here is an example. image

Twinklebear commented 3 years ago

Yeah @arrayJY is right here, this loader will output a unique position for every unique vertex. A unique vertex is every unique combination of position/texcoord/normal . So even if there's only 6036 unique positions in the mesh, there may be more than 6036 unique vertices. To allow referencing each vertex with a single integer index (as in OpenGL, Vulkan, etc.), these re-used positions have to be duplicated. I'd guess that's the case with the suzanne mesh you shared. You could test this in Blender by exporting suzanne without normals and texture coordinates, then you should have # vertices == # positions .

Mautar55 commented 3 years ago

Ok, learned something new then haha. Thanks for the reply.

It is worth to close this one.