X File Loading


The x file format is a Microsoft format for holding mesh data. Exporters exist for most 3D packages and DirectX provides objects and methods in the D3DX library to work with the data. This section describes the different ways of loading and using x files in your game. An easy way to use .x files is to use my XAnimator library.

Methods of loading x files

There are a number of D3DX functions that can be used to load an x file, these are divided into simple methods that collapse any hierarchy in the file but are easy to use and more complex methods that maintain the hierarchy and hence allow animation, skinning etc.

Simple methods, collapses hierarchy

  • D3DXLoadMeshFromX – the simplest way but unfortunately all hierarchy information is lost.
  • D3DXLoadMeshFromXInMemory – as above but to load from memory rather than disk.
  • D3DXLoadMeshFromXof – as above but loads a mesh from a ID3DXFileData object
  • D3DXLoadMeshFromXResource – as above but loads from a resource in a module

These functions are described in the Load X Simply notes.

More complex methods, maintains hierarchy

  • D3DXLoadMeshHierarchyFromX – loads animation data and frame hierarchy from a .x file
  • D3DXLoadMeshHierarchyFromXInMemory – as above but loads from memory not disk.
  • D3DXLoadSkinMeshFromXof – loads hierarchy and skinning data from a ID3DXFileData object.

These methods allow skinning and animation.

These functions are described in the Load X Hierarchy notes.


These notes refer to the new X file interfaces first introduced in the December 2004 update of the SDK. The old interfaces still work but are now marked as deprecated.

The old legacy interfaces were:

  • IDirectXFile
    • Pointer type: LPDIRECTXFILE
  • IDirectXFileData
    • Pointer type: LPDIRECTXFILEDATA
  • IDirectXFileObject
  • IDirectXFileSaveObject
  • IDirectXFileBinary
  • IDirectXFileDataReference
  • IDirectXFileEnumObject

The new interfaces are:

  • ID3DXFile
    • Pointer type: LPD3DXFILE
  • ID3DXFileData
    • Pointer type: LPD3DXFILEDATA
  • ID3DXFileEnumObject
    • Pointer type: LPD3DXFILEENUMOBJECT
  • ID3DXFileSaveData
    • Pointer type: LPD3DXFILESAVEDATA
  • ID3DXFileSaveObject
    • Pointer type: LPD3DXFILESAVEOBJECT

The pointer type is simply used to ease typing since you generally use a pointer to these interface classes. For example LPD3DXFILE is defined like this:

typedef ID3DXFile* LPD3DXFILE;

In these notes I will not use these typedefs as I find they confuse people, instead I will use the full pointer declaration.