Difference between revisions of "BSP data structure"
Line 6: | Line 6: | ||
This document was written by John Slagel from Volition Inc., with revisions and bugfixing from Garry Knudson and Francis "Pastel" Avila. | 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. | |
− | The first byte defines the block now following (0- | ||
[[Media:Bsp_chunk.png]] | [[Media:Bsp_chunk.png]] | ||
− | 0 - EOF | + | ===0 - EOF=== |
+ | Means end of a local data structure reached | ||
+ | * Must follow every SORTNORM | ||
+ | * Must end a series of TMAPPOLY | ||
<blockquote><pre>+ 0 int id = 0 | <blockquote><pre>+ 0 int id = 0 | ||
+ 4 int size</pre></blockquote> | + 4 int size</pre></blockquote> | ||
− | |||
− | 1 - DEFPOINTS | + | ===1 - DEFPOINTS=== |
+ | Defines the vertices and normals | ||
+ | * Must be the first chunk in bsp data and may not be included more than once | ||
<blockquote><pre>+ 0 int id = 1 | <blockquote><pre>+ 0 int id = 1 | ||
+ 4 int size | + 4 int size | ||
Line 24: | Line 27: | ||
+offset vertex_data // Each vertex n is a point followed by norm_counts[n] normals.</pre></blockquote> | +offset vertex_data // Each vertex n is a point followed by norm_counts[n] normals.</pre></blockquote> | ||
** 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 mayor cause of bus errors on ARM arch. | ** 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 mayor cause of bus errors on ARM arch. | ||
− | 2 - FLATPOLY | + | |
+ | ===2 - FLATPOLY=== | ||
+ | Flat (non-textured) polygon | ||
+ | * May be listed several times in a row, after a BOUNDBOX, and punctuated with EOF | ||
<blockquote><pre>+ 0 int id = 2 | <blockquote><pre>+ 0 int id = 2 | ||
+ 4 int size | + 4 int size | ||
Line 39: | Line 45: | ||
short normnum[i] | short normnum[i] | ||
}</pre></blockquote> | }</pre></blockquote> | ||
− | 3 - TMAPPOLY | + | |
+ | ===3 - TMAPPOLY=== | ||
+ | Textured polygons | ||
+ | * May be listed several times in a row, after a BOUNDBOX, and punctuated with EOF | ||
<blockquote><pre>+ 0 int id = 3 | <blockquote><pre>+ 0 int id = 3 | ||
+ 4 int size | + 4 int size | ||
Line 53: | Line 62: | ||
float v[i] | float v[i] | ||
}</pre></blockquote> | }</pre></blockquote> | ||
− | 4 - SORTNORM | + | |
+ | ===4 - SORTNORM=== | ||
+ | Sortnorms are planes that split the model recursively | ||
+ | * All offsets must lead to EOF, another SORTNORM, or BOUNDBOX | ||
<blockquote><pre>+ 0 int id = 4 | <blockquote><pre>+ 0 int id = 4 | ||
+ 4 int size | + 4 int size | ||
Line 67: | Line 79: | ||
+68 vector max_bounding_box_point // of all polys under here</pre></blockquote> | +68 vector max_bounding_box_point // of all polys under here</pre></blockquote> | ||
5 - BOUNDBOX - Bounding boxes are used to speed up lighting and collision calculations. | 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 | ||
<blockquote><pre>+ 0 int id = 5 | <blockquote><pre>+ 0 int id = 5 | ||
+ 4 int size | + 4 int size | ||
+ 8 vector min_point | + 8 vector min_point | ||
+20 vector max_point</pre></blockquote> | +20 vector max_point</pre></blockquote> | ||
− | 6 - TMAP2POLY | + | |
− | <blockquote><pre>+ 0 int id = | + | ==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. | ||
+ | <blockquote><pre>+ 0 int id = 6 | ||
+ 4 int size | + 4 int size | ||
− | + 8 vector | + | + 8 vector min_bounding_box_point |
− | +20 | + | + 20 vector max_bounding_box_point |
− | + | + | + 32 vector normal |
− | + | + | + 44 int tmap_num |
+ | + 48 uint nverts | ||
+ | for each vertex, i { | ||
uint vertnum[i] | uint vertnum[i] | ||
uint normnum[i] | uint normnum[i] | ||
Line 83: | Line 103: | ||
float v[i] | float v[i] | ||
}</pre></blockquote> | }</pre></blockquote> | ||
− | ** Note: TMAP2POLY increases the vertex and normal limit for subobjects, which is the main distinction from TMAPPOLY. | + | ** 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, more space efficient than SORTNORM | ||
+ | * Offsets must lead to another SORTNORM2 or a single TMAP2POLY | ||
+ | <blockquote><pre>+ 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 </pre></blockquote> | ||
[[Category:File Types]] | [[Category:File Types]] |
Revision as of 06:31, 21 April 2022
This info is copied from the Descent Developer's Network bsp_data page.
Contents
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 mayor 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, 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, more space efficient than SORTNORM
- Offsets must lead to another SORTNORM2 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