I've wrote a little wavefront's .obj file parser (3d model format), I'm able to display the geometry correctly but am having problems texturing it correctly.
The only way I'm able to get a correct texture is by dividing the model in my 3d editor, exporting and parsing it this way.. ie: I'm no longer sharing vertex data, each triangle is on it own so my indexBuffer's array looks like this [0,1,2,3,4,5,6...] which I want to avoid.
The correct texture/inefficient geometry (No reusing of vertices: 36 vertices):
Correct http://imageshack.us/a/img29/2242/textureright.jpg
Wrong texture/right topology (Sharing data: 8 vertices only = efficient):
Wrong http://imageshack.us/a/img443/6160/texturewrong.jpg
I thought to try and separate the UVs buffer from the indexBuffer destined to the vertices but didn't found a way to do it; if indeed it is doable.
I also messed with the agal code but haven't achieved any results.
The desired end is being able to pass different UVs coordinates to the same vertex in context of the triangle being drawn atm.
What to do?
Thanks. (I'm new to 3d programming)

- 537
- 4
- 14
2 Answers
It might seem like you need just one vertex per 'vertex location' of your model but, from what I understand of an .obj parser, you need to define your vertices around the FACES. This means you may have multiple vertices for some locations - depending on how many faces adjoin that location - but the pay off is you can have different UV coordinates for those vertices in the same location.
I'd suggest altering your parser to create vertices based on the faces they define rather than solely their positions. I know this bumps up the number of vertices but, from what I've read, it's unavoidable if you need different UVs for the same vertex location.
So, unfortunately, I'm pretty sure your first option is the way to go.

- 1,841
- 2
- 23
- 39
-
I can't believe this is the only option.. This doesn't apply to an .obj parser only: Let's say that I want to create a quad and have it's two triangles of two distinct colors, I am sure this can be achievable in some other way than having 6 vertices for this single quad. Existent stage3d games cannot possibly have their number of vertices exploded exponentially in that way... Thank for answering though :) – chadiik Apr 29 '13 at 12:10
-
If you scroll down to a heading that reads 'Defining geometry with Vertex Buffers and Index Buffers' there's information on this page... http://www.adobe.com/devnet/flashplayer/articles/how-stage3d-works.html about how the vertex buffer defines faces. – moosefetcher Apr 29 '13 at 14:14
it seems like your welding operation is wrong. For welding vertices you must be sure that positions, UV-coordinates, normals and tangents(if you need them) are equal

- 31
- 4