BSPParser
Simple and modern library for parsing the Valve BSP format
Loading...
Searching...
No Matches
Concepts | Functions
BspParser::Accessors Namespace Reference

Functions

void iterateModels (const Bsp &bsp, const std::function< void(const Structs::Model &model, const std::vector< PhysModel > &physicsModels)> &iteratee)
 
void iterateFaces (const Bsp &bsp, const Structs::Model &model, const std::function< void(const Structs::Face &face, const Structs::Plane &plane, const Structs::TexInfo &textureInfo, std::span< const int32_t > surfaceEdges)> &iteratee)
 
size_t getVertexCount (const Bsp &bsp, const Structs::Face &face, const std::span< const int32_t > surfaceEdges)
 
size_t getTriangleListIndexCount (const Bsp &bsp, const Structs::Face &face, const std::span< const int32_t > surfaceEdges)
 
void generateVertices (const Bsp &bsp, const Structs::Face &face, const Structs::Plane &plane, const Structs::TexInfo &textureInfo, const std::span< const int32_t > surfaceEdges, const std::function< void(const Vertex &vertex)> &iteratee)
 
void generateTriangleListIndices (const Bsp &bsp, const Structs::Face &face, const std::span< const int32_t > surfaceEdges, const std::function< void(uint32_t i0, uint32_t i1, uint32_t i2)> &iteratee)
 
template<StaticPropIteratee Iteratee>
void iterateStaticProps (const Bsp &bsp, Iteratee iteratee)
 
void iterateTextures (const Bsp &bsp, const std::function< void(const Structs::TexData &texture, const char *path)> &iteratee)
 

Detailed Description

Accessor helpers for iterating contents of the BSP.

A collection of helper functions to ease traversing the MDL, VTX and VVD structures together.

Function Documentation

◆ generateTriangleListIndices()

void BspParser::Accessors::generateTriangleListIndices ( const Bsp bsp,
const Structs::Face face,
std::span< const int32_t >  surfaceEdges,
const std::function< void(uint32_t i0, uint32_t i1, uint32_t i2)> &  iteratee 
)

Calls iteratee once for each triangle forming a mesh which triangulates the given face. Indices start from 0 and index into the vertices generated by generateFaceVertices.

Parameters
bspBSP instance.
faceFace to generate a triangle list for.
surfaceEdgesSurface edge indices of the face.
iterateeCalled with each triplet of indices defining a triangle with clockwise winding.
Exceptions
std::runtime_errorFace cannot be triangulated (less than 3 edges).

◆ generateVertices()

void BspParser::Accessors::generateVertices ( const Bsp bsp,
const Structs::Face face,
const Structs::Plane plane,
const Structs::TexInfo textureInfo,
std::span< const int32_t >  surfaceEdges,
const std::function< void(const Vertex &vertex)> &  iteratee 
)

Calls iteratee once for each unique vertex in the face's edges or displacement. Generates normals, tangents and UVs.

Parameters
bspBSP instance.
faceFace to generate vertices for.
planePlane referenced by the face.
textureInfoTexture info referenced by the face.
surfaceEdgesSurface edge indices of the face.
iterateeFunction to call with each generated vertex.
Exceptions
std::runtime_errorFace cannot be triangulated (less than 3 edges).

◆ getTriangleListIndexCount()

size_t BspParser::Accessors::getTriangleListIndexCount ( const Bsp bsp,
const Structs::Face face,
std::span< const int32_t >  surfaceEdges 
)

Returns the number of indices that will be generated by generateFaceTriangleList. Useful for precomputing the size of index buffer needed to reduce allocations.

Parameters
bspBSP instance.
faceFace to get the index count of.
surfaceEdgesSurface edges of the face.
Returns
Number of indices for the face.
Exceptions
std::runtime_errorFace cannot be triangulated (less than 3 edges).

◆ getVertexCount()

size_t BspParser::Accessors::getVertexCount ( const Bsp bsp,
const Structs::Face face,
std::span< const int32_t >  surfaceEdges 
)

Returns the number of vertices that will be generated by generateFaceVertices. Useful for precomputing the size of vertex buffer needed to reduce allocations.

Parameters
bspBSP instance.
faceFace to get the vertex count of.
surfaceEdgesSurface edge indices of the face.
Returns
Number of vertices for the face.
Exceptions
std::runtime_errorFace cannot be triangulated (less than 3 edges).

◆ iterateFaces()

void BspParser::Accessors::iterateFaces ( const Bsp bsp,
const Structs::Model model,
const std::function< void(const Structs::Face &face, const Structs::Plane &plane, const Structs::TexInfo &textureInfo, std::span< const int32_t > surfaceEdges)> &  iteratee 
)

Calls the provided function for each face in the BSP's model, passing a reference to the Structs::Face along with its corresponding Structs::Plane, Structs::TexInfo and surface edge indices.

Parameters
bspBSP instance.
modelModel to iterate the faces of.
iterateeFunction to be called.

◆ iterateModels()

void BspParser::Accessors::iterateModels ( const Bsp bsp,
const std::function< void(const Structs::Model &model, const std::vector< PhysModel > &physicsModels)> &  iteratee 
)

Calls the provided function for each model in the BSP, passing a reference to the Structs::Model and its corresponding physics models.

Parameters
bspBSP instance.
iterateeFunction to be called.

◆ iterateStaticProps()

template<StaticPropIteratee Iteratee>
void BspParser::Accessors::iterateStaticProps ( const Bsp bsp,
Iteratee  iteratee 
)

Calls the provided visitor for each static prop in the given BSP.

Template Parameters
IterateeVisitor type declaring an overload for each supported static prop version.
Parameters
bspBSP instance to iterate.
iterateeInstance of Iteratee.

◆ iterateTextures()

void BspParser::Accessors::iterateTextures ( const Bsp bsp,
const std::function< void(const Structs::TexData &texture, const char *path)> &  iteratee 
)

Calls the given function for each Structs::TexData in the BSP, along with its path.

Parameters
bspBSP instance.
iterateeFunction to be called.