GridMap

package
v0.0.0-...-0d6c339 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

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 graphics.gd/classdb/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 graphics.gd/classdb/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.

Note: GridMap doesn't extend graphics.gd/classdb/VisualInstance3D and therefore can't be hidden or cull masked based on graphics.gd/classdb/VisualInstance3D.Instance.Layers. If you make a light not affect the first layer, the whole GridMap won't be lit by the light in question.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsGridMap() Instance
}

type CellItem

type CellItem int
const InvalidCellItem CellItem = -1 //gd:GridMap.INVALID_CELL_ITEM

type Expanded

type Expanded [1]gdclass.GridMap

func (Expanded) MakeBakedMeshes

func (self Expanded) MakeBakedMeshes(gen_lightmap_uv bool, lightmap_uv_texel_size Float.X)

Generates a baked mesh that represents all meshes in the assigned graphics.gd/classdb/MeshLibrary for use with graphics.gd/classdb/LightmapGI. If 'gen_lightmap_uv' is true, UV2 data will be generated for each mesh currently used in the graphics.gd/classdb/GridMap. Otherwise, only meshes that already have UV2 data present will be able to use baked lightmaps. When generating UV2, 'lightmap_uv_texel_size' controls the texel density for lightmaps, with lower values resulting in more detailed lightmaps. 'lightmap_uv_texel_size' is ignored if 'gen_lightmap_uv' is false. See also Instance.GetBakeMeshes, which relies on the output of this method.

Note: Calling this method will not actually bake lightmaps, as lightmap baking is performed using the graphics.gd/classdb/LightmapGI node.

func (Expanded) SetCellItem

func (self Expanded) SetCellItem(position Vector3i.XYZ, item CellItem, orientation int)

Sets the mesh index for the cell referenced by its grid coordinates.

A negative item index such as InvalidCellItem will clear the cell.

Optionally, the item's orientation can be passed. For valid orientation values, see Instance.GetOrthogonalIndexFromBasis.

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsGridMap

func (self *Extension[T]) AsGridMap() Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsNode3D

func (self *Extension[T]) AsNode3D() Node3D.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.GridMap

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsGridMap

func (self Instance) AsGridMap() Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsNode3D

func (self Instance) AsNode3D() Node3D.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) BakeNavigation

func (self Instance) BakeNavigation() bool

func (Instance) CellCenterX

func (self Instance) CellCenterX() bool

func (Instance) CellCenterY

func (self Instance) CellCenterY() bool

func (Instance) CellCenterZ

func (self Instance) CellCenterZ() bool

func (Instance) CellOctantSize

func (self Instance) CellOctantSize() int

func (Instance) CellScale

func (self Instance) CellScale() Float.X

func (Instance) CellSize

func (self Instance) CellSize() Vector3.XYZ

func (Instance) Clear

func (self Instance) Clear()

Clear all cells.

func (Instance) ClearBakedMeshes

func (self Instance) ClearBakedMeshes()

Clears all baked meshes. See Instance.MakeBakedMeshes.

func (Instance) CollisionLayer

func (self Instance) CollisionLayer() int

func (Instance) CollisionMask

func (self Instance) CollisionMask() int

func (Instance) CollisionPriority

func (self Instance) CollisionPriority() Float.X

func (Instance) GetBakeMeshInstance

func (self Instance) GetBakeMeshInstance(idx int) RID.Mesh

Returns [Resource.ID] of a baked mesh with the given 'idx'.

func (Instance) GetBakeMeshes

func (self Instance) GetBakeMeshes() []any

Returns an array of [graphics.gd/classdb/ArrayMesh]es and [Transform3D.BasisOrigin] references of all bake meshes that exist within the current GridMap. Even indices contain [graphics.gd/classdb/ArrayMesh]es, while odd indices contain [Transform3D.BasisOrigin]s that are always equal to [Transform3d.Identity].

This method relies on the output of Instance.MakeBakedMeshes, which will be called with gen_lightmap_uv set to true and lightmap_uv_texel_size set to 0.1 if it hasn't been called yet.

func (Instance) GetBasisWithOrthogonalIndex

func (self Instance) GetBasisWithOrthogonalIndex(index int) Basis.XYZ

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 (Instance) GetCellItem

func (self Instance) GetCellItem(position Vector3i.XYZ) CellItem

The graphics.gd/classdb/MeshLibrary item index located at the given grid coordinates. If the cell is empty, InvalidCellItem will be returned.

func (Instance) GetCellItemBasis

func (self Instance) GetCellItemBasis(position Vector3i.XYZ) Basis.XYZ

Returns the basis that gives the specified cell its orientation.

func (Instance) GetCellItemOrientation

func (self Instance) GetCellItemOrientation(position Vector3i.XYZ) CellItem

The orientation of the cell at the given grid coordinates. -1 is returned if the cell is empty.

func (Instance) GetCollisionLayerValue

func (self Instance) GetCollisionLayerValue(layer_number int) bool

Returns whether or not the specified layer of the Instance.CollisionLayer is enabled, given a 'layer_number' between 1 and 32.

func (Instance) GetCollisionMaskValue

func (self Instance) GetCollisionMaskValue(layer_number int) bool

Returns whether or not the specified layer of the Instance.CollisionMask is enabled, given a 'layer_number' between 1 and 32.

func (Instance) GetMeshes

func (self Instance) GetMeshes() []any

