Overview
TheBrushSource class is a decompiling module responsible for rebuilding solid brushes from the LUMP_BRUSHES and LUMP_BRUSHSIDES lumps in BSP files. It processes brush geometry and writes them to VMF format, handling various brush types including world brushes, detail brushes, and entity-associated brushes.
This module is based on Vmex’s vmfbrushes() and writebrush() methods.
Package: info.ata4.bspsrc.decompiler.modules.geom
Constructor
BSP file reader for accessing BSP data
VMF writer for outputting brush data
Configuration settings for decompilation
Texture source module for material handling
BSP protection handler for detecting protected brushes
VMF metadata handler for UIDs and visgroups
Mapper for brush side to face relationships
Factory for creating winding geometry from brush sides
Occluder reallocation data
Public Methods
writeBrushes
- Detail brushes if
config.writeDetailsis enabled - Areaportals if
config.writeAreaportalsis enabled - Ladders if
config.writeLaddersis enabled (for games using object-based ladders)
writeBrush
Brush index in the BSP brush lump
Origin offset to apply to brush geometry (for entity brushes)
Rotation angles to apply to brush geometry (for entity brushes)
true if the brush was successfully written, false if skipped
Behavior:
- Validates all brush sides before writing
- Skips invalid brush sides (bevels, degenerate geometry, huge brushes)
- Requires at least 3 valid sides to write a brush
- Maps brush indices to VMF IDs for reference by other modules
writeModel
Model index in the BSP model lump
Origin offset for the model’s brushes
Rotation angles for the model’s brushes
true if successful, false if model index is invalid
isFuncDetail
func_detail entity.
Brush to check
true if the brush was a func_detail
getBrushSideIDForIndex
writeSide.
Brush side index
-1 if not found
getBrushIDForIndex
Brush index
-1 if not found
getWorldbrushes
Configuration Options
This module respects the following configuration options fromBspSourceConfig:
- writeDetails - Skip detail brushes during world brush writing
- writeAreaportals - Skip areaportal brushes during world brush writing
- writeLadders - Skip ladder brushes during world brush writing (game-dependent)
- faceTexture - Override texture string for all brush sides
- debug - Write debugging metadata to VMF output
Usage Example
Implementation Details
BSP Tree Walking
The module walks the BSP tree starting from model headnodes to:- Associate brushes with their corresponding entities
- Find the index of the last worldbrush
- Calculate brush ranges for each model
- Recover null-faced brushes
Brush Side Validation
Before writing, each brush side is validated to ensure:- It’s not a bevel face (which causes bad brushes)
- It has at least 3 vertices
- The winding is not empty or degenerate
- The size is not excessively large (within map bounds)
- The plane has valid, unique points
Texture Fixing
The module usesTextureBuilder to reconstruct texture alignment for brush sides. It enables texture fixing for brush sides that may have compacted texture info (those without corresponding original faces).
Related Modules
- FaceSource - Alternative brush writing using face lumps
- EntitySource - Entity decompilation that uses BrushSource
- TextureSource - Texture handling for brush sides