Question

Im trying to draw a globe in Android, I use OpenGL for this. However to make it easier to understand i will start by making a simple 3D cube. I use Blender to create my 3D object (cube) and export it as a .obj file after i have unwrapped it to get Texture Coords (vt). Problem is i get 8 different vertices and 9 different texture coords.

v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vt 0.000000 0.000000
vt 0.000000 -1.000000
vt -1.000000 -1.000000
vt -1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
vt -1.000000 1.000000
vt 1.000000 -1.000000

Therefore, i also gets a real messed up setup of Indices that makes it impossible to rearrange the position of texture coords to match the position in vertices.

f 5/1 1/2 4/3
f 5/1 4/3 8/4
f 3/1 7/5 8/6
f 3/1 8/6 4/7
f 2/1 6/5 3/4
f 6/7 7/1 3/2
f 1/1 5/5 2/4
f 5/7 6/1 2/2
f 5/5 8/8 6/1
f 8/1 7/2 6/9
f 1/1 2/2 3/3
f 1/1 3/3 4/4

Since iv'e understod now i can only use one array for indices since one vertex consists of both vertices and texture coords. Therefor i would need to rearrange one of the v/vt arrays a bit. But i can't, since if i move vt(at position 1) to position 5 (first line of faces), i would need to move it again to make it go all the way thru the indices array.

So basicly i wonder if this is a problem with the program "Blender" or if there is a solution to this that i can apply.

Was it helpful?

Solution

What you have there is entirely normal, and in fact I would expect to have seen more than 9 texture coordinates if the cube was unwrapped properly. if done in a common way a cube would be unwrapped, you should really have 12 vts I believe.

A whole Vertex is generally comprised of it's xyz coordinates, as well as it's normal and texture coordinates as well. A single Vertex can only hold one index position (with respects to the index array in OpenGL) if all of these parts are the same. If you look at how the faces are defined, they are made up of Vertices that comprise of both a v and vt. If you had normals as well, they'd have an extra number to represent each normal used (or vn line in an OBJ export). In the faces, take Vertex 5/1, 5/5 and 5/7. The xyz coordinate is the same, but the texture coordinate is not. This is because when unwrapped, the same point in 3D space appears in 3 places on the UV/Image Editor. Because of this, there will be 3 separate indices in the index array in the OpenGL side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top