class_gridmap.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the GridMap.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_GridMap:
  6. GridMap
  7. =======
  8. **Inherits:** :ref:`Node3D<class_Node3D>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. Node for 3D tile-based maps.
  10. Description
  11. -----------
  12. GridMap lets you place meshes on a grid interactively. It works both from the editor and from scripts, which can help you create in-game level editors.
  13. GridMaps use a :ref:`MeshLibrary<class_MeshLibrary>` which contains a list of tiles. Each tile is a mesh with materials plus optional collision and navigation shapes.
  14. A GridMap contains a collection of cells. Each grid cell refers to a tile in the :ref:`MeshLibrary<class_MeshLibrary>`. All cells in the map have the same dimensions.
  15. Internally, a GridMap is split into a sparse collection of octants for efficient rendering and physics processing. Every octant has the same dimensions and can contain several cells.
  16. **Note:** GridMap doesn't extend :ref:`VisualInstance3D<class_VisualInstance3D>` and therefore can't be hidden or cull masked based on :ref:`VisualInstance3D.layers<class_VisualInstance3D_property_layers>`. If you make a light not affect the first layer, the whole GridMap won't be lit by the light in question.
  17. Tutorials
  18. ---------
  19. - :doc:`Using gridmaps <../tutorials/3d/using_gridmaps>`
  20. - `3D Platformer Demo <https://godotengine.org/asset-library/asset/125>`__
  21. - `3D Kinematic Character Demo <https://godotengine.org/asset-library/asset/126>`__
  22. Properties
  23. ----------
  24. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  25. | :ref:`bool<class_bool>` | :ref:`bake_navigation<class_GridMap_property_bake_navigation>` | ``false`` |
  26. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  27. | :ref:`bool<class_bool>` | :ref:`cell_center_x<class_GridMap_property_cell_center_x>` | ``true`` |
  28. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  29. | :ref:`bool<class_bool>` | :ref:`cell_center_y<class_GridMap_property_cell_center_y>` | ``true`` |
  30. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  31. | :ref:`bool<class_bool>` | :ref:`cell_center_z<class_GridMap_property_cell_center_z>` | ``true`` |
  32. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  33. | :ref:`int<class_int>` | :ref:`cell_octant_size<class_GridMap_property_cell_octant_size>` | ``8`` |
  34. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  35. | :ref:`float<class_float>` | :ref:`cell_scale<class_GridMap_property_cell_scale>` | ``1.0`` |
  36. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  37. | :ref:`Vector3<class_Vector3>` | :ref:`cell_size<class_GridMap_property_cell_size>` | ``Vector3(2, 2, 2)`` |
  38. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  39. | :ref:`int<class_int>` | :ref:`collision_layer<class_GridMap_property_collision_layer>` | ``1`` |
  40. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  41. | :ref:`int<class_int>` | :ref:`collision_mask<class_GridMap_property_collision_mask>` | ``1`` |
  42. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  43. | :ref:`MeshLibrary<class_MeshLibrary>` | :ref:`mesh_library<class_GridMap_property_mesh_library>` | |
  44. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  45. | :ref:`int<class_int>` | :ref:`navigation_layers<class_GridMap_property_navigation_layers>` | ``1`` |
  46. +---------------------------------------+--------------------------------------------------------------------+----------------------+
  47. Methods
  48. -------
  49. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`clear<class_GridMap_method_clear>` **(** **)** |
  51. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`clear_baked_meshes<class_GridMap_method_clear_baked_meshes>` **(** **)** |
  53. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`RID<class_RID>` | :ref:`get_bake_mesh_instance<class_GridMap_method_get_bake_mesh_instance>` **(** :ref:`int<class_int>` idx **)** |
  55. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Array<class_Array>` | :ref:`get_bake_meshes<class_GridMap_method_get_bake_meshes>` **(** **)** |
  57. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`int<class_int>` | :ref:`get_cell_item<class_GridMap_method_get_cell_item>` **(** :ref:`Vector3i<class_Vector3i>` position **)** |const| |
  59. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`int<class_int>` | :ref:`get_cell_item_orientation<class_GridMap_method_get_cell_item_orientation>` **(** :ref:`Vector3i<class_Vector3i>` position **)** |const| |
  61. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`bool<class_bool>` | :ref:`get_collision_layer_value<class_GridMap_method_get_collision_layer_value>` **(** :ref:`int<class_int>` layer_number **)** |const| |
  63. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_value<class_GridMap_method_get_collision_mask_value>` **(** :ref:`int<class_int>` layer_number **)** |const| |
  65. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Array<class_Array>` | :ref:`get_meshes<class_GridMap_method_get_meshes>` **(** **)** |
  67. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Array<class_Array>` | :ref:`get_used_cells<class_GridMap_method_get_used_cells>` **(** **)** |const| |
  69. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`make_baked_meshes<class_GridMap_method_make_baked_meshes>` **(** :ref:`bool<class_bool>` gen_lightmap_uv=false, :ref:`float<class_float>` lightmap_uv_texel_size=0.1 **)** |
  71. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Vector3<class_Vector3>` | :ref:`map_to_world<class_GridMap_method_map_to_world>` **(** :ref:`Vector3i<class_Vector3i>` map_position **)** |const| |
  73. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`resource_changed<class_GridMap_method_resource_changed>` **(** :ref:`Resource<class_Resource>` resource **)** |
  75. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`set_cell_item<class_GridMap_method_set_cell_item>` **(** :ref:`Vector3i<class_Vector3i>` position, :ref:`int<class_int>` item, :ref:`int<class_int>` orientation=0 **)** |
  77. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`set_clip<class_GridMap_method_set_clip>` **(** :ref:`bool<class_bool>` enabled, :ref:`bool<class_bool>` clipabove=true, :ref:`int<class_int>` floor=0, Vector3.Axis axis=0 **)** |
  79. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`set_collision_layer_value<class_GridMap_method_set_collision_layer_value>` **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)** |
  81. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`set_collision_mask_value<class_GridMap_method_set_collision_mask_value>` **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)** |
  83. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`Vector3i<class_Vector3i>` | :ref:`world_to_map<class_GridMap_method_world_to_map>` **(** :ref:`Vector3<class_Vector3>` world_position **)** |const| |
  85. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. Signals
  87. -------
  88. .. _class_GridMap_signal_cell_size_changed:
  89. - **cell_size_changed** **(** :ref:`Vector3<class_Vector3>` cell_size **)**
  90. Emitted when :ref:`cell_size<class_GridMap_property_cell_size>` changes.
  91. Constants
  92. ---------
  93. .. _class_GridMap_constant_INVALID_CELL_ITEM:
  94. - **INVALID_CELL_ITEM** = **-1** --- Invalid cell item that can be used in :ref:`set_cell_item<class_GridMap_method_set_cell_item>` to clear cells (or represent an empty cell in :ref:`get_cell_item<class_GridMap_method_get_cell_item>`).
  95. Property Descriptions
  96. ---------------------
  97. .. _class_GridMap_property_bake_navigation:
  98. - :ref:`bool<class_bool>` **bake_navigation**
  99. +-----------+----------------------------+
  100. | *Default* | ``false`` |
  101. +-----------+----------------------------+
  102. | *Setter* | set_bake_navigation(value) |
  103. +-----------+----------------------------+
  104. | *Getter* | is_baking_navigation() |
  105. +-----------+----------------------------+
  106. If ``true``, this GridMap bakes a navigation region.
  107. ----
  108. .. _class_GridMap_property_cell_center_x:
  109. - :ref:`bool<class_bool>` **cell_center_x**
  110. +-----------+---------------------+
  111. | *Default* | ``true`` |
  112. +-----------+---------------------+
  113. | *Setter* | set_center_x(value) |
  114. +-----------+---------------------+
  115. | *Getter* | get_center_x() |
  116. +-----------+---------------------+
  117. If ``true``, grid items are centered on the X axis.
  118. ----
  119. .. _class_GridMap_property_cell_center_y:
  120. - :ref:`bool<class_bool>` **cell_center_y**
  121. +-----------+---------------------+
  122. | *Default* | ``true`` |
  123. +-----------+---------------------+
  124. | *Setter* | set_center_y(value) |
  125. +-----------+---------------------+
  126. | *Getter* | get_center_y() |
  127. +-----------+---------------------+
  128. If ``true``, grid items are centered on the Y axis.
  129. ----
  130. .. _class_GridMap_property_cell_center_z:
  131. - :ref:`bool<class_bool>` **cell_center_z**
  132. +-----------+---------------------+
  133. | *Default* | ``true`` |
  134. +-----------+---------------------+
  135. | *Setter* | set_center_z(value) |
  136. +-----------+---------------------+
  137. | *Getter* | get_center_z() |
  138. +-----------+---------------------+
  139. If ``true``, grid items are centered on the Z axis.
  140. ----
  141. .. _class_GridMap_property_cell_octant_size:
  142. - :ref:`int<class_int>` **cell_octant_size**
  143. +-----------+------------------------+
  144. | *Default* | ``8`` |
  145. +-----------+------------------------+
  146. | *Setter* | set_octant_size(value) |
  147. +-----------+------------------------+
  148. | *Getter* | get_octant_size() |
  149. +-----------+------------------------+
  150. The size of each octant measured in number of cells. This applies to all three axis.
  151. ----
  152. .. _class_GridMap_property_cell_scale:
  153. - :ref:`float<class_float>` **cell_scale**
  154. +-----------+-----------------------+
  155. | *Default* | ``1.0`` |
  156. +-----------+-----------------------+
  157. | *Setter* | set_cell_scale(value) |
  158. +-----------+-----------------------+
  159. | *Getter* | get_cell_scale() |
  160. +-----------+-----------------------+
  161. The scale of the cell items.
  162. This does not affect the size of the grid cells themselves, only the items in them. This can be used to make cell items overlap their neighbors.
  163. ----
  164. .. _class_GridMap_property_cell_size:
  165. - :ref:`Vector3<class_Vector3>` **cell_size**
  166. +-----------+----------------------+
  167. | *Default* | ``Vector3(2, 2, 2)`` |
  168. +-----------+----------------------+
  169. | *Setter* | set_cell_size(value) |
  170. +-----------+----------------------+
  171. | *Getter* | get_cell_size() |
  172. +-----------+----------------------+
  173. The dimensions of the grid's cells.
  174. This does not affect the size of the meshes. See :ref:`cell_scale<class_GridMap_property_cell_scale>`.
  175. ----
  176. .. _class_GridMap_property_collision_layer:
  177. - :ref:`int<class_int>` **collision_layer**
  178. +-----------+----------------------------+
  179. | *Default* | ``1`` |
  180. +-----------+----------------------------+
  181. | *Setter* | set_collision_layer(value) |
  182. +-----------+----------------------------+
  183. | *Getter* | get_collision_layer() |
  184. +-----------+----------------------------+
  185. The physics layers this GridMap is in.
  186. GridMaps act as static bodies, meaning they aren't affected by gravity or other forces. They only affect other physics bodies that collide with them.
  187. ----
  188. .. _class_GridMap_property_collision_mask:
  189. - :ref:`int<class_int>` **collision_mask**
  190. +-----------+---------------------------+
  191. | *Default* | ``1`` |
  192. +-----------+---------------------------+
  193. | *Setter* | set_collision_mask(value) |
  194. +-----------+---------------------------+
  195. | *Getter* | get_collision_mask() |
  196. +-----------+---------------------------+
  197. The physics layers this GridMap detects collisions in. See `Collision layers and masks <../tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  198. ----
  199. .. _class_GridMap_property_mesh_library:
  200. - :ref:`MeshLibrary<class_MeshLibrary>` **mesh_library**
  201. +----------+-------------------------+
  202. | *Setter* | set_mesh_library(value) |
  203. +----------+-------------------------+
  204. | *Getter* | get_mesh_library() |
  205. +----------+-------------------------+
  206. The assigned :ref:`MeshLibrary<class_MeshLibrary>`.
  207. ----
  208. .. _class_GridMap_property_navigation_layers:
  209. - :ref:`int<class_int>` **navigation_layers**
  210. +-----------+------------------------------+
  211. | *Default* | ``1`` |
  212. +-----------+------------------------------+
  213. | *Setter* | set_navigation_layers(value) |
  214. +-----------+------------------------------+
  215. | *Getter* | get_navigation_layers() |
  216. +-----------+------------------------------+
  217. The navigation layers the GridMap generates its navigable regions in.
  218. Method Descriptions
  219. -------------------
  220. .. _class_GridMap_method_clear:
  221. - void **clear** **(** **)**
  222. Clear all cells.
  223. ----
  224. .. _class_GridMap_method_clear_baked_meshes:
  225. - void **clear_baked_meshes** **(** **)**
  226. ----
  227. .. _class_GridMap_method_get_bake_mesh_instance:
  228. - :ref:`RID<class_RID>` **get_bake_mesh_instance** **(** :ref:`int<class_int>` idx **)**
  229. ----
  230. .. _class_GridMap_method_get_bake_meshes:
  231. - :ref:`Array<class_Array>` **get_bake_meshes** **(** **)**
  232. Returns an array of :ref:`ArrayMesh<class_ArrayMesh>`\ es and :ref:`Transform3D<class_Transform3D>` references of all bake meshes that exist within the current GridMap.
  233. ----
  234. .. _class_GridMap_method_get_cell_item:
  235. - :ref:`int<class_int>` **get_cell_item** **(** :ref:`Vector3i<class_Vector3i>` position **)** |const|
  236. The :ref:`MeshLibrary<class_MeshLibrary>` item index located at the given grid coordinates. If the cell is empty, :ref:`INVALID_CELL_ITEM<class_GridMap_constant_INVALID_CELL_ITEM>` will be returned.
  237. ----
  238. .. _class_GridMap_method_get_cell_item_orientation:
  239. - :ref:`int<class_int>` **get_cell_item_orientation** **(** :ref:`Vector3i<class_Vector3i>` position **)** |const|
  240. The orientation of the cell at the given grid coordinates. ``-1`` is returned if the cell is empty.
  241. ----
  242. .. _class_GridMap_method_get_collision_layer_value:
  243. - :ref:`bool<class_bool>` **get_collision_layer_value** **(** :ref:`int<class_int>` layer_number **)** |const|
  244. Returns whether or not the specified layer of the :ref:`collision_layer<class_GridMap_property_collision_layer>` is enabled, given a ``layer_number`` between 1 and 32.
  245. ----
  246. .. _class_GridMap_method_get_collision_mask_value:
  247. - :ref:`bool<class_bool>` **get_collision_mask_value** **(** :ref:`int<class_int>` layer_number **)** |const|
  248. Returns whether or not the specified layer of the :ref:`collision_mask<class_GridMap_property_collision_mask>` is enabled, given a ``layer_number`` between 1 and 32.
  249. ----
  250. .. _class_GridMap_method_get_meshes:
  251. - :ref:`Array<class_Array>` **get_meshes** **(** **)**
  252. Returns an array of :ref:`Transform3D<class_Transform3D>` and :ref:`Mesh<class_Mesh>` references corresponding to the non-empty cells in the grid. The transforms are specified in world space.
  253. ----
  254. .. _class_GridMap_method_get_used_cells:
  255. - :ref:`Array<class_Array>` **get_used_cells** **(** **)** |const|
  256. Returns an array of :ref:`Vector3<class_Vector3>` with the non-empty cell coordinates in the grid map.
  257. ----
  258. .. _class_GridMap_method_make_baked_meshes:
  259. - void **make_baked_meshes** **(** :ref:`bool<class_bool>` gen_lightmap_uv=false, :ref:`float<class_float>` lightmap_uv_texel_size=0.1 **)**
  260. ----
  261. .. _class_GridMap_method_map_to_world:
  262. - :ref:`Vector3<class_Vector3>` **map_to_world** **(** :ref:`Vector3i<class_Vector3i>` map_position **)** |const|
  263. Returns the position of a grid cell in the GridMap's local coordinate space.
  264. ----
  265. .. _class_GridMap_method_resource_changed:
  266. - void **resource_changed** **(** :ref:`Resource<class_Resource>` resource **)**
  267. ----
  268. .. _class_GridMap_method_set_cell_item:
  269. - void **set_cell_item** **(** :ref:`Vector3i<class_Vector3i>` position, :ref:`int<class_int>` item, :ref:`int<class_int>` orientation=0 **)**
  270. Sets the mesh index for the cell referenced by its grid coordinates.
  271. A negative item index such as :ref:`INVALID_CELL_ITEM<class_GridMap_constant_INVALID_CELL_ITEM>` will clear the cell.
  272. Optionally, the item's orientation can be passed. For valid orientation values, see :ref:`Basis.get_orthogonal_index<class_Basis_method_get_orthogonal_index>`.
  273. ----
  274. .. _class_GridMap_method_set_clip:
  275. - void **set_clip** **(** :ref:`bool<class_bool>` enabled, :ref:`bool<class_bool>` clipabove=true, :ref:`int<class_int>` floor=0, Vector3.Axis axis=0 **)**
  276. ----
  277. .. _class_GridMap_method_set_collision_layer_value:
  278. - void **set_collision_layer_value** **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)**
  279. Based on ``value``, enables or disables the specified layer in the :ref:`collision_layer<class_GridMap_property_collision_layer>`, given a ``layer_number`` between 1 and 32.
  280. ----
  281. .. _class_GridMap_method_set_collision_mask_value:
  282. - void **set_collision_mask_value** **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)**
  283. Based on ``value``, enables or disables the specified layer in the :ref:`collision_mask<class_GridMap_property_collision_mask>`, given a ``layer_number`` between 1 and 32.
  284. ----
  285. .. _class_GridMap_method_world_to_map:
  286. - :ref:`Vector3i<class_Vector3i>` **world_to_map** **(** :ref:`Vector3<class_Vector3>` world_position **)** |const|
  287. Returns the coordinates of the grid cell containing the given point.
  288. ``pos`` should be in the GridMap's local coordinate space.
  289. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  290. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  291. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  292. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  293. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  294. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`