# 4DS

*37*pages on

this wiki

## Introduction Edit

The .4ds format in version 41 is the basic format for 3D objects in Hidden & Dangerous 2. 4ds was also used for Mafia and Chameleon but in different versions.

## Structure Edit

For having a better and easier understanding, we split the file into three parts: header, images and objects.

### Header Edit

Each .4ds file has following values at its beginning.

Map.4ds | meaning | example |
---|---|---|

first 4 bytes | file format | 4ds. |

16-bit INT | file version | 2900 (41) |

8 bytes | timestamp | 002E 9F89 5048 C301 |

### Images Edit

Here all images listed which are used. Allowed are Bitmaps(.bmp) and Targa Image Files (.tga)

First we have the attribute for the total amount of pictures. If you added a picture in your map.4ds file, don't forget to update this value.

It's a 16-bit INT e.g. **0700**, 7 images.

After the amount, each image is listed after the following structure:

Image | ||
---|---|---|

4x 8-bit INT | unknown, activates Alpha channel (transparency) | 0 128 63 15 (1 128 21 32) |

4x 32-bit FLOAT | Ambient color | 0.5 0.5 0.5 0 |

4x 32-bit FLOAT | Diffuse color | 0.5 0.5 0.5 0 |

4x 32-bit FLOAT | Specular color | 0.045 0.045 0.045 0 |

4x 32-bit FLOAT | Self illumination color | 0.0 0.0 0.0 0.0 |

32-bit FLOAT | shininess/glossiness | 25 |

8-bit INT | unknown | 0 |

32-bit FLOAT | opacity | 0(0%) to 1 (100%) |

8-bit INT | amount of characters (of label) | 14 |

differs | label | MAPA_AF3_2.BMP |

### Objects Edit

The last image is followed by a 16-bit INT, which represents the number of objects e.g. 0A00 (10 objects).

Each object has a header, which is described below. After the header comes the actual object data. A list of all object types can be found here: object types

#### Object header Edit

The visual object type and flags are only present if the object type is a visual object.

Description | Example | |
---|---|---|

8-bit INT | object type | object types |

8-bit INT | visual object type | visual types |

16-bit INT | flags | static collision? receive shadows? cast shadows? |

16-bit INT | father index (0: none) | 2 |

3x 32-bit FLOAT | position: x, y, z | -0.192 -0.132 -0.273 (position relavitly to father object) |

4x 32-bit FLOAT | rotation: x, y, z, w (quaternions) | 0.5 0.5 -0.5 0.5 |

3x 32-bit FLOAT | scale: x, y, z | 1 1 1 |

32-bit FLOAT | unknown | always 0 |

8-bit INT | unknown | always 9 for non sector objects |

8-bit INT | number of letters | 10 |

Label | unique object name | "objective1" |

8-bit INT | number of letters | 7 |

Label | custom user properties | "VOLB,36" |

#### Visual Edit

##### MeshObject Edit

Description | Example | |
---|---|---|

16-bit INT | instance ID | |

8-bit INT | number of LODs (Level of Detail) | |

for each LOD | ||

32-bit FLOAT | LOD draw distance | |

32-bit INT | extra data (length) | |

16-bit INT | number of vertices | |

for each vertex | ||

3x 32-bit FLOATs | vertex position: x, y, z | |

3x 32-bit FLOATs | vertex normal: nx, ny, nz | |

2x 32-bit FLOATs | texture vertex: u, v | |

end for each vertex | ||

8-bit INT | number of face groups | |

for each face group | ||

16-bit INT | number of faces | |

Nx (3x 16-bit INT) | face vertex indices: a, b, c | |

16-bit INT | bitmap id |

##### SingleMesh Edit

Inherits MeshObject data.

Description | Example | |
---|---|---|

8-bit INT | number of joints | |

4x 32-bit FLOAT | minimum position? x, y, z, 0 | |

4x 32-bit FLOAT | maximum position? x, y, z, 0 | |

N x 8-bit INT | parent index of N-th joint | |

for each joint | ||

