class_gridmap.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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:`Spatial<class_Spatial>` **<** :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:`VisualInstance<class_VisualInstance>` and therefore can't be hidden or cull masked based on :ref:`VisualInstance.layers<class_VisualInstance_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:`../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:`cell_center_x<class_GridMap_property_cell_center_x>` | ``true`` |
  26. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`cell_center_y<class_GridMap_property_cell_center_y>` | ``true`` |
  28. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`cell_center_z<class_GridMap_property_cell_center_z>` | ``true`` |
  30. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  31. | :ref:`int<class_int>` | :ref:`cell_octant_size<class_GridMap_property_cell_octant_size>` | ``8`` |
  32. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  33. | :ref:`float<class_float>` | :ref:`cell_scale<class_GridMap_property_cell_scale>` | ``1.0`` |
  34. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  35. | :ref:`Vector3<class_Vector3>` | :ref:`cell_size<class_GridMap_property_cell_size>` | ``Vector3( 2, 2, 2 )`` |
  36. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  37. | :ref:`int<class_int>` | :ref:`collision_layer<class_GridMap_property_collision_layer>` | ``1`` |
  38. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  39. | :ref:`int<class_int>` | :ref:`collision_mask<class_GridMap_property_collision_mask>` | ``1`` |
  40. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  41. | :ref:`MeshLibrary<class_MeshLibrary>` | :ref:`mesh_library<class_GridMap_property_mesh_library>` | |
  42. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`use_in_baked_light<class_GridMap_property_use_in_baked_light>` | ``false`` |
  44. +---------------------------------------+----------------------------------------------------------------------+------------------------+
  45. Methods
  46. -------
  47. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`clear<class_GridMap_method_clear>` **(** **)** |
  49. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`clear_baked_meshes<class_GridMap_method_clear_baked_meshes>` **(** **)** |
  51. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`RID<class_RID>` | :ref:`get_bake_mesh_instance<class_GridMap_method_get_bake_mesh_instance>` **(** :ref:`int<class_int>` idx **)** |
  53. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Array<class_Array>` | :ref:`get_bake_meshes<class_GridMap_method_get_bake_meshes>` **(** **)** |
  55. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`int<class_int>` | :ref:`get_cell_item<class_GridMap_method_get_cell_item>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` z **)** |const| |
  57. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`int<class_int>` | :ref:`get_cell_item_orientation<class_GridMap_method_get_cell_item_orientation>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` z **)** |const| |
  59. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`bool<class_bool>` | :ref:`get_collision_layer_bit<class_GridMap_method_get_collision_layer_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  61. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_bit<class_GridMap_method_get_collision_mask_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  63. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`Array<class_Array>` | :ref:`get_meshes<class_GridMap_method_get_meshes>` **(** **)** |
  65. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Array<class_Array>` | :ref:`get_used_cells<class_GridMap_method_get_used_cells>` **(** **)** |const| |
  67. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | 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 **)** |
  69. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Vector3<class_Vector3>` | :ref:`map_to_world<class_GridMap_method_map_to_world>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` z **)** |const| |
  71. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`resource_changed<class_GridMap_method_resource_changed>` **(** :ref:`Resource<class_Resource>` resource **)** |
  73. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`set_cell_item<class_GridMap_method_set_cell_item>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` z, :ref:`int<class_int>` item, :ref:`int<class_int>` orientation=0 **)** |
  75. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | 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 **)** |
  77. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`set_collision_layer_bit<class_GridMap_method_set_collision_layer_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  79. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`set_collision_mask_bit<class_GridMap_method_set_collision_mask_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  81. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Vector3<class_Vector3>` | :ref:`world_to_map<class_GridMap_method_world_to_map>` **(** :ref:`Vector3<class_Vector3>` pos **)** |const| |
  83. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. Signals
  85. -------
  86. .. _class_GridMap_signal_cell_size_changed:
  87. - **cell_size_changed** **(** :ref:`Vector3<class_Vector3>` cell_size **)**
  88. Emitted when :ref:`cell_size<class_GridMap_property_cell_size>` changes.
  89. Constants
  90. ---------
  91. .. _class_GridMap_constant_INVALID_CELL_ITEM:
  92. - **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>`).
  93. Property Descriptions
  94. ---------------------
  95. .. _class_GridMap_property_cell_center_x:
  96. - :ref:`bool<class_bool>` **cell_center_x**
  97. +-----------+---------------------+
  98. | *Default* | ``true`` |
  99. +-----------+---------------------+
  100. | *Setter* | set_center_x(value) |
  101. +-----------+---------------------+
  102. | *Getter* | get_center_x() |
  103. +-----------+---------------------+
  104. If ``true``, grid items are centered on the X axis.
  105. ----
  106. .. _class_GridMap_property_cell_center_y:
  107. - :ref:`bool<class_bool>` **cell_center_y**
  108. +-----------+---------------------+
  109. | *Default* | ``true`` |
  110. +-----------+---------------------+
  111. | *Setter* | set_center_y(value) |
  112. +-----------+---------------------+
  113. | *Getter* | get_center_y() |
  114. +-----------+---------------------+
  115. If ``true``, grid items are centered on the Y axis.
  116. ----
  117. .. _class_GridMap_property_cell_center_z:
  118. - :ref:`bool<class_bool>` **cell_center_z**
  119. +-----------+---------------------+
  120. | *Default* | ``true`` |
  121. +-----------+---------------------+
  122. | *Setter* | set_center_z(value) |
  123. +-----------+---------------------+
  124. | *Getter* | get_center_z() |
  125. +-----------+---------------------+
  126. If ``true``, grid items are centered on the Z axis.
  127. ----
  128. .. _class_GridMap_property_cell_octant_size:
  129. - :ref:`int<class_int>` **cell_octant_size**
  130. +-----------+------------------------+
  131. | *Default* | ``8`` |
  132. +-----------+------------------------+
  133. | *Setter* | set_octant_size(value) |
  134. +-----------+------------------------+
  135. | *Getter* | get_octant_size() |
  136. +-----------+------------------------+
  137. The size of each octant measured in number of cells. This applies to all three axis.
  138. ----
  139. .. _class_GridMap_property_cell_scale:
  140. - :ref:`float<class_float>` **cell_scale**
  141. +-----------+-----------------------+
  142. | *Default* | ``1.0`` |
  143. +-----------+-----------------------+
  144. | *Setter* | set_cell_scale(value) |
  145. +-----------+-----------------------+
  146. | *Getter* | get_cell_scale() |
  147. +-----------+-----------------------+
  148. The scale of the cell items.
  149. 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.
  150. ----
  151. .. _class_GridMap_property_cell_size:
  152. - :ref:`Vector3<class_Vector3>` **cell_size**
  153. +-----------+------------------------+
  154. | *Default* | ``Vector3( 2, 2, 2 )`` |
  155. +-----------+------------------------+
  156. | *Setter* | set_cell_size(value) |
  157. +-----------+------------------------+
  158. | *Getter* | get_cell_size() |
  159. +-----------+------------------------+
  160. The dimensions of the grid's cells.
  161. This does not affect the size of the meshes. See :ref:`cell_scale<class_GridMap_property_cell_scale>`.
  162. ----
  163. .. _class_GridMap_property_collision_layer:
  164. - :ref:`int<class_int>` **collision_layer**
  165. +-----------+----------------------------+
  166. | *Default* | ``1`` |
  167. +-----------+----------------------------+
  168. | *Setter* | set_collision_layer(value) |
  169. +-----------+----------------------------+
  170. | *Getter* | get_collision_layer() |
  171. +-----------+----------------------------+
  172. The physics layers this GridMap is in.
  173. 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.
  174. ----
  175. .. _class_GridMap_property_collision_mask:
  176. - :ref:`int<class_int>` **collision_mask**
  177. +-----------+---------------------------+
  178. | *Default* | ``1`` |
  179. +-----------+---------------------------+
  180. | *Setter* | set_collision_mask(value) |
  181. +-----------+---------------------------+
  182. | *Getter* | get_collision_mask() |
  183. +-----------+---------------------------+
  184. The physics layers this GridMap detects collisions in. See `Collision layers and masks <https://docs.godotengine.org/en/3.4/tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  185. ----
  186. .. _class_GridMap_property_mesh_library:
  187. - :ref:`MeshLibrary<class_MeshLibrary>` **mesh_library**
  188. +----------+-------------------------+
  189. | *Setter* | set_mesh_library(value) |
  190. +----------+-------------------------+
  191. | *Getter* | get_mesh_library() |
  192. +----------+-------------------------+
  193. The assigned :ref:`MeshLibrary<class_MeshLibrary>`.
  194. ----
  195. .. _class_GridMap_property_use_in_baked_light:
  196. - :ref:`bool<class_bool>` **use_in_baked_light**
  197. +-----------+-------------------------------+
  198. | *Default* | ``false`` |
  199. +-----------+-------------------------------+
  200. | *Setter* | set_use_in_baked_light(value) |
  201. +-----------+-------------------------------+
  202. | *Getter* | get_use_in_baked_light() |
  203. +-----------+-------------------------------+
  204. Controls whether this GridMap will be baked in a :ref:`BakedLightmap<class_BakedLightmap>` or not.
  205. Method Descriptions
  206. -------------------
  207. .. _class_GridMap_method_clear:
  208. - void **clear** **(** **)**
  209. Clear all cells.
  210. ----
  211. .. _class_GridMap_method_clear_baked_meshes:
  212. - void **clear_baked_meshes** **(** **)**
  213. ----
  214. .. _class_GridMap_method_get_bake_mesh_instance:
  215. - :ref:`RID<class_RID>` **get_bake_mesh_instance** **(** :ref:`int<class_int>` idx **)**
  216. ----
  217. .. _class_GridMap_method_get_bake_meshes:
  218. - :ref:`Array<class_Array>` **get_bake_meshes** **(** **)**
  219. Returns an array of :ref:`ArrayMesh<class_ArrayMesh>`\ es and :ref:`Transform<class_Transform>` references of all bake meshes that exist within the current GridMap.
  220. ----
  221. .. _class_GridMap_method_get_cell_item:
  222. - :ref:`int<class_int>` **get_cell_item** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` z **)** |const|
  223. The :ref:`MeshLibrary<class_MeshLibrary>` item index located at the grid-based X, Y and Z coordinates. If the cell is empty, :ref:`INVALID_CELL_ITEM<class_GridMap_constant_INVALID_CELL_ITEM>` will be returned.
  224. ----
  225. .. _class_GridMap_method_get_cell_item_orientation:
  226. - :ref:`int<class_int>` **get_cell_item_orientation** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` z **)** |const|
  227. The orientation of the cell at the grid-based X, Y and Z coordinates. -1 is returned if the cell is empty.
  228. ----
  229. .. _class_GridMap_method_get_collision_layer_bit:
  230. - :ref:`bool<class_bool>` **get_collision_layer_bit** **(** :ref:`int<class_int>` bit **)** |const|
  231. Returns an individual bit on the :ref:`collision_layer<class_GridMap_property_collision_layer>`.
  232. ----
  233. .. _class_GridMap_method_get_collision_mask_bit:
  234. - :ref:`bool<class_bool>` **get_collision_mask_bit** **(** :ref:`int<class_int>` bit **)** |const|
  235. Returns an individual bit on the :ref:`collision_mask<class_GridMap_property_collision_mask>`.
  236. ----
  237. .. _class_GridMap_method_get_meshes:
  238. - :ref:`Array<class_Array>` **get_meshes** **(** **)**
  239. Returns an array of :ref:`Transform<class_Transform>` and :ref:`Mesh<class_Mesh>` references corresponding to the non-empty cells in the grid. The transforms are specified in world space.
  240. ----
  241. .. _class_GridMap_method_get_used_cells:
  242. - :ref:`Array<class_Array>` **get_used_cells** **(** **)** |const|
  243. Returns an array of :ref:`Vector3<class_Vector3>` with the non-empty cell coordinates in the grid map.
  244. ----
  245. .. _class_GridMap_method_make_baked_meshes:
  246. - void **make_baked_meshes** **(** :ref:`bool<class_bool>` gen_lightmap_uv=false, :ref:`float<class_float>` lightmap_uv_texel_size=0.1 **)**
  247. ----
  248. .. _class_GridMap_method_map_to_world:
  249. - :ref:`Vector3<class_Vector3>` **map_to_world** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` z **)** |const|
  250. Returns the position of a grid cell in the GridMap's local coordinate space.
  251. ----
  252. .. _class_GridMap_method_resource_changed:
  253. - void **resource_changed** **(** :ref:`Resource<class_Resource>` resource **)**
  254. ----
  255. .. _class_GridMap_method_set_cell_item:
  256. - void **set_cell_item** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` z, :ref:`int<class_int>` item, :ref:`int<class_int>` orientation=0 **)**
  257. Sets the mesh index for the cell referenced by its grid-based X, Y and Z coordinates.
  258. A negative item index such as :ref:`INVALID_CELL_ITEM<class_GridMap_constant_INVALID_CELL_ITEM>` will clear the cell.
  259. Optionally, the item's orientation can be passed. For valid orientation values, see :ref:`Basis.get_orthogonal_index<class_Basis_method_get_orthogonal_index>`.
  260. ----
  261. .. _class_GridMap_method_set_clip:
  262. - void **set_clip** **(** :ref:`bool<class_bool>` enabled, :ref:`bool<class_bool>` clipabove=true, :ref:`int<class_int>` floor=0, Vector3.Axis axis=0 **)**
  263. ----
  264. .. _class_GridMap_method_set_collision_layer_bit:
  265. - void **set_collision_layer_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  266. Sets an individual bit on the :ref:`collision_layer<class_GridMap_property_collision_layer>`.
  267. ----
  268. .. _class_GridMap_method_set_collision_mask_bit:
  269. - void **set_collision_mask_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  270. Sets an individual bit on the :ref:`collision_mask<class_GridMap_property_collision_mask>`.
  271. ----
  272. .. _class_GridMap_method_world_to_map:
  273. - :ref:`Vector3<class_Vector3>` **world_to_map** **(** :ref:`Vector3<class_Vector3>` pos **)** |const|
  274. Returns the coordinates of the grid cell containing the given point.
  275. ``pos`` should be in the GridMap's local coordinate space.
  276. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  277. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  278. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`