Awpy

Getting Started

  • Installation
  • Frequently Asked Questions (FAQs)
  • License and Acknowledgments
  • Example Parser Output

Example Notebooks

  • Parsing a Counter-Strike 2 Demo
  • Using the Awpy CLI
  • Calculating Counter-Strike 2 Stats
  • Visualizing a Demo
  • Calculating Visibility in Counter-Strike 2
  • Working with Navigation Meshes

Documentation

  • Command-Line Interface
  • Data
  • Demo
  • Nav
    • awpy.nav
      • DynamicAttributeFlags
      • Nav
        • Nav.MAGIC
        • Nav.version
        • Nav.sub_version
        • Nav.areas
        • Nav.is_analyzed
        • Nav.MAGIC
        • Nav.find_path()
        • Nav.from_json()
        • Nav.from_path()
        • Nav.to_dict()
        • Nav.to_json()
      • NavArea
        • NavArea.area_id
        • NavArea.hull_index
        • NavArea.dynamic_attribute_flags
        • NavArea.corners
        • NavArea.connections
        • NavArea.ladders_above
        • NavArea.ladders_below
        • NavArea.centroid
        • NavArea.connected_areas
        • NavArea.from_data()
        • NavArea.from_dict()
        • NavArea.read_connections()
        • NavArea.size
        • NavArea.to_dict()
      • NavAreaDict
        • NavAreaDict.area_id
        • NavAreaDict.connections
        • NavAreaDict.corners
        • NavAreaDict.dynamic_attribute_flags
        • NavAreaDict.hull_index
        • NavAreaDict.ladders_above
        • NavAreaDict.ladders_below
      • NavDict
        • NavDict.areas
        • NavDict.is_analyzed
        • NavDict.sub_version
        • NavDict.version
      • NavDirectionType
        • NavDirectionType.EAST
        • NavDirectionType.NORTH
        • NavDirectionType.SOUTH
        • NavDirectionType.WEST
      • NavMeshConnection
        • NavMeshConnection.area_id
        • NavMeshConnection.edge_id
        • NavMeshConnection.from_binary()
  • Visualization & Plotting
  • Stats
  • Visibility
Awpy
  • Nav
  • View page source

Nav

This module contains the Nav class, which is used to represent navigation meshes in Counter-Strike 2.

awpy.nav

Module to parse and represent navigation mesh files.

Reference: https://github.com/ValveResourceFormat/ValveResourceFormat/tree/master/ValveResourceFormat/NavMesh

class awpy.nav.DynamicAttributeFlags(value: Any)[source]

Bases: int

A custom integer class for dynamic attribute flags.

class awpy.nav.Nav(*, version: int = 0, sub_version: int = 0, areas: dict[int, NavArea] | None = None, is_analyzed: bool = False)[source]

Bases: object

Navigation mesh file parser.

MAGIC

Magic number for nav mesh file format.

Type:

int

version

Version of the nav mesh file.

sub_version

Sub-version of the nav mesh file.

areas

Dictionary of navigation areas indexed by area ID.

is_analyzed

Whether the nav mesh has been analyzed.

MAGIC: int = 4277009102
find_path(start_id: int, end_id: int, weight: Literal['size', 'dist'] | None = None) → list[NavArea][source]

Finds the path between two areas in the graph.

Parameters:
  • start_id – The area ID of the starting NavArea.

  • end_id – The area ID of the ending NavArea.

  • weight – The edge attribute to use as weight (optional). If None, treats edges as unweighted. Size treats edges as the sum of the areas’ sizes. Dist treats edges as the Euclidean distance between centroids.

Returns:

A list of NavArea objects representing the path from start to end. Returns an empty list if no path exists.

classmethod from_json(path: str | Path) → Nav[source]

Reads the navigation mesh data from a JSON file.

Parameters:

path – Path to the JSON file to read from.

classmethod from_path(path: str | Path) → Self[source]

Initializes and reads a navigation mesh from a file.

Parameters:

path – Path to the nav mesh file to read.

Raises:

FileNotFoundError – If the nav mesh file does not exist.

to_dict() → NavDict[source]

Converts the entire navigation mesh to a dictionary.

to_json(path: str | Path) → None[source]

Writes the navigation mesh data to a JSON file.

Parameters:

path – Path to the JSON file to write.

class awpy.nav.NavArea(area_id: int = 0, hull_index: int = 0, dynamic_attribute_flags: DynamicAttributeFlags = 0, corners: list[Vector3] | None = None, connections: list[int] | None = None, ladders_above: list[int] | None = None, ladders_below: list[int] | None = None)[source]

Bases: object

Represents an area in the navigation mesh.

area_id

Unique identifier for the area.

hull_index

Index of the hull.

dynamic_attribute_flags

Dynamic attributes of the area.

corners

List of corner positions.

connections

List of connections for each corner.

ladders_above

List of ladder IDs above this area.

ladders_below

List of ladder IDs below this area.

property centroid: Vector3

Calculates the centroid of the polygon defined by the corners.

Returns:

A Vector3 representing the centroid (geometric center) of the polygon.

property connected_areas: set[int]

Returns a set of connected area IDs.

classmethod from_data(br: BinaryIO, nav_mesh_version: int, polygons: list[list[Vector3]] | None = None) → Self[source]

Reads area data from a binary stream.

Parameters:
  • br – Binary reader stream to read from.

  • nav_mesh_version – Version of the nav mesh file.

  • polygons – Optional list of predefined polygons for version 31+.

classmethod from_dict(data: NavAreaDict) → Self[source]

Load a NavArea from a dictionary.

static read_connections(br: BinaryIO) → list[NavMeshConnection][source]

Reads a list of connections from a binary stream.

Parameters:

br – Binary reader stream to read from.

Returns:

List of NavMeshConnection objects.

property size: float

Calculates the area of the polygon defined by the corners.

Returns:

The area of the polygon in 2D (ignoring the z-coordinate).

to_dict() → NavAreaDict[source]

Converts the navigation area to a dictionary.

class awpy.nav.NavAreaDict[source]

Bases: TypedDict

Typed dict representation of a NavArea.

area_id: int
connections: list[int]
corners: list[Vector3Dict]
dynamic_attribute_flags: int
hull_index: int
ladders_above: list[int]
ladders_below: list[int]
class awpy.nav.NavDict[source]

Bases: TypedDict

Typed dict representation of a Nav.

areas: dict[int, NavAreaDict]
is_analyzed: bool
sub_version: int
version: int
class awpy.nav.NavDirectionType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration for navigation directions.

EAST = 1
NORTH = 0
SOUTH = 2
WEST = 3
class awpy.nav.NavMeshConnection(area_id: int = 0, edge_id: int = 0)[source]

Bases: object

Represents a connection between navigation mesh areas.

area_id

ID of the connected area.

edge_id

ID of the connecting edge.

classmethod from_binary(br: BinaryIO) → Self[source]

Creates a NavMeshConnection from a binary stream.

Parameters:

br – Binary reader stream to read from.

Returns:

A new NavMeshConnection object.

Previous Next

© Copyright 2024, Peter Xenopoulos.

Built with Sphinx using a theme provided by Read the Docs.