navigation_mesh.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*************************************************************************/
  2. /* navigation_mesh.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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_MESH_H
  31. #define NAVIGATION_MESH_H
  32. #include "scene/3d/spatial.h"
  33. #include "scene/resources/mesh.h"
  34. class Mesh;
  35. class NavigationMesh : public Resource {
  36. OBJ_TYPE(NavigationMesh, Resource);
  37. DVector<Vector3> vertices;
  38. struct Polygon {
  39. Vector<int> indices;
  40. };
  41. Vector<Polygon> polygons;
  42. Ref<Mesh> debug_mesh;
  43. struct _EdgeKey {
  44. Vector3 from;
  45. Vector3 to;
  46. bool operator<(const _EdgeKey &p_with) const { return from == p_with.from ? to < p_with.to : from < p_with.from; }
  47. };
  48. protected:
  49. static void _bind_methods();
  50. void _set_polygons(const Array &p_array);
  51. Array _get_polygons() const;
  52. public:
  53. void create_from_mesh(const Ref<Mesh> &p_mesh);
  54. void set_vertices(const DVector<Vector3> &p_vertices);
  55. DVector<Vector3> get_vertices() const;
  56. void add_polygon(const Vector<int> &p_polygon);
  57. int get_polygon_count() const;
  58. Vector<int> get_polygon(int p_idx);
  59. void clear_polygons();
  60. Ref<Mesh> get_debug_mesh();
  61. NavigationMesh();
  62. };
  63. class Navigation;
  64. class NavigationMeshInstance : public Spatial {
  65. OBJ_TYPE(NavigationMeshInstance, Spatial);
  66. bool enabled;
  67. int nav_id;
  68. Navigation *navigation;
  69. Ref<NavigationMesh> navmesh;
  70. Node *debug_view;
  71. protected:
  72. void _notification(int p_what);
  73. static void _bind_methods();
  74. public:
  75. void set_enabled(bool p_enabled);
  76. bool is_enabled() const;
  77. void set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh);
  78. Ref<NavigationMesh> get_navigation_mesh() const;
  79. String get_configuration_warning() const;
  80. NavigationMeshInstance();
  81. };
  82. #endif // NAVIGATION_MESH_H