Simple and modern library for parsing the Valve BSP map format.
Documentation: https://taservers.github.io/BSPParser/
See also:
What's included
- Class for parsing and abstracing the
BSP
file format for the Source engine.
- Helper functions to simplify accessing the complex data structures of the BSP (see example below)
- Enums and structs with decent coverage of the BSP lumps and their versions.
- Runtime errors for issues when parsing the data due to corruption or a bug in the parser.
Example
Generating a triangle list for all models in the BSP:
#include "BSPParser.hpp"
const auto bspData = ...;
bsp.smoothNeighbouringDisplacements();
bsp,
[&bsp](
const std::vector<BspParser::PhysModel>& physicsModels
) {
bsp,
model,
[&bsp](
const std::span<const int32_t> surfaceEdges
) {
if (isFaceNoDraw(surfaceEdges, textureInfo)) {
return;
}
bsp,
face,
plane,
textureInfo,
surfaceEdges,
}
);
bsp,
face,
surfaceEdges,
[](const int32_t index0, const int32_t index1, const int32_t index2) {
}
);
}
);
}
);
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)
Definition: face-accessors.cpp:165
void iterateModels(const Bsp &bsp, const std::function< void(const Structs::Model &model, const std::vector< PhysModel > &physicsModels)> &iteratee)
Definition: face-accessors.cpp:16
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)
Definition: face-accessors.cpp:34
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)
Definition: face-accessors.cpp:133
Definition: geometry.hpp:21
Definition: geometry.hpp:8
Definition: textures.hpp:8
Generating colliders for all physmeshes in the BSP:
#include "BSPParser.hpp"
const auto bspData = ...;
bsp,
[&bsp](
const std::vector<BspParser::PhysModel>& physicsModels
) {
for (const auto& physicsModel : physicsModels) {
const auto [solidsForModel, _] = PhyParser::parseSurfaces(physicsModel.collisionData, physicsModel.solidCount);
}
}
);