CODECUBE VENTURES

X File Format Header RegEx

I wanted to play around with some OpenGL and C# using NEHE's C# basecode. Unlike Direct3D, OpenGL has no canned model loading code ... so if you want to use art assets created in a tool such as Maya or 3D Studio Max you need to parse the file yourself. Now, save me the speeches about not reinventing the wheel (which is what D3D is all about) ... if you're interested in OpenGL then you're bound to reinvent a wheel or two ;-)

So I decided I wanted to use a relatively standard 3D file format ... what better than the DirectX .x format. There's already a ton of exporters available for all the major 3D packages, and a ton of free .x models on the web. After a quick search on wotsit, I found the .x spec.

I had a few minutes this morning so I wrote a quick regular expression to parse out the header info.

xof (\d{2})(\d{2})(\w{3}) (\d{4}).*

Edit: Here is a modified regex that will include the header template in a semi-colon delimited list. xof (\d{2})(\d{2})(\w{3}) (\d{4})\s+Header\s+{([^}]+)}[.|\s*]*

The resulting grouped matches are (group index):

1Minor Version 2Major Version 3Format 4Float Accuracy

So if you run that against:

xof 0302txt 0032

Header {
1;
0;
1;
}

You'll get version 3.2, txt format, 32 bit accuracy.

The next thing I plan on doing is to make it read a simple mesh template so I can pull out the vertices and indices (the plural of index ...sounds so wierd :-P )

Latest post: Digging Up the First Version of CodeCube

See more in the archives