BspData

Struct BspData 

Source
pub struct BspData {
Show 18 fields pub format: BspFormat, pub entities: String, pub planes: Vec<BspPlane>, pub textures: Vec<Option<BspMipTexture>>, pub vertices: Vec<Vec3>, pub visibility: BspVisData, pub nodes: Vec<BspNode>, pub tex_info: Vec<BspTexInfo>, pub faces: Vec<BspFace>, pub lighting: Option<BspLighting>, pub clip_nodes: Vec<BspClipNode>, pub leaves: Vec<BspLeaf>, pub mark_surfaces: Vec<UBspValue>, pub edges: Vec<BspEdge>, pub surface_edges: Vec<i32>, pub models: Vec<BspModel>, pub bspx: BspxData, pub parse_ctx: BspParseContext,
}
Expand description

A BSP files contents parsed into structures for easy access.

Fields§

§format: BspFormat§entities: String

Essentially an embedded .map file, the differences being:

  • Brush data has been stripped.
  • Brush entities have a model property indexing into the models field of this struct.
§planes: Vec<BspPlane>§textures: Vec<Option<BspMipTexture>>§vertices: Vec<Vec3>

All vertex positions.

§visibility: BspVisData

RLE encoded bit array. For BSP38, this is cluster-based. For BSP29, BSP2 and BSP30 this is leaf-based, and models will have their own indices into the visdata array.

Use potentially_visible_set_at() and related functions to query this data.

See the specification for more info.

§nodes: Vec<BspNode>§tex_info: Vec<BspTexInfo>§faces: Vec<BspFace>§lighting: Option<BspLighting>§clip_nodes: Vec<BspClipNode>§leaves: Vec<BspLeaf>§mark_surfaces: Vec<UBspValue>

Indices into the face list, pointed to by leaves.

§edges: Vec<BspEdge>§surface_edges: Vec<i32>§models: Vec<BspModel>§bspx: BspxData§parse_ctx: BspParseContext

Additional information from the BSP parsed. For example, contains the BspFormat of the file.

Implementations§

Source§

impl BspData

Source

pub fn get_texture_name<'a>( &'a self, tex_info: &'a BspTexInfo, ) -> Option<&'a str>

Helper function to get a texture name from a BspTexInfo without worrying about format.

Source§

impl BspData

Source

pub fn compute_lightmap_atlas<P: LightmapPacker>( &self, packer: P, ) -> Result<LightmapAtlasOutput<P>, ComputeLightmapAtlasError>

Packs every face’s lightmap together onto a single atlas for GPU rendering.

Source§

impl BspData

Source

pub fn mesh_model( &self, model_idx: usize, lightmap_uvs: Option<&LightmapUvMap>, ) -> MeshModelOutput

Meshes a model at the specified index. Returns one mesh for each texture used in the model.

Source§

impl BspData

Source

pub fn leaf_at_point(&self, model_idx: usize, point: Vec3) -> usize

Returns the index of the BSP leaf point is in of model.

Source

pub fn leaf_at_point_in_node(&self, node_ref: BspNodeRef, point: Vec3) -> usize

Returns the index of the BSP leaf point is in inside a specific node. Usually, you probably want Self::leaf_at_point.

Source

pub fn potentially_visible_set(&self, leaf_idx: usize) -> Option<VisResult<'_>>

Get the potentially visible set of the leaf with index leaf_idx. These are the maximum set of leaves that could ever be visible from this leaf. Depending on format, this will either be expressed as a set of leaf indices (VisdataRef::Offset), or a cluster (VisdataRef::Cluster). In the latter case, you should check the visdata field of BspLeaf to work out which leaves are visible.

If None, the leaf has no visdata - this usually means that the leaf represents an out-of-bounds area. In this case, most BSP implementations consider all leaves visible.

Source

pub fn potentially_visible_set_at( &self, model_idx: usize, point: Vec3, ) -> Option<VisResult<'_>>

Get the potentially visible set at the point point in the model at the index model_idx. These are the maximum set of leaves that could ever be visible from this leaf. Depending on format, this will either be expressed as a set of leaf indices (VisdataRef::Offset), or a cluster (VisdataRef::Cluster). In the latter case, you should check the visdata field of BspLeaf to work out which leaves are visible.

If None, the leaf has no visdata - this usually means that the leaf represents an out-of-bounds area. In this case, most BSP implementations consider all leaves visible.

Source

pub fn potentially_audible_set(&self, leaf_idx: usize) -> Option<VisResult<'_>>

Get the potentially audible set of the leaf with index leaf_idx.

If None, the leaf has no visdata - this usually means that the leaf represents an out-of-bounds area. In this case, most BSP implementations consider all leaves audible.

Note: This will only potentially return something different for Quake 2. All other implementations have identical implementations for whether two points are potentially-visible vs potentially-audible. In most cases, you want potentially_visible_set().

Source

pub fn potentially_audible_set_at( &self, model_idx: usize, point: Vec3, ) -> Option<VisResult<'_>>

Get the potentially audible set at the point point in the model at the index model_idx.

If None, the leaf has no visdata - this usually means that the leaf represents an out-of-bounds area. In this case, most BSP implementations consider all leaves audible.

Source

pub fn raycast(&self, model_idx: usize, from: Vec3, to: Vec3) -> RaycastResult

Implementation of Quake’s SV_RecursiveHullCheck function. Traces a line through this data’s model at model_idx, returning information of the leaf it ends up at, and the first surface it hits if any.

TODO There are more numerically stable implementations, but i couldn’t get them to work. I guess if it works for Quake it works for me!

Source§

impl BspData

Source

pub fn parse(input: BspParseInput<'_>) -> BspResult<Self>

Parses the data from BSP input.

Source

pub fn parse_embedded_textures<'a, 'p: 'a>( &'a self, palette: &'p Palette, ) -> impl Iterator<Item = (&'a str, RgbImage)> + 'a

Parses embedded textures using the provided palette. Use QUAKE_PALETTE for the default Quake palette.

Trait Implementations§

Source§

impl Clone for BspData

Source§

fn clone(&self) -> BspData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BspData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BspData

Source§

fn default() -> BspData

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.