summaryrefslogtreecommitdiff
path: root/modules/gridmap
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-09-08 09:19:19 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-09-08 09:19:19 +0200
commit207c747ac0266e4c29528df83328cb2c7e2deda5 (patch)
tree7d3779170432aaddeae0a9eb7065e35cebb008da /modules/gridmap
parent6ac1a811dd027c6708504f691a5e60b6bcd70885 (diff)
parent41c529a94d7c690dca127bbc4f37c7f65d040f6b (diff)
Merge pull request #64193 from smix8/navigation_gridmap_navmap_change_4.x
Add GridMap function to change navigation map for baked navigation regions
Diffstat (limited to 'modules/gridmap')
-rw-r--r--modules/gridmap/doc_classes/GridMap.xml14
-rw-r--r--modules/gridmap/grid_map.cpp36
-rw-r--r--modules/gridmap/grid_map.h4
3 files changed, 52 insertions, 2 deletions
diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml
index 5548006834..ed6cb8656a 100644
--- a/modules/gridmap/doc_classes/GridMap.xml
+++ b/modules/gridmap/doc_classes/GridMap.xml
@@ -94,6 +94,13 @@
Returns whether or not the specified layer of the [member navigation_layers] bitmask is enabled, given a [code]layer_number[/code] between 1 and 32.
</description>
</method>
+ <method name="get_navigation_map" qualifiers="const">
+ <return type="RID" />
+ <description>
+ Returns the [RID] of the navigation map this GridMap node uses for its cell baked navigation meshes.
+ This function returns always the map set on the GridMap node and not the map on the NavigationServer. If the map is changed directly with the NavigationServer API the GridMap node will not be aware of the map change.
+ </description>
+ </method>
<method name="get_orthogonal_index_from_basis" qualifiers="const">
<return type="int" />
<param index="0" name="basis" type="Basis" />
@@ -176,6 +183,13 @@
Based on [code]value[/code], enables or disables the specified layer in the [member navigation_layers] bitmask, given a [code]layer_number[/code] between 1 and 32.
</description>
</method>
+ <method name="set_navigation_map">
+ <return type="void" />
+ <param index="0" name="navigation_map" type="RID" />
+ <description>
+ Sets the [RID] of the navigation map this GridMap node should use for its cell baked navigation meshes.
+ </description>
+ </method>
</methods>
<members>
<member name="bake_navigation" type="bool" setter="set_bake_navigation" getter="is_baking_navigation" default="false">
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index dd57db8105..466a2efd21 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -226,6 +226,27 @@ bool GridMap::is_baking_navigation() {
return bake_navigation;
}
+void GridMap::set_navigation_map(RID p_navigation_map) {
+ map_override = p_navigation_map;
+ for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
+ Octant &g = *octant_map[E.key];
+ for (KeyValue<IndexKey, Octant::NavMesh> &F : g.navmesh_ids) {
+ if (F.value.region.is_valid()) {
+ NavigationServer3D::get_singleton()->region_set_map(F.value.region, map_override);
+ }
+ }
+ }
+}
+
+RID GridMap::get_navigation_map() const {
+ if (map_override.is_valid()) {
+ return map_override;
+ } else if (is_inside_tree()) {
+ return get_world_3d()->get_navigation_map();
+ }
+ return RID();
+}
+
void GridMap::set_navigation_layers(uint32_t p_navigation_layers) {
navigation_layers = p_navigation_layers;
_recreate_octant_data();
@@ -639,7 +660,11 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
NavigationServer3D::get_singleton()->region_set_navmesh(region, navmesh);
NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * nm.xform);
if (is_inside_tree()) {
- NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
+ if (map_override.is_valid()) {
+ NavigationServer3D::get_singleton()->region_set_map(region, map_override);
+ } else {
+ NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
+ }
}
nm.region = region;
@@ -757,7 +782,11 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
NavigationServer3D::get_singleton()->region_set_navigation_layers(region, navigation_layers);
NavigationServer3D::get_singleton()->region_set_navmesh(region, nm);
NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * F.value.xform);
- NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
+ if (map_override.is_valid()) {
+ NavigationServer3D::get_singleton()->region_set_map(region, map_override);
+ } else {
+ NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
+ }
F.value.region = region;
}
@@ -1022,6 +1051,9 @@ void GridMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_bake_navigation", "bake_navigation"), &GridMap::set_bake_navigation);
ClassDB::bind_method(D_METHOD("is_baking_navigation"), &GridMap::is_baking_navigation);
+ ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &GridMap::set_navigation_map);
+ ClassDB::bind_method(D_METHOD("get_navigation_map"), &GridMap::get_navigation_map);
+
ClassDB::bind_method(D_METHOD("set_navigation_layers", "layers"), &GridMap::set_navigation_layers);
ClassDB::bind_method(D_METHOD("get_navigation_layers"), &GridMap::get_navigation_layers);
diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h
index 4a4e970fd3..6a53457d25 100644
--- a/modules/gridmap/grid_map.h
+++ b/modules/gridmap/grid_map.h
@@ -152,6 +152,7 @@ class GridMap : public Node3D {
uint32_t collision_mask = 1;
Ref<PhysicsMaterial> physics_material;
bool bake_navigation = false;
+ RID map_override;
uint32_t navigation_layers = 1;
Transform3D last_transform;
@@ -247,6 +248,9 @@ public:
void set_bake_navigation(bool p_bake_navigation);
bool is_baking_navigation();
+ void set_navigation_map(RID p_navigation_map);
+ RID get_navigation_map() const;
+
void set_navigation_layers(uint32_t p_navigation_layers);
uint32_t get_navigation_layers() const;