Reading obj and raw files

Hi guys.
I saw a lot of people asking how to load a model from obj and raw files exported from blender, but I couldn’t understand 100% the meaning of the information in these files.

I exported a cone in raw and obj formats. In raw format it seems I don’t have information about the normal vectors for each face.
In obj format there is more information but I don’t understand what they mean. I wanted to get the information exported to use in my C code for opengl.

Could someone explain or tell me where I can find it?
I’d appreciate that.

OBJ is quite simple, the wikipedia page seem to explain everything correctly :
http://en.wikipedia.org/wiki/Obj

Feel free to ask for details.
(no idea about raw though)

Cool, I think I got it.
Suppose a I have a obj file like:

Blender3D v249 OBJ File:

www.blender3d.org

mtllib cone.mtl
v 0.707107 -1.000000 -0.707107
v 0.831470 -1.000000 -0.555570
v 0.923880 -1.000000 -0.382683
v 0.980785 -1.000000 -0.195090
v 1.000000 -1.000000 -0.000000

usemtl (null)
s off
f 2 1 33
f 33 3 2
f 33 4 3
f 33 5 4
f 33 6 5
f 33 7 6

If I want to reproduce the image in OpenGL C code, could I get the first face, identify the 3 vertexes defined by it and draw a polygon triangle using those vertexes and then do the same with second face and so on?
Which would be the normal vector?

f 2 1 33 <- this is you first face, that uses vertices number 2, 1 and 33.

v 0.707107 -1.000000 -0.707107 <- coordinates of vertex 1
v 0.831470 -1.000000 -0.555570 <- coordinates of vertex 2

etc

Yes, I understood it.
But suppose I wanted to draw a cube and drawing one of the faces would be:
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(40.0, 40.0, 40.0);
glVertex3f(-40.0, 40.0, 40.0);
glVertex3f(-40.0, -40.0, 40.0);
glVertex3f(40.0, -40.0, 40.0);
glEnd();

As you can see, I need a normal vector. But I don’t have it in my obj file. Would it be a problem?
Here is the complete file, it’s a simple cone:

Blender3D v249 OBJ File:

www.blender3d.org

mtllib cone.mtl
v 0.707107 -1.000000 -0.707107
v 0.831470 -1.000000 -0.555570
v 0.923880 -1.000000 -0.382683
v 0.980785 -1.000000 -0.195090
v 1.000000 -1.000000 -0.000000
v 0.980785 -1.000000 0.195090
v 0.923880 -1.000000 0.382683
v 0.831470 -1.000000 0.555570
v 0.707107 -1.000000 0.707107
v 0.555570 -1.000000 0.831470
v 0.382683 -1.000000 0.923880
v 0.195090 -1.000000 0.980785
v -0.000000 -1.000000 1.000000
v -0.195091 -1.000000 0.980785
v -0.382684 -1.000000 0.923879
v -0.555571 -1.000000 0.831469
v -0.707107 -1.000000 0.707106
v -0.831470 -1.000000 0.555570
v -0.923880 -1.000000 0.382683
v -0.980785 -1.000000 0.195090
v -1.000000 -1.000000 -0.000001
v -0.980785 -1.000000 -0.195091
v -0.923879 -1.000000 -0.382684
v -0.831469 -1.000000 -0.555571
v -0.707106 -1.000000 -0.707108
v -0.555569 -1.000000 -0.831470
v -0.382682 -1.000000 -0.923880
v -0.195089 -1.000000 -0.980785
v 0.000002 -1.000000 -1.000000
v 0.195092 -1.000000 -0.980785
v 0.382685 -1.000000 -0.923879
v 0.555572 -1.000000 -0.831469
v 0.000000 1.000000 -0.000000
v 0.000000 -1.000000 0.000000
usemtl (null)
s off
f 2 1 33
f 33 3 2
f 33 4 3
f 33 5 4
f 33 6 5
f 33 7 6
f 33 8 7
f 33 9 8
f 33 10 9
f 33 11 10
f 33 12 11
f 33 13 12
f 33 14 13
f 33 15 14
f 33 16 15
f 33 17 16
f 33 18 17
f 33 19 18
f 33 20 19
f 33 21 20
f 33 22 21
f 33 23 22
f 33 24 23
f 33 25 24
f 33 26 25
f 33 27 26
f 33 28 27
f 33 29 28
f 33 30 29
f 33 31 30
f 33 32 31
f 33 1 32
f 34 1 2
f 34 2 3
f 34 3 4
f 34 4 5
f 34 5 6
f 34 6 7
f 34 7 8
f 34 8 9
f 34 9 10
f 34 10 11
f 34 11 12
f 34 12 13
f 34 13 14
f 34 14 15
f 34 15 16
f 34 16 17
f 34 17 18
f 34 18 19
f 34 19 20
f 34 20 21
f 34 21 22
f 34 22 23
f 34 23 24
f 34 24 25
f 34 25 26
f 34 26 27
f 34 27 28
f 34 28 29
f 34 29 30
f 34 30 31
f 34 31 32
f 32 1 34

Well it just means you forgot to activate the “Normals” button on the export to OBJ panel :slight_smile:

It is off by default on my Blender 2.49

EDIT : test with a cube first, it makes a simpler file.

Or you could have in your parser a sanity check in that if any normals are not specified for a face they are automatically generated using the vertices. If you plan on using normal mapping with .obj meshes you will need to at least generate the tangent and bitangent manually.

Thanks guys.
I try do read some basic files first and then build a better version!