Debian Codegraph @

doc/classes/NavigationPolygon.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <class name="NavigationPolygon" inherits="Resource" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 A 2D navigation mesh that describes a traversable surface for pathfinding.
5 </brief_description>
6 <description>
7 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.
8 To bake a navigation mesh at least one outline needs to be added that defines the outer bounds of the baked area.
9 [codeblocks]
10 [gdscript]
11 var new_navigation_mesh = NavigationPolygon.new()
12 var bounding_outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
13 new_navigation_mesh.add_outline(bounding_outline)
14 NavigationServer2D.bake_from_source_geometry_data(new_navigation_mesh, NavigationMeshSourceGeometryData2D.new());
15 $NavigationRegion2D.navigation_polygon = new_navigation_mesh
16 [/gdscript]
17 [csharp]
18 var newNavigationMesh = new NavigationPolygon();
19 Vector2[] boundingOutline = [new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0)];
20 newNavigationMesh.AddOutline(boundingOutline);
21 NavigationServer2D.BakeFromSourceGeometryData(newNavigationMesh, new NavigationMeshSourceGeometryData2D());
22 GetNode&lt;NavigationRegion2D&gt;("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
23 [/csharp]
24 [/codeblocks]
25 Adding vertices and polygon indices manually.
26 [codeblocks]
27 [gdscript]
28 var new_navigation_mesh = NavigationPolygon.new()
29 var new_vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
30 new_navigation_mesh.vertices = new_vertices
31 var new_polygon_indices = PackedInt32Array([0, 1, 2, 3])
32 new_navigation_mesh.add_polygon(new_polygon_indices)
33 $NavigationRegion2D.navigation_polygon = new_navigation_mesh
34 [/gdscript]
35 [csharp]
36 var newNavigationMesh = new NavigationPolygon();
37 Vector2[] newVertices = [new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0)];
38 newNavigationMesh.Vertices = newVertices;
39 int[] newPolygonIndices = [0, 1, 2, 3];
40 newNavigationMesh.AddPolygon(newPolygonIndices);
41 GetNode&lt;NavigationRegion2D&gt;("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
42 [/csharp]
43 [/codeblocks]
44 </description>
45 <tutorials>
46 <link title="Using NavigationMeshes">$DOCS_URL/tutorials/navigation/navigation_using_navigationmeshes.html</link>
47 <link title="Navigation Polygon 2D Demo">https://godotengine.org/asset-library/asset/2722</link>
48 </tutorials>
49 <methods>
50 <method name="add_outline">
51 <return type="void" />
52 <param index="0" name="outline" type="PackedVector2Array" />
53 <description>
54 Appends a [PackedVector2Array] that contains the vertices of an outline to the internal array that contains all the outlines.
55 </description>
56 </method>
57 <method name="add_outline_at_index">
58 <return type="void" />
59 <param index="0" name="outline" type="PackedVector2Array" />
60 <param index="1" name="index" type="int" />
61 <description>
62 Adds a [PackedVector2Array] that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position.
63 </description>
64 </method>
65 <method name="add_polygon">
66 <return type="void" />
67 <param index="0" name="polygon" type="PackedInt32Array" />
68 <description>
69 Adds a polygon using the indices of the vertices you get when calling [method get_vertices].
70 </description>
71 </method>
72 <method name="clear">
73 <return type="void" />
74 <description>
75 Clears the internal arrays for vertices and polygon indices.
76 </description>
77 </method>
78 <method name="clear_outlines">
79 <return type="void" />
80 <description>
81 Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
82 </description>
83 </method>
84 <method name="clear_polygons">
85 <return type="void" />
86 <description>
87 Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
88 </description>
89 </method>
90 <method name="get_navigation_mesh">
91 <return type="NavigationMesh" />
92 <description>
93 Returns the [NavigationMesh] resulting from this navigation polygon. This navigation mesh can be used to update the navigation mesh of a region with the [method NavigationServer3D.region_set_navigation_mesh] API directly.
94 </description>
95 </method>
96 <method name="get_outline" qualifiers="const">
97 <return type="PackedVector2Array" />
98 <param index="0" name="idx" type="int" />
99 <description>
100 Returns a [PackedVector2Array] containing the vertices of an outline that was created in the editor or by script.
101 </description>
102 </method>
103 <method name="get_outline_count" qualifiers="const">
104 <return type="int" />
105 <description>
106 Returns the number of outlines that were created in the editor or by script.
107 </description>
108 </method>
109 <method name="get_parsed_collision_mask_value" qualifiers="const">
110 <return type="bool" />
111 <param index="0" name="layer_number" type="int" />
112 <description>
113 Returns whether or not the specified layer of the [member parsed_collision_mask] is enabled, given a [param layer_number] between 1 and 32.
114 </description>
115 </method>
116 <method name="get_polygon">
117 <return type="PackedInt32Array" />
118 <param index="0" name="idx" type="int" />
119 <description>
120 Returns a [PackedInt32Array] containing the indices of the vertices of a created polygon.
121 </description>
122 </method>
123 <method name="get_polygon_count" qualifiers="const">
124 <return type="int" />
125 <description>
126 Returns the count of all polygons.
127 </description>
128 </method>
129 <method name="get_vertices" qualifiers="const">
130 <return type="PackedVector2Array" />
131 <description>
132 Returns a [PackedVector2Array] containing all the vertices being used to create the polygons.
133 </description>
134 </method>
135 <method name="make_polygons_from_outlines" deprecated="Use [method NavigationServer2D.parse_source_geometry_data] and [method NavigationServer2D.bake_from_source_geometry_data] instead.">
136 <return type="void" />
137 <description>
138 Creates polygons from the outlines added in the editor or by script.
139 </description>
140 </method>
141 <method name="remove_outline">
142 <return type="void" />
143 <param index="0" name="idx" type="int" />
144 <description>
145 Removes an outline created in the editor or by script. You have to call [method make_polygons_from_outlines] for the polygons to update.
146 </description>
147 </method>
148 <method name="set_outline">
149 <return type="void" />
150 <param index="0" name="idx" type="int" />
151 <param index="1" name="outline" type="PackedVector2Array" />
152 <description>
153 Changes an outline created in the editor or by script. You have to call [method make_polygons_from_outlines] for the polygons to update.
154 </description>
155 </method>
156 <method name="set_parsed_collision_mask_value">
157 <return type="void" />
158 <param index="0" name="layer_number" type="int" />
159 <param index="1" name="value" type="bool" />
160 <description>
161 Based on [param value], enables or disables the specified layer in the [member parsed_collision_mask], given a [param layer_number] between 1 and 32.
162 </description>
163 </method>
164 <method name="set_vertices">
165 <return type="void" />
166 <param index="0" name="vertices" type="PackedVector2Array" />
167 <description>
168 Sets the vertices that can be then indexed to create polygons with the [method add_polygon] method.
169 </description>
170 </method>
171 </methods>
172 <members>
173 <member name="agent_radius" type="float" setter="set_agent_radius" getter="get_agent_radius" default="10.0">
174 The distance to erode/shrink the walkable surface when baking the navigation mesh.
175 [b]Note:[/b] The radius must be equal or higher than [code]0.0[/code]. If the radius is [code]0.0[/code], 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.
176 </member>
177 <member name="baking_rect" type="Rect2" setter="set_baking_rect" getter="get_baking_rect" default="Rect2(0, 0, 0, 0)">
178 If the baking [Rect2] has an area the navigation mesh baking will be restricted to its enclosing area.
179 </member>
180 <member name="baking_rect_offset" type="Vector2" setter="set_baking_rect_offset" getter="get_baking_rect_offset" default="Vector2(0, 0)">
181 The position offset applied to the [member baking_rect] [Rect2].
182 </member>
183 <member name="border_size" type="float" setter="set_border_size" getter="get_border_size" default="0.0">
184 The size of the non-navigable border around the bake bounding area defined by the [member baking_rect] [Rect2].
185 In conjunction with the [member baking_rect] the border size can be used to bake tile aligned navigation meshes without the tile edges being shrunk by [member agent_radius].
186 </member>
187 <member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="1.0">
188 The cell size used to rasterize the navigation mesh vertices. Must match with the cell size on the navigation map.
189 </member>
190 <member name="parsed_collision_mask" type="int" setter="set_parsed_collision_mask" getter="get_parsed_collision_mask" default="4294967295">
191 The physics layers to scan for static colliders.
192 Only used when [member parsed_geometry_type] is [constant PARSED_GEOMETRY_STATIC_COLLIDERS] or [constant PARSED_GEOMETRY_BOTH].
193 </member>
194 <member name="parsed_geometry_type" type="int" setter="set_parsed_geometry_type" getter="get_parsed_geometry_type" enum="NavigationPolygon.ParsedGeometryType" default="2">
195 Determines which type of nodes will be parsed as geometry.
196 </member>
197 <member name="sample_partition_type" type="int" setter="set_sample_partition_type" getter="get_sample_partition_type" enum="NavigationPolygon.SamplePartitionType" default="0">
198 Partitioning algorithm for creating the navigation mesh polys.
199 </member>
200 <member name="source_geometry_group_name" type="StringName" setter="set_source_geometry_group_name" getter="get_source_geometry_group_name" default="&amp;&quot;navigation_polygon_source_geometry_group&quot;">
201 The group name of nodes that should be parsed for baking source geometry.
202 Only used when [member source_geometry_mode] is [constant SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN] or [constant SOURCE_GEOMETRY_GROUPS_EXPLICIT].
203 </member>
204 <member name="source_geometry_mode" type="int" setter="set_source_geometry_mode" getter="get_source_geometry_mode" enum="NavigationPolygon.SourceGeometryMode" default="0">
205 The source of the geometry used when baking.
206 </member>
207 </members>
208 <constants>
209 <constant name="SAMPLE_PARTITION_CONVEX_PARTITION" value="0" enum="SamplePartitionType">
210 Convex partitioning that results in a navigation mesh with convex polygons.
211 </constant>
212 <constant name="SAMPLE_PARTITION_TRIANGULATE" value="1" enum="SamplePartitionType">
213 Triangulation partitioning that results in a navigation mesh with triangle polygons.
214 </constant>
215 <constant name="SAMPLE_PARTITION_MAX" value="2" enum="SamplePartitionType">
216 Represents the size of the [enum SamplePartitionType] enum.
217 </constant>
218 <constant name="PARSED_GEOMETRY_MESH_INSTANCES" value="0" enum="ParsedGeometryType">
219 Parses mesh instances as obstruction geometry. This includes [Polygon2D], [MeshInstance2D], [MultiMeshInstance2D], and [TileMap] nodes.
220 Meshes are only parsed when they use a 2D vertices surface format.
221 </constant>
222 <constant name="PARSED_GEOMETRY_STATIC_COLLIDERS" value="1" enum="ParsedGeometryType">
223 Parses [StaticBody2D] and [TileMap] colliders as obstruction geometry. The collider should be in any of the layers specified by [member parsed_collision_mask].
224 </constant>
225 <constant name="PARSED_GEOMETRY_BOTH" value="2" enum="ParsedGeometryType">
226 Both [constant PARSED_GEOMETRY_MESH_INSTANCES] and [constant PARSED_GEOMETRY_STATIC_COLLIDERS].
227 </constant>
228 <constant name="PARSED_GEOMETRY_MAX" value="3" enum="ParsedGeometryType">
229 Represents the size of the [enum ParsedGeometryType] enum.
230 </constant>
231 <constant name="SOURCE_GEOMETRY_ROOT_NODE_CHILDREN" value="0" enum="SourceGeometryMode">
232 Scans the child nodes of the root node recursively for geometry.
233 </constant>
234 <constant name="SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN" value="1" enum="SourceGeometryMode">
235 Scans nodes in a group and their child nodes recursively for geometry. The group is specified by [member source_geometry_group_name].
236 </constant>
237 <constant name="SOURCE_GEOMETRY_GROUPS_EXPLICIT" value="2" enum="SourceGeometryMode">
238 Uses nodes in a group for geometry. The group is specified by [member source_geometry_group_name].
239 </constant>
240 <constant name="SOURCE_GEOMETRY_MAX" value="3" enum="SourceGeometryMode">
241 Represents the size of the [enum SourceGeometryMode] enum.
242 </constant>
243 </constants>
244 </class>