navigation_path_query_parameters_3d.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**************************************************************************/
  2. /* navigation_path_query_parameters_3d.cpp */
  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. #include "navigation_path_query_parameters_3d.h"
  31. void NavigationPathQueryParameters3D::set_pathfinding_algorithm(const NavigationPathQueryParameters3D::PathfindingAlgorithm p_pathfinding_algorithm) {
  32. switch (p_pathfinding_algorithm) {
  33. case PATHFINDING_ALGORITHM_ASTAR: {
  34. parameters.pathfinding_algorithm = NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR;
  35. } break;
  36. default: {
  37. WARN_PRINT_ONCE("No match for used PathfindingAlgorithm - fallback to default");
  38. parameters.pathfinding_algorithm = NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR;
  39. } break;
  40. }
  41. }
  42. NavigationPathQueryParameters3D::PathfindingAlgorithm NavigationPathQueryParameters3D::get_pathfinding_algorithm() const {
  43. switch (parameters.pathfinding_algorithm) {
  44. case NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR:
  45. return PATHFINDING_ALGORITHM_ASTAR;
  46. default:
  47. WARN_PRINT_ONCE("No match for used PathfindingAlgorithm - fallback to default");
  48. return PATHFINDING_ALGORITHM_ASTAR;
  49. }
  50. }
  51. void NavigationPathQueryParameters3D::set_path_postprocessing(const NavigationPathQueryParameters3D::PathPostProcessing p_path_postprocessing) {
  52. switch (p_path_postprocessing) {
  53. case PATH_POSTPROCESSING_CORRIDORFUNNEL: {
  54. parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL;
  55. } break;
  56. case PATH_POSTPROCESSING_EDGECENTERED: {
  57. parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED;
  58. } break;
  59. default: {
  60. WARN_PRINT_ONCE("No match for used PathPostProcessing - fallback to default");
  61. parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL;
  62. } break;
  63. }
  64. }
  65. NavigationPathQueryParameters3D::PathPostProcessing NavigationPathQueryParameters3D::get_path_postprocessing() const {
  66. switch (parameters.path_postprocessing) {
  67. case NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL:
  68. return PATH_POSTPROCESSING_CORRIDORFUNNEL;
  69. case NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED:
  70. return PATH_POSTPROCESSING_EDGECENTERED;
  71. default:
  72. WARN_PRINT_ONCE("No match for used PathPostProcessing - fallback to default");
  73. return PATH_POSTPROCESSING_CORRIDORFUNNEL;
  74. }
  75. }
  76. void NavigationPathQueryParameters3D::set_map(const RID &p_map) {
  77. parameters.map = p_map;
  78. }
  79. const RID &NavigationPathQueryParameters3D::get_map() const {
  80. return parameters.map;
  81. }
  82. void NavigationPathQueryParameters3D::set_start_position(const Vector3 &p_start_position) {
  83. parameters.start_position = p_start_position;
  84. }
  85. const Vector3 &NavigationPathQueryParameters3D::get_start_position() const {
  86. return parameters.start_position;
  87. }
  88. void NavigationPathQueryParameters3D::set_target_position(const Vector3 &p_target_position) {
  89. parameters.target_position = p_target_position;
  90. }
  91. const Vector3 &NavigationPathQueryParameters3D::get_target_position() const {
  92. return parameters.target_position;
  93. }
  94. void NavigationPathQueryParameters3D::set_navigation_layers(uint32_t p_navigation_layers) {
  95. parameters.navigation_layers = p_navigation_layers;
  96. }
  97. uint32_t NavigationPathQueryParameters3D::get_navigation_layers() const {
  98. return parameters.navigation_layers;
  99. }
  100. void NavigationPathQueryParameters3D::set_metadata_flags(BitField<NavigationPathQueryParameters3D::PathMetadataFlags> p_flags) {
  101. parameters.metadata_flags = (int64_t)p_flags;
  102. }
  103. BitField<NavigationPathQueryParameters3D::PathMetadataFlags> NavigationPathQueryParameters3D::get_metadata_flags() const {
  104. return (int64_t)parameters.metadata_flags;
  105. }
  106. void NavigationPathQueryParameters3D::set_simplify_path(bool p_enabled) {
  107. parameters.simplify_path = p_enabled;
  108. }
  109. bool NavigationPathQueryParameters3D::get_simplify_path() const {
  110. return parameters.simplify_path;
  111. }
  112. void NavigationPathQueryParameters3D::set_simplify_epsilon(real_t p_epsilon) {
  113. parameters.simplify_epsilon = MAX(0.0, p_epsilon);
  114. }
  115. real_t NavigationPathQueryParameters3D::get_simplify_epsilon() const {
  116. return parameters.simplify_epsilon;
  117. }
  118. void NavigationPathQueryParameters3D::_bind_methods() {
  119. ClassDB::bind_method(D_METHOD("set_pathfinding_algorithm", "pathfinding_algorithm"), &NavigationPathQueryParameters3D::set_pathfinding_algorithm);
  120. ClassDB::bind_method(D_METHOD("get_pathfinding_algorithm"), &NavigationPathQueryParameters3D::get_pathfinding_algorithm);
  121. ClassDB::bind_method(D_METHOD("set_path_postprocessing", "path_postprocessing"), &NavigationPathQueryParameters3D::set_path_postprocessing);
  122. ClassDB::bind_method(D_METHOD("get_path_postprocessing"), &NavigationPathQueryParameters3D::get_path_postprocessing);
  123. ClassDB::bind_method(D_METHOD("set_map", "map"), &NavigationPathQueryParameters3D::set_map);
  124. ClassDB::bind_method(D_METHOD("get_map"), &NavigationPathQueryParameters3D::get_map);
  125. ClassDB::bind_method(D_METHOD("set_start_position", "start_position"), &NavigationPathQueryParameters3D::set_start_position);
  126. ClassDB::bind_method(D_METHOD("get_start_position"), &NavigationPathQueryParameters3D::get_start_position);
  127. ClassDB::bind_method(D_METHOD("set_target_position", "target_position"), &NavigationPathQueryParameters3D::set_target_position);
  128. ClassDB::bind_method(D_METHOD("get_target_position"), &NavigationPathQueryParameters3D::get_target_position);
  129. ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationPathQueryParameters3D::set_navigation_layers);
  130. ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationPathQueryParameters3D::get_navigation_layers);
  131. ClassDB::bind_method(D_METHOD("set_metadata_flags", "flags"), &NavigationPathQueryParameters3D::set_metadata_flags);
  132. ClassDB::bind_method(D_METHOD("get_metadata_flags"), &NavigationPathQueryParameters3D::get_metadata_flags);
  133. ClassDB::bind_method(D_METHOD("set_simplify_path", "enabled"), &NavigationPathQueryParameters3D::set_simplify_path);
  134. ClassDB::bind_method(D_METHOD("get_simplify_path"), &NavigationPathQueryParameters3D::get_simplify_path);
  135. ClassDB::bind_method(D_METHOD("set_simplify_epsilon", "epsilon"), &NavigationPathQueryParameters3D::set_simplify_epsilon);
  136. ClassDB::bind_method(D_METHOD("get_simplify_epsilon"), &NavigationPathQueryParameters3D::get_simplify_epsilon);
  137. ADD_PROPERTY(PropertyInfo(Variant::RID, "map"), "set_map", "get_map");
  138. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "start_position"), "set_start_position", "get_start_position");
  139. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "target_position"), "set_target_position", "get_target_position");
  140. ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_3D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");
  141. ADD_PROPERTY(PropertyInfo(Variant::INT, "pathfinding_algorithm", PROPERTY_HINT_ENUM, "AStar"), "set_pathfinding_algorithm", "get_pathfinding_algorithm");
  142. ADD_PROPERTY(PropertyInfo(Variant::INT, "path_postprocessing", PROPERTY_HINT_ENUM, "Corridorfunnel,Edgecentered"), "set_path_postprocessing", "get_path_postprocessing");
  143. ADD_PROPERTY(PropertyInfo(Variant::INT, "metadata_flags", PROPERTY_HINT_FLAGS, "Include Types,Include RIDs,Include Owners"), "set_metadata_flags", "get_metadata_flags");
  144. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "simplify_path"), "set_simplify_path", "get_simplify_path");
  145. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "simplify_epsilon"), "set_simplify_epsilon", "get_simplify_epsilon");
  146. BIND_ENUM_CONSTANT(PATHFINDING_ALGORITHM_ASTAR);
  147. BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_CORRIDORFUNNEL);
  148. BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_EDGECENTERED);
  149. BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_NONE);
  150. BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_TYPES);
  151. BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_RIDS);
  152. BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_OWNERS);
  153. BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_ALL);
  154. }