Class RegionBoxVoxelVisibility
Namespace: ValveResourceFormat.Blocks
Assembly: ValveResourceFormat.dll
An octree whose leaves list boxes, each tagged with the cluster that owns it, so resolving a query is box overlap. The tree and the visibility rows are packed one after the other in the block payload.
public sealed class RegionBoxVoxelVisibility : IWorldVisibilityInheritance
object ← RegionBoxVoxelVisibility
Implements
Fields
NoCluster
The cluster id of a region no cluster claims. A third of the regions in some maps carry it.
public const ushort NoCluster = 65535Field Value
ushort
Properties
BytesPerCluster
Gets the number of bytes in one cluster's visibility row.
public int BytesPerCluster { get; }Property Value
int
ClusterBitfieldWordCount
Gets how many 32 bit words a cluster bitfield needs.
public int ClusterBitfieldWordCount { get; }Property Value
int
ClusterCount
Gets the number of clusters, excluding the sky row.
public int ClusterCount { get; }Property Value
int
ClusterRowOffsets
Gets the byte offset of each cluster's row within RegionBoxVoxelVisibility.VisBlocks.
public int[] ClusterRowOffsets { get; }Property Value
int[]
GridSize
Gets the grid cell size.
public float GridSize { get; }Property Value
float
HasVisibilityData
Gets whether this holds visibility that can be queried.
public bool HasVisibilityData { get; }Property Value
bool
IsRawPvs
Gets whether the rows are stored uncompressed. Nothing can be read out of them when they are not.
public bool IsRawPvs { get; }Property Value
bool
MaxBounds
Gets the maximum bounds of the octree.
public Vector3 MaxBounds { get; }Property Value
MergedVisBlocks
Gets the merged rows, RegionBoxVoxelVisibility.BytesPerCluster bytes each. A merged row is the union of the rows of several clusters, and is what a point inside a box whose clusters overlap sees.
public byte[] MergedVisBlocks { get; }Property Value
byte[]
MinBounds
Gets the minimum bounds of the octree.
public Vector3 MinBounds { get; }Property Value
Nodes
Gets the octree nodes.
public RegionBoxVoxelVisibility.Node[] Nodes { get; }Property Value
RegionBoxVoxelVisibility.Node[]
Regions
Gets the region entries.
public RegionBoxVoxelVisibility.Region[] Regions { get; }Property Value
RegionBoxVoxelVisibility.Region[]
SkyRowOffset
Gets the byte offset of the sky row within RegionBoxVoxelVisibility.VisBlocks, or -1 when absent.
public int SkyRowOffset { get; }Property Value
int
SkyVisibility
Gets the visibility row listing the clusters the sky reaches, empty when there is no sky row.
public ReadOnlyMemory<byte> SkyVisibility { get; }Property Value
ReadOnlyMemory<byte>
SunRowOffset
Gets the byte offset of the sun row within RegionBoxVoxelVisibility.VisBlocks, or -1 when the file carries no sun row.
public int SunRowOffset { get; }Property Value
int
SunVisibility
Gets the visibility row listing the clusters sunlight reaches, empty when the format has none.
public ReadOnlyMemory<byte> SunVisibility { get; }Property Value
ReadOnlyMemory<byte>
Remarks
Empty when the file carries no sun row, which leaves shadow casters uncullable.
VisBlocks
Gets the raw visibility rows, one per cluster plus the sky row.
public byte[] VisBlocks { get; }Property Value
byte[]
Methods
BuildClusterChildBounds()
Builds the list of boxes making up each cluster, for debug drawing.
public Dictionary<ushort, List<(Vector3 Min, Vector3 Max)>> BuildClusterChildBounds()Returns
Dictionary<ushort, List<(Vector3 Min, Vector3 Max)>>
GetClusterForPosition(Vector3)
Gets the cluster containing the given point, or -1 when it is outside every region.
public int GetClusterForPosition(Vector3 position)Parameters
position Vector3
World-space point.
Returns
int
GetVisClustersForBox(Vector3, Vector3, Span<uint>)
Fills a bitfield with every cluster the given box overlaps, one bit per cluster id.
public void GetVisClustersForBox(Vector3 min, Vector3 max, Span<uint> clusterBits)Parameters
min Vector3
Minimum corner of the box.
max Vector3
Maximum corner of the box.
clusterBits Span<uint>
Destination bitfield, at least RegionBoxVoxelVisibility.ClusterCount bits long.
Remarks
The box grows by a unit on every side first. A box swallowing the whole volume, or a query without a tree, reports the catch-all cluster 0, and a box no cluster claims reports cluster 1, which is reserved for such space.
GetVisibilityRow(int)
Gets the visibility row for a cluster, or an empty row when it has none.
public ReadOnlyMemory<byte> GetVisibilityRow(int clusterId)Parameters
clusterId int
Cluster to look up.
Returns
ReadOnlyMemory<byte>
GetVisibilityRowForPoint(Vector3)
Gets the visibility row seen from a point, or an empty row when there is none to cull with.
public ReadOnlyMemory<byte> GetVisibilityRowForPoint(Vector3 point)Parameters
point Vector3
World-space point.
Returns
ReadOnlyMemory<byte>
Remarks
Inside a box whose clusters overlap, this is their merged row. Outside every box it is the row of the catch-all cluster 0.
Read(KVObject, BinaryReader, long)
Reads the tree and the visibility rows out of the block.
public void Read(KVObject data, BinaryReader reader, long blockOffset)Parameters
data KVObject
The block's KV3 data.
reader BinaryReader
Reader positioned anywhere in the resource.
blockOffset long
Byte offset of the block's payload in the resource.

