MDL file format (FSX): Difference between revisions
m (→LODE: lod level is int, not float) |
No edit summary |
||
Line 178: | Line 178: | ||
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: | 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 | short material_flags | ||
short (?) | short (?) | ||
float (?) | float (?) | ||
int | int diffuse_texture_index | ||
float (?) | float (?) | ||
float (?) | float (?) | ||
float (?) | float (?) | ||
int emissive_texture_index | |||
float (?) | float (?) | ||
float (?) | float (?) | ||
float | float diffuse_color_R | ||
float | float diffuse_color_G | ||
float | float diffuse_color_B | ||
float | float diffuse_color_A | ||
float specular_color_R | float specular_color_R | ||
float specular_color_G | float specular_color_G | ||
Line 210: | Line 210: | ||
float z_write_alpha | float z_write_alpha | ||
material_flags is a bitmask: | |||
0x01: material has a base color | |||
0x02: material has a diffuse texture (the diffuse color is then only used as a fallback) | |||
0x80: material has an emissive texture (for night) | |||
The source_blend and destination_blend parameters seem to use the following enumeration: | The source_blend and destination_blend parameters seem to use the following enumeration: |
Revision as of 11:34, 22 October 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 Block | RIFF |
CRAS | Object crashbox | RIFF |
BBOX | Object boundingbox | RIFF |
RADI | Object radius | RIFF |
MDLD | Exterior Node Root | 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 Space list (?) | VERB |
TRAN | Static transformation matrices | MDLD |
AMAP | Animation Map | MDLD |
SCEN | Scenegraph Node Root | MDLD |
SGAL | Scenegraph Animation Linkage | MDLD |
SGVL | Scenegraph Visibility Linkage | MDLD |
SGJC | Scenegraph Joint Constraints | MDLD |
SGBR | Scenegraph Bone Reference | MDLD |
LODT | LOD table | MDLD |
LODE | LOD Entry | LODT |
PART | Part list | LODE |
ANIB | Animation Block | MDLD |
The main RIFF section itself has one additional parameter, this is a four character string that indicates the type of RIFF MDL file. For an FsX MDL file the value should always be MDLX.
The following subsection show more details about the content of these different sections.
MDLH
This the FS MDL object header. It seems to contain of an integer that always has the value of 123456 and a float of value 10. The purpose of these parameter is unknown.
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
This is the ParamsBlock section, containing parameter block data.
CRAS
This section stores the crashtree of the object. It has first two unknown integer values, then there are 3 float values giving the front lower left corner of the object, then 3 float values giving the length, height, and width, then another unknown integer, and then the branches of the tree, which are all integer values (instead of bytes which had been used in FS2004). If the value of a cell is -1 the cell is solid, if it is -2 the cell is free, every other value is the offset of the octet of the next lower node in the branch.
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_flags short (?) float (?) int diffuse_texture_index float (?) float (?) float (?) int emissive_texture_index float (?) float (?) float diffuse_color_R float diffuse_color_G float diffuse_color_B float diffuse_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
material_flags is a bitmask:
0x01: material has a base color 0x02: material has a diffuse texture (the diffuse color is then only used as a fallback) 0x80: material has an emissive texture (for night)
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
This section is contains tangent space list data. The first paramter of this list seems to be a zero. Then for each vertex two vectors are given that define a plane that is tangent to the vertex (these vectors are defined as three floats). This data only seems to be set for textured polygons, untextured polygons have null vectors defined here.
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
This section contains animation map data.
SCEN
Unknown at the moment.
SGAL
This is the scenegraph animation linkage section.
SGVL
This is the scenegraph visibility linkage section.
SGJC
This scenegraph section contains IK joint constraint data.
SGBR
This is the scenegraph bone reference section.
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 an int 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 type (1 = Triangle List, 2 = Triangle Fan, 3 = Triangle Strip) int scenegraph_reference (?) int material_index int vertex_buffer_index int vertex_offset int vertex_count int index_offset int index_count int mouse_rectangle_ref (?)
vertex_buffer_index tells which VERT structure inside the VERB section is to be used.
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
Animation block section. Data type is uint8.