2

I'm writing a method to parse the data in wavefront obj files and I understand the format for the most part, however some things are still a bit confusing to me. For instance, I would have expected most files to list all the vertices first, followed by the texture and normal map coordinates and then the face indices. However, some files that I have opened alternate between these different sections. For instance, one .obj file I have of the Venus de Milo (obtained here: http://graphics.im.ntu.edu.tw/~robin/courses/cg03/model/ ) starts off with the vertices (v), then does normal coordinates (vn), then faces (f), then defines more vertices, normals and faces again. Why is the file broken up into two sections like this? Why not list all the vertices up front? Is this meant to signify that there are multiple segments to the mesh? If so, how do I deal with this?

user1855952
  • 1,515
  • 5
  • 26
  • 55

2 Answers2

1

not an direct answer but it will be unreadable in comment

I do not use this file-format but mesh segmentation is usually done for these reasons:

  1. more easy management of the model for editing

  2. separation of parts of model with different material or texture properties

    mainly to speed up the rendering by cut down unnecessary material or texture switching

  3. if the mesh has dynamically moving parts then they must be separated

    Most 3D mesh file formats contains also transform matrix for each mesh part and some even an skeleton hierarchy

Now how to handle segmented meshes:

  1. if your engine supports only unsegmented models then merge all parts together

    This will loose all the advantages of segmented mesh. Do not forget to apply transform matrices of sub segments before merging

  2. or you can implement mesh segmentation into your model class

    By adding model hierarchy , transform matrices , ...

Now how to handle mixed model fileformat:

  1. scan file for all necessary chunks of data

    • remember if they are present
    • also store their size,and start address in file
    • and do not forget that there may be more that one chunk of the same data type
  2. preallocate space for all data you need

  3. load/merge all data you need

    • load chunks of data to you model classes or merge it to single model
    • of course check if all data needed id present like number of points match number of normals or texture coords ...
Spektre
  • 49,595
  • 11
  • 110
  • 380
1

Because this is how the file format was designed. There is no requirement for a specific ordering of the data inside the OBJ, so each modelling package writes it in its own way. Here is one brief summary of the file format, if you haven't read this one yet.

That said, the OBJ format is quite outdated and doesn't support animation by default. It is useful for exchanging of static meshes between modelling tools but not much else. If you need a more robust and modern file format, I'd suggest taking a look at the Collada format or the FBX.

glampert
  • 4,371
  • 2
  • 23
  • 49