Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

OBJ files and indices

Sign in to follow this  
Alex Hopkins


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.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!