summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-08-25 22:24:10 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-08-25 22:24:10 +0200
commit5beb4ee691312bcaed80315b3ede6faef813af8a (patch)
tree16163ce52b440f3019cf86897be551ba8742c49c
parent8bb5db6ebd8232bf915f4fa53135ea143d4a26a2 (diff)
parent3fae26277a0e355441190f7b5325969808b89ecb (diff)
downloadredot-engine-5beb4ee691312bcaed80315b3ede6faef813af8a.tar.gz
Merge pull request #92684 from smix8/mesh_conv_dialog
Add confirm dialog for render mesh to navigation mesh conversion
-rw-r--r--editor/plugins/mesh_instance_3d_editor_plugin.cpp67
-rw-r--r--editor/plugins/mesh_instance_3d_editor_plugin.h3
2 files changed, 48 insertions, 22 deletions
diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
index 4ebacbd0b3..369d6ab009 100644
--- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp
+++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
@@ -214,28 +214,7 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
} break;
case MENU_OPTION_CREATE_NAVMESH: {
- Ref<NavigationMesh> nmesh = memnew(NavigationMesh);
-
- if (nmesh.is_null()) {
- return;
- }
-
- nmesh->create_from_mesh(mesh);
- NavigationRegion3D *nmi = memnew(NavigationRegion3D);
- nmi->set_navigation_mesh(nmesh);
-
- Node *owner = get_tree()->get_edited_scene_root();
-
- EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
- ur->create_action(TTR("Create Navigation Mesh"));
-
- ur->add_do_method(node, "add_child", nmi, true);
- ur->add_do_method(nmi, "set_owner", owner);
- ur->add_do_method(Node3DEditor::get_singleton(), SceneStringName(_request_gizmo), nmi);
-
- ur->add_do_reference(nmi);
- ur->add_undo_method(node, "remove_child", nmi);
- ur->commit_action();
+ navigation_mesh_dialog->popup_centered(Vector2(200, 90));
} break;
case MENU_OPTION_CREATE_OUTLINE_MESH: {
@@ -472,6 +451,36 @@ void MeshInstance3DEditor::_debug_uv_draw() {
debug_uv->draw_multiline(uv_lines, get_theme_color(SNAME("mono_color"), EditorStringName(Editor)) * Color(1, 1, 1, 0.5));
}
+void MeshInstance3DEditor::_create_navigation_mesh() {
+ Ref<Mesh> mesh = node->get_mesh();
+ if (mesh.is_null()) {
+ return;
+ }
+
+ Ref<NavigationMesh> nmesh = memnew(NavigationMesh);
+
+ if (nmesh.is_null()) {
+ return;
+ }
+
+ nmesh->create_from_mesh(mesh);
+ NavigationRegion3D *nmi = memnew(NavigationRegion3D);
+ nmi->set_navigation_mesh(nmesh);
+
+ Node *owner = get_tree()->get_edited_scene_root();
+
+ EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
+ ur->create_action(TTR("Create Navigation Mesh"));
+
+ ur->add_do_method(node, "add_child", nmi, true);
+ ur->add_do_method(nmi, "set_owner", owner);
+ ur->add_do_method(Node3DEditor::get_singleton(), SceneStringName(_request_gizmo), nmi);
+
+ ur->add_do_reference(nmi);
+ ur->add_undo_method(node, "remove_child", nmi);
+ ur->commit_action();
+}
+
void MeshInstance3DEditor::_create_outline_mesh() {
Ref<Mesh> mesh = node->get_mesh();
if (mesh.is_null()) {
@@ -608,6 +617,20 @@ MeshInstance3DEditor::MeshInstance3DEditor() {
debug_uv->set_custom_minimum_size(Size2(600, 600) * EDSCALE);
debug_uv->connect(SceneStringName(draw), callable_mp(this, &MeshInstance3DEditor::_debug_uv_draw));
debug_uv_dialog->add_child(debug_uv);
+
+ navigation_mesh_dialog = memnew(ConfirmationDialog);
+ navigation_mesh_dialog->set_title(TTR("Create NavigationMesh"));
+ navigation_mesh_dialog->set_ok_button_text(TTR("Create"));
+
+ VBoxContainer *navigation_mesh_dialog_vbc = memnew(VBoxContainer);
+ navigation_mesh_dialog->add_child(navigation_mesh_dialog_vbc);
+
+ Label *navigation_mesh_l = memnew(Label);
+ navigation_mesh_l->set_text(TTR("Before converting a rendering mesh to a navigation mesh, please verify:\n\n- The mesh is two-dimensional.\n- The mesh has no surface overlap.\n- The mesh has no self-intersection.\n- The mesh surfaces have indices.\n\nIf the mesh does not fulfill these requirements, the pathfinding will be broken."));
+ navigation_mesh_dialog_vbc->add_child(navigation_mesh_l);
+
+ add_child(navigation_mesh_dialog);
+ navigation_mesh_dialog->connect("confirmed", callable_mp(this, &MeshInstance3DEditor::_create_navigation_mesh));
}
void MeshInstance3DEditorPlugin::edit(Object *p_object) {
diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.h b/editor/plugins/mesh_instance_3d_editor_plugin.h
index 20c151fb92..c982df9c5f 100644
--- a/editor/plugins/mesh_instance_3d_editor_plugin.h
+++ b/editor/plugins/mesh_instance_3d_editor_plugin.h
@@ -82,10 +82,13 @@ class MeshInstance3DEditor : public Control {
Control *debug_uv = nullptr;
Vector<Vector2> uv_lines;
+ ConfirmationDialog *navigation_mesh_dialog = nullptr;
+
void _create_collision_shape();
Vector<Ref<Shape3D>> create_shape_from_mesh(Ref<Mesh> p_mesh, int p_option, bool p_verbose);
void _menu_option(int p_option);
void _create_outline_mesh();
+ void _create_navigation_mesh();
void _create_uv_lines(int p_layer);
friend class MeshInstance3DEditorPlugin;