| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/os/rw_lock.h" |
| 34 |
#include "scene/resources/mesh.h" |
| 35 |
#include "servers/navigation_3d/navigation_constants_3d.h" |
| 36 |
|
| 37 |
class NavigationMesh : public Resource { |
| 38 |
GDCLASS(NavigationMesh, Resource); |
| 39 |
RWLock rwlock; |
| 40 |
|
| 41 |
Vector<Vector3> vertices; |
| 42 |
Vector<Vector<int>> polygons; |
| 43 |
Ref<ArrayMesh> debug_mesh; |
| 44 |
|
| 45 |
protected: |
| 46 |
static void _bind_methods(); |
| 47 |
void _validate_property(PropertyInfo &p_property) const; |
| 48 |
|
| 49 |
#ifndef DISABLE_DEPRECATED |
| 50 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 51 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 52 |
#endif |
| 53 |
|
| 54 |
void _set_polygons(const Array &p_array); |
| 55 |
Array _get_polygons() const; |
| 56 |
|
| 57 |
public: |
| 58 |
enum SamplePartitionType { |
| 59 |
SAMPLE_PARTITION_WATERSHED = 0, |
| 60 |
SAMPLE_PARTITION_MONOTONE, |
| 61 |
SAMPLE_PARTITION_LAYERS, |
| 62 |
SAMPLE_PARTITION_MAX |
| 63 |
}; |
| 64 |
|
| 65 |
enum ParsedGeometryType { |
| 66 |
PARSED_GEOMETRY_MESH_INSTANCES = 0, |
| 67 |
PARSED_GEOMETRY_STATIC_COLLIDERS, |
| 68 |
PARSED_GEOMETRY_BOTH, |
| 69 |
PARSED_GEOMETRY_MAX |
| 70 |
}; |
| 71 |
|
| 72 |
enum SourceGeometryMode { |
| 73 |
SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0, |
| 74 |
SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN, |
| 75 |
SOURCE_GEOMETRY_GROUPS_EXPLICIT, |
| 76 |
SOURCE_GEOMETRY_MAX |
| 77 |
}; |
| 78 |
|
| 79 |
protected: |
| 80 |
float cell_size = NavigationDefaults3D::NAV_MESH_CELL_SIZE; |
| 81 |
float cell_height = NavigationDefaults3D::NAV_MESH_CELL_HEIGHT; |
| 82 |
float border_size = 0.0f; |
| 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_BOTH; |
| 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 |
|
| 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(const 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_border_size(float p_value); |
| 135 |
float get_border_size() const; |
| 136 |
|
| 137 |
void set_agent_height(float p_value); |
| 138 |
float get_agent_height() const; |
| 139 |
|
| 140 |
void set_agent_radius(float p_value); |
| 141 |
float get_agent_radius(); |
| 142 |
|
| 143 |
void set_agent_max_climb(float p_value); |
| 144 |
float get_agent_max_climb() const; |
| 145 |
|
| 146 |
void set_agent_max_slope(float p_value); |
| 147 |
float get_agent_max_slope() const; |
| 148 |
|
| 149 |
void set_region_min_size(float p_value); |
| 150 |
float get_region_min_size() const; |
| 151 |
|
| 152 |
void set_region_merge_size(float p_value); |
| 153 |
float get_region_merge_size() const; |
| 154 |
|
| 155 |
void set_edge_max_length(float p_value); |
| 156 |
float get_edge_max_length() const; |
| 157 |
|
| 158 |
void set_edge_max_error(float p_value); |
| 159 |
float get_edge_max_error() const; |
| 160 |
|
| 161 |
void set_vertices_per_polygon(float p_value); |
| 162 |
float get_vertices_per_polygon() const; |
| 163 |
|
| 164 |
void set_detail_sample_distance(float p_value); |
| 165 |
float get_detail_sample_distance() const; |
| 166 |
|
| 167 |
void set_detail_sample_max_error(float p_value); |
| 168 |
float get_detail_sample_max_error() const; |
| 169 |
|
| 170 |
void set_filter_low_hanging_obstacles(bool p_value); |
| 171 |
bool get_filter_low_hanging_obstacles() const; |
| 172 |
|
| 173 |
void set_filter_ledge_spans(bool p_value); |
| 174 |
bool get_filter_ledge_spans() const; |
| 175 |
|
| 176 |
void set_filter_walkable_low_height_spans(bool p_value); |
| 177 |
bool get_filter_walkable_low_height_spans() const; |
| 178 |
|
| 179 |
void set_filter_baking_aabb(const AABB &p_aabb); |
| 180 |
AABB get_filter_baking_aabb() const; |
| 181 |
|
| 182 |
void set_filter_baking_aabb_offset(const Vector3 &p_aabb_offset); |
| 183 |
Vector3 get_filter_baking_aabb_offset() const; |
| 184 |
|
| 185 |
void create_from_mesh(const Ref<Mesh> &p_mesh); |
| 186 |
|
| 187 |
void set_vertices(const Vector<Vector3> &p_vertices); |
| 188 |
Vector<Vector3> get_vertices() const; |
| 189 |
|
| 190 |
void add_polygon(const Vector<int> &p_polygon); |
| 191 |
int get_polygon_count() const; |
| 192 |
Vector<int> get_polygon(int p_idx); |
| 193 |
void clear_polygons(); |
| 194 |
void set_polygons(const Vector<Vector<int>> &p_polygons); |
| 195 |
Vector<Vector<int>> get_polygons() const; |
| 196 |
|
| 197 |
void clear(); |
| 198 |
|
| 199 |
void set_data(const Vector<Vector3> &p_vertices, const Vector<Vector<int>> &p_polygons); |
| 200 |
void get_data(Vector<Vector3> &r_vertices, Vector<Vector<int>> &r_polygons); |
| 201 |
|
| 202 |
#ifdef DEBUG_ENABLED |
| 203 |
Ref<ArrayMesh> get_debug_mesh(); |
| 204 |
#endif |
| 205 |
}; |
| 206 |
|
| 207 |
VARIANT_ENUM_CAST(NavigationMesh::SamplePartitionType); |
| 208 |
VARIANT_ENUM_CAST(NavigationMesh::ParsedGeometryType); |
| 209 |
VARIANT_ENUM_CAST(NavigationMesh::SourceGeometryMode); |