Class NavigationMeshGeneratorInstance
- Namespace
- Godot
- Assembly
- GodotSharp.dll
This class is responsible for creating and clearing 3D navigation meshes used as NavigationMesh resources inside NavigationRegion3D. The NavigationMeshGenerator has very limited to no use for 2D as the navigation mesh baking process expects 3D node types and 3D source geometry to parse.
The entire navigation mesh baking is best done in a separate thread as the voxelization, collision tests and mesh optimization steps involved are very performance and time hungry operations.
Navigation mesh baking happens in multiple steps and the result depends on 3D source geometry and properties of the NavigationMesh resource. In the first step, starting from a root node and depending on NavigationMesh properties all valid 3D source geometry nodes are collected from the SceneTree. Second, all collected nodes are parsed for their relevant 3D geometry data and a combined 3D mesh is build. Due to the many different types of parsable objects, from normal MeshInstance3Ds to CsgShape3Ds or various CollisionObject3Ds, some operations to collect geometry data can trigger RenderingServer and PhysicsServer3D synchronizations. Server synchronization can have a negative effect on baking time or framerate as it often involves Mutex locking for thread security. Many parsable objects and the continuous synchronization with other threaded Servers can increase the baking time significantly. On the other hand only a few but very large and complex objects will take some time to prepare for the Servers which can noticeably stall the next frame render. As a general rule the total number of parsable objects and their individual size and complexity should be balanced to avoid framerate issues or very long baking times. The combined mesh is then passed to the Recast Navigation Object to test the source geometry for walkable terrain suitable to NavigationMesh agent properties by creating a voxel world around the meshes bounding area.
The finalized navigation mesh is then returned and stored inside the NavigationMesh for use as a resource inside NavigationRegion3D nodes.
Note: Using meshes to not only define walkable surfaces but also obstruct navigation baking does not always work. The navigation baking has no concept of what is a geometry "inside" when dealing with mesh source geometry and this is intentional. Depending on current baking parameters, as soon as the obstructing mesh is large enough to fit a navigation mesh area inside, the baking will generate navigation mesh areas that are inside the obstructing source geometry mesh.
[Obsolete("This class is deprecated.")]
[GodotClassName("NavigationMeshGenerator")]
public class NavigationMeshGeneratorInstance : GodotObject, IDisposable
- Inheritance
-
NavigationMeshGeneratorInstance
- Implements
- Inherited Members
Methods
Bake(NavigationMesh, Node)
The bake function is deprecated due to core threading changes. To upgrade existing code, first create a NavigationMeshSourceGeometryData3D resource. Use this resource with ParseSourceGeometryData(NavigationMesh, NavigationMeshSourceGeometryData3D, Node, Callable) to parse the SceneTree for nodes that should contribute to the navigation mesh baking. The SceneTree parsing needs to happen on the main thread. After the parsing is finished use the resource with BakeFromSourceGeometryData(NavigationMesh, NavigationMeshSourceGeometryData3D, Callable) to bake a navigation mesh.
[Obsolete("This method is deprecated.")]
public void Bake(NavigationMesh navigationMesh, Node rootNode)
Parameters
navigationMesh
NavigationMeshrootNode
Node
BakeFromSourceGeometryData(NavigationMesh, NavigationMeshSourceGeometryData3D, Callable)
Bakes the provided navigationMesh
with the data from the provided sourceGeometryData
. After the process is finished the optional callback
will be called.
public void BakeFromSourceGeometryData(NavigationMesh navigationMesh, NavigationMeshSourceGeometryData3D sourceGeometryData, Callable callback = default)
Parameters
navigationMesh
NavigationMeshsourceGeometryData
NavigationMeshSourceGeometryData3Dcallback
Callable
Clear(NavigationMesh)
Removes all polygons and vertices from the provided navigationMesh
resource.
public void Clear(NavigationMesh navigationMesh)
Parameters
navigationMesh
NavigationMesh
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
ParseSourceGeometryData(NavigationMesh, NavigationMeshSourceGeometryData3D, Node, Callable)
Parses the SceneTree for source geometry according to the properties of navigationMesh
. Updates the provided sourceGeometryData
resource with the resulting data. The resource can then be used to bake a navigation mesh with BakeFromSourceGeometryData(NavigationMesh, NavigationMeshSourceGeometryData3D, Callable). After the process is finished the optional callback
will be called.
Note: This function needs to run on the main thread or with a deferred call as the SceneTree is not thread-safe.
Performance: While convenient, reading data arrays from Mesh resources can affect the frame rate negatively. The data needs to be received from the GPU, stalling the RenderingServer in the process. For performance prefer the use of e.g. collision shapes or creating the data arrays entirely in code.
public void ParseSourceGeometryData(NavigationMesh navigationMesh, NavigationMeshSourceGeometryData3D sourceGeometryData, Node rootNode, Callable callback = default)
Parameters
navigationMesh
NavigationMeshsourceGeometryData
NavigationMeshSourceGeometryData3DrootNode
Nodecallback
Callable