bsp Module

Source code: bsp.py

The bsp module provides an Bsp class which derives from Bsp and is used to read and write Hexen 2 bsp data.

vgio.hexen2.bsp.is_bspfile(filename)

Quickly see if a file is a bsp file by checking the magic number.

The filename argument may be a file for file-like object.

Parameters

filename – File to check as string or file-like object.

Returns

True if given file’s magic number is correct.

Bsp Class

class vgio.hexen2.bsp.Bsp

Class for working with Bsp files

Example

Basic usage:

from vgio.quake.bsp.bsp29a import Bsp
b = Bsp.open('ad_sepulcher.bsp')
version

Version of the map file. Vanilla Quake is 29.

entities

A string containing the entity definitions.

planes

A sequence of Planes used by the bsp tree data structure.

miptextures

A sequence of Miptextures.

vertexes

A sequence of Vertexes.

visibilities

A sequence of ints representing visibility data.

nodes

A sequence of Nodes used by the bsp tree data structure.

texture_infos

A sequence of TextureInfo objects.

faces

A sequence of Faces.

lighting

A sequence of ints representing lighting data.

clip_nodes

A sequence of ClipNodes used by the bsp tree data structure.

leafs

A sequence of Leafs used by the bsp tree data structure.

mark_surfaces

A sequence of ints representing lists of consecutive faces used by the Node objects.

edges

A sequence of Edges.

surf_edges

A sequence of ints representing list of consecutive edges used by the Face objects.

models

A sequence of Models.

Note

The first model is the entire level.

fp

The file-like object to read data from.

mode

The file mode for the file-like object.

Bsp.__init__()

Initializes a ReadWriteFile object. Derving classes must call this.

classmethod Bsp.open(file, mode='r')

Open a ReadWriteFile object where file can be a path to a file (a string), or a file-like object.

The mode parameter should be ‘r’ to read an existing file, ‘w’ to truncate and write a new file, or ‘a’ to append to an existing file.

open() is also a context manager and supports the with statement:

with ReadWriteFile.open('file.ext') as file:
    file.save('file2.ext')
Parameters
  • file – Either the path to the file, a file-like object, or bytes.

  • mode – An optional string that indicates which mode to open the file

Returns

An ReadWriteFile object constructed from the information read from the file-like object.

Raises
  • ValueError – If an invalid file mode is given.

  • TypeError – If attempting to write to a bytes object.

  • OSError – If the file argument is not a file-like object.

Bsp.close()

Closes the file pointer if possible. If mode is ‘w’ or ‘a’, the file will be written to.

Bsp.save(file)

Writes data to file.

Parameters

file – Either the path to the file, or a file-like object.

Raises

OSError – If file argument is not a file-like object.

Model Class

class vgio.hexen2.bsp.Model(bounding_box_min_x, bounding_box_min_y, bounding_box_min_z, bounding_box_max_x, bounding_box_max_y, bounding_box_max_z, origin_x, origin_y, origin_z, head_node_0, head_node_1, head_node_2, head_node_3, head_node_4, head_node_5, head_node_6, head_node_7, visleafs, first_face, number_of_faces)

Class for representing a model

bounding_box_min

The minimum coordinate of the bounding box containing the model.

bounding_box_max

The maximum coordinate of the bounding box containing the model.

origin

The origin of the model.

head_node

An eight-tuple of indexes. Corresponds to number of map hulls.

visleafs

The number of leaves in the bsp tree?

first_face

The number of the first face in Bsp.mark_surfaces.

number_of_faces

The number of faces contained in the node. These are stored in consecutive order in Bsp.mark_surfaces starting at Model.first_face.

Model.__init__(bounding_box_min_x, bounding_box_min_y, bounding_box_min_z, bounding_box_max_x, bounding_box_max_y, bounding_box_max_z, origin_x, origin_y, origin_z, head_node_0, head_node_1, head_node_2, head_node_3, head_node_4, head_node_5, head_node_6, head_node_7, visleafs, first_face, number_of_faces)

Constructs a Model object.

classmethod Model.read(file)
classmethod Model.write(file, model)