navigation_mesh_source_geometry_data_3d.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**************************************************************************/
  2. /* navigation_mesh_source_geometry_data_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_MESH_SOURCE_GEOMETRY_DATA_3D_H
  31. #define NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H
  32. #include "core/os/rw_lock.h"
  33. #include "scene/resources/mesh.h"
  34. class NavigationMeshSourceGeometryData3D : public Resource {
  35. GDCLASS(NavigationMeshSourceGeometryData3D, Resource);
  36. RWLock geometry_rwlock;
  37. Vector<float> vertices;
  38. Vector<int> indices;
  39. AABB bounds;
  40. bool bounds_dirty = true;
  41. public:
  42. struct ProjectedObstruction;
  43. private:
  44. Vector<ProjectedObstruction> _projected_obstructions;
  45. protected:
  46. bool _set(const StringName &p_name, const Variant &p_value);
  47. bool _get(const StringName &p_name, Variant &r_ret) const;
  48. static void _bind_methods();
  49. private:
  50. void _add_vertex(const Vector3 &p_vec3);
  51. void _add_mesh(const Ref<Mesh> &p_mesh, const Transform3D &p_xform);
  52. void _add_mesh_array(const Array &p_array, const Transform3D &p_xform);
  53. void _add_faces(const PackedVector3Array &p_faces, const Transform3D &p_xform);
  54. public:
  55. struct ProjectedObstruction {
  56. static inline uint32_t VERSION = 1; // Increase when format changes so we can detect outdated formats and provide compatibility.
  57. Vector<float> vertices;
  58. float elevation = 0.0;
  59. float height = 0.0;
  60. bool carve = false;
  61. };
  62. // kept root node transform here on the geometry data
  63. // if we add this transform to all exposed functions we need to break comp on all functions later
  64. // when navmesh changes from global transform to relative to navregion
  65. // but if it stays here we can just remove it and change the internal functions only
  66. Transform3D root_node_transform;
  67. void set_vertices(const Vector<float> &p_vertices);
  68. const Vector<float> &get_vertices() const;
  69. void set_indices(const Vector<int> &p_indices);
  70. const Vector<int> &get_indices() const;
  71. void append_arrays(const Vector<float> &p_vertices, const Vector<int> &p_indices);
  72. bool has_data();
  73. void clear();
  74. void clear_projected_obstructions();
  75. void add_mesh(const Ref<Mesh> &p_mesh, const Transform3D &p_xform);
  76. void add_mesh_array(const Array &p_mesh_array, const Transform3D &p_xform);
  77. void add_faces(const PackedVector3Array &p_faces, const Transform3D &p_xform);
  78. void merge(const Ref<NavigationMeshSourceGeometryData3D> &p_other_geometry);
  79. void add_projected_obstruction(const Vector<Vector3> &p_vertices, float p_elevation, float p_height, bool p_carve);
  80. Vector<ProjectedObstruction> _get_projected_obstructions() const;
  81. void set_projected_obstructions(const Array &p_array);
  82. Array get_projected_obstructions() const;
  83. void set_data(const Vector<float> &p_vertices, const Vector<int> &p_indices, Vector<ProjectedObstruction> &p_projected_obstructions);
  84. void get_data(Vector<float> &r_vertices, Vector<int> &r_indices, Vector<ProjectedObstruction> &r_projected_obstructions);
  85. AABB get_bounds();
  86. NavigationMeshSourceGeometryData3D() {}
  87. ~NavigationMeshSourceGeometryData3D() { clear(); }
  88. };
  89. #endif // NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H