class_navigationpolygon.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/NavigationPolygon.xml.
  6. .. _class_NavigationPolygon:
  7. NavigationPolygon
  8. =================
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A node that has methods to draw outlines or use indices of vertices to create navigation polygons.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. There are two ways to create polygons. Either by using the :ref:`add_outline<class_NavigationPolygon_method_add_outline>` method, or using the :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` method.
  15. Using :ref:`add_outline<class_NavigationPolygon_method_add_outline>`:
  16. .. tabs::
  17. .. code-tab:: gdscript
  18. var polygon = NavigationPolygon.new()
  19. var outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
  20. polygon.add_outline(outline)
  21. polygon.make_polygons_from_outlines()
  22. $NavigationRegion2D.navigation_polygon = polygon
  23. .. code-tab:: csharp
  24. var polygon = new NavigationPolygon();
  25. var outline = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
  26. polygon.AddOutline(outline);
  27. polygon.MakePolygonsFromOutlines();
  28. GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = polygon;
  29. Using :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` and indices of the vertices array.
  30. .. tabs::
  31. .. code-tab:: gdscript
  32. var polygon = NavigationPolygon.new()
  33. var vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
  34. polygon.vertices = vertices
  35. var indices = PackedInt32Array([0, 1, 2, 3])
  36. polygon.add_polygon(indices)
  37. $NavigationRegion2D.navigation_polygon = polygon
  38. .. code-tab:: csharp
  39. var polygon = new NavigationPolygon();
  40. var vertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
  41. polygon.Vertices = vertices;
  42. var indices = new int[] { 0, 1, 2, 3 };
  43. polygon.AddPolygon(indices);
  44. GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = polygon;
  45. .. rst-class:: classref-introduction-group
  46. Tutorials
  47. ---------
  48. - `2D Navigation Demo <https://godotengine.org/asset-library/asset/117>`__
  49. - :doc:`Using NavigationMeshes <../tutorials/navigation/navigation_using_navigationmeshes>`
  50. .. rst-class:: classref-reftable-group
  51. Methods
  52. -------
  53. .. table::
  54. :widths: auto
  55. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`add_outline<class_NavigationPolygon_method_add_outline>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` outline **)** |
  57. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`add_outline_at_index<class_NavigationPolygon_method_add_outline_at_index>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` outline, :ref:`int<class_int>` index **)** |
  59. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` **(** :ref:`PackedInt32Array<class_PackedInt32Array>` polygon **)** |
  61. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`clear_outlines<class_NavigationPolygon_method_clear_outlines>` **(** **)** |
  63. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`clear_polygons<class_NavigationPolygon_method_clear_polygons>` **(** **)** |
  65. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`NavigationMesh<class_NavigationMesh>` | :ref:`get_navigation_mesh<class_NavigationPolygon_method_get_navigation_mesh>` **(** **)** |
  67. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_outline<class_NavigationPolygon_method_get_outline>` **(** :ref:`int<class_int>` idx **)** |const| |
  69. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`int<class_int>` | :ref:`get_outline_count<class_NavigationPolygon_method_get_outline_count>` **(** **)** |const| |
  71. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`get_polygon<class_NavigationPolygon_method_get_polygon>` **(** :ref:`int<class_int>` idx **)** |
  73. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`int<class_int>` | :ref:`get_polygon_count<class_NavigationPolygon_method_get_polygon_count>` **(** **)** |const| |
  75. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>` **(** **)** |const| |
  77. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` **(** **)** |
  79. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`remove_outline<class_NavigationPolygon_method_remove_outline>` **(** :ref:`int<class_int>` idx **)** |
  81. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`set_outline<class_NavigationPolygon_method_set_outline>` **(** :ref:`int<class_int>` idx, :ref:`PackedVector2Array<class_PackedVector2Array>` outline **)** |
  83. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`set_vertices<class_NavigationPolygon_method_set_vertices>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` vertices **)** |
  85. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. .. rst-class:: classref-section-separator
  87. ----
  88. .. rst-class:: classref-descriptions-group
  89. Method Descriptions
  90. -------------------
  91. .. _class_NavigationPolygon_method_add_outline:
  92. .. rst-class:: classref-method
  93. void **add_outline** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` outline **)**
  94. Appends a :ref:`PackedVector2Array<class_PackedVector2Array>` that contains the vertices of an outline to the internal array that contains all the outlines. You have to call :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` in order for this array to be converted to polygons that the engine will use.
  95. .. rst-class:: classref-item-separator
  96. ----
  97. .. _class_NavigationPolygon_method_add_outline_at_index:
  98. .. rst-class:: classref-method
  99. void **add_outline_at_index** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` outline, :ref:`int<class_int>` index **)**
  100. Adds a :ref:`PackedVector2Array<class_PackedVector2Array>` that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position. You have to call :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` in order for this array to be converted to polygons that the engine will use.
  101. .. rst-class:: classref-item-separator
  102. ----
  103. .. _class_NavigationPolygon_method_add_polygon:
  104. .. rst-class:: classref-method
  105. void **add_polygon** **(** :ref:`PackedInt32Array<class_PackedInt32Array>` polygon **)**
  106. Adds a polygon using the indices of the vertices you get when calling :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>`.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_NavigationPolygon_method_clear_outlines:
  110. .. rst-class:: classref-method
  111. void **clear_outlines** **(** **)**
  112. Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_NavigationPolygon_method_clear_polygons:
  116. .. rst-class:: classref-method
  117. void **clear_polygons** **(** **)**
  118. Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_NavigationPolygon_method_get_navigation_mesh:
  122. .. rst-class:: classref-method
  123. :ref:`NavigationMesh<class_NavigationMesh>` **get_navigation_mesh** **(** **)**
  124. Returns the :ref:`NavigationMesh<class_NavigationMesh>` resulting from this navigation polygon. This navigation mesh can be used to update the navigation mesh of a region with the :ref:`NavigationServer3D.region_set_navigation_mesh<class_NavigationServer3D_method_region_set_navigation_mesh>` API directly (as 2D uses the 3D server behind the scene).
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_NavigationPolygon_method_get_outline:
  128. .. rst-class:: classref-method
  129. :ref:`PackedVector2Array<class_PackedVector2Array>` **get_outline** **(** :ref:`int<class_int>` idx **)** |const|
  130. Returns a :ref:`PackedVector2Array<class_PackedVector2Array>` containing the vertices of an outline that was created in the editor or by script.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_NavigationPolygon_method_get_outline_count:
  134. .. rst-class:: classref-method
  135. :ref:`int<class_int>` **get_outline_count** **(** **)** |const|
  136. Returns the number of outlines that were created in the editor or by script.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_NavigationPolygon_method_get_polygon:
  140. .. rst-class:: classref-method
  141. :ref:`PackedInt32Array<class_PackedInt32Array>` **get_polygon** **(** :ref:`int<class_int>` idx **)**
  142. Returns a :ref:`PackedInt32Array<class_PackedInt32Array>` containing the indices of the vertices of a created polygon.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_NavigationPolygon_method_get_polygon_count:
  146. .. rst-class:: classref-method
  147. :ref:`int<class_int>` **get_polygon_count** **(** **)** |const|
  148. Returns the count of all polygons.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_NavigationPolygon_method_get_vertices:
  152. .. rst-class:: classref-method
  153. :ref:`PackedVector2Array<class_PackedVector2Array>` **get_vertices** **(** **)** |const|
  154. Returns a :ref:`PackedVector2Array<class_PackedVector2Array>` containing all the vertices being used to create the polygons.
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_NavigationPolygon_method_make_polygons_from_outlines:
  158. .. rst-class:: classref-method
  159. void **make_polygons_from_outlines** **(** **)**
  160. Creates polygons from the outlines added in the editor or by script.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_NavigationPolygon_method_remove_outline:
  164. .. rst-class:: classref-method
  165. void **remove_outline** **(** :ref:`int<class_int>` idx **)**
  166. Removes an outline created in the editor or by script. You have to call :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` for the polygons to update.
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_NavigationPolygon_method_set_outline:
  170. .. rst-class:: classref-method
  171. void **set_outline** **(** :ref:`int<class_int>` idx, :ref:`PackedVector2Array<class_PackedVector2Array>` outline **)**
  172. Changes an outline created in the editor or by script. You have to call :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` for the polygons to update.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_NavigationPolygon_method_set_vertices:
  176. .. rst-class:: classref-method
  177. void **set_vertices** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` vertices **)**
  178. Sets the vertices that can be then indexed to create polygons with the :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` method.
  179. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  180. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  181. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  182. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  183. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  184. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`