![]() |
ezEngine Release 26.9
|
#include <VoxelNavigation.h>
Public Types | |
| enum class | State { Idle , PathFound , NoPathFound , InvalidStartPosition , InvalidTargetPosition } |
Public Member Functions | |
| State | FindPath (const ezVec3 &vStart, const ezVec3 &vTarget, const ezAiVoxelGridFinder &gridFinder, float fSearchMargin=5.0f, ezUInt32 uiMaxIterationsPerHop=10000, ezUInt32 uiMaxHops=16) |
| void | SetDirectPath (const ezVec3 &vStart, const ezVec3 &vTarget) |
| const ezDynamicArray< ezVec3 > & | GetWaypoints () const |
| const ezDynamicArray< bool > & | GetSegmentInsideGrid () const |
| ezUInt32 | GetCurrentWaypointIndex () const |
| bool | AdvanceWaypoint () |
| Advances to the next waypoint. Returns true if there are more waypoints. | |
| ezVec3 | GetNextWaypoint () const |
| Returns the next waypoint to move towards. | |
| bool | IsPathComplete () const |
| Returns true if the end of the path has been reached. | |
| ezVec3 | GetLookAheadPoint (const ezVec3 &vCurrentPos, float fLookAheadDistance) const |
| ezVec3 | AdvanceAlongPath (const ezVec3 &vCurrentPos, float fDistance) |
| void | CancelNavigation () |
| State | GetState () const |
| void | DebugDrawPath (const ezDebugRendererContext &context, const ezColor &color) const |
| Draws the path as a line strip. | |
| void | DebugDrawPathSegments (const ezDebugRendererContext &context, const ezColor &insideGridColor, const ezColor &freeSpaceColor) const |
A* pathfinding through one or more ezVoxelGrid instances.
Uses 6-connected (face) neighbors only - no diagonal moves. Diagonal movement would let a path cut across a corner between two solid voxels that only touch edge-to-edge or corner-to-corner, squeezing through a gap that isn't actually open. After finding a raw voxel path, applies line-of-sight string-pulling to remove unnecessary waypoints.
A single search may span multiple, disjoint voxel grids: pathfinding is always performed within one grid at a time. If the target lies outside the grid that is currently being searched, the search only looks for a way out of that grid (any reachable voxel on its boundary), then continues from there in the next grid found on the way to the target. Space that is not covered by any grid is assumed to be free (no obstacles).
Advances a position by fDistance along the remaining path polyline, starting from vCurrentPos (which does not need to lie exactly on the path). Unlike GetLookAheadPoint(), this consumes (advances past) any waypoints crossed along the way, i.e. GetCurrentWaypointIndex() moves forward as a side effect. Returns the resulting point, clamped at the final waypoint once the path end is reached, or vCurrentPos itself if the path is already complete.
| void ezAiVoxelNavigation::DebugDrawPathSegments | ( | const ezDebugRendererContext & | context, |
| const ezColor & | insideGridColor, | ||
| const ezColor & | freeSpaceColor | ||
| ) | const |
Draws the path, coloring each segment by whether it runs inside a voxel grid or crosses free space in a straight line.
| ezAiVoxelNavigation::State ezAiVoxelNavigation::FindPath | ( | const ezVec3 & | vStart, |
| const ezVec3 & | vTarget, | ||
| const ezAiVoxelGridFinder & | gridFinder, | ||
| float | fSearchMargin = 5.0f, |
||
| ezUInt32 | uiMaxIterationsPerHop = 10000, |
||
| ezUInt32 | uiMaxHops = 16 |
||
| ) |
Computes a path from vStart to vTarget, potentially through multiple voxel grids.
gridFinder is called (potentially multiple times) to find the voxel grids relevant for the next hop of the search, given a search box around the current position and vTarget. fSearchMargin is added around that box. uiMaxIterationsPerHop limits the A* node expansion within a single grid, to prevent frame stalls. uiMaxHops limits how many grids the path may pass through, as a safety net against infinite loops.
| ezVec3 ezAiVoxelNavigation::GetLookAheadPoint | ( | const ezVec3 & | vCurrentPos, |
| float | fLookAheadDistance | ||
| ) | const |
Walks the remaining path polyline starting from vCurrentPos (which does not need to lie exactly on the path), accumulating distance up to fLookAheadDistance. Returns the point at that distance along the path, or the final waypoint if the remaining path is shorter. Returns vCurrentPos itself if the path is already complete.
Pure query - does not affect GetCurrentWaypointIndex(). See AdvanceAlongPath() for the mutating equivalent.
|
inline |
One entry per segment of GetWaypoints() (GetWaypoints().GetCount() - 1 entries). True if the segment [i, i + 1] runs through a voxel grid, false if it is a straight line through free space.
Sets a trivial, single-segment path straight from vStart to vTarget, bypassing pathfinding and occlusion checks entirely. Useful for emergency recovery (e.g. moving out of a voxel that turned solid) or any other case where a straight line is known to be fine.