navigation_obstacle_3d.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**************************************************************************/
  2. /* navigation_obstacle_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. #ifndef NAVIGATION_OBSTACLE_3D_H
  31. #define NAVIGATION_OBSTACLE_3D_H
  32. #include "scene/3d/node_3d.h"
  33. class NavigationMesh;
  34. class NavigationMeshSourceGeometryData3D;
  35. class NavigationObstacle3D : public Node3D {
  36. GDCLASS(NavigationObstacle3D, Node3D);
  37. RID obstacle;
  38. RID map_before_pause;
  39. RID map_override;
  40. RID map_current;
  41. real_t height = 1.0;
  42. real_t radius = 0.0;
  43. Vector<Vector3> vertices;
  44. bool vertices_are_clockwise = true;
  45. bool vertices_are_valid = true;
  46. bool avoidance_enabled = true;
  47. uint32_t avoidance_layers = 1;
  48. bool use_3d_avoidance = false;
  49. Vector3 velocity;
  50. Vector3 previous_velocity;
  51. bool velocity_submitted = false;
  52. bool affect_navigation_mesh = false;
  53. bool carve_navigation_mesh = false;
  54. #ifdef DEBUG_ENABLED
  55. RID fake_agent_radius_debug_instance_rid;
  56. RID fake_agent_radius_debug_mesh_rid;
  57. RID static_obstacle_debug_instance_rid;
  58. RID static_obstacle_debug_mesh_rid;
  59. private:
  60. void _update_debug();
  61. void _update_fake_agent_radius_debug();
  62. void _update_static_obstacle_debug();
  63. void _clear_debug();
  64. #endif // DEBUG_ENABLED
  65. protected:
  66. static void _bind_methods();
  67. void _notification(int p_what);
  68. public:
  69. NavigationObstacle3D();
  70. virtual ~NavigationObstacle3D();
  71. RID get_rid() const { return obstacle; }
  72. void set_avoidance_enabled(bool p_enabled);
  73. bool get_avoidance_enabled() const;
  74. void set_navigation_map(RID p_navigation_map);
  75. RID get_navigation_map() const;
  76. void set_radius(real_t p_radius);
  77. real_t get_radius() const { return radius; }
  78. void set_height(real_t p_height);
  79. real_t get_height() const { return height; }
  80. void set_vertices(const Vector<Vector3> &p_vertices);
  81. const Vector<Vector3> &get_vertices() const { return vertices; }
  82. bool are_vertices_clockwise() const { return vertices_are_clockwise; }
  83. bool are_vertices_valid() const { return vertices_are_valid; }
  84. void set_avoidance_layers(uint32_t p_layers);
  85. uint32_t get_avoidance_layers() const;
  86. void set_avoidance_layer_value(int p_layer_number, bool p_value);
  87. bool get_avoidance_layer_value(int p_layer_number) const;
  88. void set_use_3d_avoidance(bool p_use_3d_avoidance);
  89. bool get_use_3d_avoidance() const { return use_3d_avoidance; }
  90. void set_velocity(const Vector3 p_velocity);
  91. Vector3 get_velocity() const { return velocity; }
  92. void _avoidance_done(Vector3 p_new_velocity); // Dummy
  93. void set_affect_navigation_mesh(bool p_enabled);
  94. bool get_affect_navigation_mesh() const;
  95. void set_carve_navigation_mesh(bool p_enabled);
  96. bool get_carve_navigation_mesh() const;
  97. PackedStringArray get_configuration_warnings() const override;
  98. private:
  99. static Callable _navmesh_source_geometry_parsing_callback;
  100. static RID _navmesh_source_geometry_parser;
  101. public:
  102. static void navmesh_parse_init();
  103. static void navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, Node *p_node);
  104. private:
  105. void _update_map(RID p_map);
  106. void _update_position(const Vector3 p_position);
  107. void _update_transform();
  108. void _update_use_3d_avoidance(bool p_use_3d_avoidance);
  109. };
  110. #endif // NAVIGATION_OBSTACLE_3D_H