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 ¶
- type Advanced
- type Any
- type Extension
- type ID
- type Instance
- func (self Instance) AddOutline(outline []Vector2.XY)
- func (self Instance) AddOutlineAtIndex(outline []Vector2.XY, index int)
- func (self Instance) AddPolygon(polygon []int32)
- func (self Instance) AgentRadius() Float.X
- func (self Instance) AsNavigationPolygon() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResource() Resource.Instance
- func (self Instance) BakingRect() Rect2.PositionSize
- func (self Instance) BakingRectOffset() Vector2.XY
- func (self Instance) BorderSize() Float.X
- func (self Instance) CellSize() Float.X
- func (self Instance) Clear()
- func (self Instance) ClearOutlines()
- func (self Instance) ClearPolygons()
- func (self Instance) GetNavigationMesh() NavigationMesh.Instance
- func (self Instance) GetOutline(idx int) []Vector2.XY
- func (self Instance) GetOutlineCount() int
- func (self Instance) GetParsedCollisionMaskValue(layer_number int) bool
- func (self Instance) GetPolygon(idx int) []int32
- func (self Instance) GetPolygonCount() int
- func (self Instance) ID() ID
- func (self Instance) MakePolygonsFromOutlines()
- func (self Instance) ParsedCollisionMask() int
- func (self Instance) ParsedGeometryType() ParsedGeometryType
- func (self Instance) RemoveOutline(idx int)
- func (self Instance) SamplePartitionType() SamplePartitionType
- func (self Instance) SetAgentRadius(value Float.X)
- func (self Instance) SetBakingRect(value Rect2.PositionSize)
- func (self Instance) SetBakingRectOffset(value Vector2.XY)
- func (self Instance) SetBorderSize(value Float.X)
- func (self Instance) SetCellSize(value Float.X)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetOutline(idx int, outline []Vector2.XY)
- func (self Instance) SetParsedCollisionMask(value int)
- func (self Instance) SetParsedCollisionMaskValue(layer_number int, value bool)
- func (self Instance) SetParsedGeometryType(value ParsedGeometryType)
- func (self Instance) SetSamplePartitionType(value SamplePartitionType)
- func (self Instance) SetSourceGeometryGroupName(value string)
- func (self Instance) SetSourceGeometryMode(value SourceGeometryMode)
- func (self Instance) SetVertices(value []Vector2.XY)
- func (self Instance) SourceGeometryGroupName() string
- func (self Instance) SourceGeometryMode() SourceGeometryMode
- func (self Instance) Vertices() []Vector2.XY
- func (self Instance) Virtual(name string) reflect.Value
- type ParsedGeometryType
- type SamplePartitionType
- type SourceGeometryMode
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 Extension ¶
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 (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsResource ¶
type 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.
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 (Instance) AddOutline ¶
Appends a []Vector2.XY that contains the vertices of an outline to the internal array that contains all the outlines.
func (Instance) AddOutlineAtIndex ¶
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 ¶
Adds a polygon using the indices of the vertices you get when calling GetVertices.
func (Instance) AgentRadius ¶
func (Instance) AsNavigationPolygon ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResource ¶
func (Instance) BakingRect ¶
func (self Instance) BakingRect() Rect2.PositionSize
func (Instance) BakingRectOffset ¶
func (Instance) BorderSize ¶
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 ¶
Returns a []Vector2.XY containing the vertices of an outline that was created in the editor or by script.
func (Instance) GetOutlineCount ¶
Returns the number of outlines that were created in the editor or by script.
func (Instance) GetParsedCollisionMaskValue ¶
Returns whether or not the specified layer of the ParsedCollisionMask is enabled, given a 'layer_number' between 1 and 32.
func (Instance) GetPolygon ¶
Returns a []int32 containing the indices of the vertices of a created polygon.
func (Instance) GetPolygonCount ¶
Returns the count of all polygons.
func (Instance) MakePolygonsFromOutlines ¶
func (self Instance) MakePolygonsFromOutlines()
Creates polygons from the outlines added in the editor or by script.
func (Instance) ParsedCollisionMask ¶
func (Instance) ParsedGeometryType ¶
func (self Instance) ParsedGeometryType() ParsedGeometryType
func (Instance) RemoveOutline ¶
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 (Instance) SetBakingRect ¶
func (self Instance) SetBakingRect(value Rect2.PositionSize)
func (Instance) SetBakingRectOffset ¶
func (Instance) SetBorderSize ¶
func (Instance) SetCellSize ¶
func (Instance) SetOutline ¶
Changes an outline created in the editor or by script. You have to call MakePolygonsFromOutlines for the polygons to update.
func (Instance) SetParsedCollisionMask ¶
func (Instance) SetParsedCollisionMaskValue ¶
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 (Instance) SetSourceGeometryMode ¶
func (self Instance) SetSourceGeometryMode(value SourceGeometryMode)
func (Instance) SetVertices ¶
func (Instance) SourceGeometryGroupName ¶
func (Instance) SourceGeometryMode ¶
func (self Instance) SourceGeometryMode() SourceGeometryMode
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 )