summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorPawel Lampe <pawel.lampe@gmail.com>2022-05-04 23:00:18 +0200
committerPawel Lampe <pawel.lampe@gmail.com>2022-05-04 23:00:18 +0200
commit88d3f14697a91348eab236a675399d0342ff3566 (patch)
treef74006a9b0a26c1ec9597d7d8c6a413d32da7e4a /scene/3d
parentc11482347133ac093899d39e5cb2d3221e9a4486 (diff)
Add ability to `bake_navigation_mesh` off thread.
This feature makes it possible to workaround problems such as: - long baking time due to heavy synchronization when parsing geometry from mesh instances - crash when freeing `NavigationMeshInstance` while baking - errors when actively baking node tree is being detached from the scene tree
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/navigation_region_3d.cpp10
-rw-r--r--scene/3d/navigation_region_3d.h4
2 files changed, 9 insertions, 5 deletions
diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp
index 7f6ecbebb7..80be770dfc 100644
--- a/scene/3d/navigation_region_3d.cpp
+++ b/scene/3d/navigation_region_3d.cpp
@@ -165,13 +165,17 @@ void _bake_navigation_mesh(void *p_user_data) {
}
}
-void NavigationRegion3D::bake_navigation_mesh() {
+void NavigationRegion3D::bake_navigation_mesh(bool p_on_thread) {
ERR_FAIL_COND_MSG(bake_thread.is_started(), "Unable to start another bake request. The navigation mesh bake thread is already baking a navigation mesh.");
BakeThreadsArgs *args = memnew(BakeThreadsArgs);
args->nav_region = this;
- bake_thread.start(_bake_navigation_mesh, args);
+ if (p_on_thread) {
+ bake_thread.start(_bake_navigation_mesh, args);
+ } else {
+ _bake_navigation_mesh(args);
+ }
}
void NavigationRegion3D::_bake_finished(Ref<NavigationMesh> p_nav_mesh) {
@@ -204,7 +208,7 @@ void NavigationRegion3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_region_rid"), &NavigationRegion3D::get_region_rid);
- ClassDB::bind_method(D_METHOD("bake_navigation_mesh"), &NavigationRegion3D::bake_navigation_mesh);
+ ClassDB::bind_method(D_METHOD("bake_navigation_mesh", "on_thread"), &NavigationRegion3D::bake_navigation_mesh, DEFVAL(true));
ClassDB::bind_method(D_METHOD("_bake_finished", "nav_mesh"), &NavigationRegion3D::_bake_finished);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navmesh", PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh"), "set_navigation_mesh", "get_navigation_mesh");
diff --git a/scene/3d/navigation_region_3d.h b/scene/3d/navigation_region_3d.h
index 1c559bc31a..140dfebf6a 100644
--- a/scene/3d/navigation_region_3d.h
+++ b/scene/3d/navigation_region_3d.h
@@ -62,9 +62,9 @@ public:
void set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh);
Ref<NavigationMesh> get_navigation_mesh() const;
- /// Bakes the navigation mesh in a dedicated thread; once done, automatically
+ /// Bakes the navigation mesh; once done, automatically
/// sets the new navigation mesh and emits a signal
- void bake_navigation_mesh();
+ void bake_navigation_mesh(bool p_on_thread);
void _bake_finished(Ref<NavigationMesh> p_nav_mesh);
TypedArray<String> get_configuration_warnings() const override;