MAP file format
file format spec + sample parser code for Quake .MAP files ("Valve" style, mapversion 220)
This is a technical file format specification article for programmers.
For mapping tutorials, see Quake resources instead.
The .MAP file format is a 3D file format devised for Quake 1 (1996).
It is gradually emerging as the standard file type for brush-based levels in any game engine, partly because it is relatively simple to parse and edit. It's similar to how .OBJ has become a simple 3D standard too, even though it lacks many advanced features.
Parsers
There's a good chance someone has already written a generic .MAP parser for your game engine / programming language.
For game engine-specific MAP importers and integrations, see TrenchBroom.
File format
Text based with curly braces and line breaks
Z axis is up (Quake convention), right-handed
angle
values are Euler degrees from 0-359-1 means "up"
-2 means "down"
some Quake mods implement rotations as a 3D vector called
m_angle
Entities
Every object in a .MAP must be an entity, a generic actor / game object container type.
There are two types of entities:
point entities: monsters, items, lights, things with fixed size / no size
brush entities: point entities with 3D shapes embedded inside them
worldspawn: global static brush entity, the "root" of the entire game world
world brushes: brushes bound to worldspawn
Entity data and templates are defined by a .FGD file loaded into the level editor.
Brush geometry
A brush is a convex 3D shape defined by 4 or more planes.
It is NOT a traditional 3D mesh format made of vertices and triangles. You need an additional map compile step to process the brush data into a usable 3D mesh. For example, Quake maps use an editor-time command line tool called QBSP that outputs a compiled .BSP map file; meanwhile many .MAP parsers for other engines instead generate this mesh at runtime.
Every brush line defines one 3D plane (a triangle) and its texture coordinates:
Building the 3D mesh based on plane intersections is a bit complicated. Most libraries implement some variant on Stefan Hajnoczi's 2001 C++ implementation. His paper explains the math and process in detail, PDF download mirrored below:
Texturing / UVs
The Quake .MAP file format has two versions: the original Standard version, and an updated format by Valve Software.
The original Standard format had problems storing texture rotations. Given a 3D brush plane normal in XYZ, it discards the longest axis and stores the resulting Vector2. But if the plane is at a 45 degree angle, then the longest axis is now ambiguous and the map compiler must now arbitrarily favor an axis; floating point imprecision makes this preference even less predictable, often resulting in unpleasant texture stretching.
Standard texture coordinates:
TEXTURE_NAME offsetX offsetY rotation scaleX scaleY
Meanwhile, more recent Valve format .MAPs have the "mapversion" "220"
key value set in the worldspawn. Valve format 220 resolves the 45 degree ambiguity case by storing UVs in Vector3 space, which also enables some useful UV skewing operations in TrenchBroom as well.
Valve format texture coordinates:
TEXTURE_NAME [ ux uy uz offsetX ] [ vx vy vz offsetY ] rotation scaleX scaleY
We generally recommend using Valve format, and there's no reason to use standard format other than backwards compatibility / porting old files to the updated format.
Example .MAP file
For much more complex example .MAP files, see Quake resources.
Sources
Last updated