Debian Codegraph @

modules/navigation_3d/3d/nav_mesh_queries_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* nav_mesh_queries_3d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "../nav_utils_3d.h"
34
35 #include "core/templates/a_hash_map.h"
36
37 #include "servers/nav_heap.h"
38 #include "servers/navigation_3d/navigation_constants_3d.h"
39 #include "servers/navigation_3d/navigation_path_query_parameters_3d.h"
40 #include "servers/navigation_3d/navigation_path_query_result_3d.h"
41
42 using namespace NavigationDefaults3D;
43 using namespace NavigationEnums3D;
44
45 class NavMap3D;
46 struct NavMapIteration3D;
47
48 class NavMeshQueries3D {
49 public:
50 struct PathQuerySlot {
51 LocalVector<Nav3D::NavigationPoly> path_corridor;
52 Heap<Nav3D::NavigationPoly *, Nav3D::NavPolyTravelCostGreaterThan, Nav3D::NavPolyHeapIndexer> traversable_polys;
53 bool in_use = false;
54 uint32_t slot_index = 0;
55 AHashMap<const Nav3D::Polygon *, uint32_t> poly_to_id;
56 };
57
58 struct NavMeshPathQueryTask3D {
59 enum TaskStatus {
60 QUERY_STARTED,
61 QUERY_FINISHED,
62 QUERY_FAILED,
63 CALLBACK_DISPATCHED,
64 CALLBACK_FAILED,
65 };
66
67 // Parameters.
68 Vector3 start_position;
69 Vector3 target_position;
70 uint32_t navigation_layers;
71 BitField<PathMetadataFlags> metadata_flags = PathMetadataFlags::PATH_INCLUDE_ALL;
72 PathfindingAlgorithm pathfinding_algorithm = PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR;
73 PathPostProcessing path_postprocessing = PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL;
74 bool simplify_path = false;
75 real_t simplify_epsilon = 0.0;
76
77 bool exclude_regions = false;
78 bool include_regions = false;
79 LocalVector<RID> excluded_regions;
80 LocalVector<RID> included_regions;
81
82 float path_return_max_length = 0.0;
83 float path_return_max_radius = 0.0;
84 int path_search_max_polygons = NavigationDefaults3D::path_search_max_polygons;
85 float path_search_max_distance = 0.0;
86
87 // Path building.
88 Vector3 begin_position;
89 Vector3 end_position;
90 const Nav3D::Polygon *begin_polygon = nullptr;
91 const Nav3D::Polygon *end_polygon = nullptr;
92 uint32_t least_cost_id = 0;
93
94 // Map.
95 Vector3 map_up;
96 NavMap3D *map = nullptr;
97 PathQuerySlot *path_query_slot = nullptr;
98
99 // Path points.
100 LocalVector<Vector3> path_points;
101 LocalVector<int32_t> path_meta_point_types;
102 LocalVector<RID> path_meta_point_rids;
103 LocalVector<int64_t> path_meta_point_owners;
104 float path_length = 0.0;
105
106 Ref<NavigationPathQueryParameters3D> query_parameters;
107 Ref<NavigationPathQueryResult3D> query_result;
108 Callable callback;
109 NavMeshPathQueryTask3D::TaskStatus status = NavMeshPathQueryTask3D::TaskStatus::QUERY_STARTED;
110
111 void path_clear() {
112 path_points.clear();
113 path_meta_point_types.clear();
114 path_meta_point_rids.clear();
115 path_meta_point_owners.clear();
116 }
117
118 void path_reverse() {
119 path_points.reverse();
120 path_meta_point_types.reverse();
121 path_meta_point_rids.reverse();
122 path_meta_point_owners.reverse();
123 }
124 };
125
126 static bool emit_callback(const Callable &p_callback);
127
128 static Vector3 polygons_get_random_point(const LocalVector<Nav3D::Polygon> &p_polygons, uint32_t p_navigation_layers, bool p_uniformly);
129
130 static Vector3 polygons_get_closest_point_to_segment(const LocalVector<Nav3D::Polygon> &p_polygons, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision);
131 static Vector3 polygons_get_closest_point(const LocalVector<Nav3D::Polygon> &p_polygons, const Vector3 &p_point);
132 static Vector3 polygons_get_closest_point_normal(const LocalVector<Nav3D::Polygon> &p_polygons, const Vector3 &p_point);
133 static Nav3D::ClosestPointQueryResult polygons_get_closest_point_info(const LocalVector<Nav3D::Polygon> &p_polygons, const Vector3 &p_point);
134 static RID polygons_get_closest_point_owner(const LocalVector<Nav3D::Polygon> &p_polygons, const Vector3 &p_point);
135
136 static Vector3 map_iteration_get_closest_point_to_segment(const NavMapIteration3D &p_map_iteration, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision);
137 static Vector3 map_iteration_get_closest_point(const NavMapIteration3D &p_map_iteration, const Vector3 &p_point);
138 static Vector3 map_iteration_get_closest_point_normal(const NavMapIteration3D &p_map_iteration, const Vector3 &p_point);
139 static RID map_iteration_get_closest_point_owner(const NavMapIteration3D &p_map_iteration, const Vector3 &p_point);
140 static Nav3D::ClosestPointQueryResult map_iteration_get_closest_point_info(const NavMapIteration3D &p_map_iteration, const Vector3 &p_point);
141 static Vector3 map_iteration_get_random_point(const NavMapIteration3D &p_map_iteration, uint32_t p_navigation_layers, bool p_uniformly);
142
143 static void map_query_path(NavMap3D *map, const Ref<NavigationPathQueryParameters3D> &p_query_parameters, Ref<NavigationPathQueryResult3D> p_query_result, const Callable &p_callback);
144
145 static void query_task_map_iteration_get_path(NavMeshPathQueryTask3D &p_query_task, const NavMapIteration3D &p_map_iteration);
146 static void _query_task_push_back_point_with_metadata(NavMeshPathQueryTask3D &p_query_task, const Vector3 &p_point, const Nav3D::Polygon *p_point_polygon);
147 static void _query_task_find_start_end_positions(NavMeshPathQueryTask3D &p_query_task, const NavMapIteration3D &p_map_iteration);
148 static void _query_task_build_path_corridor(NavMeshPathQueryTask3D &p_query_task, const NavMapIteration3D &p_map_iteration);
149 static void _query_task_post_process_corridorfunnel(NavMeshPathQueryTask3D &p_query_task);
150 static void _query_task_post_process_edgecentered(NavMeshPathQueryTask3D &p_query_task);
151 static void _query_task_post_process_nopostprocessing(NavMeshPathQueryTask3D &p_query_task);
152 static void _query_task_clip_path(NavMeshPathQueryTask3D &p_query_task, const Nav3D::NavigationPoly *from_poly, const Vector3 &p_to_point, const Nav3D::NavigationPoly *p_to_poly);
153 static void _query_task_simplified_path_points(NavMeshPathQueryTask3D &p_query_task);
154 static bool _query_task_is_connection_owner_usable(const NavMeshPathQueryTask3D &p_query_task, const NavBaseIteration3D *p_owner);
155 static void _query_task_process_path_result_limits(NavMeshPathQueryTask3D &p_query_task);
156
157 static void _query_task_search_polygon_connections(NavMeshPathQueryTask3D &p_query_task, const Nav3D::Connection &p_connection, uint32_t p_least_cost_id, const Nav3D::NavigationPoly &p_least_cost_poly, real_t p_poly_enter_cost, const Vector3 &p_end_point);
158
159 static void simplify_path_segment(int p_start_inx, int p_end_inx, const LocalVector<Vector3> &p_points, real_t p_epsilon, LocalVector<uint32_t> &r_simplified_path_indices);
160 static LocalVector<uint32_t> get_simplified_path_indices(const LocalVector<Vector3> &p_path, real_t p_epsilon);
161
162 static float _calculate_path_length(const LocalVector<Vector3> &p_path, uint32_t p_start_index, uint32_t p_end_index);
163 };