Results 1 to 8 of 8

Thread: Has anyone had luck loading .obj files?

  1. #1
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Has anyone had luck loading .obj files?

    I started writing an obj file loader last night and mostly got it working. My problem isn't with the loader, but how the normals are assigned in the file. When I load the faces, I get vertex indices and normal vertex indices. The problem is that the normal indices get reassigned.

    For an example, here is a short obj file I'm using:
    Code :
    # Blender3D v248 OBJ File: 
    # [url]www.blender3d.org[/url]
    v 0.437500 0.500000 0.468750
    v -0.437500 0.500000 0.468750
    v -0.437500 0.500000 -0.468750
    v 0.437500 0.500000 -0.468750
    v -0.437500 -0.500000 0.468750
    v 0.437500 -0.500000 0.468750
    v -0.437500 -0.500000 -0.468750
    v 0.437500 -0.500000 -0.468750
    vn 1.000000 0.000000 -0.000000
    vn -1.000000 0.000000 0.000000
    vn 0.000000 -0.000000 1.000000
    vn -0.000000 -1.000000 -0.000000
    vn 0.000000 1.000000 0.000000
    vn -0.000000 0.000000 -1.000000
    usemtl (null)
    s off
    f 2//1 5//1 7//1
    f 1//2 8//2 6//2
    f 3//1 2//1 7//1
    f 3//3 7//3 8//3
    f 3//3 8//3 4//3
    f 8//2 1//2 4//2
    f 1//4 3//4 4//4
    f 1//4 2//4 3//4
    f 6//5 8//5 7//5
    f 5//5 6//5 7//5
    f 2//6 1//6 6//6 5//6

    For those that are unfamiliar with the file format, the "f x//y" translates to "face vertex index//normal vertex index". In this case, there are 10 triangles and one quad.

    Now look at face #1. The first vertex index is 2 and the first normal index is 1. If I assign that vertex that normal, when I get down to face #8, I end up reassigning vertex #2 with normal #4. At face #11, it is reassigned again to normal #6.

    Am I doing the assignment wrong or is the .obj exporter that comes with Blender screwed up?

    I'm sorry that this isn't exactly on topic, but I will be using GL to do the rendering. I need to load from a file because some of the models are quite complex and I do not want to hard code the objects.

  2. #2
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Has anyone had luck loading .obj files?

    Edit...

    Never mind. Upon further inspection, it is a problem with the exporter and I'll need to take it up Blender's developers. It should be exporting 8 normals and is only exporting 6.

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Has anyone had luck loading .obj files?

    Each normal is per vertex per polygon, meaning you should think the face list as the actual geometry, not the vertex list.

  4. #4
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Has anyone had luck loading .obj files?

    Correct, however, the exporter is exporting face normals instead of vertex normals. The model I presented is a rectangular prism. Look at the normals. They are axis aligned. If they were vertex normals, they wouldn't be.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Has anyone had luck loading .obj files?

    well that depends if you are using vertex smoothing or not, if not then they are most likely to be axis aligned, especially if you have an axis aligned rectangular prism like you have.
    obviously you haven't since you have the line "s off" there (which means normal smoothing off).
    to get smoothing select the object and then press "set smooth" in the lower left corner.

    and it only looks like it's exporting face normals since it only exports unique normals.

  6. #6
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Has anyone had luck loading .obj files?

    Blender creates normals for each vertex and face. You can view them and Ive seen them, so I know for certain that the calculations are being performed. I've read over the file format specifications (not official, but what I could find) and it only mentions vertex normals, which, correct me if I'm wrong, are averaged face normals. I cannot find any reference to face normals in what references I could find online.

    Other than that, you're saying that the face list does not share vertices? Again, what examples I could find show otherwise. I'm really thinking this is an exporter issue.

  7. #7
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Has anyone had luck loading .obj files?

    Well i actually tried the exporter and it works just fine, i could replicate what you got and also where the normals are smoothed out, it worked as expected, and i don't think they would screw up on such an important feature, at least not in v248, so i think it's more of an pebcac problem.

    Vertex normals can be the same as face normals, it depends on how sharp of an edge you want, in the case where you want sharp edges the vertex normals are not averaged and instead just kept as they where.
    There are also instances where the vertex normals are averaged but are still not the same as all their counterparts, but that's whole other issue.
    (i.e. they don't have to be averaged.)

  8. #8
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Has anyone had luck loading .obj files?

    I set the faces to smooth and got the desired results. Although this whole discussion may be moot. I do not want the polys smoothed. I just need the normals for GL. This means that each panel needs to be separate. Oh well... At least I know what was going on and why.

Similar Threads

  1. Loading OBJ and MTL files
    By imported_Rodrigo in forum OpenGL: Windows
    Replies: 7
    Last Post: 10-09-2012, 05:52 AM
  2. loading 3ds files
    By MMMovania in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-09-2005, 08:06 AM
  3. LOading BMP files
    By freaker in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-04-2001, 09:03 PM
  4. Loading .mdl files
    By codemaster in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-09-2000, 11:55 PM
  5. loading RAW files / general model loading question
    By tcs in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-23-2000, 12:41 PM

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