X file format
From GDWiki
The X File format is a file used by Microsoft for easy loading, and animating of meshes in Direct3D.
Contents |
[edit] History
The X File was first introduced around DirectX 7 or 8 SDK. Taking their name from their .x file extension X files are used to store any kind of data. In most cases though they are used to store models and animations.
[edit] Using in D3D
The X file format can store any type of data in any size. Furthermore data in .x files can be stored as binary or as text. X files use a template system which allows you to store any kind of data your game will use.
An example of a custom .x file is the following :
xof 0302txt 0064
template SIMPLE_ITEM{
<AA1308FD-FF98-4f6e-9A55-CD083178672F>
STRING name;
DWORD price;
}
SIMPLE_ITEM Sword1{
"Sword";
24;
}
The file begins with xof 0302txt 0064 which is the header of the file which states the version number and if the file is in text mode or binary. As you can see the .x use a C like structure with template Declaration and Definitions. The template shows how the object is structured. Note that the large code inside the declaration of SIMPLE_ITEM is a GUID (globally unique identifier). This code helps DirectX to identify different template types. For custom templates it is generated by a application created by Microsoft. The other two lines contain the attributes of the template. Each attribute must have a type which is either a predefined type or another template (even a custom one if it has been already declared). At the end there is a data object which is an instance of the template SIMPLE_ITEM.
The advantages of using X files specifically for models is that all coordinates for mesh and texture are in the file, and the file can be loaded and parsed with a few built in functions in the DirectX SDK. However, it is harder to use X files due to their sheer complexity; although everything is in one file, it takes some code to set up, and it can be intimidating when converting from one model type such as Milkshape files since when the DirectX API reads the mesh file, there are the possibilities of holes to be in the final product even if the modeling program shows none. If simple meshes (cubes) are used, in a game it might be better to use a standard file such as 3DS or just 'hard coded' coordinates.

