NavigationPolygon

package
v0.0.0-...-fa94a0d Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

A navigation mesh can be created either by baking it with the help of the NavigationServer2D, or by adding vertices and convex polygon indices arrays manually.

To bake a navigation mesh at least one outline needs to be added that defines the outer bounds of the baked area.

package main

import (
	"graphics.gd/classdb/NavigationMeshSourceGeometryData2D"
	"graphics.gd/classdb/NavigationPolygon"
	"graphics.gd/classdb/NavigationRegion2D"
	"graphics.gd/classdb/NavigationServer2D"
	"graphics.gd/variant/Vector2"
)

func ExampleNavigationPolygon(region NavigationRegion2D.Instance) {
	var new_navigation_mesh = NavigationPolygon.New()
	var bounding_outline = []Vector2.XY{{0, 0}, {0, 50}, {50, 50}, {50, 0}}
	new_navigation_mesh.AddOutline(bounding_outline)
	NavigationServer2D.BakeFromSourceGeometryData(new_navigation_mesh, NavigationMeshSourceGeometryData2D.New(), nil)
	region.SetNavigationPolygon(new_navigation_mesh)
}

Adding vertices and polygon indices manually.

package main

import (
	"graphics.gd/classdb/NavigationPolygon"
	"graphics.gd/classdb/NavigationRegion2D"
	"graphics.gd/variant/Vector2"
)

func ExampleNavigationPolygon2(region NavigationRegion2D.Instance) {
	var new_navigation_mesh = NavigationPolygon.New()
	var new_vertices = []Vector2.XY{{0, 0}, {0, 50}, {50, 50}, {50, 0}}
	new_navigation_mesh.SetVertices(new_vertices)
	var new_polygon_indices = []int32{0, 1, 2, 3}
	new_navigation_mesh.AddPolygon(new_polygon_indices)
	region.SetNavigationPolygon(new_navigation_mesh.AsNavigationPolygon())
}

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
	AsNavigationPolygon() Instance
}

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]) AsNavigationPolygon

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

func (*Extension[T]) AsObject

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

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

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.NavigationPolygon

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) AddOutline

func (self Instance) AddOutline(outline []Vector2.XY)

Appends a []Vector2.XY that contains the vertices of an outline to the internal array that contains all the outlines.

func (Instance) AddOutlineAtIndex

func (self Instance) AddOutlineAtIndex(outline []Vector2.XY, index int)

Adds a []Vector2.XY that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position.

func (Instance) AddPolygon

func (self Instance) AddPolygon(polygon []int32)

Adds a polygon using the indices of the vertices you get when calling GetVertices.

func (Instance) AgentRadius

func (self Instance) AgentRadius() Float.X

func (Instance) AsNavigationPolygon

func (self Instance) AsNavigationPolygon() Instance

func (Instance) AsObject

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

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) BakingRect

func (self Instance) BakingRect() Rect2.PositionSize

func (Instance) BakingRectOffset

func (self Instance) BakingRectOffset() Vector2.XY

func (Instance) BorderSize

func (self Instance) BorderSize() Float.X

func (Instance) CellSize

func (self Instance) CellSize() Float.X

func (Instance) Clear

func (self Instance) Clear()

Clears the internal arrays for vertices and polygon indices.

func (Instance) ClearOutlines

func (self Instance) ClearOutlines()

Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.

func (Instance) ClearPolygons

func (self Instance) ClearPolygons()

Clears the array of polygons, but it doesn't clear the array of outlines and vertices.

func (Instance) GetNavigationMesh

func (self Instance) GetNavigationMesh() NavigationMesh.Instance

Returns the NavigationMesh resulting from this navigation polygon. This navigation mesh can be used to update the navigation mesh of a region with the NavigationServer3D.RegionSetNavigationMesh API directly.

func (Instance) GetOutline

func (self Instance) GetOutline(idx int) []Vector2.XY

Returns a []Vector2.XY containing the vertices of an outline that was created in the editor or by script.

func (Instance) GetOutlineCount

func (self Instance) GetOutlineCount() int

Returns the number of outlines that were created in the editor or by script.

func (Instance) GetParsedCollisionMaskValue

func (self Instance) GetParsedCollisionMaskValue(layer_number int) bool

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

func (Instance) GetPolygon

func (self Instance) GetPolygon(idx int) []int32

Returns a []int32 containing the indices of the vertices of a created polygon.

func (Instance) GetPolygonCount

func (self Instance) GetPolygonCount() int

Returns the count of all polygons.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) MakePolygonsFromOutlines

func (self Instance) MakePolygonsFromOutlines()

Creates polygons from the outlines added in the editor or by script.

func (Instance) ParsedCollisionMask

func (self Instance) ParsedCollisionMask() int

func (Instance) ParsedGeometryType

func (self Instance) ParsedGeometryType() ParsedGeometryType

func (Instance) RemoveOutline

func (self Instance) RemoveOutline(idx int)

Removes an outline created in the editor or by script. You have to call MakePolygonsFromOutlines for the polygons to update.

func (Instance) SamplePartitionType

func (self Instance) SamplePartitionType() SamplePartitionType

func (Instance) SetAgentRadius

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

func (Instance) SetBakingRect

func (self Instance) SetBakingRect(value Rect2.PositionSize)

func (Instance) SetBakingRectOffset

func (self Instance) SetBakingRectOffset(value Vector2.XY)

func (Instance) SetBorderSize

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

func (Instance) SetCellSize

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

func (*Instance) SetObject

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

func (Instance) SetOutline

func (self Instance) SetOutline(idx int, outline []Vector2.XY)

Changes an outline created in the editor or by script. You have to call MakePolygonsFromOutlines for the polygons to update.

func (Instance) SetParsedCollisionMask

func (self Instance) SetParsedCollisionMask(value int)

func (Instance) SetParsedCollisionMaskValue

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

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

func (Instance) SetParsedGeometryType

func (self Instance) SetParsedGeometryType(value ParsedGeometryType)

func (Instance) SetSamplePartitionType

func (self Instance) SetSamplePartitionType(value SamplePartitionType)

func (Instance) SetSourceGeometryGroupName

func (self Instance) SetSourceGeometryGroupName(value string)

func (Instance) SetSourceGeometryMode

func (self Instance) SetSourceGeometryMode(value SourceGeometryMode)

func (Instance) SetVertices

func (self Instance) SetVertices(value []Vector2.XY)

func (Instance) SourceGeometryGroupName

func (self Instance) SourceGeometryGroupName() string

func (Instance) SourceGeometryMode

func (self Instance) SourceGeometryMode() SourceGeometryMode

func (Instance) Vertices

func (self Instance) Vertices() []Vector2.XY

func (Instance) Virtual

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

type ParsedGeometryType

type ParsedGeometryType int //gd:NavigationPolygon.ParsedGeometryType
const (
	// Parses mesh instances as obstruction geometry. This includes [Polygon2D], [MeshInstance2D], [MultiMeshInstance2D], and [TileMap] nodes.
	//
	// Meshes are only parsed when they use a 2D vertices surface format.
	//
	// [MeshInstance2D]: https://pkg.go.dev/graphics.gd/classdb/MeshInstance2D
	// [MultiMeshInstance2D]: https://pkg.go.dev/graphics.gd/classdb/MultiMeshInstance2D
	// [Polygon2D]: https://pkg.go.dev/graphics.gd/classdb/Polygon2D
	// [TileMap]: https://pkg.go.dev/graphics.gd/classdb/TileMap
	ParsedGeometryMeshInstances ParsedGeometryType = 0
	// Parses [StaticBody2D] and [TileMap] colliders as obstruction geometry. The collider should be in any of the layers specified by [ParsedCollisionMask].
	//
	// [ParsedCollisionMask]: https://pkg.go.dev/graphics.gd/classdb/#Instance.ParsedCollisionMask
	// [StaticBody2D]: https://pkg.go.dev/graphics.gd/classdb/StaticBody2D
	// [TileMap]: https://pkg.go.dev/graphics.gd/classdb/TileMap
	ParsedGeometryStaticColliders ParsedGeometryType = 1
	// Both [ParsedGeometryMeshInstances] and [ParsedGeometryStaticColliders].
	ParsedGeometryBoth ParsedGeometryType = 2
	// Represents the size of the [ParsedGeometryType] enum.
	ParsedGeometryMax ParsedGeometryType = 3
)

type SamplePartitionType

type SamplePartitionType int //gd:NavigationPolygon.SamplePartitionType
const (
	// Convex partitioning that yields navigation mesh with convex polygons.
	SamplePartitionConvexPartition SamplePartitionType = 0
	// Triangulation partitioning that yields navigation mesh with triangle polygons.
	SamplePartitionTriangulate SamplePartitionType = 1
	// Represents the size of the [SamplePartitionType] enum.
	SamplePartitionMax SamplePartitionType = 2
)

type SourceGeometryMode

type SourceGeometryMode int //gd:NavigationPolygon.SourceGeometryMode
const (
	// Scans the child nodes of the root node recursively for geometry.
	SourceGeometryRootNodeChildren SourceGeometryMode = 0
	// Scans nodes in a group and their child nodes recursively for geometry. The group is specified by [SourceGeometryGroupName].
	//
	// [SourceGeometryGroupName]: https://pkg.go.dev/graphics.gd/classdb/#Instance.SourceGeometryGroupName
	SourceGeometryGroupsWithChildren SourceGeometryMode = 1
	// Uses nodes in a group for geometry. The group is specified by [SourceGeometryGroupName].
	//
	// [SourceGeometryGroupName]: https://pkg.go.dev/graphics.gd/classdb/#Instance.SourceGeometryGroupName
	SourceGeometryGroupsExplicit SourceGeometryMode = 2
	// Represents the size of the [SourceGeometryMode] enum.
	SourceGeometryMax SourceGeometryMode = 3
)

Jump to

Keyboard shortcuts

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