Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gridmap/doc_classes/GridMap.xml
10278 views
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<class name="GridMap" inherits="Node3D" keywords="tilemap" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
3
<brief_description>
4
Node for 3D tile-based maps.
5
</brief_description>
6
<description>
7
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.
8
GridMaps use a [MeshLibrary] which contains a list of tiles. Each tile is a mesh with materials plus optional collision and navigation shapes.
9
A GridMap contains a collection of cells. Each grid cell refers to a tile in the [MeshLibrary]. All cells in the map have the same dimensions.
10
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.
11
[b]Note:[/b] GridMap doesn't extend [VisualInstance3D] and therefore can't be hidden or cull masked based on [member VisualInstance3D.layers]. If you make a light not affect the first layer, the whole GridMap won't be lit by the light in question.
12
</description>
13
<tutorials>
14
<link title="Using gridmaps">$DOCS_URL/tutorials/3d/using_gridmaps.html</link>
15
<link title="3D Platformer Demo">https://godotengine.org/asset-library/asset/2748</link>
16
<link title="3D Kinematic Character Demo">https://godotengine.org/asset-library/asset/2739</link>
17
</tutorials>
18
<methods>
19
<method name="clear">
20
<return type="void" />
21
<description>
22
Clear all cells.
23
</description>
24
</method>
25
<method name="clear_baked_meshes">
26
<return type="void" />
27
<description>
28
Clears all baked meshes. See [method make_baked_meshes].
29
</description>
30
</method>
31
<method name="get_bake_mesh_instance">
32
<return type="RID" />
33
<param index="0" name="idx" type="int" />
34
<description>
35
Returns [RID] of a baked mesh with the given [param idx].
36
</description>
37
</method>
38
<method name="get_bake_meshes">
39
<return type="Array" />
40
<description>
41
Returns an array of [ArrayMesh]es and [Transform3D] references of all bake meshes that exist within the current GridMap. Even indices contain [ArrayMesh]es, while odd indices contain [Transform3D]s that are always equal to [constant Transform3D.IDENTITY].
42
This method relies on the output of [method make_baked_meshes], which will be called with [code]gen_lightmap_uv[/code] set to [code]true[/code] and [code]lightmap_uv_texel_size[/code] set to [code]0.1[/code] if it hasn't been called yet.
43
</description>
44
</method>
45
<method name="get_basis_with_orthogonal_index" qualifiers="const">
46
<return type="Basis" />
47
<param index="0" name="index" type="int" />
48
<description>
49
Returns one of 24 possible rotations that lie along the vectors (x,y,z) with each component being either -1, 0, or 1. For further details, refer to the Godot source code.
50
</description>
51
</method>
52
<method name="get_cell_item" qualifiers="const">
53
<return type="int" />
54
<param index="0" name="position" type="Vector3i" />
55
<description>
56
The [MeshLibrary] item index located at the given grid coordinates. If the cell is empty, [constant INVALID_CELL_ITEM] will be returned.
57
</description>
58
</method>
59
<method name="get_cell_item_basis" qualifiers="const">
60
<return type="Basis" />
61
<param index="0" name="position" type="Vector3i" />
62
<description>
63
Returns the basis that gives the specified cell its orientation.
64
</description>
65
</method>
66
<method name="get_cell_item_orientation" qualifiers="const">
67
<return type="int" />
68
<param index="0" name="position" type="Vector3i" />
69
<description>
70
The orientation of the cell at the given grid coordinates. [code]-1[/code] is returned if the cell is empty.
71
</description>
72
</method>
73
<method name="get_collision_layer_value" qualifiers="const">
74
<return type="bool" />
75
<param index="0" name="layer_number" type="int" />
76
<description>
77
Returns whether or not the specified layer of the [member collision_layer] is enabled, given a [param layer_number] between 1 and 32.
78
</description>
79
</method>
80
<method name="get_collision_mask_value" qualifiers="const">
81
<return type="bool" />
82
<param index="0" name="layer_number" type="int" />
83
<description>
84
Returns whether or not the specified layer of the [member collision_mask] is enabled, given a [param layer_number] between 1 and 32.
85
</description>
86
</method>
87
<method name="get_meshes" qualifiers="const">
88
<return type="Array" />
89
<description>
90
Returns an array of [Transform3D] and [Mesh] references corresponding to the non-empty cells in the grid. The transforms are specified in local space. Even indices contain [Transform3D]s, while odd indices contain [Mesh]es related to the [Transform3D] in the index preceding it.
91
</description>
92
</method>
93
<method name="get_navigation_map" qualifiers="const">
94
<return type="RID" />
95
<description>
96
Returns the [RID] of the navigation map this GridMap node uses for its cell baked navigation meshes.
97
This function returns always the map set on the GridMap node and not the map on the NavigationServer. If the map is changed directly with the NavigationServer API the GridMap node will not be aware of the map change.
98
</description>
99
</method>
100
<method name="get_orthogonal_index_from_basis" qualifiers="const">
101
<return type="int" />
102
<param index="0" name="basis" type="Basis" />
103
<description>
104
This function considers a discretization of rotations into 24 points on unit sphere, lying along the vectors (x,y,z) with each component being either -1, 0, or 1, and returns the index (in the range from 0 to 23) of the point best representing the orientation of the object. For further details, refer to the Godot source code.
105
</description>
106
</method>
107
<method name="get_used_cells" qualifiers="const">
108
<return type="Vector3i[]" />
109
<description>
110
Returns an array of [Vector3] with the non-empty cell coordinates in the grid map.
111
</description>
112
</method>
113
<method name="get_used_cells_by_item" qualifiers="const">
114
<return type="Vector3i[]" />
115
<param index="0" name="item" type="int" />
116
<description>
117
Returns an array of all cells with the given item index specified in [param item].
118
</description>
119
</method>
120
<method name="local_to_map" qualifiers="const">
121
<return type="Vector3i" />
122
<param index="0" name="local_position" type="Vector3" />
123
<description>
124
Returns the map coordinates of the cell containing the given [param local_position]. If [param local_position] is in global coordinates, consider using [method Node3D.to_local] before passing it to this method. See also [method map_to_local].
125
</description>
126
</method>
127
<method name="make_baked_meshes">
128
<return type="void" />
129
<param index="0" name="gen_lightmap_uv" type="bool" default="false" />
130
<param index="1" name="lightmap_uv_texel_size" type="float" default="0.1" />
131
<description>
132
Generates a baked mesh that represents all meshes in the assigned [MeshLibrary] for use with [LightmapGI]. If [param gen_lightmap_uv] is [code]true[/code], UV2 data will be generated for each mesh currently used in the [GridMap]. Otherwise, only meshes that already have UV2 data present will be able to use baked lightmaps. When generating UV2, [param lightmap_uv_texel_size] controls the texel density for lightmaps, with lower values resulting in more detailed lightmaps. [param lightmap_uv_texel_size] is ignored if [param gen_lightmap_uv] is [code]false[/code]. See also [method get_bake_meshes], which relies on the output of this method.
133
[b]Note:[/b] Calling this method will not actually bake lightmaps, as lightmap baking is performed using the [LightmapGI] node.
134
</description>
135
</method>
136
<method name="map_to_local" qualifiers="const">
137
<return type="Vector3" />
138
<param index="0" name="map_position" type="Vector3i" />
139
<description>
140
Returns the position of a grid cell in the GridMap's local coordinate space. To convert the returned value into global coordinates, use [method Node3D.to_global]. See also [method local_to_map].
141
</description>
142
</method>
143
<method name="resource_changed" deprecated="Use [signal Resource.changed] instead.">
144
<return type="void" />
145
<param index="0" name="resource" type="Resource" />
146
<description>
147
This method does nothing.
148
</description>
149
</method>
150
<method name="set_cell_item">
151
<return type="void" />
152
<param index="0" name="position" type="Vector3i" />
153
<param index="1" name="item" type="int" />
154
<param index="2" name="orientation" type="int" default="0" />
155
<description>
156
Sets the mesh index for the cell referenced by its grid coordinates.
157
A negative item index such as [constant INVALID_CELL_ITEM] will clear the cell.
158
Optionally, the item's orientation can be passed. For valid orientation values, see [method get_orthogonal_index_from_basis].
159
</description>
160
</method>
161
<method name="set_collision_layer_value">
162
<return type="void" />
163
<param index="0" name="layer_number" type="int" />
164
<param index="1" name="value" type="bool" />
165
<description>
166
Based on [param value], enables or disables the specified layer in the [member collision_layer], given a [param layer_number] between 1 and 32.
167
</description>
168
</method>
169
<method name="set_collision_mask_value">
170
<return type="void" />
171
<param index="0" name="layer_number" type="int" />
172
<param index="1" name="value" type="bool" />
173
<description>
174
Based on [param value], enables or disables the specified layer in the [member collision_mask], given a [param layer_number] between 1 and 32.
175
</description>
176
</method>
177
<method name="set_navigation_map">
178
<return type="void" />
179
<param index="0" name="navigation_map" type="RID" />
180
<description>
181
Sets the [RID] of the navigation map this GridMap node should use for its cell baked navigation meshes.
182
</description>
183
</method>
184
</methods>
185
<members>
186
<member name="bake_navigation" type="bool" setter="set_bake_navigation" getter="is_baking_navigation" default="false">
187
If [code]true[/code], this GridMap creates a navigation region for each cell that uses a [member mesh_library] item with a navigation mesh. The created navigation region will use the navigation layers bitmask assigned to the [MeshLibrary]'s item.
188
</member>
189
<member name="cell_center_x" type="bool" setter="set_center_x" getter="get_center_x" default="true">
190
If [code]true[/code], grid items are centered on the X axis.
191
</member>
192
<member name="cell_center_y" type="bool" setter="set_center_y" getter="get_center_y" default="true">
193
If [code]true[/code], grid items are centered on the Y axis.
194
</member>
195
<member name="cell_center_z" type="bool" setter="set_center_z" getter="get_center_z" default="true">
196
If [code]true[/code], grid items are centered on the Z axis.
197
</member>
198
<member name="cell_octant_size" type="int" setter="set_octant_size" getter="get_octant_size" default="8">
199
The size of each octant measured in number of cells. This applies to all three axis.
200
</member>
201
<member name="cell_scale" type="float" setter="set_cell_scale" getter="get_cell_scale" default="1.0">
202
The scale of the cell items.
203
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.
204
</member>
205
<member name="cell_size" type="Vector3" setter="set_cell_size" getter="get_cell_size" default="Vector3(2, 2, 2)">
206
The dimensions of the grid's cells.
207
This does not affect the size of the meshes. See [member cell_scale].
208
</member>
209
<member name="collision_layer" type="int" setter="set_collision_layer" getter="get_collision_layer" default="1">
210
The physics layers this GridMap is in.
211
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.
212
</member>
213
<member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
214
The physics layers this GridMap detects collisions in. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
215
</member>
216
<member name="collision_priority" type="float" setter="set_collision_priority" getter="get_collision_priority" default="1.0">
217
The priority used to solve colliding when occurring penetration. The higher the priority is, the lower the penetration into the object will be. This can for example be used to prevent the player from breaking through the boundaries of a level.
218
</member>
219
<member name="mesh_library" type="MeshLibrary" setter="set_mesh_library" getter="get_mesh_library">
220
The assigned [MeshLibrary].
221
</member>
222
<member name="physics_material" type="PhysicsMaterial" setter="set_physics_material" getter="get_physics_material">
223
Overrides the default friction and bounce physics properties for the whole [GridMap].
224
</member>
225
</members>
226
<signals>
227
<signal name="cell_size_changed">
228
<param index="0" name="cell_size" type="Vector3" />
229
<description>
230
Emitted when [member cell_size] changes.
231
</description>
232
</signal>
233
<signal name="changed">
234
<description>
235
Emitted when the [MeshLibrary] of this GridMap changes.
236
</description>
237
</signal>
238
</signals>
239
<constants>
240
<constant name="INVALID_CELL_ITEM" value="-1">
241
Invalid cell item that can be used in [method set_cell_item] to clear cells (or represent an empty cell in [method get_cell_item]).
242
</constant>
243
</constants>
244
</class>
245
246