Returns an array of [Transform3D.BasisOrigin] and graphics.gd/classdb/Mesh references corresponding to the non-empty cells in the grid. The transforms are specified in local space. Even indices contain [Transform3D.BasisOrigin]s, while odd indices contain [graphics.gd/classdb/Mesh]es related to the [Transform3D.BasisOrigin] in the index preceding it.

func (Instance) GetNavigationMap

func (self Instance) GetNavigationMap() RID.NavigationMap3D

Returns the [Resource.ID] of the navigation map this GridMap node uses for its cell baked navigation meshes.

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.

func (Instance) GetOrthogonalIndexFromBasis

func (self Instance) GetOrthogonalIndexFromBasis(basis Basis.XYZ) int

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 (Instance) GetUsedCells

func (self Instance) GetUsedCells() []Vector3i.XYZ

Returns an array of [Vector3.XYZ] with the non-empty cell coordinates in the grid map.

func (Instance) GetUsedCellsByItem

func (self Instance) GetUsedCellsByItem(item CellItem) []Vector3i.XYZ

Returns an array of all cells with the given item index specified in 'item'.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) LocalToMap

func (self Instance) LocalToMap(local_position Vector3.XYZ) Vector3i.XYZ

Returns the map coordinates of the cell containing the given 'local_position'. If 'local_position' is in global coordinates, consider using graphics.gd/classdb/Node3D.Instance.ToLocal before passing it to this method. See also Instance.MapToLocal.

func (Instance) MakeBakedMeshes

func (self Instance) MakeBakedMeshes()

Generates a baked mesh that represents all meshes in the assigned graphics.gd/classdb/MeshLibrary for use with graphics.gd/classdb/LightmapGI. If 'gen_lightmap_uv' is true, UV2 data will be generated for each mesh currently used in the graphics.gd/classdb/GridMap. Otherwise, only meshes that already have UV2 data present will be able to use baked lightmaps. When generating UV2, 'lightmap_uv_texel_size' controls the texel density for lightmaps, with lower values resulting in more detailed lightmaps. 'lightmap_uv_texel_size' is ignored if 'gen_lightmap_uv' is false. See also Instance.GetBakeMeshes, which relies on the output of this method.

Note: Calling this method will not actually bake lightmaps, as lightmap baking is performed using the graphics.gd/classdb/LightmapGI node.

func (Instance) MapToLocal

func (self Instance) MapToLocal(map_position Vector3i.XYZ) Vector3.XYZ

Returns the position of a grid cell in the GridMap's local coordinate space. To convert the returned value into global coordinates, use graphics.gd/classdb/Node3D.Instance.ToGlobal. See also Instance.LocalToMap.

func (Instance) MeshLibrary

func (self Instance) MeshLibrary() MeshLibrary.Instance

func (Instance) OnCellSizeChanged

func (self Instance) OnCellSizeChanged(cb func(cell_size Vector3.XYZ), flags ...Signal.Flags)

func (Instance) OnChanged

func (self Instance) OnChanged(cb func(), flags ...Signal.Flags)

func (Instance) PhysicsMaterial

func (self Instance) PhysicsMaterial() PhysicsMaterial.Instance

func (Instance) ResourceChanged

func (self Instance) ResourceChanged(resource Resource.Instance)

This method does nothing.

func (Instance) SetBakeNavigation

func (self Instance) SetBakeNavigation(value bool)

func (Instance) SetCellCenterX

func (self Instance) SetCellCenterX(value bool)

func (Instance) SetCellCenterY

func (self Instance) SetCellCenterY(value bool)

func (Instance) SetCellCenterZ

func (self Instance) SetCellCenterZ(value bool)

func (Instance) SetCellItem

func (self Instance) SetCellItem(position Vector3i.XYZ, item CellItem)

Sets the mesh index for the cell referenced by its grid coordinates.

A negative item index such as InvalidCellItem will clear the cell.

Optionally, the item's orientation can be passed. For valid orientation values, see Instance.GetOrthogonalIndexFromBasis.

func (Instance) SetCellOctantSize

func (self Instance) SetCellOctantSize(value int)

func (Instance) SetCellScale

func (self Instance) SetCellScale(value Float.X)

func (Instance) SetCellSize

func (self Instance) SetCellSize(value Vector3.XYZ)

func (Instance) SetCollisionLayer

func (self Instance) SetCollisionLayer(value int)

func (Instance) SetCollisionLayerValue

func (self Instance) SetCollisionLayerValue(layer_number int, value bool)

Based on 'value', enables or disables the specified layer in the Instance.CollisionLayer, given a 'layer_number' between 1 and 32.

func (Instance) SetCollisionMask

func (self Instance) SetCollisionMask(value int)

func (Instance) SetCollisionMaskValue

func (self Instance) SetCollisionMaskValue(layer_number int, value bool)

Based on 'value', enables or disables the specified layer in the Instance.CollisionMask, given a 'layer_number' between 1 and 32.

func (Instance) SetCollisionPriority

func (self Instance) SetCollisionPriority(value Float.X)

func (Instance) SetMeshLibrary

func (self Instance) SetMeshLibrary(value MeshLibrary.Instance)

func (Instance) SetNavigationMap

func (self Instance) SetNavigationMap(navigation_map RID.NavigationMap3D)

Sets the [Resource.ID] of the navigation map this GridMap node should use for its cell baked navigation meshes.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetPhysicsMaterial

func (self Instance) SetPhysicsMaterial(value PhysicsMaterial.Instance)

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL