Merge pull request #92684 from smix8/mesh_conv_dialog

Add confirm dialog for render mesh to navigation mesh conversion
This commit is contained in:
Rémi Verschelde 2024-08-25 22:24:10 +02:00
commit 5beb4ee691
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 48 additions and 22 deletions

View file

@ -214,28 +214,7 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
} break; } break;
case MENU_OPTION_CREATE_NAVMESH: { case MENU_OPTION_CREATE_NAVMESH: {
Ref<NavigationMesh> nmesh = memnew(NavigationMesh); navigation_mesh_dialog->popup_centered(Vector2(200, 90));
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();
} break; } break;
case MENU_OPTION_CREATE_OUTLINE_MESH: { 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)); 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() { void MeshInstance3DEditor::_create_outline_mesh() {
Ref<Mesh> mesh = node->get_mesh(); Ref<Mesh> mesh = node->get_mesh();
if (mesh.is_null()) { if (mesh.is_null()) {
@ -608,6 +617,20 @@ MeshInstance3DEditor::MeshInstance3DEditor() {
debug_uv->set_custom_minimum_size(Size2(600, 600) * EDSCALE); debug_uv->set_custom_minimum_size(Size2(600, 600) * EDSCALE);
debug_uv->connect(SceneStringName(draw), callable_mp(this, &MeshInstance3DEditor::_debug_uv_draw)); debug_uv->connect(SceneStringName(draw), callable_mp(this, &MeshInstance3DEditor::_debug_uv_draw));
debug_uv_dialog->add_child(debug_uv); 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) { void MeshInstance3DEditorPlugin::edit(Object *p_object) {

View file

@ -82,10 +82,13 @@ class MeshInstance3DEditor : public Control {
Control *debug_uv = nullptr; Control *debug_uv = nullptr;
Vector<Vector2> uv_lines; Vector<Vector2> uv_lines;
ConfirmationDialog *navigation_mesh_dialog = nullptr;
void _create_collision_shape(); void _create_collision_shape();
Vector<Ref<Shape3D>> create_shape_from_mesh(Ref<Mesh> p_mesh, int p_option, bool p_verbose); Vector<Ref<Shape3D>> create_shape_from_mesh(Ref<Mesh> p_mesh, int p_option, bool p_verbose);
void _menu_option(int p_option); void _menu_option(int p_option);
void _create_outline_mesh(); void _create_outline_mesh();
void _create_navigation_mesh();
void _create_uv_lines(int p_layer); void _create_uv_lines(int p_layer);
friend class MeshInstance3DEditorPlugin; friend class MeshInstance3DEditorPlugin;