quake3 bsp 地图格式简介

本文档详细介绍了Quake3 BSP文件格式的结构与内容,包括文件头、目录及17种数据块的详细说明。这些数据块涵盖了游戏地图的各种元素,如纹理、平面、节点、模型等。

come from:http://www.mralligator.com/q3/

Unofficial Quake 3 Map Specs 



Introduction[top]

This document describes the Quake 3 BSP file format. This is an unofficial document. Quake 3 is a registered trademark of id Software, which does not sponsor, authorize, or endorse this document.

This document describes the Quake 3 BSP file format as the author understands it. While every effort has been made to ensure that the contents of this document are accurate, the author does not guarantee that any portion of this document is actually correct. In addition, the author cannot be held responsible the consequences of the any use or misuse of the information contained in this document.

Copyright © 2000 Kekoa Proudfoot. All rights reserved.

Description[top]

File structure

Quake 3 BSP files are IBSP files, and therefore have a structure similar to previous BSP files from id Software. Every IBSP file begins with a header, which in turn contains a lump directory. The lump directory describes the layout of the rest of the file, which contains some number of lumps. Each lump stores a particular kind of map data.

Header / Directory
Lump
Lump
Lump
...
The layout of an IBSP file. An IBSP file consists of a header followed by a number of lumps. The header contains a directory which identifies the locations and sizes of the lumps.

Data types

Quake 3 BSP files contains only four basic data types. They are:

TypeDescription
ubyteunsigned byte
int4-byte integer, little-endian
float4-byte IEEE float, little-endian
string[n]string of n ASCII bytes, not necessarily null-terminated

All data in a BSP file is organized into records composed of these four data types.

Header and Directory

The header record looks like this:

header

string[4] magicMagic number. Always "IBSP".
int versionVersion number. 0x2e for the BSP files distributed with Quake 3.
direntry[17] direntriesLump directory, seventeen entries.

Each direntry locates a single lump in the BSP file:

direntry

int offsetOffset to start of lump, relative to beginning of file.
int lengthLength of lump. Always a multiple of 4.

Lumps

There are 17 lumps in a Quake 3 BSP file. In the order that they appear in the lump directory, they are:

IndexLump NameDescription
0EntitiesGame-related object descriptions.
1TexturesSurface descriptions.
2PlanesPlanes used by map geometry.
3NodesBSP tree nodes.
4LeafsBSP tree leaves.
5LeaffacesLists of face indices, one list per leaf.
6LeafbrushesLists of brush indices, one list per leaf.
7ModelsDescriptions of rigid world geometry in map.
8BrushesConvex polyhedra used to describe solid space.
9BrushsidesBrush surfaces.
10VertexesVertices used to describe faces.
11MeshvertsLists of offsets, one list per mesh.
12EffectsList of special map effects.
13FacesSurface geometry.
14LightmapsPacked lightmap data.
15LightvolsLocal illumination data.
16VisdataCluster-cluster visibility data.

Entities

The entities lump stores game-related map information, including information about the map name, weapons, health, armor, triggers, spawn points, lights, and .md3 models to be placed in the map. The lump contains only one record, a string that describes all of the entities:

entities

string[lengthentsEntity descriptions, stored as a string.

The length of the entity string is given by the size of the lump itself, as specified in the lump directory.

The meanings, formats, and parameters of the various entity descriptions are currently outside the scope of this document. For more information about entity descriptions, see the documentation to Q3Radiant, the Quake 3 level editor.

Textures

The textures lump stores information about surfaces and volumes, which are in turn associated with faces, brushes, and brushsides. There are a total of length / sizeof(texture) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

texture

string[64] nameTexture name.
int flagsSurface flags.
int contentsContent flags.

Planes

The planes lump stores a generic set of planes that are in turn referenced by nodes and brushsides. There are a total of length / sizeof(plane) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

plane

float[3] normalPlane normal.
float distDistance from origin to plane along normal.

Note that planes are paired. The pair of planes with indices i and i ^ 1 are coincident planes with opposing normals.

Nodes

The nodes lump stores all of the nodes in the map's BSP tree. The BSP tree is used primarily as a spatial subdivision scheme, dividing the world into convex regions called leafs. The first node in the lump is the tree's root node. There are a total of length / sizeof(node) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

node

int planePlane index.
int[2] childrenChildren indices. Negative numbers are leaf indices: -(leaf+1).
int[3] minsInteger bounding box min coord.
int[3] maxsInteger bounding box max coord.

Leafs

The leafs lump stores the leaves of the map's BSP tree. Each leaf is a convex region that contains, among other things, a cluster index (for determining the other leafs potentially visible from within the leaf), a list of faces (for rendering), and a list of brushes (for collision detection). There are a total of length / sizeof(leaf) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

leaf

int clusterVisdata cluster index.
int areaAreaportal area.
int[3] minsInteger bounding box min coord.
int[3] maxsInteger bounding box max coord.
int leaffaceFirst leafface for leaf.
int n_leaffacesNumber of leaffaces for leaf.
int leafbrushFirst leafbrush for leaf.
int n_leafbrushesNumber of leafbrushes for leaf.

If cluster is negative, the leaf is outside the map or otherwise invalid.

Leaffaces

The leaffaces lump stores lists of face indices, with one list per leaf. There are a total of length / sizeof(leafface) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

leafface

int faceFace index.

Leafbrushes

The leafbrushes lump stores lists of brush indices, with one list per leaf. There are a total of length / sizeof(leafbrush) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

leafbrush

int brushBrush index.

Models

The models lump describes rigid groups of world geometry. The first model correponds to the base portion of the map while the remaining models correspond to movable portions of the map, such as the map's doors, platforms, and buttons. Each model has a list of faces and list of brushes; these are especially important for the movable parts of the map, which (unlike the base portion of the map) do not have BSP trees associated with them. There are a total of length / sizeof(models) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

model

float[3] minsBounding box min coord.
float[3] maxsBounding box max coord.
int faceFirst face for model.
int n_facesNumber of faces for model.
int brushFirst brush for model.
int n_brushesNumber of brushes for model.

Brushes

The brushes lump stores a set of brushes, which are in turn used for collision detection. Each brush describes a convex volume as defined by its surrounding surfaces. There are a total of length / sizeof(brushes) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

brush

int brushsideFirst brushside for brush.
int n_brushsidesNumber of brushsides for brush.
int textureTexture index.

Brushsides

The brushsides lump stores descriptions of brush bounding surfaces. There are a total of length / sizeof(brushsides) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

brushside

int planePlane index.
int textureTexture index.

Vertexes

The vertexes lump stores lists of vertices used to describe faces. There are a total of length / sizeof(vertex) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

vertex

float[3] positionVertex position.
float[2][2] texcoordVertex texture coordinates. 0=surface, 1=lightmap.
float[3] normalVertex normal.
ubyte[4] colorVertex color. RGBA.

Meshverts

The meshverts lump stores lists of vertex offsets, used to describe generalized triangle meshes. There are a total of length / sizeof(meshvert) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

meshvert

int offsetVertex index offset, relative to first vertex of corresponding face.

Effects

The effects lump stores references to volumetric shaders (typically fog) which affect the rendering of a particular group of faces. There are a total of length / sizeof(effect) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

effect

string[64] nameEffect shader.
int brushBrush that generated this effect.
int unknownAlways 5, except in q3dm8, which has one effect with -1.

Faces

The faces lump stores information used to render the surfaces of the map. There are a total of length / sizeof(faces) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

face

int textureTexture index.
int effectIndex into lump 12 (Effects), or -1.
int typeFace type. 1=polygon, 2=patch, 3=mesh, 4=billboard
int vertexIndex of first vertex.
int n_vertexesNumber of vertices.
int meshvertIndex of first meshvert.
int n_meshvertsNumber of meshverts.
int lm_indexLightmap index.
int[2] lm_startCorner of this face's lightmap image in lightmap.
int[2] lm_sizeSize of this face's lightmap image in lightmap.
float[3] lm_originWorld space origin of lightmap.
float[2][3] lm_vecsWorld space lightmap s and t unit vectors.
float[3] normalSurface normal.
int[2] sizePatch dimensions.

There are four types of faces: polygons, patches, meshes, and billboards.

Several components have different meanings depending on the face type.

For type 1 faces (polygons), vertex and n_vertexes describe a set of vertices that form a polygon. The set always contains a loop of vertices, and sometimes also includes an additional vertex near the center of the polygon. For these faces, meshvert and n_meshverts describe a valid polygon triangulation. Every three meshverts describe a triangle. Each meshvert is an offset from the first vertex of the face, given by vertex.

For type 2 faces (patches), vertex and n_vertexes describe a 2D rectangular grid of control vertices with dimensions given by size. Within this rectangular grid, regions of 3×3 vertices represent biquadratic Bezier patches. Adjacent patches share a line of three vertices. There are a total of (size[0] - 1) / 2 by (size[1] - 1) / 2 patches. Patches in the grid start at (i, j) given by:

i = 2n, n in [ 0 .. ( size[0] - 1) / 2 ), and
j = 2m, m in [ 0 .. ( size[1] - 1) / 2 ).

For type 3 faces (meshes), meshvert and n_meshverts are used to describe the independent triangles that form the mesh. As with type 1 faces, every three meshverts describe a triangle, and each meshvert is an offset from the first vertex of the face, given by vertex.

For type 4 faces (billboards), vertex describes the single vertex that determines the location of the billboard. Billboards are used for effects such as flares. Exactly how each billboard vertex is to be interpreted has not been investigated.

The lm_ variables are primarily used to deal with lightmap data. A face that has a lightmap has a non-negative lm_index. For such a face, lm_index is the index of the image in the lightmaps lump that contains the lighting data for the face. The data in the lightmap image can be located using the rectangle specified by lm_start andlm_size.

For type 1 faces (polygons) only, lm_origin and lm_vecs can be used to compute the world-space positions corresponding to lightmap samples. These positions can in turn be used to compute dynamic lighting across the face.

None of the lm_ variables are used to compute texture coordinates for indexing into lightmaps. In fact, lightmap coordinates need not be computed. Instead, lightmap coordinates are simply stored with the vertices used to describe each face.

Lightmaps

The lightmaps lump stores the light map textures used make surface lighting look more realistic. There are a total of length / sizeof(lightmap) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

lightmap

ubyte[128][128][3] mapLightmap color data. RGB.

Lightvols

The lightvols lump stores a uniform grid of lighting information used to illuminate non-map objects. There are a total of length / sizeof(lightvol) records in the lump, where length is the size of the lump itself, as specified in the lump directory.

Lightvols make up a 3D grid whose dimensions are:

nx = floor(models[0].maxs[0] / 64) - ceil(models[0].mins[0] / 64) + 1
ny = floor(models[0].maxs[1] / 64) - ceil(models[0].mins[1] / 64) + 1
nz = floor(models[0].maxs[2] / 128) - ceil(models[0].mins[2] / 128) + 1

lightvol

ubyte[3] ambientAmbient color component. RGB.
ubyte[3] directionalDirectional color component. RGB.
ubyte[2] dirDirection to light. 0=phi, 1=theta.

Visdata

The visdata lump stores bit vectors that provide cluster-to-cluster visibility information. There is exactly one visdata record, with a length equal to that specified in the lump directory.

visdata

int n_vecsNumber of vectors.
int sz_vecsSize of each vector, in bytes.
ubyte[n_vecs * sz_vecsvecsVisibility data. One bit per cluster per vector.

Cluster x is visible from cluster y if the (1 << y % 8) bit of vecs[x * sz_vecs + y / 8] is set.

Note that clusters are associated with leaves.

Known Issues and Missing Items[top]

This document is very brief. I have gathered more information, but have not had time to write it up. Occasionally, I add more information to this document.

At some point I put together a page that describes triangle meshes and other q3 leaf elements. I forget the exact reason I created that page, but you might find it interesting.

Feel free to ask for clarification, but please accept my apologies if I can't find the time to answer.

 


Copyright © 2000 Kekoa Proudfoot. All rights reserved.

Keywords: quake 3 quake3 q3 arena quake3arena q3arena map bsp file spec specs format

转载于:https://www.cnblogs.com/zengqh/archive/2012/08/03/2621307.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值