| 1 | /**************************************************************************/ |
| 2 | /* navigation_mesh.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 | #ifndef NAVIGATION_MESH_H |
| 32 | #define NAVIGATION_MESH_H |
| 33 | |
| 34 | #include "scene/resources/mesh.h" |
| 35 | |
| 36 | class NavigationMesh : public Resource { |
| 37 | GDCLASS(NavigationMesh, Resource); |
| 38 | |
| 39 | Vector<Vector3> vertices; |
| 40 | struct Polygon { |
| 41 | Vector<int> indices; |
| 42 | }; |
| 43 | Vector<Polygon> polygons; |
| 44 | Ref<ArrayMesh> debug_mesh; |
| 45 | |
| 46 | protected: |
| 47 | static void _bind_methods(); |
| 48 | void _validate_property(PropertyInfo &p_property) const; |
| 49 | |
| 50 | #ifndef DISABLE_DEPRECATED |
| 51 | bool _set(const StringName &p_name, const Variant &p_value); |
| 52 | bool _get(const StringName &p_name, Variant &r_ret) const; |
| 53 | #endif // DISABLE_DEPRECATED |
| 54 | |
| 55 | void _set_polygons(const Array &p_array); |
| 56 | Array _get_polygons() const; |
| 57 | |
| 58 | public: |
| 59 | enum SamplePartitionType { |
| 60 | SAMPLE_PARTITION_WATERSHED = 0, |
| 61 | SAMPLE_PARTITION_MONOTONE, |
| 62 | SAMPLE_PARTITION_LAYERS, |
| 63 | SAMPLE_PARTITION_MAX |
| 64 | }; |
| 65 | |
| 66 | enum ParsedGeometryType { |
| 67 | PARSED_GEOMETRY_MESH_INSTANCES = 0, |
| 68 | PARSED_GEOMETRY_STATIC_COLLIDERS, |
| 69 | PARSED_GEOMETRY_BOTH, |
| 70 | PARSED_GEOMETRY_MAX |
| 71 | }; |
| 72 | |
| 73 | enum SourceGeometryMode { |
| 74 | SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0, |
| 75 | SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN, |
| 76 | SOURCE_GEOMETRY_GROUPS_EXPLICIT, |
| 77 | SOURCE_GEOMETRY_MAX |
| 78 | }; |
| 79 | |
| 80 | protected: |
| 81 | float cell_size = 0.25f; // Must match ProjectSettings default 3D cell_size and NavigationServer NavMap cell_size. |
| 82 | float cell_height = 0.25f; // Must match ProjectSettings default 3D cell_height and NavigationServer NavMap cell_height. |
| 83 | float agent_height = 1.5f; |
| 84 | float agent_radius = 0.5f; |
| 85 | float agent_max_climb = 0.25f; |
| 86 | float agent_max_slope = 45.0f; |
| 87 | float region_min_size = 2.0f; |
| 88 | float region_merge_size = 20.0f; |
| 89 | float edge_max_length = 0.0f; |
| 90 | float edge_max_error = 1.3f; |
| 91 | float vertices_per_polygon = 6.0f; |
| 92 | float detail_sample_distance = 6.0f; |
| 93 | float detail_sample_max_error = 1.0f; |
| 94 | |
| 95 | SamplePartitionType partition_type = SAMPLE_PARTITION_WATERSHED; |
| 96 | ParsedGeometryType parsed_geometry_type = PARSED_GEOMETRY_MESH_INSTANCES; |
| 97 | uint32_t collision_mask = 0xFFFFFFFF; |
| 98 | |
| 99 | SourceGeometryMode source_geometry_mode = SOURCE_GEOMETRY_ROOT_NODE_CHILDREN; |
| 100 | StringName source_group_name = "navigation_mesh_source_group" ; |
| 101 | |
| 102 | bool filter_low_hanging_obstacles = false; |
| 103 | bool filter_ledge_spans = false; |
| 104 | bool filter_walkable_low_height_spans = false; |
| 105 | AABB filter_baking_aabb; |
| 106 | Vector3 filter_baking_aabb_offset; |
| 107 | |
| 108 | public: |
| 109 | // Recast settings |
| 110 | void set_sample_partition_type(SamplePartitionType p_value); |
| 111 | SamplePartitionType get_sample_partition_type() const; |
| 112 | |
| 113 | void set_parsed_geometry_type(ParsedGeometryType p_value); |
| 114 | ParsedGeometryType get_parsed_geometry_type() const; |
| 115 | |
| 116 | void set_collision_mask(uint32_t p_mask); |
| 117 | uint32_t get_collision_mask() const; |
| 118 | |
| 119 | void set_collision_mask_value(int p_layer_number, bool p_value); |
| 120 | bool get_collision_mask_value(int p_layer_number) const; |
| 121 | |
| 122 | void set_source_geometry_mode(SourceGeometryMode p_geometry_mode); |
| 123 | SourceGeometryMode get_source_geometry_mode() const; |
| 124 | |
| 125 | void set_source_group_name(StringName p_group_name); |
| 126 | StringName get_source_group_name() const; |
| 127 | |
| 128 | void set_cell_size(float p_value); |
| 129 | float get_cell_size() const; |
| 130 | |
| 131 | void set_cell_height(float p_value); |
| 132 | float get_cell_height() const; |
| 133 | |
| 134 | void set_agent_height(float p_value); |
| 135 | float get_agent_height() const; |
| 136 | |
| 137 | void set_agent_radius(float p_value); |
| 138 | float get_agent_radius(); |
| 139 | |
| 140 | void set_agent_max_climb(float p_value); |
| 141 | float get_agent_max_climb() const; |
| 142 | |
| 143 | void set_agent_max_slope(float p_value); |
| 144 | float get_agent_max_slope() const; |
| 145 | |
| 146 | void set_region_min_size(float p_value); |
| 147 | float get_region_min_size() const; |
| 148 | |
| 149 | void set_region_merge_size(float p_value); |
| 150 | float get_region_merge_size() const; |
| 151 | |
| 152 | void set_edge_max_length(float p_value); |
| 153 | float get_edge_max_length() const; |
| 154 | |
| 155 | void set_edge_max_error(float p_value); |
| 156 | float get_edge_max_error() const; |
| 157 | |
| 158 | void set_vertices_per_polygon(float p_value); |
| 159 | float get_vertices_per_polygon() const; |
| 160 | |
| 161 | void set_detail_sample_distance(float p_value); |
| 162 | float get_detail_sample_distance() const; |
| 163 | |
| 164 | void set_detail_sample_max_error(float p_value); |
| 165 | float get_detail_sample_max_error() const; |
| 166 | |
| 167 | void set_filter_low_hanging_obstacles(bool p_value); |
| 168 | bool get_filter_low_hanging_obstacles() const; |
| 169 | |
| 170 | void set_filter_ledge_spans(bool p_value); |
| 171 | bool get_filter_ledge_spans() const; |
| 172 | |
| 173 | void set_filter_walkable_low_height_spans(bool p_value); |
| 174 | bool get_filter_walkable_low_height_spans() const; |
| 175 | |
| 176 | void set_filter_baking_aabb(const AABB &p_aabb); |
| 177 | AABB get_filter_baking_aabb() const; |
| 178 | |
| 179 | void set_filter_baking_aabb_offset(const Vector3 &p_aabb_offset); |
| 180 | Vector3 get_filter_baking_aabb_offset() const; |
| 181 | |
| 182 | void create_from_mesh(const Ref<Mesh> &p_mesh); |
| 183 | |
| 184 | void set_vertices(const Vector<Vector3> &p_vertices); |
| 185 | Vector<Vector3> get_vertices() const; |
| 186 | |
| 187 | void add_polygon(const Vector<int> &p_polygon); |
| 188 | int get_polygon_count() const; |
| 189 | Vector<int> get_polygon(int p_idx); |
| 190 | void clear_polygons(); |
| 191 | |
| 192 | void clear(); |
| 193 | |
| 194 | #ifdef DEBUG_ENABLED |
| 195 | Ref<ArrayMesh> get_debug_mesh(); |
| 196 | #endif // DEBUG_ENABLED |
| 197 | |
| 198 | NavigationMesh(); |
| 199 | }; |
| 200 | |
| 201 | VARIANT_ENUM_CAST(NavigationMesh::SamplePartitionType); |
| 202 | VARIANT_ENUM_CAST(NavigationMesh::ParsedGeometryType); |
| 203 | VARIANT_ENUM_CAST(NavigationMesh::SourceGeometryMode); |
| 204 | |
| 205 | #endif // NAVIGATION_MESH_H |
| 206 | |