Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Interpreting a Wavefront Obj...

  1. #1
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    20

    Interpreting a Wavefront Obj...

    I need some help interpreting a WavefrontOBJ File. For example, at its simplest, I have the following cube:

    # Object "object01":
    # ComRec:
    g cube01
    # No. points 8:
    v -0.5 -0.5 -0.5
    v -0.5 -0.5 0.5
    v -0.5 0.5 -0.5
    v -0.5 0.5 0.5
    v 0.5 -0.5 -0.5
    v 0.5 -0.5 0.5
    v 0.5 0.5 -0.5
    v 0.5 0.5 0.5

    # No. normals 30:
    vn 0 0 -1
    vn 0 0 1
    vn -1 0 0
    vn 1 0 0
    vn 0 1 0
    vn 0 -1 0
    vn 0 0 -1
    vn 0 -1 0
    vn -1 0 0
    vn 0 0 1
    vn 0 -1 0
    vn -1 0 0
    vn 0 0 -1
    vn 0 1 0
    vn -1 0 0
    vn 0 0 1
    vn 0 1 0
    vn -1 0 0
    vn 0 0 -1
    vn 0 -1 0
    vn 1 0 0
    vn 0 0 1
    vn 0 -1 0
    vn 1 0 0
    vn 0 0 -1
    vn 0 1 0
    vn 1 0 0
    vn 0 0 1
    vn 0 1 0
    vn 1 0 0

    # No. texture coordinates 8:
    vt 0 0
    vt 0 0
    vt 0 1
    vt 0 1
    vt 1 0
    vt 1 0
    vt 1 1
    vt 1 1

    # No. faces 6:
    f 3/3/13 7/7/25 5/5/19 1/1/7
    f 6/6/22 8/8/28 4/4/16 2/2/10
    f 2/2/12 4/4/18 3/3/15 1/1/9
    f 7/7/27 8/8/30 6/6/24 5/5/21
    f 4/4/17 8/8/29 7/7/26 3/3/14
    f 5/5/20 6/6/23 2/2/11 1/1/8

    The first section, the vertexes, clearly sow a cube. I can also see that I have to somehow utilise the last section, the indexes to arrange and draw them onto the screen..

    Can any tell me how I can draw this cube onto the screen using OpenGL ?

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Interpreting a Wavefront Obj...

    google for:
    wavefront obj file format

    some tips:
    -the 'f' entries define index arrays for vertices, normals and texture coordinates - they're 1-based
    -if there are multiple objects in the file then vertex indices do not start from 1 for each object. In other words: one .obj file cannot define two vertices having the same index.

    So an example:
    o test -beginning of object named 'test'
    v 0.0 0.0 0.0 -vertex 1
    v 1.1 2.2 3.3 -vertex 2
    v 4.4 5.5 6.6 -vertex 3
    vn 0.0 0.0 1.0 -normal 1
    f 1/1 2/1 3/1 -a triangle (vertex/normal vertex/normal...)
    f 3/1 2/1 1/1 -another triangle
    o test2 -beginning of object 'test2'
    v 7.7 8.8 9.9 -vertex 4
    v 1.7 3.8 5.9 -vertex 5
    v 2.7 4.8 6.9 -vertex 6
    vn 0.0 1.0 0.0 - normal 2
    vn 0.0 1.0 0.0 - normal 3
    f 4/2 5/2 6/3 -triangle using 2 vertices and 2 normals

  3. #3
    Guest

    Re: Interpreting a Wavefront Obj...

    f v1/vn1/t1 v2/vn2/t2 v3/vn3/t3
    In its simplest form a face can consist of three vertices, making up a triangle. The first parameter gives you the vertex number. When you parse the vertices, the first vertex has index 1, the second vertex has index 2 etc. The same with the vertex normals, the first vertex normal has index 1 etc. In the above example v1 is the number of the first vertex of the face, vn1 is the corresponding vertex normal, and t1 is the corresponding texture coordinate of that vertex. Once you store each face in a data structure so that you can access these variable directly, you can render the .obj file like the following:

    for each face of the model
    glBegin(GL_POLYGON);
    for each vertex of the face
    glTexCoord1f(t);
    glNormal3f(vn.x, vn.y, vn.z);
    glVertex3f(v.x, v.y, v.z);
    end
    glEnd();
    end

    voila!

  4. #4
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    20

    Re: Interpreting a Wavefront Obj...

    Thanks..but..

    Say, For example this index: .. "2/2/10" (End of second line)

    This corresponds to
    2nd vertex: v -0.5 -0.5 0.5
    2nd normal: vn 0 0 1
    10th tex co-ord: ??

    Right ? But if so, there are only 8 textureco-ordinates ?

  5. #5
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    20

    Re: Interpreting a Wavefront Obj...

    EDIT: Maybe it is vertex pos/normal/tex co-ord,as opposed to vertex pos/tex co-ord/normal ?

  6. #6
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Interpreting a Wavefront Obj...

    I just did what I suggested in my first post - googled for: wavefront obj file format. First page I've found answers your question - values are: pos/normal/tex

  7. #7
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    20

    Re: Interpreting a Wavefront Obj...

    Yes, but pos/normal/tex wouldn't work ? Which is the reason for this post..

    Read my last about "2/2/10" .. There isn't 10 tex co-ords, so pos/normal/tex wouldn't be possible..

  8. #8
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    20

    Re: Interpreting a Wavefront Obj...

    Oh wait...

    First page from google:

    "A polygonal face. The numbers are indexes into the arrays of vertex positions, texture coordinates, and normals respectively"

    So it seems I was right.. tis pos/tex/normal..

    Thanks for the help everyone

  9. #9
    Guest

    Re: Interpreting a Wavefront Obj...

    tex coords. and normals are optional, so you can have the following possibilities:
    f 1 2 3
    f 1/1 2/2 3/3
    f 1//1 2//2 3//3
    f 1/1/1 2/2/2 3/3/3

  10. #10
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    20

    Re: Interpreting a Wavefront Obj...

    Right..

    Now thats over, it leads me onto my next section ..

    How can I use the indices to draw _this_ cube using OpenGL (preferabbly OpenGL|ES, so no glBegin/glEnd calls, just vertex arrays..) ??

    oh and btw: Thanks all..

Page 1 of 3 123 LastLast

Similar Threads

  1. interpreting matrix transform
    By subflood in forum OpenGL: General
    Replies: 3
    Last Post: 12-10-2011, 02:50 PM
  2. Interpreting rotation animations
    By Luke1410 in forum COLLADA
    Replies: 6
    Last Post: 02-17-2009, 09:59 PM
  3. Problem interpreting depth values
    By knackered in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 03-11-2005, 06:49 AM
  4. Interpreting glGetError() results... drv differences?
    By Glossifah in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-03-2001, 11:50 AM
  5. Interpreting GL_MAX_TEXTURE_SIZE
    By imported_Rob in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-07-2000, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean