c++ - Why does the number of vt and v elements in a blender .obj file differ? -


having followed instructions of tutorial https://www.youtube.com/watch?v=yc0b5gcyl3u (how unwrap uv sphere in blender) succeeded in generating textured sphere within blender program.

now want in opengl c++ program. end followed tutorial http://en.wikibooks.org/wiki/opengl_programming/modern_opengl_tutorial_load_objexported in order save sphere .obj file (using triangulation export option stated in said tutorial) , joyfully found lot of 'v', 'vt', , 'f' lines within result.

however, parsing file found 642 vertices (v), 561 'texture vertices' (vt)[, , 1216 elements lines (f) of expected structure 'f a/at b/bt c/ct'].

what baffles me this: naive understanding of opengl tells me each point on textured object has site in space (the vertex) , site on texture (the uv point). hence expect numbers of vs , vts matche. not: 642!=561. how can be?

because obj , opengl use different definition of "vertex", , handle indices differently.

in following explanation, i'll call coordinates of vertex, values in v records of obj format, "positions".

obj

the main characteristic of obj vertex/index model uses separate indices different vertex attributes (positions, normals, texture coordinates).

this means can have independent lists of positions , texture coordinates, different sizes. file needs list each unique position once, , each unique texture coordinate pair once.

a vertex defined specifying 3 indices: 1 each position, texture coordinates, , normal.

opengl

opengl on other hand uses single set of indices, reference complete vertices.

a vertex defined position, texture coordinates, , normal. vertex needed each unique combination of position, texture coordinates, , normal.

conversion

when read obj file opengl rendering, need create vertex each unique combination of position, texture coordinates, , normal. since referenced indices in f records, need create opengl vertex each unique index triplet find in f records. each of these vertices, use position, texture coordinates, , normals @ given index, read obj file.

my older answer here contains pseudo-code illustrate process: opengl - index buffers difficulties.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -