luchete80 / WeldFormGUI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parse wavefront Obj

luchete80 opened this issue · comments

2

If you look at an OBJ file, face definitions look something like this:

f 1//1 2//2 3//3
Every line starting with an f(ace) indicator defines one primitive. In this case, there are 3 sections present separated by whitespace. Each section defines a single vertex. If there are 3 of these sections per face, you know the face must be a triangle. If it's 4, the face is a quad (though this format is relatively uncommon nowadays).

Looking at a single vertex definition:
https://stackoverflow.com/questions/41587904/how-to-derive-index-buffer-from-obj-faces

1/1/1
Which has the form:

[vertex]/[texture]/[normal]
You see here 3 integers separated by slahes. Each integer refers to the index of which the respective value was defined in the OBJ file. Not, however, that these indices are 1-indexed. For 0-indexed languages such as C, you need to subtract 1 from every index.

Because OpenGL can only render vertices which are truly unique (that is, same vertex coordinate, texture coordinate and normal), generating a compact index buffer is slightly tricky and involves checking which vertices you have seen previously. The easier approach is to simply create an index buffer which counts from 0, and create a separate vertex for every vertex of every face in your geometry buffer(s).