16x 32-bit FLOAT | joint transform matrix | |

4x 32-bit FLOAT | minimum position? x, y, z, 0 | |

4x 32-bit FLOAT | maximum position? x, y, z, 0 | |

end for each joint | ||

for each LOD (from Object) | ||

32-bit INT | number of weighted vertices | |

for each weighted vertex | ||

8-bit INT | joint index | |

8-bit INT | vertex weight? |

##### SingleMorph Edit

Inherits SingleMesh and Morph data.

##### Billboard Edit

Inherits MeshObject data.

Description | Example | |
---|---|---|

32-bit INT | axis? | |

8-bit INT | unknown |

##### Morph Edit

Inherits MeshObject data.

Description | Example | |
---|---|---|

8-bit INT | number of morph targets | |

8-bit INT | number of morphed parts (hand, eye, etc) | |

8-bit INT | unknown | |

for each morphed parts | ||

16-bit INT | number of morphed vertices | |

for each morphed vertex | ||

for each morph target | ||

3x 32-bit FLOAT | morphed vertex position: x, y, z | |

3x 32-bit FLOAT | morphed vertex normal: nx, ny, nz | |

end for each morph target | ||

end for each morphed vertex | ||

Nx 16-bit INT | mapping from N-th morphed vertex to origial vertex | |

end for each morphed parts | ||

12x 32-bit FLOAT/INT | unknown |

##### Lens Edit

Description | Example | |
---|---|---|

8-bit INT | number of glows | |

for each glow | ||

32-bit FLOAT | unknown | |

32-bit FLOAT | unknown | |

16-bit INT | material ID |

##### Mirror Edit

Description | Example | |
---|---|---|

33x 32-bit FLOAT/INT | unknown | |

32-bit INT | number of vertices | |

32-bit INT | number of faces | |

Nx (4x 32-bit FLOAT) | vertex positions: x, y, z, 0 | |

Nx (3x 16-bit INT) | face vertex indices: a, b, c |

#### Sector Edit

Description | Example | |
---|---|---|

32-bit INT | unknown | |

32-bit INT | unknown | |

32-bit INT | number of vertices | |

32-bit INT | number of faces | |

4x 32-bit FLOAT | minimum vertex position: x, y, z, 0 | |

4x 32-bit FLOAT | maxmimum vertex position: x, y, z, 0 | |

N x (4x 32-bit FLOAT) | vertex positions: x, y, z, 0 | |

N x (3x 16-bit INT) | face vertex indices: a, b, c | |

8-bit INT | number of portals | |

for each portal | ||

8-bit INT | number of portal vertices | |

3x 32-bit FLOAT | portal plane normal | |

32-bit FLOAT | portal plane distance | |

32-bit INT | portal flags? | |

32-bit FLOAT | portal near range? | |

32-bit FLOAT | portal far range? | |

32-bit FLOAT/INT | unknown | |

Nx (4x 32-bit FLOAT) | portal vertex positions: x, y, z, 0 |

#### Dummy Edit

Dummies are cuboids, mostly cubes. The 2 extents are two points in space which form the diagonal of a cuboid/box.

Description | Example | |
---|---|---|

3x 32-bit FLOAT | minimum extent of dummy box | |

32-bit INT | unknown | |

3x 32-bit FLOAT | maximum extent of dummy box | |

32-bit INT | unknown |

#### Target Edit

Description | Example | |
---|---|---|

16-bit INT | unknown | |

8-bit INT | unknown : N | |

Nx (16-bit INT) | target ID? |

#### Joint Edit

Description | Example | |
---|---|---|

32-bit INT | unique joint ID |

#### Occluder Edit

Description | Example | |
---|---|---|

32-bit INT | number of vertices | |

32-bit INT | number of faces | |

Nx (4x 32-bit FLOAT) | vertex positions: x, y, z, 0 | |

Nx (3x 16-bit INT) | face vertex indices: a, b, c |

### Animation Edit

Finally, at the end of each .4ds file comes a 8-bit INT value, which is always 0 unless an corresponding .5ds animation file exists.