Difference between revisions of "MDL file format (FSX)"

From FSDeveloper Wiki
Jump to: navigation, search
(ANIB)
(TRAN)
Line 260: Line 260:
 
==== TRAN ====
 
==== TRAN ====
  
Unknown at the moment.
+
This section stores the static transformation matrices. Each matrix is defined by 16 floats. For a definition of these matrices see the [http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_m_Summer_04/directx/direct3d/gettingstarted/transforms/matrices/matrices.asp DirectX SDK].
  
 
==== AMAP ====
 
==== AMAP ====

Revision as of 12:58, 14 January 2007

This document describes the structure of FsX MDL files. This document is mainly useful for people who want to read or decode these MDL files in a tool.

Compared to the Fs2004 MDL format there are quite a few changes. One of the biggest is that aircraft and scenery MDL files now have the same format. At the moment the knowledge in this document mainly comes from evaluating simple scenery objects, so it is certainly not yet complete. If you have anything to add, please do so.

MDL sections

The MDL file uses the RIFF format, this means that the file consists of different sections. Each section starts with a four character label, followed by the size of the content in bytes (this size is thus without the length of the header itself). The tabel below shows how the different section can be nested.

Name Description Parent section
RIFF General RIFF section (covers entire file) None
MDLH MDL header RIFF
MDLG Object GUID RIFF
MDLN Object friendly name RIFF
PARA Parameters (?) RIFF
CRAS Object crashbox RIFF
BBOX Object boundingbox RIFF
RADI Object radius RIFF
MDLD Object data (?) RIFF
TEXT Texture list MDLD
MATE Material list MDLD
INDE Triangle index list MDLD
VERB Vertex buffer list MDLD
VERT Vertex list VERB
TANS Tangent list (?) VERB
TRAN Static transformation matrices MDLD
AMAP (?) MDLD
SCEN Object scenegraph (?) MDLD
SGAL Scenegraph ... (?) MDLD
SGVL Scenegraph ... (?) MDLD
SGJC Scenegraph ... (?) MDLD
SGBR Scenegraph ... (?) MDLD
LODT LOD table MDLD
LODE External LOD (?) LODT
PART Part list LODE
ANIB (?) MDLD

The following subsection show more details about the content of these different sections.

MDLH

This the FS MDL object header. For FsX MDL objects it should contain the four characters MDLX as content.

MDLG

This section stores the object GUID. The GUID is stored in the following parts:

unsigned long data1
unsigned short data2
unsigned short data3
unsigned char data4[8]

In hexadecimal form the GUID is then written as:

{data1-data2-data3-data4[0:1]-data4[2:7]}

MDLN

This section contains a string with the friendly name of the object.

PARA

Unknown at the moment.

CRAS

This section stores the crashtree of the object. Exact details of the tree structure are still unknown (might be the same as the Fs2004 crashtree).

BBOX

This section stores the bounding box of the object in the following format:

float xmin
float ymin
float zmin
float xmax
float ymax
float zmax

RADI

This section stores the radius of the object as a float.

MDLD

This section contains the actual data defining the object.

TEXT

This section contains the list of all textures of the object. Each texture is given as a 64 character string. Unlike the Fs2004 format no additional parameters are stored in the texture list, only the texture name.

MATE

This section contains a list of all materials of the object. Each material is defined by a 120 byte long record. The definition of this record is given below:

short  material_type
short  (?)
float  (?)
int    texture_index;
float  (?)
float  (?)
float  (?)
float  (?)
float  (?)
float  (?)
float  base_color_R
float  base_color_G
float  base_color_B
float  base_color_A
float  specular_color_R
float  specular_color_G
float  specular_color_B
float  specular_color_A
float  specular_power
float  (?)
float  (?)
float  (?)
float  (?)
float  specular_bloom_floor
float  ambient_light_scale
float  (?)
int    source_blend
int    destination_blend
int    alpha_test_function
float  alpha_test_threshold
float  z_write_alpha

The material_type is 1 for materials without a texture and 3 for a materials that have a texture.

The source_blend and destination_blend parameters seem to use the following enumeration:

 1 zero
 2 once
 3 srcColor
 4 invSrcColor
 5 srcAlpha
 6 invSrcAlpha
 7 destAlpha
 8 invDestAlpha
 9 destColor
10 invDestColor

The alpha_test_function parameter seems to use the following enumeration:

1 never
2 less
3 equal
4 lessEqual
5 greater
6 notEqual
7 greaterEqual
8 always

The z_write_alpha parameter has a value of 1 (float) when it is enabled (TRUE).

INDE

This section contains of a lot of triangles, each given by three short values. These values are the indices of the vertices to use. In the PART list an offset is specified for these indices, so the first vertex of a part seems to be zero always.

VERB

This section gives the vertex buffer of the object.

VERT

This section contains a list of all vertices of the object. Each vertex is given by a 32 byte record. The definition of this record is given below:

float position_x
float position_y
float position_z
float normal_x
float normal_y
float normal_z
float texture_mapping_x
float texture_mapping_y
TANS

Unknown at the moment.

TRAN

This section stores the static transformation matrices. Each matrix is defined by 16 floats. For a definition of these matrices see the DirectX SDK.

AMAP

Unknown at the moment.

SCEN

Unknown at the moment.

SGAL

Unknown at the moment.

SGVL

Unknown at the moment.

SGJC

Unknown at the moment.

SGBR

Unknown at the moment.

LODT

This section defines the LOD table of the object. It is followed by a LODE section for each LOD level in the object.

LODE

This section defines a LOD level for the object. It contains a float that indicates the value of this LOD. The default value if only one LOD is used in the object is 100. This section is followed by a PART section for each part in this LOD level.

PART

This section defines an object part. The part definition contains the following parameters:

int  (?)
int  (?)
int  material_index
int  scene_ref (?)
int  vertex_offset
int  vertex_count  
int  index_offset
int  index_count
int  mouse_rectangle_ref (?)

The index_offset and index_count are given in indices, so it should be divided by three to get a triangle offset and count.

ANIB

Unknown at the moment.