ODFL File Format
From ODF::Wiki
The ODFL File Format (ODFL stands for "ODF Level") is a level file format which was written by Lo and Cent for Flight Back in April 2009. ODFL files shall end on .odfl.
This article always describes the newest version of the ODFL File Format. The current version is 1.4 (to read as major.minor), as declared on September 19, 2010.
Contents |
[edit] Importing to ODFL
Originally, ODFL was written for importing Descent3's D3L levels using d3l master. This also explains why it is similar to it in some points. Currently, an RL2 (Descent2) and RDL (Descent1) exporter is in work (rl2 master and rdl master).
If you want to write your own importer, look at the file specs below.
[edit] Definitions
The following definitions have to be made to understand the file specifications (see below). Consider each struct packed, i.e. no space is aligned between the data.
struct String { ubyte length; char str[length]; // non null terminated }; struct Vert { float x, y, z; }; typedef Vert[3] Matrix; struct Connect { ushort connect_id; // id to vertex at this connection float u; float v; ubyte alpha; }; struct Face { ubyte connects; Connect[connects]; // edges of the faces sbyte portal_num; // -1 for no portal Vert normal; ushort lmi_handle; }; // contains all faces in one room struct FacesInRoom { uint num_faces; Face[num_faces]; // all faces in this room } struct TextureInfo { String name; float r,g,b, alpha; // emitted light. unused at the moment. }; struct Material { ushort texture_id; short lightmap_id; // handle to the bitmap, -1 if lightmaps are not supported by format ushort num_faces; ushort face_ids[num_faces]; // indexes to faces with this Texture }; struct Object { ubyte type; uint room_num; // TODO: ushort!! Vert position; Matrix orientation; String name; }; struct LightMap { short width, height; ubyte xspacing, yspacing; // use not clear by now Vert upperleft; // upper left corner of lightmap (in 3D) ushort data[width*height]; };
[edit] The Official File Specs
struct header { char[4] ODFL; ubyte major_version; // for the current version, see the very top of this page. ubyte minor_version; String name; String notes; String designer; String copyright; ushort num_rooms; }; struct verts { uint num_verts; Vert[num_verts]; }; struct faces { FacesInRoom[num_rooms]; // faces, sorted by rooms }; struct textures { ushort num_textures; TextureInfo texture_names[num_textures]; uint num_materials; Material materials[num_materials]; // ordered by rooms }; struct objects { ushort num_objs; Object objs[num_objs]; }; struct lm_data { uint num_lightmaps; // zero if lightmaps are not supported. TODO: short better? LightMap lm[num_lightmaps]; };
[edit] Example for a simple cube
Note: If a number has no letter behind it, consider it a byte, otherwise, a 's' indicates the value is a short, a 'i' indicates the value is an int, and 'f' indicates that the value is a float. The letter is stored as a single ASCII char.
O D F L // tag 1 4 // major and minor version 4 H a n s // author name 0 0 0 // three empty strings 1s // num rooms 8i // num verts <8*3 floats, each float 4 byte> 6i // num faces 4 // number of connects 0s 0f 0f 0b // id of vert, u, v, alpha 1s 0f 1f 0b 2s 1f 0f 0b 3s 1f 1f 0b -1 // this face has no neighbor room <3 floats, each float 4 byte> // normal 0s // lmi handle, not used in this level ... <5 other faces follow> 1s // num textures 6 sample 10f 10f 10f 10f // name, rgba 1i // num materials 0s // texture id -1s // lightmap_id - none here 6s 0s 1s 2s 3s 4s 5s // num faces, then all faces that have this material 1s // num objs 0 // type byte - TODO - what is a player? 0i // room num <3 floats, each float 4 byte> // position vert <3*3 floats, each float 4 byte> // orientation matrix 4 s h i p // name 0i // num_lightmaps - (none used here)
[edit] File format revisions
Here is a small history of file format changes. Please note that old versions are usually not supported by ODFL readers of new versions.
1.0 first recorded file format number. Format supports verts, faces, textures,
lightmaps and objects
1.1 added red/gree/blue/alpha values for each texture to allow dynamic lighting
1.2 extended lightmap details, restructured textures into materials (current)
1.3 changed lightmap buffer size into real height and width
1.4 num_materials changed from ushort to uint, switched height and width in LightMap struct,
added x- and y-spacing and upperleft vert.

