Main Topics
Browse All TopicsHiya fella's
I need a little help to get started in writing a parser for Directx Binary file(eof file). haha before you tell me to use directx's builtin loader functions i aint using direct3d i am using OpenGL. I have seen code to parse text file version but i want to use the binary version. I should also add i don't expect anyone to write the whole lot i just need a little kickstart and i will figure the rest out. Another thing is i don't require any animation, just need to load a mesh and it's materials.
i can load in the header of the binary file.
//////////////////////////
//from MSDN:
#define XOFFILE_FORMAT_MAGIC \
((long)'x' + ((long)'o' << 8) + ((long)'f' << 16) + ((long)' ' << 24))
#define XOFFILE_FORMAT_VERSION03 \
((long)'0' + ((long)'3' << 8)) //+ ((long)'0' << 16) + ((long)'2' << 24))
#define XOFFILE_FORMAT_BINARY \
((long)'b' + ((long)'i' << 8) + ((long)'n' << 16) + ((long)' ' << 24))
#define XOFFILE_FORMAT_TEXT \
((long)'t' + ((long)'x' << 8) + ((long)'t' << 16) + ((long)' ' << 24))
#define XOFFILE_FORMAT_COMPRESSED \
((long)'c' + ((long)'m' << 8) + ((long)'p' << 16) + ((long)' ' << 24))
#define XOFFILE_FORMAT_FLOAT_BITS_
((long)'0' + ((long)'0' << 8) + ((long)'3' << 16) + ((long)'2' << 24))
#define XOFFILE_FORMAT_FLOAT_BITS_
((long)'0' + ((long)'0' << 8) + ((long)'6' << 16) + ((long)'4' << 24))
struct X_HEADER
{
unsigned long Magic;
unsigned short MajVersion;
unsigned short MinVersion;
unsigned long Format;
unsigned long Size;
};
ifstream myFile;
X_Header header;
.......................
void main()
{
myFile.open("test.x",ios::
myFile.read((char*)&header
if(!ProcessHeader())
{
//error code
}
}
//check file header is correct binary file
bool ProcessHeader()
{
if (header.Magic != XOFFILE_FORMAT_MAGIC)
{
printf("Not a .X model file. Aborted...\n");
return false;
}
if (header.Format != XOFFILE_FORMAT_BINARY)
{
printf("Not A Binary .x Model File. Aborted...\n");
return false;
}
if (header.MajVersion != XOFFILE_FORMAT_VERSION03)
{
printf("Wrong File Version. Aborted...\n");
return false;
}
if (header.MinVersion != XOFFILE_FORMAT_VERSION03)
{
printf("Wrong File Version. Aborted...\n");
return false;
}
return true;
}
//////////////////////////
I just haven't got my head around all this token and template stuff that MSDN is talking and howto parse it properly.
so if someone could just get me started and show me how to load say just the first template...hopefully after i see how it is done i will understand it better and can than load the other stuff like the mesh and it's vertices etc etc
Thanks everyone
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Alright nutterx it took me a while to find the time to dig through this but here's the jist:
If you checked out the examples and templates:
template : TOKEN_TEMPLATE name TOKEN_OBRACE
class_id
template_parts
TOKEN_CBRACE
template_parts : template_members_part TOKEN_OBRACKET
template_option_info
TOKEN_CBRACKET
| template_members_list
template_members_part : /* Empty */
| template_members_list
template_option_info : ellipsis
| template_option_list
template_members_list : template_members
| template_members_list template_members
template_members : primitive
| array
| template_reference
primitive : primitive_type optional_name TOKEN_SEMICOLON
array : TOKEN_ARRAY array_data_type name dimension_list
TOKEN_SEMICOLON
template_reference : name optional_name YT_SEMICOLON
primitive_type : TOKEN_WORD
| TOKEN_DWORD
| TOKEN_FLOAT
| TOKEN_DOUBLE
| TOKEN_CHAR
| TOKEN_UCHAR
| TOKEN_SWORD
| TOKEN_SDWORD
| TOKEN_LPSTR
| TOKEN_UNICODE
| TOKEN_CSTRING
array_data_type : primitive_type
| name
dimension_list : dimension
| dimension_list dimension
dimension : TOKEN_OBRACKET dimension_size TOKEN_CBRACKET
dimension_size : TOKEN_INTEGER
| name
template_option_list : template_option_part
| template_option_list template_option_part
template_option_part : name optional_class_id
name : TOKEN_NAME
optional_name : /* Empty */
| name
class_id : TOKEN_GUID
optional_class_id : /* Empty */
| class_id
ellipsis : TOKEN_DOT TOKEN_DOT TOKEN_DOT
That gives you the token explination of how to parse this file.
The data object explination:
object : identifier optional_name TOKEN_OBRACE
optional_class_id
data_parts_list
TOKEN_CBRACE
data_parts_list : data_part
| data_parts_list data_part
data_part : data_reference
| object
| number_list
| float_list
| string_list
number_list : TOKEN_INTEGER_LIST
float_list : TOKEN_FLOAT_LIST
string_list : string_list_1 list_separator
string_list_1 : string
| string_list_1 list_separator string
list_separator : comma
| semicolon
string : TOKEN_STRING
identifier : name
| primitive_type
data_reference : TOKEN_OBRACE name optional_class_id TOKEN_CBRACE
Gives you data object token information.
The general idea is given in the examples:
TOKEN_TEMPLATE, TOKEN_NAME, 3, 'R', 'G', 'B', TOKEN_OBRACE,
TOKEN_GUID, 55b6d780, 37ec, 11d0, ab, 39, 00, 20, af, 71, e4, 33,
TOKEN_FLOAT, TOKEN_NAME, 1, 'r', TOKEN_SEMICOLON,
TOKEN_FLOAT, TOKEN_NAME, 1, 'g', TOKEN_SEMICOLON,
TOKEN_FLOAT, TOKEN_NAME, 1, 'b', TOKEN_SEMICOLON,
TOKEN_CBRACE
Meaning this:
The token name you have a 3 wide binary data segment defining an RGB triplet. It would look something along the lines of:
Hex: 0x00 0x00 0x00 aka 0x000000 to 0xFFFFFF same as html works also meaning you would have this in binary:
Binary: 'B'(0000 0000) 'B'(0000 0000) 'B'(0000 0000) wich is the same as 'B'(0000 0000 0000 0000 0000 0000)
Pretty much each hex position is defined by 4 binary positions so F in hex is the same as 1111 in Binary. (F being 15)
But it is stating lower that you have the token r then a semicolon the g then a semicolon then b and then a semicolon which will define a single RGB triplet.
THen you have your matrix definition:
TOKEN_TEMPLATE, TOKEN_NAME, 9, 'M', 'a', 't', 'r', 'i', 'x', '4', 'x', '4', TOKEN_OBRACE,
TOKEN_GUID, 55b6d781, 37ec, 11d0, ab, 39, 00, 20, af, 71, e4, 33,
TOKEN_ARRAY, TOKEN_FLOAT, TOKEN_NAME, 6, 'm', 'a', 't', 'r', 'i', 'x',
TOKEN_OBRACKET, TOKEN_INTEGER, 4, TOKEN_CBRACKET,
TOKEN_OBRACKET, TOKEN_INTEGER, 4, TOKEN_CBRACKET,
TOKEN_CBRACE
It will be a 9x4 Matrix defined by an array of 6 then 2 sets of 4 and the TOKEN_GUID is the format and ranges of the tokens same as the RGB triplet tokens.
Pretty much Microsoft is giving you templates you can plug into MSDN Visual Stuidio.NET and make it fly with the data they are giving you. Reading and writing 'X' format files is not a very simple task... If I were to recomend you a place to start looking I would recomend looking at the token information for PPM formats as they are defined fairly simple:
Header defines the max color required aka whether the max color value is 0-255 and the number of rows and columns plus some various other BS that you don't need to read in. You are jumping off the deep end here and going for one of the biggest file formats to decript and looking for the token information from MSDN which always offer such Robust explinations *laughs* Nothing against Microsoft but they have never been great for explaining things.
Flip through what I said and look at a few files in a hex editor instead of looking at the straight binarys and read the hex data as it should be much more straight forward than straight binarys.
Good luck Nutterx!
~Aqua
Business Accounts
Answer for Membership
by: aqua9880Posted on 2005-10-24 at 12:17:22ID: 15149057
nutterx,
I would have to say that MSDN is only telling you the format of the binary file. However to further help you in your understanding of the interworkings of how the file is formatted could you please post the MSDN location you are getting your information from? I'm unfamiliar with DX bin files but if I took a look at what you are asking I'm sure I could help you further.
~Aqua