Skip to content

Instantly share code, notes, and snippets.

@Polda18
Last active March 28, 2021 17:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Polda18/e491dca3b8fa3be2c83c29ae32c8bb87 to your computer and use it in GitHub Desktop.
Save Polda18/e491dca3b8fa3be2c83c29ae32c8bb87 to your computer and use it in GitHub Desktop.
Quake III Arena & Quake Live IBSP file format spec
// Source: http://www.mralligator.com/q3/
// Source: https://github.com/id-Software/GtkRadiant/blob/master/tools/quake3/q3map2/q3map2.h
#ifndef __IBSP_FORMAT_DEF_H__
#define __IBSP_FORMAT_DEF_H__
// Byte definition
typedef unsigned char ubyte;
// Vectors definition
typedef struct {
float s, t;
} vec_t;
typedef struct {
float x, y, z;
} vec3_t;
// Header definition
typedef struct {
unsigned int offset; // Lump directory entry offset (address relative to *.bsp file beginning)
unsigned int length; // Lump directory length in bytes
} lump_direntry_t;
typedef struct {
const char[4] magic; // magic number = always string "IBSP"!
unsigned int version; // IBSP version = Quake Live is v47
lump_direntry_t[18] direntries; // Lump directories entries
} ibsp_head_t;
// LUMPS LIKE BELOW
// Entities lump
//char[ibsp_head.direntries[0].length] ents; // Entities info (string)
// Textures lump
typedef struct {
char[64] name; // Texture name = always limit of 64 bytes!
int surface; // Surface flags
int contents; // Content flags
} texture_t;
// Planes lump
typedef struct {
vec3_t normal; // Normal vector
float dist; // Distance from origin to plane alongside normal vector
} plane_t;
// Nodes lump
typedef struct {
int plane; // Plane index
int[2] children; // Children indices. Negative number marks leaf
int[3] mins; // Integer bounding box min coord
int[3] maxs; // Integer bounding box max coord
} node_t;
// Leafs lump
typedef struct {
int cluster; // Visdata cluster index. Negative value means outside map or invalid.
int area; // Areaportal area
int[3] mins; // Integer bounding box min coord
int[3] maxs; // Integer bounding box max coord
int leafface; // First leafface for leaf
int n_leaffaces; // Number of leaffaces for leaf
int leafbrush; // First leafbrush for leaf
int n_leafbrushes; // Number of leafbrushes for leaf
} leaf_t;
// Leaffaces lump
//int face; // Face index (integer number, counting from zero)
// Leafbrushes lump
//int brush; // Brush index (integer number, counting from zero)
// Models lump
typedef struct {
vec3_t mins; // Bounding box min coord
vec3_t maxs; // Bounding box max coord
int face; // First face for model
int n_faces; // Number of faces for model
int brush; // First brush for model
int n_brushes; // Number of brushes for model
} model_t;
// Brushes lump
typedef struct {
int brushside; // First brushside for brush
int n_brushsides; // Number of brushsides for brush
int texture; // Texture index
} brush_t;
// Brushsides lump
typedef struct {
int plane; // Plane index
int texture; // Texture index
} brushside_t;
// Vertexes lump
typedef struct {
vec3_t position; // Vertex position
vec3_t[2] texcoord; // Vertex texture coordinates. 0=surface, 1=lightmap.
vec3_t normal; // Vertex normal
ubyte[4] color; // Vertex color. RGBA.
} vertex_t;
// Meshverts lump
//int offset; // Vertex index offset, relative to first vertex of corresponding face
// Effects lump
typedef struct {
char[64] name; // Effect shader
int brush; // Brush that generated this effect
int unknown; // Always 5, except in q3dm8, which has one effect with -1
} effect_t;
// Faces lump
typedef struct {
int texture; // Texture index
int effect; // Index into lump 12 (Effects), or -1.
int type; // Face type. 1=polygon, 2=patch, 3=mesh, 4=billboard
int vertex; // Index of first vertex
int n_vertexes; // Number of vertices
int meshvert; // Index of first meshvert
int n_meshverts; // Number of meshverts
int lm_index; // Lightmap index
int[2] lm_start; // Corner of this face's lightmap image in lightmap
int[2] lm_size; // Size of this face's lightmap image in lightmap
vec3_t lm_origin; // World space origin of lightmap
vec_t[3] lm_vecs; // World space lightmap s and t unit vectors
vec3_t normal; // Surface normal
int[2] size; // Patch dimensions
} face_t;
// Lightmaps lump
//ubyte[128][128][3] map; // Lightmap color data. RGB.
// Lightvols lump
typedef struct {
ubyte[3] ambient; // Ambient color component. RGB.
ubyte[3] directional; // Directional color component. RGB.
ubyte[2] dir; // Direction to light. 0=phi, 1=theta.
} lightvol_t;
// Visdata lump
typedef struct {
int n_vecs; // Number of vectors
int sz_vecs; // Size of each vector, in bytes
ubyte * vecs; // Visibility data. One bit per cluster per vector.
// Made into pointer: create using malloc(n_vecs * sz_vecs);
} visdata_t;
// Advertisements lump
typedef struct {
// Single advertisements lump cell (a single advertisement data)
int cellId; // The cellId key/value pair defined in Radiant
vec3_t norm; // Normal vector to the advertisement plane
vec3_t[4] rect; // Advertisement plane boundaries
char[64] model; // Advertisement display model
} advertisement_t;
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment