Browse Source

Emit changed signal after baking navigation mesh

Emits changed signal after baking navigation mesh.
smix8 5 months ago
parent
commit
565ea927d2

+ 5 - 0
modules/navigation_2d/2d/nav_mesh_generator_2d.cpp

@@ -93,6 +93,7 @@ void NavMeshGenerator2D::sync() {
 				if (generator_task->callback.is_valid()) {
 				if (generator_task->callback.is_valid()) {
 					generator_emit_callback(generator_task->callback);
 					generator_emit_callback(generator_task->callback);
 				}
 				}
+				generator_task->navigation_mesh->emit_changed();
 				memdelete(generator_task);
 				memdelete(generator_task);
 			}
 			}
 		}
 		}
@@ -150,6 +151,7 @@ void NavMeshGenerator2D::bake_from_source_geometry_data(Ref<NavigationPolygon> p
 		if (p_callback.is_valid()) {
 		if (p_callback.is_valid()) {
 			generator_emit_callback(p_callback);
 			generator_emit_callback(p_callback);
 		}
 		}
+		p_navigation_mesh->emit_changed();
 		return;
 		return;
 	}
 	}
 
 
@@ -169,6 +171,8 @@ void NavMeshGenerator2D::bake_from_source_geometry_data(Ref<NavigationPolygon> p
 	if (p_callback.is_valid()) {
 	if (p_callback.is_valid()) {
 		generator_emit_callback(p_callback);
 		generator_emit_callback(p_callback);
 	}
 	}
+
+	p_navigation_mesh->emit_changed();
 }
 }
 
 
 void NavMeshGenerator2D::bake_from_source_geometry_data_async(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, const Callable &p_callback) {
 void NavMeshGenerator2D::bake_from_source_geometry_data_async(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, const Callable &p_callback) {
@@ -180,6 +184,7 @@ void NavMeshGenerator2D::bake_from_source_geometry_data_async(Ref<NavigationPoly
 		if (p_callback.is_valid()) {
 		if (p_callback.is_valid()) {
 			generator_emit_callback(p_callback);
 			generator_emit_callback(p_callback);
 		}
 		}
+		p_navigation_mesh->emit_changed();
 		return;
 		return;
 	}
 	}
 
 

+ 5 - 0
modules/navigation_3d/3d/nav_mesh_generator_3d.cpp

@@ -92,6 +92,7 @@ void NavMeshGenerator3D::sync() {
 				if (generator_task->callback.is_valid()) {
 				if (generator_task->callback.is_valid()) {
 					generator_emit_callback(generator_task->callback);
 					generator_emit_callback(generator_task->callback);
 				}
 				}
+				generator_task->navigation_mesh->emit_changed();
 				memdelete(generator_task);
 				memdelete(generator_task);
 			}
 			}
 		}
 		}
@@ -149,6 +150,7 @@ void NavMeshGenerator3D::bake_from_source_geometry_data(Ref<NavigationMesh> p_na
 		if (p_callback.is_valid()) {
 		if (p_callback.is_valid()) {
 			generator_emit_callback(p_callback);
 			generator_emit_callback(p_callback);
 		}
 		}
+		p_navigation_mesh->emit_changed();
 		return;
 		return;
 	}
 	}
 
 
@@ -168,6 +170,8 @@ void NavMeshGenerator3D::bake_from_source_geometry_data(Ref<NavigationMesh> p_na
 	if (p_callback.is_valid()) {
 	if (p_callback.is_valid()) {
 		generator_emit_callback(p_callback);
 		generator_emit_callback(p_callback);
 	}
 	}
+
+	p_navigation_mesh->emit_changed();
 }
 }
 
 
 void NavMeshGenerator3D::bake_from_source_geometry_data_async(Ref<NavigationMesh> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, const Callable &p_callback) {
 void NavMeshGenerator3D::bake_from_source_geometry_data_async(Ref<NavigationMesh> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, const Callable &p_callback) {
@@ -179,6 +183,7 @@ void NavMeshGenerator3D::bake_from_source_geometry_data_async(Ref<NavigationMesh
 		if (p_callback.is_valid()) {
 		if (p_callback.is_valid()) {
 			generator_emit_callback(p_callback);
 			generator_emit_callback(p_callback);
 		}
 		}
+		p_navigation_mesh->emit_changed();
 		return;
 		return;
 	}
 	}
 
 

+ 20 - 23
scene/2d/navigation/navigation_region_2d.cpp

@@ -198,27 +198,12 @@ void NavigationRegion2D::set_navigation_polygon(const Ref<NavigationPolygon> &p_
 	}
 	}
 
 
 	navigation_polygon = p_navigation_polygon;
 	navigation_polygon = p_navigation_polygon;
-#ifdef DEBUG_ENABLED
-	debug_mesh_dirty = true;
-#endif // DEBUG_ENABLED
-
-	_update_bounds();
-
-	NavigationServer2D::get_singleton()->region_set_navigation_polygon(region, p_navigation_polygon);
 
 
 	if (navigation_polygon.is_valid()) {
 	if (navigation_polygon.is_valid()) {
 		navigation_polygon->connect_changed(callable_mp(this, &NavigationRegion2D::_navigation_polygon_changed));
 		navigation_polygon->connect_changed(callable_mp(this, &NavigationRegion2D::_navigation_polygon_changed));
 	}
 	}
 
 
-#ifdef DEBUG_ENABLED
-	if (navigation_polygon.is_null()) {
-		_set_debug_visible(false);
-	}
-#endif // DEBUG_ENABLED
-
 	_navigation_polygon_changed();
 	_navigation_polygon_changed();
-
-	update_configuration_warnings();
 }
 }
 
 
 Ref<NavigationPolygon> NavigationRegion2D::get_navigation_polygon() const {
 Ref<NavigationPolygon> NavigationRegion2D::get_navigation_polygon() const {
@@ -254,19 +239,18 @@ void NavigationRegion2D::bake_navigation_polygon(bool p_on_thread) {
 	NavigationServer2D::get_singleton()->parse_source_geometry_data(navigation_polygon, source_geometry_data, this);
 	NavigationServer2D::get_singleton()->parse_source_geometry_data(navigation_polygon, source_geometry_data, this);
 
 
 	if (p_on_thread) {
 	if (p_on_thread) {
-		NavigationServer2D::get_singleton()->bake_from_source_geometry_data_async(navigation_polygon, source_geometry_data, callable_mp(this, &NavigationRegion2D::_bake_finished).bind(navigation_polygon));
+		NavigationServer2D::get_singleton()->bake_from_source_geometry_data_async(navigation_polygon, source_geometry_data, callable_mp(this, &NavigationRegion2D::_bake_finished));
 	} else {
 	} else {
-		NavigationServer2D::get_singleton()->bake_from_source_geometry_data(navigation_polygon, source_geometry_data, callable_mp(this, &NavigationRegion2D::_bake_finished).bind(navigation_polygon));
+		NavigationServer2D::get_singleton()->bake_from_source_geometry_data(navigation_polygon, source_geometry_data, callable_mp(this, &NavigationRegion2D::_bake_finished));
 	}
 	}
 }
 }
 
 
-void NavigationRegion2D::_bake_finished(Ref<NavigationPolygon> p_navigation_polygon) {
+void NavigationRegion2D::_bake_finished() {
 	if (!Thread::is_main_thread()) {
 	if (!Thread::is_main_thread()) {
-		callable_mp(this, &NavigationRegion2D::_bake_finished).call_deferred(p_navigation_polygon);
+		callable_mp(this, &NavigationRegion2D::_bake_finished).call_deferred();
 		return;
 		return;
 	}
 	}
 
 
-	set_navigation_polygon(p_navigation_polygon);
 	emit_signal(SNAME("bake_finished"));
 	emit_signal(SNAME("bake_finished"));
 }
 }
 
 
@@ -275,12 +259,25 @@ bool NavigationRegion2D::is_baking() const {
 }
 }
 
 
 void NavigationRegion2D::_navigation_polygon_changed() {
 void NavigationRegion2D::_navigation_polygon_changed() {
+	_update_bounds();
+
+	NavigationServer2D::get_singleton()->region_set_navigation_polygon(region, navigation_polygon);
+
+#ifdef DEBUG_ENABLED
+	debug_mesh_dirty = true;
+
+	if (navigation_polygon.is_null()) {
+		_set_debug_visible(false);
+	}
+
 	if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) {
 	if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) {
 		queue_redraw();
 		queue_redraw();
 	}
 	}
