File Format Help

gurgi

Regular
So I'm slowly writing a software renderer, and I'm currently implementing a file reader. I don't care what format I use, so long as it's simple enough that I can load vertex (and eventually texture) data.

So I've decided on .obj for the time being, because it seems simple. When I look at the file, I see something like:

Code:
# Blender3D v249 OBJ File: cube.blend
# [url]www.blender3d.org[/url]
mtllib cube.mtl
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
usemtl Material
s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8


So from what I can tell, the v's are obviously the vertex's, and the f's are the faces of the cube. I guess that would be fine, but I've written my engine so far with a poly object that has state/attribute data to eventually implement culling, or specify solid polys or whatever.

If I'm going to use a poly object, do I need to write some code to parse faces into polygons? If this is the case, how do I determine what coordinates belong to which polygon? In the case of the first face, is v1,2,3 from the first poly, and v2,3,4 in the second? I believe verticies are written in clockwise order in OBJ files?

I guess I'm just confused. I could try to use a vertex based render list instead of a polygon based list (please excuse my obvious ignorance, I'm learning as I go), but then I wouldn't know if a polygon was culled or clipped or whatever.

So I'm guessing I just need to interpolate the polygons from the face and vertex data?

THANKS! :)
 
You are a little bit confused. ;) OBJ contains polygons (not triangles, in your example fe. are quads), all points in a "f" are coplanar and given ordered on a ring. The winding is per custom convention (means there is none in practice), if you want real hard orientations you have to obtain an OBJ with vertex-normals. But's much easier just to pick up some public-domain code, no need to reverse-engineer this.
 
I am at least a bit confused, but I'm making progress. :)

But's much easier just to pick up some public-domain code, no need to reverse-engineer this.

where is the fun in that?



at any rate, i was able to export an obj as triangle polygons, and so i think i have what i need for now

Code:
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
usemtl Material
s off
f 5 1 8
f 1 4 8
f 3 7 8
f 3 8 4
f 2 6 3
f 6 7 3
f 1 5 2
f 5 6 2
f 5 8 7
f 5 7 6
f 1 2 3
f 1 3 4

so now i can load those easily into my poly object and do some transformations...i'm starting to get close to seeing some results
 
Back
Top