Class VoxelVisibility
Namespace: ValveResourceFormat.Blocks
Assembly: ValveResourceFormat.dll
"VXVS" block. Three layouts, differing in how space is cut into clusters:
, latest: an octree that dices each leaf into a 4x4x4 grid of cells, where every cluster reaching that leaf owns a 64 bit mask of the cells it covers.
, until 2022: an octree whose leaves list boxes, each box tagged with the cluster that owns it.
, until 2018: a binary tree of arbitrary split planes, where a leaf is a cluster outright and nothing subdivides it further.
public class VoxelVisibility : Block, IWorldVisibilityInheritance
object ← Block ← VoxelVisibility
Implements
Inherited Members
Block.Type, Block.Offset, Block.Size, Block.Resource, Block.Read(BinaryReader), Block.ToString(), Block.WriteText(IndentedTextWriter), Block.Serialize(Stream)
Extension Methods
ResourceDataExtensions.AsKeyValueCollection(Block)
Fields
ClusterBitfieldWords
The number of 32 bit words in a cluster bitfield.
public const int ClusterBitfieldWords = 128Field Value
MaxClusters
The maximum number of clusters a visibility query can report.
public const int MaxClusters = 4096Field Value
Properties
BaseClusterCount
Gets the number of visibility clusters.
public uint BaseClusterCount { get; }Property Value
ClusterBitfieldWordCount
Gets how many 32 bit words a cluster bitfield needs.
public int ClusterBitfieldWordCount { get; }Property Value
ClusterCount
Gets the number of clusters, excluding any rows stored past them.
public int ClusterCount { get; }Property Value
EnclosedClusterList
Gets the enclosed cluster list entries.
public (int Offset, int Count)[] EnclosedClusterList { get; }Property Value
EnclosedClusters
Gets the enclosed cluster ids.
public ushort[] EnclosedClusters { get; }Property Value
ushort[]
GridSize
Gets the grid cell size.
public float GridSize { get; }Property Value
HasVisibilityData
Gets whether this block holds visibility that can be queried. Files from before the octree format, and maps compiled without visibility, have none.
public bool HasVisibilityData { get; }Property Value
Masks
Gets the spatial occupancy masks.
public ulong[] Masks { get; }Property Value
ulong[]
MaxBounds
Gets the maximum bounds of the octree.
public Vector3 MaxBounds { get; }Property Value
MinBounds
Gets the minimum bounds of the octree.
public Vector3 MinBounds { get; }Property Value
Nodes
Gets the octree nodes.
public VoxelVisibility.Node[] Nodes { get; }Property Value
PVSBytesPerCluster
Gets the number of PVS bytes per cluster.
public uint PVSBytesPerCluster { get; }Property Value
RegionBoxTree
Gets the region box tree this file holds instead, or null when it uses the mask octree. Everything else on this class stays empty when it is set.
public RegionBoxVoxelVisibility? RegionBoxTree { get; }Property Value
Regions
Gets the region entries.
public VoxelVisibility.Region[] Regions { get; }Property Value
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
SkyVisibilityCluster
Gets the cluster index used for sky visibility.
public uint SkyVisibilityCluster { get; }Property Value
SunVisibility
Gets the visibility row listing the clusters sunlight reaches, empty when there is no sun row. Nothing outside it can be lit by the sun, so nothing outside it casts a sun shadow.
public ReadOnlyMemory<byte> SunVisibility { get; }Property Value
SunVisibilityCluster
Gets the cluster index used for sun visibility.
public uint SunVisibilityCluster { get; }Property Value
Type
Gets the block type.
public override BlockType Type { get; }Property Value
VisBlocks
Gets the raw PVS bit table.
public byte[] VisBlocks { get; }Property Value
byte[]
Methods
BuildClusterChildBounds()
Builds a list of bounding boxes for each cluster.
public Dictionary<ushort, List<(Vector3 Min, Vector3 Max)>> BuildClusterChildBounds()Returns
Dictionary<ushort, List<(Vector3 Min, Vector3 Max)>>
GetClusterForPosition(Vector3)
Gets the cluster id for a given world-space position, falling back to the first cluster within half a grid cell of it, or -1 when there is none.
public int GetClusterForPosition(Vector3 position)Parameters
position Vector3
Returns
GetPVSForPoint(Vector3)
Gets the PVS bitfield for the cluster(s) at the given point, or null if there is none.
public byte[]? GetPVSForPoint(Vector3 point)Parameters
point Vector3
Returns
byte[]?
GetVisClusterList(Vector3, Vector3, Span<ushort>, bool)
Writes the id of every cluster the given box overlaps.
public int GetVisClusterList(Vector3 min, Vector3 max, Span<ushort> clusters, bool exact = false)Parameters
min Vector3
Minimum corner of the box.
max Vector3
Maximum corner of the box.
Destination for the cluster ids. When more clusters overlap than fit, the result collapses to the catch-all cluster 0 instead of an arbitrary subset.
exact bool
Visit every leaf rather than taking the precomputed cluster list of a fully enclosed octree node.
Returns
The number of cluster ids written.
GetVisClustersForBox(Vector3, Vector3, Span<uint>, bool)
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, bool exact = false)Parameters
min Vector3
Minimum corner of the box.
max Vector3
Maximum corner of the box.
Destination bitfield, at least words long.
exact bool
Visit every leaf rather than taking the precomputed cluster list of a fully enclosed octree node.
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
Remarks
A point no region claims, or one outside the octree, sees every cluster.
GetWorldVisibility(Resource)
Gets the world visibility a resource holds, whichever of the three layouts it was written in, or null when it holds none that can be queried. An octree of two clusters or fewer counts as none and culls nothing.
public static IWorldVisibility? GetWorldVisibility(Resource resource)Parameters
resource Resource
A .vvis_c resource.
Returns
Read(BinaryReader)
Reads the block data from a binary reader.
public override void Read(BinaryReader reader)Parameters
reader BinaryReader
The binary reader to read from.
Serialize(Stream)
Writes the binary representation of the object to Stream.
public override void Serialize(Stream stream)Parameters
stream Stream
Stream.
WriteText(IndentedTextWriter)
Writes the correct text dump of the object to .
public override void WriteText(IndentedTextWriter writer)Parameters
writer IndentedTextWriter
See Also
https://s2v.app/SchemaExplorer/cs2/worldrenderer/CVoxelVisibility