-	if (navigation_polygon.is_valid()) {
-		NavigationServer2D::get_singleton()->region_set_navigation_polygon(region, navigation_polygon);
-	}
+#endif // DEBUG_ENABLED
+
+	emit_signal(SNAME("navigation_polygon_changed"));
+
+	update_configuration_warnings();
 }
 }
 
 
 #ifdef DEBUG_ENABLED
 #ifdef DEBUG_ENABLED

+ 1 - 1
scene/2d/navigation/navigation_region_2d.h

@@ -111,7 +111,7 @@ public:
 	PackedStringArray get_configuration_warnings() const override;
 	PackedStringArray get_configuration_warnings() const override;
 
 
 	void bake_navigation_polygon(bool p_on_thread);
 	void bake_navigation_polygon(bool p_on_thread);
-	void _bake_finished(Ref<NavigationPolygon> p_navigation_polygon);
+	void _bake_finished();
 	bool is_baking() const;
 	bool is_baking() const;
 
 
 	Rect2 get_bounds() const { return bounds; }
 	Rect2 get_bounds() const { return bounds; }

+ 27 - 31
scene/3d/navigation/navigation_region_3d.cpp

@@ -194,30 +194,7 @@ void NavigationRegion3D::set_navigation_mesh(const Ref<NavigationMesh> &p_naviga
 		navigation_mesh->connect_changed(callable_mp(this, &NavigationRegion3D::_navigation_mesh_changed));
 		navigation_mesh->connect_changed(callable_mp(this, &NavigationRegion3D::_navigation_mesh_changed));
 	}
 	}
 
 
