Where to begin
Posted by: whaledawg on
Sep 16th, 2008 |
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:
- Simply tack my information onto the end of the .OBJ with a new pattern.
- Place my information into .OBJ comments so it’s still a valid .OBJ file.
- 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.

Be the first!
Tags: