BSP data structure

From FreeSpace Wiki
Jump to: navigation, search

This info is copied from the Descent Developer's Network bsp_data page.

Introduction

The BSP data in FreeSpace in similar to the Descent 1-3 BSP data (also called IDTA). In FreeSpace, the BSP data is located in the POF files.

This document was written by John Slagel from Volition Inc., with revisions and bugfixing from Garry Knudson and Francis "Pastel" Avila.

The first byte defines the block now following (0-7, see below). After a block the following byte defines the data of the next block, etc. Media:Bsp_chunk.png

0 - EOF

Means end of a local data structure reached

  • Must follow every SORTNORM
  • Must end a series of TMAPPOLY
+ 0 int id = 0
+ 4 int size

1 - DEFPOINTS

Defines the vertices and normals

  • Must be the first chunk in bsp data and may not be included more than once
+ 0 int id = 1
+ 4 int size
+ 8 int n_verts
+12 int n_norms
+16 int offset // from start of chunk to vertex data
+20 n_verts*char norm_counts
+offset vertex_data // Each vertex n is a point followed by norm_counts[n] normals.
    • Note: DEFPOINTS is the only type of chunk on bsp_data that could be unaligned. The offset to vertex data must be divisible by 4. This is a major cause of bus errors on ARM arch.

2 - FLATPOLY

Flat (non-textured) polygon

  • May be listed several times in a row, after a BOUNDBOX, and punctuated with EOF
+ 0 int id = 2
+ 4 int size 
+ 8 vector normal
+20 vector center
+32 float radius
+36 int nverts
+40 byte red
+41 byte green
+42 byte blue
+43 byte pad
for each vertex, i {
 short vertnum[i]
 short normnum[i]
}

3 - TMAPPOLY

Textured polygons

  • May be listed several times in a row, after a BOUNDBOX, and punctuated with EOF
+ 0 int id = 3
+ 4 int size
+ 8 vector normal
+20 vector center
+32 float radius
+36 int nverts
+40 int tmap_num
for each vertex, i {
 ushort vertnum[i]
 ushort normnum[i]
 float u[i]
 float v[i]
}

4 - SORTNORM

Sortnorms are planes that split the model recursively

  • All offsets must lead to EOF, another SORTNORM, SORTNORM2, or BOUNDBOX
+ 0 int id = 4
+ 4 int size
+ 8 vector plane_normal
+20 vector plane_point
+32 int reserved // set to 0
+36 int front_offset // Only recurse into this if non-zero.
+40 int back_offset // Only recurse into this if non-zero.
+44 int prelist_offset // Only recurse into this if non-zero.
+48 int postlist_offset // Only recurse into this if non-zero.
+52 int online_offset // Only recurse into this if non-zero.
+56 vector min_bounding_box_point // of all polys under here
+68 vector max_bounding_box_point // of all polys under here

5 - BOUNDBOX

Bounding boxes are used to speed up lighting and collision calculations.

  • May be followed by any number of TMAPPOLY or FLATPOLY, punctuated with EOF
+ 0 int id = 5
+ 4 int size
+ 8 vector min_point
+20 vector max_point

Version 2300 or Higher

6 - TMAP2POLY

Textured polygons with increased vertex limit

  • Is not preceded by BOUNDBOX, ended with EOF, or listed in a series.
+ 0 int id = 6
+ 4 int size
+ 8 vector min_bounding_box_point 
+ 20 vector max_bounding_box_point 
+ 32 vector normal
+ 44 int tmap_num
+ 48 uint nverts
for each vertex, i {
 uint vertnum[i]
 uint normnum[i]
 float u[i]
 float v[i]
}
    • Note: TMAP2POLY increases the vertex and normal limit for subobjects and includes bounding box info, which is the main distinction from TMAPPOLY.

7 - SORTNORM2

Recursively splits into TMAP2POLY or more SORTNORM2/SORTNORM, more space efficient than SORTNORM

  • Offsets must lead to another SORTNORM2, SORTNORM, or a single TMAP2POLY
+ 0 int id = 7
+ 4 int size
+ 8 int front_offset // Only recurse into this if non-zero.
+ 12 int back_offset // Only recurse into this if non-zero.
+ 16 vector min_bounding_box_point 
+ 28 vector max_bounding_box_point