-	_update_bounds();
-
-	NavigationServer3D::get_singleton()->region_set_navigation_mesh(region, p_navigation_mesh);
-
-#ifdef DEBUG_ENABLED
-	if (is_inside_tree() && NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) {
-		if (navigation_mesh.is_valid()) {
-			_update_debug_mesh();
-			_update_debug_edge_connections_mesh();
-		} else {
-			if (debug_instance.is_valid()) {
-				RS::get_singleton()->instance_set_visible(debug_instance, false);
-			}
-			if (debug_edge_connections_instance.is_valid()) {
-				RS::get_singleton()->instance_set_visible(debug_edge_connections_instance, false);
-			}
-		}
-	}
-#endif // DEBUG_ENABLED
-
-	emit_signal(SNAME("navigation_mesh_changed"));
-
-	update_gizmos();
-	update_configuration_warnings();
+	_navigation_mesh_changed();
 }
 }
 
 
 Ref<NavigationMesh> NavigationRegion3D::get_navigation_mesh() const {
 Ref<NavigationMesh> NavigationRegion3D::get_navigation_mesh() const {
@@ -253,19 +230,18 @@ void NavigationRegion3D::bake_navigation_mesh(bool p_on_thread) {
 	NavigationServer3D::get_singleton()->parse_source_geometry_data(navigation_mesh, source_geometry_data, this);
 	NavigationServer3D::get_singleton()->parse_source_geometry_data(navigation_mesh, source_geometry_data, this);
 
 
 	if (p_on_thread) {
 	if (p_on_thread) {
-		NavigationServer3D::get_singleton()->bake_from_source_geometry_data_async(navigation_mesh, source_geometry_data, callable_mp(this, &NavigationRegion3D::_bake_finished).bind(navigation_mesh));
+		NavigationServer3D::get_singleton()->bake_from_source_geometry_data_async(navigation_mesh, source_geometry_data, callable_mp(this, &NavigationRegion3D::_bake_finished));
 	} else {
 	} else {
-		NavigationServer3D::get_singleton()->bake_from_source_geometry_data(navigation_mesh, source_geometry_data, callable_mp(this, &NavigationRegion3D::_bake_finished).bind(navigation_mesh));
+		NavigationServer3D::get_singleton()->bake_from_source_geometry_data(navigation_mesh, source_geometry_data, callable_mp(this, &NavigationRegion3D::_bake_finished));
 	}
 	}
 }
 }
 
 
-void NavigationRegion3D::_bake_finished(Ref<NavigationMesh> p_navigation_mesh) {
+void NavigationRegion3D::_bake_finished() {
 	if (!Thread::is_main_thread()) {
 	if (!Thread::is_main_thread()) {
-		callable_mp(this, &NavigationRegion3D::_bake_finished).call_deferred(p_navigation_mesh);
+		callable_mp(this, &NavigationRegion3D::_bake_finished).call_deferred();
 		return;
 		return;
 	}
 	}
 
 
-	set_navigation_mesh(p_navigation_mesh);
 	emit_signal(SNAME("bake_finished"));
 	emit_signal(SNAME("bake_finished"));
 }
 }
 
 
@@ -350,12 +326,32 @@ bool NavigationRegion3D::_get(const StringName &p_name, Variant &r_ret) const {
 #endif // DISABLE_DEPRECATED
 #endif // DISABLE_DEPRECATED
 
 
 void NavigationRegion3D::_navigation_mesh_changed() {
 void NavigationRegion3D::_navigation_mesh_changed() {
-	update_gizmos();
-	update_configuration_warnings();
+	_update_bounds();
+
+	NavigationServer3D::get_singleton()->region_set_navigation_mesh(region, navigation_mesh);
 
 
 #ifdef DEBUG_ENABLED
 #ifdef DEBUG_ENABLED
+	if (is_inside_tree() && NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) {
+		if (navigation_mesh.is_valid()) {
+			_update_debug_mesh();
+			_update_debug_edge_connections_mesh();
+		} else {
+			if (debug_instance.is_valid()) {
+				RS::get_singleton()->instance_set_visible(debug_instance, false);
+			}
+			if (debug_edge_connections_instance.is_valid()) {
+				RS::get_singleton()->instance_set_visible(debug_edge_connections_instance, false);
+			}
+		}
+	}
+
 	_update_debug_edge_connections_mesh();
 	_update_debug_edge_connections_mesh();
 #endif // DEBUG_ENABLED
 #endif // DEBUG_ENABLED
+
+	emit_signal(SNAME("navigation_mesh_changed"));
+
+	update_gizmos();
+	update_configuration_warnings();
 }
 }
 
 
 #ifdef DEBUG_ENABLED
 #ifdef DEBUG_ENABLED

+ 1 - 1
scene/3d/navigation/navigation_region_3d.h

@@ -106,7 +106,7 @@ public:
 	/// Bakes the navigation mesh; once done, automatically
 	/// Bakes the navigation mesh; once done, automatically
 	/// sets the new navigation mesh and emits a signal
 	/// sets the new navigation mesh and emits a signal
 	void bake_navigation_mesh(bool p_on_thread);
 	void bake_navigation_mesh(bool p_on_thread);
-	void _bake_finished(Ref<NavigationMesh> p_navigation_mesh);
+	void _bake_finished();
 	bool is_baking() const;
 	bool is_baking() const;
 
 
 	PackedStringArray get_configuration_warnings() const override;
 	PackedStringArray get_configuration_warnings() const override;