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
實驗性: This class may be changed or removed in future versions.
繼承: Resource < RefCounted < Object
用於定義可達區域和障礙物的導覽網格。
說明
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;
教學
屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
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) |
列舉
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
代表 SamplePartitionType 列舉的大小。
enum ParsedGeometryType: 🔗
ParsedGeometryType PARSED_GEOMETRY_MESH_INSTANCES = 0
將網格實例解析為幾何體。包括 MeshInstance3D、CSGShape3D、GridMap 等節點。
ParsedGeometryType PARSED_GEOMETRY_STATIC_COLLIDERS = 1
將 StaticBody2D 和 TileMap 碰撞器解析為幾何體。碰撞器應在由 parsed_collision_mask 指定的層中。
ParsedGeometryType PARSED_GEOMETRY_BOTH = 2
PARSED_GEOMETRY_MESH_INSTANCES 和 PARSED_GEOMETRY_STATIC_COLLIDERS.
ParsedGeometryType PARSED_GEOMETRY_MAX = 3
代表 ParsedGeometryType 列舉的大小。
enum SourceGeometryMode: 🔗
SourceGeometryMode SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0
在根節點的子節點中遞迴掃描幾何體。
SourceGeometryMode SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN = 1
以遞迴方式掃描組中的節點及其子節點以獲取幾何圖形。該組由 source_geometry_group_name 指定。
SourceGeometryMode SOURCE_GEOMETRY_GROUPS_EXPLICIT = 2
使用一個組中的節點進行幾何運算。該組由 source_geometry_group_name 指定。
SourceGeometryMode SOURCE_GEOMETRY_MAX = 3
代表 SourceGeometryMode 列舉的大小。
屬性說明
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) 🔗
If the baking Rect2 has an area the navigation mesh baking will be restricted to its enclosing area.
Vector2 baking_rect_offset = Vector2(0, 0) 🔗
The position offset applied to the baking_rect Rect2.
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.
用於將導覽網格頂點柵格化的儲存格大小。必須與導覽地圖上的儲存格大小相配對。
int parsed_collision_mask = 4294967295 🔗
用於掃描靜態碰撞的實體層。
僅在 parsed_geometry_type 是 PARSED_GEOMETRY_STATIC_COLLIDERS 或 PARSED_GEOMETRY_BOTH 時才使用。
ParsedGeometryType parsed_geometry_type = 2 🔗
void set_parsed_geometry_type(value: ParsedGeometryType)
ParsedGeometryType get_parsed_geometry_type()
Determines which type of nodes will be parsed as geometry.
SamplePartitionType sample_partition_type = 0 🔗
void set_sample_partition_type(value: SamplePartitionType)
SamplePartitionType get_sample_partition_type()
Partitioning algorithm for creating the navigation mesh polys.
StringName source_geometry_group_name = &"navigation_polygon_source_geometry_group" 🔗
void set_source_geometry_group_name(value: StringName)
StringName get_source_geometry_group_name()
群組的名稱,會在該群組中掃描幾何體。
只有當 source_geometry_mode 是 SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN 或 SOURCE_GEOMETRY_GROUPS_EXPLICIT 時才使用。
SourceGeometryMode source_geometry_mode = 0 🔗
void set_source_geometry_mode(value: SourceGeometryMode)
SourceGeometryMode get_source_geometry_mode()
The source of the geometry used when baking.
方法說明
void add_outline(outline: PackedVector2Array) 🔗
返回一個 PackedVector2Array,其中包含在編輯器中或通過腳本建立的輪廓的頂點。
void add_outline_at_index(outline: PackedVector2Array, index: int) 🔗
將包含輪廓頂點的 PackedVector2Array,追加到包含所有輪廓的內部陣列。必須調用 make_polygons_from_outlines() 才能將該陣列轉換為引擎將使用的多邊形。
void add_polygon(polygon: PackedInt32Array) 🔗
使用呼叫 get_vertices() 得到的頂點的索引新增一個多邊形。
void clear() 🔗
清除頂點和多邊形索引的內部陣列。
void clear_outlines() 🔗
清除輪廓陣列,但不清除頂點和由頂點建立的多邊形。
void clear_polygons() 🔗
清除多邊形陣列,但不清除輪廓和頂點陣列。
NavigationMesh get_navigation_mesh() 🔗
Returns the NavigationMesh resulting from this navigation polygon. This navigation mesh can be used to update the navigation mesh of a region with the NavigationServer3D.region_set_navigation_mesh() API directly.
PackedVector2Array get_outline(idx: int) const 🔗
返回一個 PackedVector2Array,其中包含在編輯器中或通過腳本建立的輪廓的頂點。
int get_outline_count() const 🔗
返回在編輯器或腳本中建立的輪廓的數量。
bool get_parsed_collision_mask_value(layer_number: int) const 🔗
返回 parsed_collision_mask 中是否啟用了指定的層,給定的 layer_number 應在 1 和 32 之間。
PackedInt32Array get_polygon(idx: int) 🔗
返回建立多邊形的頂點索引,形式為 PackedInt32Array。
int get_polygon_count() const 🔗
返回多邊形的數量。
PackedVector2Array get_vertices() const 🔗
返回一個 PackedVector2Array,其中包含用於建立多邊形的所有頂點。
void make_polygons_from_outlines() 🔗
已棄用: Use NavigationServer2D.parse_source_geometry_data() and NavigationServer2D.bake_from_source_geometry_data() instead.
Creates polygons from the outlines added in the editor or by script.
void remove_outline(idx: int) 🔗
刪除在編輯器或腳本中建立的輪廓。你必須呼叫 make_polygons_from_outlines() 來更新多邊形。
void set_outline(idx: int, outline: PackedVector2Array) 🔗
更改在編輯器或腳本中建立的輪廓。你必須呼叫 make_polygons_from_outlines() 來更新多邊形。
void set_parsed_collision_mask_value(layer_number: int, value: bool) 🔗
根據 value,啟用或禁用 parsed_collision_mask 中指定的層,給定的 layer_number 應在 1 和 32 之間。
void set_vertices(vertices: PackedVector2Array) 🔗
設定頂點,可以使用 add_polygon() 方法對其進行索引,建立多邊形。