mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Fix cell_height for navigation meshes
Fixes `cell_height` for navigation meshes.
This commit is contained in:
@@ -166,6 +166,20 @@ real_t GodotNavigationServer::map_get_cell_size(RID p_map) const {
|
||||
return map->get_cell_size();
|
||||
}
|
||||
|
||||
COMMAND_2(map_set_cell_height, RID, p_map, real_t, p_cell_height) {
|
||||
NavMap *map = map_owner.get_or_null(p_map);
|
||||
ERR_FAIL_COND(map == nullptr);
|
||||
|
||||
map->set_cell_height(p_cell_height);
|
||||
}
|
||||
|
||||
real_t GodotNavigationServer::map_get_cell_height(RID p_map) const {
|
||||
const NavMap *map = map_owner.get_or_null(p_map);
|
||||
ERR_FAIL_COND_V(map == nullptr, 0);
|
||||
|
||||
return map->get_cell_height();
|
||||
}
|
||||
|
||||
COMMAND_2(map_set_use_edge_connections, RID, p_map, bool, p_enabled) {
|
||||
NavMap *map = map_owner.get_or_null(p_map);
|
||||
ERR_FAIL_COND(map == nullptr);
|
||||
|
||||
@@ -107,6 +107,9 @@ public:
|
||||
COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size);
|
||||
virtual real_t map_get_cell_size(RID p_map) const override;
|
||||
|
||||
COMMAND_2(map_set_cell_height, RID, p_map, real_t, p_cell_height);
|
||||
virtual real_t map_get_cell_height(RID p_map) const override;
|
||||
|
||||
COMMAND_2(map_set_use_edge_connections, RID, p_map, bool, p_enabled);
|
||||
virtual bool map_get_use_edge_connections(RID p_map) const override;
|
||||
|
||||
|
||||
@@ -69,6 +69,14 @@ void NavMap::set_cell_size(real_t p_cell_size) {
|
||||
regenerate_polygons = true;
|
||||
}
|
||||
|
||||
void NavMap::set_cell_height(real_t p_cell_height) {
|
||||
if (cell_height == p_cell_height) {
|
||||
return;
|
||||
}
|
||||
cell_height = p_cell_height;
|
||||
regenerate_polygons = true;
|
||||
}
|
||||
|
||||
void NavMap::set_use_edge_connections(bool p_enabled) {
|
||||
if (use_edge_connections == p_enabled) {
|
||||
return;
|
||||
@@ -94,9 +102,9 @@ void NavMap::set_link_connection_radius(real_t p_link_connection_radius) {
|
||||
}
|
||||
|
||||
gd::PointKey NavMap::get_point_key(const Vector3 &p_pos) const {
|
||||
const int x = int(Math::floor(p_pos.x / cell_size));
|
||||
const int y = int(Math::floor(p_pos.y / cell_size));
|
||||
const int z = int(Math::floor(p_pos.z / cell_size));
|
||||
const int x = static_cast<int>(Math::floor(p_pos.x / cell_size));
|
||||
const int y = static_cast<int>(Math::floor(p_pos.y / cell_height));
|
||||
const int z = static_cast<int>(Math::floor(p_pos.z / cell_size));
|
||||
|
||||
gd::PointKey p;
|
||||
p.key = 0;
|
||||
|
||||
@@ -54,8 +54,9 @@ class NavMap : public NavRid {
|
||||
Vector3 up = Vector3(0, 1, 0);
|
||||
|
||||
/// To find the polygons edges the vertices are displaced in a grid where
|
||||
/// each cell has the following cell_size.
|
||||
real_t cell_size = 0.25;
|
||||
/// each cell has the following cell_size and cell_height.
|
||||
real_t cell_size = 0.25; // Must match ProjectSettings default 3D cell_size and NavigationMesh cell_size.
|
||||
real_t cell_height = 0.25; // Must match ProjectSettings default 3D cell_height and NavigationMesh cell_height.
|
||||
|
||||
bool use_edge_connections = true;
|
||||
/// This value is used to detect the near edges to connect.
|
||||
@@ -131,6 +132,9 @@ public:
|
||||
return cell_size;
|
||||
}
|
||||
|
||||
void set_cell_height(real_t p_cell_height);
|
||||
real_t get_cell_height() const { return cell_height; }
|
||||
|
||||
void set_use_edge_connections(bool p_enabled);
|
||||
bool get_use_edge_connections() const {
|
||||
return use_edge_connections;
|
||||
|
||||
@@ -110,6 +110,10 @@ void NavRegion::update_polygons() {
|
||||
ERR_PRINT_ONCE("Navigation map synchronization error. Attempted to update a navigation region with a navigation mesh that uses a different `cell_size` than the `cell_size` set on the navigation map.");
|
||||
}
|
||||
|
||||
if (!Math::is_equal_approx(double(map->get_cell_height()), double(mesh->get_cell_height()))) {
|
||||
ERR_PRINT_ONCE("Navigation map synchronization error. Attempted to update a navigation region with a navigation mesh that uses a different `cell_height` than the `cell_height` set on the navigation map.");
|
||||
}
|
||||
|
||||
if (map && Math::rad_to_deg(map->get_up().angle_to(transform.basis.get_column(1))) >= 90.0f) {
|
||||
ERR_PRINT_ONCE("Navigation map synchronization error. Attempted to update a navigation region transform rotated 90 degrees or more away from the current navigation map UP orientation.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user