openOMSI GitHub Discord

Docs / Reference / Content formats

o3d (binary mesh) - unit mc_o3dfiles

4 min readEdit this pagedocs/FORMATS.md

84 19            magic
ver              u8   (1,3,4,5,7 seen)
[flags]          u8   (ver >= 3)  bit0: 32-bit triangle indices
[key]            u32  (ver >= 4)  usually 0
sections, tagged by one byte, until EOF:
  0x17 vertices  count (u16, or u32 if ver>=3) × {x y z nx ny nz u v} f32
  0x49 triangles count (u16/u32) × {i0 i1 i2 (u16 or u32), material u16}
  0x26 materials count u16 × {diffuse rgba, specular rgb, emissive rgb, power} f32×11, name (u8 len + bytes)
  0x79 matrix    16 × f32 (row-major, row 3 = translation)
  0x54 bones     count u16 × {name (u8 len), weight count u16 × {vertex idx (u16/u32), weight f32}}

Section order in stock content is always 17 49 26 79 [54]. Verified on 4026/4026 stock files. Any other byte where a tag is expected is passed over, one byte at a time (the loader's case has no else branch).

Mods rely on it: 50 version-7 files with flags 3 (the MB Sprinter 412D XLWB pack, "protected" meshes) carry three junk bytes inside the 0x79 matrix and a few zero bytes after it; refusing them lost the whole body of the bus.

Axes. Mesh files use Direct3D's frame: X right, Y up, Z forward. Vertices are stored in the parent (object / vehicle) frame; the 0x79 matrix is the mesh's own pivot frame, used by origin_from_mesh animations, and must not be applied when rendering. The engine converts to its world frame (X east, Y north, Z up) by swapping Y and Z.

A data object in a .x may carry a name (FrameTransformMatrix relative {, TextureFilename tex {), as the 3ds Max exporter of the Solaris Urbino 18 and the Novi Sad objects writes them.

DirectX .x meshes (text xof 0303txt, mod content: the BVG Citaro's Atron terminal, the O530's instrument glass) are flattened like D3DXLoadMeshFromX does: every Frame's FrameTransformMatrix applies to the meshes inside it, parent after child.

The 16 numbers are row-major for row vectors (translation in elements 12-14), i.e. read column by column they are already the column-vector matrix; Blender's exporter puts a Y/Z swap (or a Z flip) in the root frame and each object's placement in its own frame.

Normals go by the inverse transpose (the Ruede Trafohaus scales its frame unevenly). 27 stock scenery .x files have translated frames (the Verkehrszeichen_MC street name signs, Ruede's chestnut trees, bus stop poles and old shelter, Trafohaus, Buildings_MC's wohn_03/04 and hoch_01).

Binary .x (xof 0303bin 0032, or 0064 for double floats) holds the same objects as little-endian tokens, each a WORD: 1 name and 2 string (DWORD length, then the bytes; a string is followed by its ,/; token as a DWORD), 3 integer, 5 GUID (16 bytes), 6 integer list and 7 float list (DWORD count, then the values), 10-20 the marks { } ( ) [ ] < > . , ;, 31 template, 40-52 the template member types.

omsi-o3d reads both encodings through one token stream; the compressed tzip/bzip variants are refused. Mod scenery exported this way (the PAD-Labs houses) loads like the text files.

DeclData inside a Mesh carries per-vertex data as a Direct3D 9 vertex declaration: a count and that many D3DVERTEXELEMENT9 entries (type, method, usage, usage index), then a count of DWORDs holding the vertex buffer, the elements packed one after another in each vertex (floats as their bit patterns).

The first NORMAL and the first TEXCOORD set replace MeshNormals / MeshTextureCoords; packed types (DEC3N, SHORT2N, FLOAT16_2, ...) widen to floats as Direct3D 9 does. Without it such meshes (the PAD-Labs houses, the Köln trees) come out in one flat colour.

Scrambled vertices (version ≥ 4). The key field (0xFFFFFFFF = none) selects a vertex scrambling reproduced from the original loader (omsi-o3d):

state = (key + version - 4 + (flags&2 ? 0x17D : 0)) mod 0xFDE8     (u16)
n     = vertex_count mod 0xFDE8;  b = 0
for each vertex (raw x y z nx ny nz u v):
    if key == 0: state = flags&2 ? 0x130 : 0
    state = (state*n + n*b) mod 8000
    b     = trunc(|frac(x)·frac(y)·frac(z)|·600) mod 256          (from the raw position)
    if state < 1000: swap(x,y) elif state < 3000: swap(x,z) elif state > 7000: swap(y,z)
    if state % 4 == 0: nx = -nx;  if state % 6 == 0: ny = -ny;  if state % 7 == 0: nz = -nz
    if state < 600: swap(ny,nz) elif state > 4500: swap(nx,ny) elif state > 6500: swap(nx,nz)
    if state % 5 == 0: u -= (state%100)² / 10000
    if state % 3 == 0: v -= (state%50)²  / 2500

Triangles, materials, matrix and bones are stored plainly. The original also refuses keys that are not in its registration list; that check is not reproduced.

Something wrong or missing? Fix it on GitHub or open an issue.

↑↓ to move↵ to open