Visibility

This module contains functions for calculating visibility in Counter-Strike 2 demos.

awpy.visibility

Module for calculating visibility.

Reference: https://github.com/AtomicBool/cs2-map-parser

class awpy.visibility.AABB(min_point: Vector3, max_point: Vector3)[source]

Bases: object

Axis-Aligned Bounding Box for efficient collision detection.

classmethod from_triangle(triangle: Triangle) AABB[source]

Create an AABB from a triangle.

Parameters:

triangle (Triangle) – Triangle to create the AABB from.

Returns:

Axis-Aligned Bounding Box encompassing the triangle.

Return type:

AABB

intersects_ray(ray_origin: Vector3, ray_direction: Vector3) bool[source]

Check if a ray intersects with the AABB.

Parameters:
  • ray_origin (awpy.vector.Vector3) – Ray origin point.

  • ray_direction (awpy.vector.Vector3) – Ray direction vector.

Returns:

True if the ray intersects with the AABB, False otherwise.

Return type:

bool

class awpy.visibility.BVHNode(aabb: AABB, triangle: Triangle | None = None, left: BVHNode | None = None, right: BVHNode | None = None)[source]

Bases: object

Node in the Bounding Volume Hierarchy tree.

class awpy.visibility.KV3Parser[source]

Bases: object

Parser for KV3 format files used in Source 2 engine.

This class provides functionality to parse KV3 files, which are used to store various game data including physics collision meshes.

content

Raw content of the KV3 file.

index

Current parsing position in the content.

parsed_data

Resulting parsed data structure.

get_value(path: str) str[source]

Get a value from the parsed data using a dot-separated path.

Parameters:

path – Dot-separated path to the desired value, e.g., “section.subsection[0].value”

Returns:

String value at the specified path, or empty string

if not found.

parse(content: str) None[source]

Parse the given KV3 content string.

Parameters:

content – String containing KV3 formatted data.

class awpy.visibility.VisibilityChecker(path: Path | None = None, triangles: list[Triangle] | None = None)[source]

Bases: object

Class for visibility checking in 3D space using a BVH structure.

is_visible(start: Vector3 | tuple | list, end: Vector3 | tuple | list) bool[source]

Check if a line segment is visible in the 3D space.

Parameters:
  • start (awpy.vector.Vector3 | tuple | list) – Start point of the line segment.

  • end (awpy.vector.Vector3 | tuple | list) – End point of the line segment.

Returns:

True if the line segment is visible, False otherwise.

Return type:

bool

static read_tri_file(tri_file: str | Path, buffer_size: int = 1000) list[Triangle][source]

Read triangles from a .tri file.

class awpy.visibility.VphysParser(vphys_file: str | Path)[source]

Bases: object

Parser for VPhys collision files.

This class extracts and processes collision geometry data

from VPhys files, converting it into a set of triangles.

vphys_file

Path to the VPhys file.

Type:

Path

triangles

List of parsed triangles from the VPhys file.

Type:

list[Triangle]

kv3_parser

Helper parser for extracting key-value data from the .vphys file.

Type:

KV3Parser

static bytes_to_vec(byte_str: str, element_type: Literal['uint8', 'int32']) list[int][source]
static bytes_to_vec(byte_str: str, element_type: Literal['float']) list[float]

Converts a space-separated string of byte values into a list of numbers.

Parameters:
  • byte_str (str) – Space-separated string of hexadecimal byte values.

  • element_type (int) – Types represented by the bytes (uint8, int32, float).

Returns:

List of converted values (integers for

uint8, floats for size 4).

Return type:

list[int | float]

get_collision_attribute_indices_for_default_group() list[str][source]

Get collision attribute indices for the default group.

Returns:

List of collision attribute indices for the default group.

Return type:

list[int]

parse() None[source]

Parses the VPhys file and extracts collision geometry.

Processes hulls and meshes in the VPhys file to generate a list of triangles.

to_tri(path: str | Path | None) None[source]

Export parsed triangles to a .tri file.

Parameters:

path – Path to the output .tri file.