bsp29
Module¶
Source code: bsp29.py
The bsp29
module provides an Bsp
class which derives
from ReadWriteFile
and is used to read and write Quake
bsp29 data.
- vgio.quake.bsp.bsp29.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.quake.bsp.bsp29.Bsp¶
Class for working with Bsp files
Example
Basic usage:
from vgio.quake.bsp.bsp29 import Bsp b = Bsp.open('e1m1.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.
Plane
Class¶
- class vgio.quake.bsp.bsp29.Plane(normal_x, normal_y, normal_z, distance, type)¶
Class for representing a bsp plane
- normal¶
The normal vector to the plane.
- distance¶
The distance from world (0, 0, 0) to a point on the plane
- type¶
Planes are classified as follows:
Axial plane aligned to the x-axis.
Axial plane aligned to the y-axis.
Axial plane aligned to the z-axis.
Non-axial plane roughly aligned to the x-axis.
Non-axial plane roughly aligned to the y-axis.
Non-axial plane roughly aligned to the z-axis.
- Plane.__init__(normal_x, normal_y, normal_z, distance, type)¶
Constructs a Plane object.
- classmethod Plane.read(file)¶
- classmethod Plane.write(file, plane)¶
Miptexture
Class¶
- class vgio.quake.bsp.bsp29.Miptexture¶
Class for representing a miptexture
A miptexture is an indexed image mip map embedded within the map. Maps usually have many miptextures, and the miptexture lump is treated like a small wad file.
- name¶
The name of the miptexture.
- width¶
The width of the miptexture. .. note:: This is the width at mipmap level 0.
- height¶
The height of the miptexture. .. note:: This is the height at mipmap level 0.
- offsets¶
The offsets for each of the mipmaps. This is a tuple of size four (this is the number of mipmap levels).
- pixels¶
A tuple of unstructured pixel data represented as integers. A palette must be used to obtain RGB data.
Note
This is the pixel data for all four mip levels. The size is calculated using the simplified form of the geometric series where r = 1/4 and n = 4.
The size of this tuple is:
miptexture.width * miptexture.height * 85 / 64
- Miptexture.__init__()¶
Constructs a MipTexture object.
- classmethod Miptexture.read(file)¶
- classmethod Miptexture.write(file, miptexture)¶
Vertex
Class¶
- class vgio.quake.bsp.bsp29.Vertex(x, y, z)¶
Class for representing a vertex
A Vertex is an XYZ triple.
- x¶
The x-coordinate
- y¶
The y-coordinate
- z¶
The z-coordinate
- Vertex.__init__(x, y, z)¶
Constructs a Vertex object.
- classmethod Vertex.read(file)¶
- classmethod Vertex.write(file, vertex)¶
Node
Class¶
- class vgio.quake.bsp.bsp29.Node(plane_number, child_front, child_back, bounding_box_min_x, bounding_box_min_y, bounding_box_min_z, bounding_box_max_x, bounding_box_max_y, bounding_box_max_z, first_face, number_of_faces)¶
Class for representing a node
A Node is a data structure used to compose a bsp tree data structure. A child may be a Node or a Leaf.
- plane_number¶
The number of the plane that partitions the node.
- children¶
A two-tuple of the two sub-spaces formed by the partitioning plane.
Note
Child 0 is the front sub-space, and 1 is the back sub-space.
Note
If bit 15 is set, the child is a leaf.
- bounding_box_min¶
The minimum coordinate of the bounding box containing this node and all of its children.
- bounding_box_max¶
The maximum coordinate of the bounding box containing this node and all of its children.
- 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 Node.first_face.
- Node.__init__(plane_number, child_front, child_back, bounding_box_min_x, bounding_box_min_y, bounding_box_min_z, bounding_box_max_x, bounding_box_max_y, bounding_box_max_z, first_face, number_of_faces)¶
Constructs a Node object.
- classmethod Node.read(file)¶
- classmethod Node.write(file, node)¶
TextureInfo
Class¶
- class vgio.quake.bsp.bsp29.TextureInfo(s_x, s_y, s_z, s_offset, t_x, t_y, t_z, t_offset, miptexture_number, flags)¶
Class for representing a texture info
- s¶
The s vector in texture space represented as an XYZ three-tuple.
- s_offset¶
Horizontal offset in texture space.
- t¶
The t vector in texture space represented as an XYZ three-tuple.
- t_offset¶
Vertical offset in texture space.
- miptexture_number¶
The index of the miptexture.
- flags¶
If set to 1 the texture will be animated like water.
- TextureInfo.__init__(s_x, s_y, s_z, s_offset, t_x, t_y, t_z, t_offset, miptexture_number, flags)¶
Constructs a TextureInfo object
- classmethod TextureInfo.read(file)¶
- classmethod TextureInfo.write(file, texture_info)¶
Face
Class¶
- class vgio.quake.bsp.bsp29.Face(plane_number, side, first_edge, number_of_edges, texture_info, style_0, style_1, style_2, style_3, light_offset)¶
Class for representing a face
- plane_number¶
The plane in which the face lies.
- side¶
Which side of the plane the face lies. 0 is the front, 1 is the back.
- first_edge¶
The number of the first edge in Bsp.surf_edges.
- number_of_edges¶
The number of edges contained within the face. These are stored in consecutive order in Bsp.surf_edges starting at Face.first_edge.
- texture_info¶
The number of the texture info for this face.
- styles¶
A four-tuple of lightmap styles.
- light_offset¶
The offset into the lighting data.
- Face.__init__(plane_number, side, first_edge, number_of_edges, texture_info, style_0, style_1, style_2, style_3, light_offset)¶
Constructs a Face object.
- classmethod Face.read(file)¶
- classmethod Face.write(file, plane)¶
ClipNode
Class¶
- class vgio.quake.bsp.bsp29.ClipNode(plane_number, child_front, child_back)¶
Class for representing a clip node
- plane_number¶
The number of the plane that partitions the node.
- children¶
A two-tuple of the two sub-spaces formed by the partitioning plane.
Note
Child 0 is the front sub-space, and 1 is the back sub-space.
- ClipNode.__init__(plane_number, child_front, child_back)¶
Constructs a ClipNode object.
- classmethod ClipNode.read(file)¶
- classmethod ClipNode.write(file, clip_node)¶
Leaf
Class¶
- class vgio.quake.bsp.bsp29.Leaf(contents, visibilitiy_offset, bounding_box_min_x, bounding_box_min_y, bounding_box_min_z, bounding_box_max_x, bounding_box_max_y, bounding_box_max_z, first_mark_surface, number_of_marked_surfaces, ambient_level_0, ambient_level_1, ambient_level_2, ambient_level_3)¶
Class for representing a leaf
- contents¶
The content of the leaf. Affect the player’s view.
- visibilitiy_offset¶
The offset into the visibility data.
- bounding_box_min¶
The minimum coordinate of the bounding box containing this node.
- bounding_box_max¶
The maximum coordinate of the bounding box containing this node.
- first_mark_surface¶
The number of the first face in Bsp.mark_surfaces.
- number_of_marked_surfaces¶
The number of surfaces contained within the leaf. These are stored in consecutive order in Bsp.mark_surfaces starting at Leaf.first_mark_surface.
- ambient_level¶
A four-tuple that represent the volume of the four ambient sounds.
- Leaf.__init__(contents, visibilitiy_offset, bounding_box_min_x, bounding_box_min_y, bounding_box_min_z, bounding_box_max_x, bounding_box_max_y, bounding_box_max_z, first_mark_surface, number_of_marked_surfaces, ambient_level_0, ambient_level_1, ambient_level_2, ambient_level_3)¶
Constructs a Leaf object.
- classmethod Leaf.read(file)¶
- classmethod Leaf.write(file, leaf)¶
Edge
Class¶
- class vgio.quake.bsp.bsp29.Edge(vertex_0, vertex_1)¶
Class for representing a edge
- vertexes¶
A two-tuple of vertexes that form the edge. Vertex 0 is the start vertex, and 1 is the end vertex.
- Edge.__init__(vertex_0, vertex_1)¶
Constructs an Edge object.
- classmethod Edge.read(file)¶
- classmethod Edge.write(file, edge)¶
Model
Class¶
- class vgio.quake.bsp.bsp29.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, 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¶
A four-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, visleafs, first_face, number_of_faces)¶
Constructs a Model object.
- classmethod Model.read(file)¶
- classmethod Model.write(file, model)¶