Jump to content

  • Log In with Google      Sign In   
  • Create Account






OBJ files and indices

Posted by Alex Hopkins, 27 August 2012 · 429 views

wavefront obj file format model mtl material index buffer array
So whenever I read about how to import a model into your game, it tends to be followed by suggestions that the user go and read the appropriate file format specification. Then a few suggestions related to model asset libraries like ASSIMP. I have tried many of the libraries and always seemed to have one or two issues with them, none of which were fatal, all of which were annoying to debug.

For my project going forward, I will require many models to be imported and I'd like to minimise the pain of doing so further on. I wrote an OpenGL-based 'sniper' game for University that allowed the importing of hundreds of models at run-time and you could fly around the city "painting" models in and rotating them individually. There were a lot of models so I wrote a custom level format which housed a list of possible models and all the meta-data. This was in XML format.

Now, I'd like to go further and gain more control over the models themselves as well as the levels. I'm favouring JSON as a format for things as it seems to map slightly more to what I want to do, plus with serialisation tricks and some reflection, it might be possible to output replays/gamestates.

So, I'm writing a custom model format. It's going to be very basic and include only things such as
  • Vertex positions,
  • Normals
  • Texture coordinates
  • Texture-file linkages
  • Lighting information per-vertex
  • Maybe smoothing information
  • Possibly hierarchical meshes
  • Extra meta-data for run-time use
The first obstacle I found while running my OBJ importer is that the "Faces" index into separate position, normal and texture index arrays which isn't compatible with a DirectX index buffer. So, algorithmically parsing these index arrays must be done first. So, my output file format will be called, tentatively, "Indexed ObjectFile Format" or IOF. I'm half-way through writing a custom tool to convert between OBJ to IOF.

It's both fun and educational to write your own model formats and certainly good practice writing game tools such as model converters. Knowing your model format intimately can only be a good thing later on down the line when you wish to incorporate more advanced features like skinning, animation etc.




July 2014 »

S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728 29 3031  

Recent Comments

PARTNERS