Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
NavigationPolygon
Expérimental : This class may be changed or removed in future versions.
Hérite de : Resource < RefCounted < Object
Un maillage de navigation 2D qui décrit une surface traversable pour la recherche de chemin.
Description
A navigation mesh can be created either by baking it with the help of the NavigationServer2D, or by adding vertices and convex polygon indices arrays manually.
To bake a navigation mesh at least one outline needs to be added that defines the outer bounds of the baked area.
var new_navigation_mesh = NavigationPolygon.new()
var bounding_outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.add_outline(bounding_outline)
NavigationServer2D.bake_from_source_geometry_data(new_navigation_mesh, NavigationMeshSourceGeometryData2D.new());
$NavigationRegion2D.navigation_polygon = new_navigation_mesh
var newNavigationMesh = new NavigationPolygon();
Vector2[] boundingOutline = [new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0)];
newNavigationMesh.AddOutline(boundingOutline);
NavigationServer2D.BakeFromSourceGeometryData(newNavigationMesh, new NavigationMeshSourceGeometryData2D());
GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
Adding vertices and polygon indices manually.
var new_navigation_mesh = NavigationPolygon.new()
var new_vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.vertices = new_vertices
var new_polygon_indices = PackedInt32Array([0, 1, 2, 3])
new_navigation_mesh.add_polygon(new_polygon_indices)
$NavigationRegion2D.navigation_polygon = new_navigation_mesh
var newNavigationMesh = new NavigationPolygon();
Vector2[] newVertices = [new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0)];
newNavigationMesh.Vertices = newVertices;
int[] newPolygonIndices = [0, 1, 2, 3];
newNavigationMesh.AddPolygon(newPolygonIndices);
GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
Tutoriels
Propriétés
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Méthodes
void |
add_outline(outline: PackedVector2Array) |
void |
add_outline_at_index(outline: PackedVector2Array, index: int) |
void |
add_polygon(polygon: PackedInt32Array) |
void |
clear() |
void |
|
void |
|
get_outline(idx: int) const |
|
get_outline_count() const |
|
get_parsed_collision_mask_value(layer_number: int) const |
|
get_polygon(idx: int) |
|
get_polygon_count() const |
|
get_vertices() const |
|
void |
|
void |
remove_outline(idx: int) |
void |
set_outline(idx: int, outline: PackedVector2Array) |
void |
set_parsed_collision_mask_value(layer_number: int, value: bool) |
void |
set_vertices(vertices: PackedVector2Array) |
Énumérations
enum SamplePartitionType: 🔗
SamplePartitionType SAMPLE_PARTITION_CONVEX_PARTITION = 0
Convex partitioning that results in a navigation mesh with convex polygons.
SamplePartitionType SAMPLE_PARTITION_TRIANGULATE = 1
Triangulation partitioning that results in a navigation mesh with triangle polygons.
SamplePartitionType SAMPLE_PARTITION_MAX = 2
Représente la taille de l'énumération SamplePartitionType.
enum ParsedGeometryType: 🔗
ParsedGeometryType PARSED_GEOMETRY_MESH_INSTANCES = 0
Parses mesh instances as obstruction geometry. This includes Polygon2D, MeshInstance2D, MultiMeshInstance2D, and TileMap nodes.
Meshes are only parsed when they use a 2D vertices surface format.
ParsedGeometryType PARSED_GEOMETRY_STATIC_COLLIDERS = 1
Parses StaticBody2D and TileMap colliders as obstruction geometry. The collider should be in any of the layers specified by parsed_collision_mask.
ParsedGeometryType PARSED_GEOMETRY_BOTH = 2
À la fois PARSED_GEOMETRY_MESH_INSTANCES et PARSED_GEOMETRY_STATIC_COLLIDERS.
ParsedGeometryType PARSED_GEOMETRY_MAX = 3
Représente la taille de l’enum ParsedGeometryType.
enum SourceGeometryMode: 🔗
SourceGeometryMode SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0
Scans the child nodes of the root node recursively for geometry.
SourceGeometryMode SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN = 1
Scanne les nœuds dans un groupe et leurs nœuds enfants récursivement pour de la géométrie. Le groupe est spécifié par source_geometry_group_name.
SourceGeometryMode SOURCE_GEOMETRY_GROUPS_EXPLICIT = 2
Utilise des nœuds dans un groupe pour la géométrie. Le groupe est spécifié par source_geometry_group_name.
SourceGeometryMode SOURCE_GEOMETRY_MAX = 3
Représente la taille de l'énumération SourceGeometryMode.
Descriptions des propriétés
The distance to erode/shrink the walkable surface when baking the navigation mesh.
Note: The radius must be equal or higher than 0.0. If the radius is 0.0, it won't be possible to fix invalid outline overlaps and other precision errors during the baking process. As a result, some obstacles may be excluded incorrectly from the final navigation mesh, or may delete the navigation mesh's polygons.
Rect2 baking_rect = Rect2(0, 0, 0, 0) 🔗
Si la Rect2 de pré-calcul a une aire, le pré-calcul du maillage de navigation sera limité à son aire englobante.
Vector2 baking_rect_offset = Vector2(0, 0) 🔗
Le décalage de position appliqué au Rect2 de baking_rect.
The size of the non-navigable border around the bake bounding area defined by the baking_rect Rect2.
In conjunction with the baking_rect the border size can be used to bake tile aligned navigation meshes without the tile edges being shrunk by agent_radius.
The cell size used to rasterize the navigation mesh vertices. Must match with the cell size on the navigation map.
int parsed_collision_mask = 4294967295 🔗
Les couches de physique à analyser pour des colliders statiques.
Seulement utilisé quand parsed_geometry_type vaut PARSED_GEOMETRY_STATIC_COLLIDERS ou PARSED_GEOMETRY_BOTH.
ParsedGeometryType parsed_geometry_type = 2 🔗
void set_parsed_geometry_type(value: ParsedGeometryType)
ParsedGeometryType get_parsed_geometry_type()
Détermine quel type de nœuds seront parsés en tant que géométrie.
SamplePartitionType sample_partition_type = 0 🔗
void set_sample_partition_type(value: SamplePartitionType)
SamplePartitionType get_sample_partition_type()
Algorithme de partitionnement pour la création des polygones du maillage de navigation.
StringName source_geometry_group_name = &"navigation_polygon_source_geometry_group" 🔗
void set_source_geometry_group_name(value: StringName)
StringName get_source_geometry_group_name()
The group name of nodes that should be parsed for baking source geometry.
Only used when source_geometry_mode is SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN or SOURCE_GEOMETRY_GROUPS_EXPLICIT.
SourceGeometryMode source_geometry_mode = 0 🔗
void set_source_geometry_mode(value: SourceGeometryMode)
SourceGeometryMode get_source_geometry_mode()
La source de la géométrie utilisée lors du pré-calcul.
Descriptions des méthodes
void add_outline(outline: PackedVector2Array) 🔗
Ajoute un PackedVector2Array contenant les sommets d'un contour au tableau interne qui contient tous les contours.
void add_outline_at_index(outline: PackedVector2Array, index: int) 🔗
Ajoute un PackedVector2Array contenant les sommets d'un contour au tableau interne qui contient tous les contours à une position fixe.
void add_polygon(polygon: PackedInt32Array) 🔗
Ajoute un polygone en utilisant les indices des sommets que obtenus avec get_vertices().
void clear() 🔗
Vide les tableaux internes pour les indices de sommets et de polygones.
void clear_outlines() 🔗
Efface le tableau des contours, mais ça n'efface pas les sommets et les polygones qui ont été créés par eux.
void clear_polygons() 🔗
Efface le tableau des polygones, mais ça n'effacera pas le tableau des contours et des sommets.
NavigationMesh get_navigation_mesh() 🔗
Renvoie le NavigationMesh résultant de ce polygone de navigation. Ce maillage de navigation peut être utilisé pour mettre à jour le maillage de navigation d'une région avec l'API NavigationServer3D.region_set_navigation_mesh() directement.
PackedVector2Array get_outline(idx: int) const 🔗
Renvoie un PackedVector2Array contenant les sommets d'un contour qui a été créé dans l'éditeur ou par un script.
int get_outline_count() const 🔗
Renvoie le nombre de contours qui ont été créés dans l'éditeur ou par un script.
bool get_parsed_collision_mask_value(layer_number: int) const 🔗
Renvoie si la couche spécifiée du parsed_collision_mask est activée, étant donné un numéro de couche layer_number entre 1 et 32.
PackedInt32Array get_polygon(idx: int) 🔗
Renvoie un PackedInt32Array contenant les indices des sommets d'un polygone créé.
int get_polygon_count() const 🔗
Renvoie le nombre de tous les polygones.
PackedVector2Array get_vertices() const 🔗
Renvoie un PackedVector2Array contenant tous les sommets utilisés pour créer les polygones.
void make_polygons_from_outlines() 🔗
Obsolète : Use NavigationServer2D.parse_source_geometry_data() and NavigationServer2D.bake_from_source_geometry_data() instead.
Crée des polygones depuis les contours ajoutés dans l'éditeur ou par script.
void remove_outline(idx: int) 🔗
Enlève un aperçu créé dans l'éditeur ou par un script. Vous devez appeler make_polygons_from_outlines() pour mettre à jour les polygones.
void set_outline(idx: int, outline: PackedVector2Array) 🔗
Change un aperçu créé dans l'éditeur ou par un script. Vous devez appeler make_polygons_from_outlines() pour mettre à jour les polygones.
void set_parsed_collision_mask_value(layer_number: int, value: bool) 🔗
Selon value, active ou désactive la couche spécifiée dans le parsed_collision_mask, étant donné un numéro de couche layer_number entre 1 et 32.
void set_vertices(vertices: PackedVector2Array) 🔗
Définit les sommets qui peuvent ensuite être indexés pour créer des polygones avec la méthode add_polygon().