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:
intA 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:
objectNavigation 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.
- 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:
objectRepresents 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:
TypedDictTyped 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:
TypedDictTyped 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:
EnumEnumeration for navigation directions.
- EAST = 1
- NORTH = 0
- SOUTH = 2
- WEST = 3