2017-02-28 12:10:29 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* navigation_mesh_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-02-28 12:10:29 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2020-01-10 11:22:34 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2017-02-28 12:10:29 +00:00
|
|
|
#include "navigation_mesh_editor_plugin.h"
|
2018-05-30 13:59:42 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/io/marshalls.h"
|
|
|
|
#include "core/io/resource_saver.h"
|
2020-01-10 11:22:34 +00:00
|
|
|
#include "navigation_mesh_generator.h"
|
2020-03-26 21:49:16 +00:00
|
|
|
#include "scene/3d/mesh_instance_3d.h"
|
2017-02-28 12:10:29 +00:00
|
|
|
#include "scene/gui/box_container.h"
|
|
|
|
|
|
|
|
void NavigationMeshEditor::_node_removed(Node *p_node) {
|
|
|
|
if (p_node == node) {
|
2020-04-01 23:20:12 +00:00
|
|
|
node = nullptr;
|
2017-02-28 12:10:29 +00:00
|
|
|
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationMeshEditor::_notification(int p_option) {
|
|
|
|
if (p_option == NOTIFICATION_ENTER_TREE) {
|
2021-07-17 21:22:52 +00:00
|
|
|
button_bake->set_icon(get_theme_icon(SNAME("Bake"), SNAME("EditorIcons")));
|
|
|
|
button_reset->set_icon(get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")));
|
2017-02-28 12:10:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationMeshEditor::_bake_pressed() {
|
2019-05-23 06:37:58 +00:00
|
|
|
button_bake->set_pressed(false);
|
2017-02-28 12:10:29 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!node);
|
2020-01-10 11:22:34 +00:00
|
|
|
if (!node->get_navigation_mesh().is_valid()) {
|
|
|
|
err_dialog->set_text(TTR("A NavigationMesh resource must be set or created for this node to work."));
|
2020-03-06 17:00:16 +00:00
|
|
|
err_dialog->popup_centered();
|
2017-02-28 12:10:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-10 11:22:34 +00:00
|
|
|
NavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh());
|
|
|
|
NavigationMeshGenerator::get_singleton()->bake(node->get_navigation_mesh(), node);
|
2017-02-28 12:10:29 +00:00
|
|
|
|
2021-06-23 14:49:50 +00:00
|
|
|
node->update_gizmos();
|
2017-02-28 12:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationMeshEditor::_clear_pressed() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (node) {
|
2020-01-10 11:22:34 +00:00
|
|
|
NavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh());
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-02-28 12:10:29 +00:00
|
|
|
|
|
|
|
button_bake->set_pressed(false);
|
|
|
|
bake_info->set_text("");
|
|
|
|
|
|
|
|
if (node) {
|
2021-06-23 14:49:50 +00:00
|
|
|
node->update_gizmos();
|
2017-02-28 12:10:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void NavigationMeshEditor::edit(NavigationRegion3D *p_nav_region) {
|
2020-04-01 23:20:12 +00:00
|
|
|
if (p_nav_region == nullptr || node == p_nav_region) {
|
2017-02-28 12:10:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-08 16:33:34 +00:00
|
|
|
node = p_nav_region;
|
2017-02-28 12:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationMeshEditor::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationMeshEditor::NavigationMeshEditor() {
|
|
|
|
bake_hbox = memnew(HBoxContainer);
|
2018-10-22 02:31:51 +00:00
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
button_bake = memnew(Button);
|
|
|
|
button_bake->set_flat(true);
|
2018-10-22 02:31:51 +00:00
|
|
|
bake_hbox->add_child(button_bake);
|
2017-02-28 12:10:29 +00:00
|
|
|
button_bake->set_toggle_mode(true);
|
2018-10-22 02:31:51 +00:00
|
|
|
button_bake->set_text(TTR("Bake NavMesh"));
|
2020-02-21 17:28:45 +00:00
|
|
|
button_bake->connect("pressed", callable_mp(this, &NavigationMeshEditor::_bake_pressed));
|
2017-02-28 12:10:29 +00:00
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
button_reset = memnew(Button);
|
|
|
|
button_reset->set_flat(true);
|
2017-02-28 12:10:29 +00:00
|
|
|
bake_hbox->add_child(button_reset);
|
2018-10-22 02:31:51 +00:00
|
|
|
// No button text, we only use a revert icon which is set when entering the tree.
|
|
|
|
button_reset->set_tooltip(TTR("Clear the navigation mesh."));
|
2020-02-21 17:28:45 +00:00
|
|
|
button_reset->connect("pressed", callable_mp(this, &NavigationMeshEditor::_clear_pressed));
|
2018-10-22 02:31:51 +00:00
|
|
|
|
|
|
|
bake_info = memnew(Label);
|
2017-02-28 12:10:29 +00:00
|
|
|
bake_hbox->add_child(bake_info);
|
|
|
|
|
|
|
|
err_dialog = memnew(AcceptDialog);
|
|
|
|
add_child(err_dialog);
|
2020-04-01 23:20:12 +00:00
|
|
|
node = nullptr;
|
2017-02-28 12:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NavigationMeshEditor::~NavigationMeshEditor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationMeshEditorPlugin::edit(Object *p_object) {
|
2020-03-26 21:49:16 +00:00
|
|
|
navigation_mesh_editor->edit(Object::cast_to<NavigationRegion3D>(p_object));
|
2017-02-28 12:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NavigationMeshEditorPlugin::handles(Object *p_object) const {
|
2020-03-26 21:49:16 +00:00
|
|
|
return p_object->is_class("NavigationRegion3D");
|
2017-02-28 12:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationMeshEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
if (p_visible) {
|
|
|
|
navigation_mesh_editor->show();
|
|
|
|
navigation_mesh_editor->bake_hbox->show();
|
|
|
|
} else {
|
|
|
|
navigation_mesh_editor->hide();
|
|
|
|
navigation_mesh_editor->bake_hbox->hide();
|
2020-04-01 23:20:12 +00:00
|
|
|
navigation_mesh_editor->edit(nullptr);
|
2017-02-28 12:10:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationMeshEditorPlugin::NavigationMeshEditorPlugin(EditorNode *p_node) {
|
|
|
|
editor = p_node;
|
|
|
|
navigation_mesh_editor = memnew(NavigationMeshEditor);
|
2020-12-28 18:51:39 +00:00
|
|
|
editor->get_main_control()->add_child(navigation_mesh_editor);
|
2017-02-28 12:10:29 +00:00
|
|
|
add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, navigation_mesh_editor->bake_hbox);
|
|
|
|
navigation_mesh_editor->hide();
|
|
|
|
navigation_mesh_editor->bake_hbox->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationMeshEditorPlugin::~NavigationMeshEditorPlugin() {
|
|
|
|
}
|
2020-01-10 11:22:34 +00:00
|
|
|
|
|
|
|
#endif
|