NavMeshSurfaceΒΆ
Inherited: Component
DescriptionΒΆ
A navigation surface collects collider geometry from a scene or an actor hierarchy and converts it into a navigation mesh. The resulting mesh can be built synchronously with build() or asynchronously with buildAsync().
The surface can also include NavMeshLink connections while building. Its agentType() and geometrySource() determine which navigation configuration and source geometry are used.
Public MethodsΒΆ
void |
addBoxColliderGeometry (BoxCollider * collider, Vector3Vector & outVertices, std::vector<int> & outIndices) |
void |
addCapsuleColliderGeometry (CapsuleCollider * collider, Vector3Vector & outVertices, std::vector<int> & outIndices) |
void |
addMeshColliderGeometry (MeshCollider * collider, Vector3Vector & outVertices, std::vector<int> & outIndices) |
void |
addSphereColliderGeometry (SphereCollider * collider, Vector3Vector & outVertices, std::vector<int> & outIndices) |
int |
agentType () const |
bool |
autoBuild () const |
bool |
build () |
std::future |
buildAsync () |
bool |
buildNavMeshData (const Vector3Vector & vertices, const std::vector<int> & indices) |
void |
clear () |
bool |
collectGeometry (Vector3Vector & outVertices, std::vector<int> & outIndices) |
void |
|
int |
geometrySource () const |
void |
loadUserData (const VariantMap & data) |
NavMesh * |
navMesh () const |
void |
|
VariantMap |
saveUserData () const |
void |
setAgentType (int type) |
void |
setAutoBuild (bool autoBuild) |
void |
setGeometrySource (int source) |
void |
setNavMesh (NavMesh * navMesh) |
void |
setTileSize (int tileSize) |
int |
tileSize () const |
Public EnumsΒΆ
enum NavMeshSurface::GeometrySource
Defines where the surface collects collider geometry from.
Constant |
Value |
Description |
NavMeshSurface::AllColliders |
0 |
Collects enabled colliders from the scene. |
NavMeshSurface::CollidersInHierarchy |
1 |
Collects enabled colliders in the actor hierarchy. |
Static MethodsΒΆ
None
Methods DescriptionΒΆ
NavMeshSurface::NavMeshSurface ()
Constructs a navigation surface with automatic building disabled.
NavMeshSurface::~NavMeshSurface ()
Destroys the navigation surface and releases its navigation mesh resource.
void NavMeshSurface::addBoxColliderGeometry (BoxCollider * collider, Vector3Vector & outVertices, std::vector & outIndices)
Appends box collider geometry to the build buffers.
The collider geometry is converted into vertices appended to outVertices and triangle indices appended to outIndices.
void NavMeshSurface::addCapsuleColliderGeometry (CapsuleCollider * collider, Vector3Vector & outVertices, std::vector & outIndices)
Appends capsule collider geometry to the build buffers.
The collider geometry would be appended to outVertices and outIndices.
Note: Capsule geometry is not implemented yet.
void NavMeshSurface::addMeshColliderGeometry (MeshCollider * collider, Vector3Vector & outVertices, std::vector & outIndices)
Appends mesh collider geometry to the build buffers.
The collider geometry is converted into vertices appended to outVertices and triangle indices appended to outIndices.
void NavMeshSurface::addSphereColliderGeometry (SphereCollider * collider, Vector3Vector & outVertices, std::vector & outIndices)
Appends sphere collider geometry to the build buffers.
The collider geometry would be appended to outVertices and outIndices.
Note: Sphere geometry is not implemented yet.
int NavMeshSurface::agentType () const
Returns the navigation mesh agent type used to build the surface.
See also setAgentType().
bool NavMeshSurface::autoBuild () const
Returns whether the surface rebuilds its navigation mesh automatically after a build-related setting changes.
See also setAutoBuild().
bool NavMeshSurface::build ()
Builds the navigation mesh from the configured collider geometry.
Returns true when the resulting navigation mesh is ready; otherwise returns false.
See also buildAsync() and clear().
std::future NavMeshSurface::buildAsync ()
Starts building the navigation mesh on an asynchronous task.
Returns a future that contains the same success state as build().
See also build().
bool NavMeshSurface::buildNavMeshData (Vector3Vector & vertices, std::vector & indices)
Converts collected geometry and off-mesh links into navigation mesh data.
The vertices buffer contains world-space positions, and indices contains triangle indices referring to those positions.
Returns true when the navigation mesh data is generated successfully.
void NavMeshSurface::clear ()
Unregisters and releases the navigation mesh generated by the surface.
bool NavMeshSurface::collectGeometry (Vector3Vector & outVertices, std::vector & outIndices)
Collects collider geometry according to geometrySource().
Collected vertex positions are appended to outVertices, while outIndices receives triangle indices referring to those vertices.
Returns true when at least one vertex and one triangle index are collected.
void NavMeshSurface::drawGizmosSelected ()
Reimplements: Component::drawGizmosSelected().
Draws the generated navigation mesh when the surface is selected.
int NavMeshSurface::geometrySource () const
Returns the source used to collect collider geometry.
See also setGeometrySource().
void NavMeshSurface::loadUserData (VariantMap & data)
Reimplements: Object::loadUserData(const VariantMap &data).
Loads the navigation mesh resource reference stored in user data.
NavMesh * NavMeshSurface::navMesh () const
Returns the navigation mesh resource generated by this surface.
See also setNavMesh().
void NavMeshSurface::onNavMeshChanged ()
Registers the current navigation mesh in NavigationSystem when it is ready.
VariantMap NavMeshSurface::saveUserData () const
Reimplements: Object::saveUserData() const.
Saves the navigation mesh resource reference to user data.
void NavMeshSurface::setAgentType (int type)
Sets the navigation mesh agent type used to build the surface.
The type value selects the agent configuration to use. When automatic building is enabled, a changed value starts a new build.
See also agentType().
void NavMeshSurface::setAutoBuild (bool autoBuild)
Enables or disables automatic rebuilding of the navigation mesh.
Setting autoBuild to true immediately starts a synchronous build.
See also autoBuild().
void NavMeshSurface::setGeometrySource (int source)
Sets the source used to collect collider geometry.
The source value selects the collider scope. When automatic building is enabled, a changed value starts a new build.
See also geometrySource().
void NavMeshSurface::setNavMesh (NavMesh * navMesh)
Assigns the navigation mesh resource owned by the surface.
The navMesh value is the resource to assign, or nullptr to clear the current resource.
See also navMesh().
void NavMeshSurface::setTileSize (int tileSize)
Sets the tile size used when building the navigation mesh.
The tileSize value is the number of cells along one navigation mesh tile edge. Non-positive values are ignored, and a valid changed value starts a new build when automatic building is enabled.
See also tileSize().
int NavMeshSurface::tileSize () const
Returns the tile size used when building the navigation mesh.
See also setTileSize().