Fucking C Programmers

author Posted by: whaledawg on date Sep 25th, 2008 | filed Filed under: general

So I’ve been working on my project for about a month now. Maybe 5 weeks. That’s 5 weeks at 40 hours a week, a pretty hard core time investment. And I’ve spent the last week, 20% of it, trying to parse a god damned .OBJ file. Fuck me.

And you might think that after investing this much time in understanding one file format I’d stick with it. I could get my engine to use the same files and just add a few new lines to represent my stuff(physical properties and the like). But writing something to parse this crap once tells me how poorly designed a file format it is.

A good system, game engine, file format, database or whatever, keeps you thinking as high up as possible for as long as possible. That’s why XML is so popular, you define everything by the rules of the shcema. I don’t have to think about the rules, they’re allready defined. That lets me concentrate on my data, the ‘high minded’ part.

With these old file formats I’m constantly thinking about the rules. When can you use a negative index? Is there a default material? Do I have to look at the material before I look at the .OBJ file, and how do I do that if the material file is listed inside the .OBJ. There’s too many valid ways to do the same thing and they involve too many unrelated sections of the file.

And why would they make a file format like that you ask? C programmers. Those mesozoic mother fuckers. See, to guys who wrote programs that parsed FAT12 any ASCII file seems simple.  And if the format updated or added new features they just spent days wading through code to find out where/what needed to be changed. As long as they had a human readable file they were happy to do it.

So now I have to deal with their poor design choices. Fuck me.

Where to begin

author Posted by: whaledawg on date Sep 16th, 2008 | filed Filed under: general

No posting for a while because the project is going well. I’m at the point where it’s time to start dealing with(ugg) files.

There’s a relatively simple solution for 3D file formats, the .OBJ. It’s text based so it’s almost human readable and other 3D tools readily export in it’s format. It’s just a series of verts, normals, texture coordinates then faces. Basically like this:


# this is a comment
# Here is the first vertex, with (x,y,z) coordinates.
v 0.123 0.234 0.345
v ...
...

#Texture coordinates
vt ...
...

#Normals in (x,y,z) form; normals might not be unit.
vn …
..

#Each face is given by a set of indices to the vertex/texture/normal
#coordinate array that precedes this.
#Hence f 1/1/1 2/2/2 3/3/3 is a triangle having texture coordinates and
#normals for those 3 vertices,
#and having the vertex 1 from the “v” list, texture coordinate 2 from
#the “vt” list, and the normal 3 from the “vn” list

f v0/vt0/vn0 v1/vt1/vn1 …

Easy to understand and process. But obviously my game library will need to have more information than just the polygons for most objects. Does it move? Does it have mass? Do other objects bounce off it or clip right through it? If they can’t move throught it what are it’s dimensions? So the questions becomes, how do I represent that?

The way I see it I have 3 options:

  1. Simply tack my information onto the end of the .OBJ with a new pattern.
  2. Place my information into .OBJ comments so it’s still a valid .OBJ file.
  3. Make my own file format from scratch.

I think I’ve talked about design principles before, that your pillars are simple, efficient, and elegant.  Effieicent isn’t that big a concern with file formats(getting it off the disk is never going to be the run) so lets concentrate on the others. Option 1 is simpler than 2, but 2 is more elegant. It’s nice that my files are compatible with a general standard. Or are they?

By burrying my propietary information in the comments they fake compatability, but is there a requirement that comments be treated a certain way by programs that use .OBJ? Not really, other than to ignore them if they find them. That means I could open up my faux-OBJ file with 3DS Max and change it’s color, then save it only to find it erased or moved my comments.

It’s actually very complicated and inelegant to try and hide new data in a standard not designed to hold it. Bad idea.

So that leaves making my own file format from scratch. I’ll be doing something XML based(simple and elegant). Sure this means I’ll have to make some tools for editing/combineing my files with .OBJ files but it’s not a huge amount of extra work and it’s worth it to have files that actually fit a standard instead of almost fit a standard. That never ends well.