GridMap
Node for 3D tile-based maps.
GridMap.swift:26class GridMap
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.
GridMaps use a MeshLibrary
which contains a list of tiles. Each tile is a mesh with materials plus optional collision and navigation shapes.
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.
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.
This object emits the following signals:
Superclasses
class Node3D
Most basic 3D game object, parent of all 3D-related nodes.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
class Signal1
Signal support.
Type members
static let invalidCellItem: Int
Invalid cell item that can be used in
setCellItem(position:item:orientation:)
to clear cells (or represent an empty cell ingetCellItem(position:)
).class var godotClassName: StringName
Instance members
var cellCenterX: Bool
If
true
, grid items are centered on the X axis.var cellCenterY: Bool
If
true
, grid items are centered on the Y axis.var cellCenterZ: Bool
If
true
, grid items are centered on the Z axis.var cellOctantSize: Int32
The size of each octant measured in number of cells. This applies to all three axis.
var cellScale: Double
The scale of the cell items.
var cellSize: Vector3
The dimensions of the grid’s cells.
var cellSizeChanged: Signal1
Emitted when
cellSize
changes.var changed: SimpleSignal
Emitted when the
MeshLibrary
of this GridMap changes.var collisionLayer: UInt32
The physics layers this GridMap is in.
var collisionMask: UInt32
The physics layers this GridMap detects collisions in. See Collision layers and masks in the documentation for more information.
var collisionPriority: Double
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.
var meshLibrary: MeshLibrary?
The assigned
MeshLibrary
.var physicsMaterial: PhysicsMaterial?
Overrides the default friction and bounce physics properties for the whole
GridMap
.func clear(
) Clear all cells.
func clearBakedMeshes(
) Clears all baked meshes. See
makeBakedMeshes(genLightmapUv:lightmapUvTexelSize:)
.func getBakeMeshInstance(idx: Int32
) -> RID Returns
RID
of a baked mesh with the givenidx
.func getBakeMeshes(
) -> GArray Returns an array of
ArrayMesh
es andTransform3D
references of all bake meshes that exist within the current GridMap.func getBasisWithOrthogonalIndex(Int32
) -> Basis 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.
func getCellItem(position: Vector3i
) -> Int32 The
MeshLibrary
item index located at the given grid coordinates. If the cell is empty,invalidCellItem
will be returned.func getCellItemBasis(position: Vector3i
) -> Basis Returns the basis that gives the specified cell its orientation.
func getCellItemOrientation(position: Vector3i
) -> Int32 The orientation of the cell at the given grid coordinates.
-1
is returned if the cell is empty.func getCollisionLayerValue(layerNumber: Int32
) -> Bool Returns whether or not the specified layer of the
collisionLayer
is enabled, given alayerNumber
between 1 and 32.func getCollisionMaskValue(layerNumber: Int32
) -> Bool Returns whether or not the specified layer of the
collisionMask
is enabled, given alayerNumber
between 1 and 32.func getMeshes(
) -> GArray Returns an array of
Transform3D
andMesh
references corresponding to the non-empty cells in the grid. The transforms are specified in local space.func getOrthogonalIndexFromBasis(Basis
) -> Int32 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.
func getUsedCells(
) -> VariantCollection<Vector3i> Returns an array of
Vector3
with the non-empty cell coordinates in the grid map.func getUsedCellsByItem(Int32
) -> VariantCollection<Vector3i> Returns an array of all cells with the given item index specified in
item
.func localToMap(localPosition: Vector3
) -> Vector3i Returns the map coordinates of the cell containing the given
localPosition
. IflocalPosition
is in global coordinates, consider usingtoLocal(globalPoint:)
before passing it to this method. See alsomapToLocal(mapPosition:)
.func makeBakedMeshes(genLightmapUv: Bool, lightmapUvTexelSize: Double
) Bakes lightmap data for all meshes in the assigned
MeshLibrary
.func mapToLocal(mapPosition: Vector3i
) -> Vector3 Returns the position of a grid cell in the GridMap’s local coordinate space. To convert the returned value into global coordinates, use
toGlobal(localPoint:)
. See alsomapToLocal(mapPosition:)
.func resourceChanged(resource: Resource?
) Obsoleted. Use [signal Resource.changed] instead.
func setCellItem(position: Vector3i, item: Int32, orientation: Int32
) Sets the mesh index for the cell referenced by its grid coordinates.
func setCollisionLayerValue(layerNumber: Int32, value: Bool
) Based on
value
, enables or disables the specified layer in thecollisionLayer
, given alayerNumber
between 1 and 32.func setCollisionMaskValue(layerNumber: Int32, value: Bool
) Based on
value
, enables or disables the specified layer in thecollisionMask
, given alayerNumber
between 1 and 32.