forked from sascha/godot
Merge pull request #63479 from DarkKilauea/nav-link
commit
2e0cffdb6f
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="NavigationLink2D" inherits="Node2D" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
|
||||
<brief_description>
|
||||
Creates a link between two locations that [NavigationServer2D] can route agents through.
|
||||
</brief_description>
|
||||
<description>
|
||||
Creates a link between two locations that [NavigationServer2D] can route agents through. Links can be used to express navigation methods that aren't just traveling along the surface of the navigation mesh, like zip-lines, teleporters, or jumping across gaps.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_navigation_layer_value" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="layer_number" type="int" />
|
||||
<description>
|
||||
Returns whether or not the specified layer of the [member navigation_layers] bitmask is enabled, given a [code]layer_number[/code] between 1 and 32.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_navigation_layer_value">
|
||||
<return type="void" />
|
||||
<param index="0" name="layer_number" type="int" />
|
||||
<param index="1" name="value" type="bool" />
|
||||
<description>
|
||||
Based on [code]value[/code], enables or disables the specified layer in the [member navigation_layers] bitmask, given a [code]layer_number[/code] between 1 and 32.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="bidirectional" type="bool" setter="set_bidirectional" getter="is_bidirectional" default="true">
|
||||
Whether this link can be traveled in both directions or only from [member start_location] to [member end_location].
|
||||
</member>
|
||||
<member name="enabled" type="bool" setter="set_enabled" getter="is_enabled" default="true">
|
||||
Whether this link is currently active. If [code]false[/code], [method NavigationServer2D.map_get_path] will ignore this link.
|
||||
</member>
|
||||
<member name="end_location" type="Vector2" setter="set_end_location" getter="get_end_location" default="Vector2(0, 0)">
|
||||
Ending position of the link.
|
||||
This position will search out the nearest polygon in the navigation mesh to attach to.
|
||||
The distance the link will search is controlled by [method NavigationServer2D.map_set_link_connection_radius].
|
||||
</member>
|
||||
<member name="enter_cost" type="float" setter="set_enter_cost" getter="get_enter_cost" default="0.0">
|
||||
When pathfinding enters this link from another regions navmesh the [code]enter_cost[/code] value is added to the path distance for determining the shortest path.
|
||||
</member>
|
||||
<member name="navigation_layers" type="int" setter="set_navigation_layers" getter="get_navigation_layers" default="1">
|
||||
A bitfield determining all navigation layers the link belongs to. These navigation layers will be checked when requesting a path with [method NavigationServer2D.map_get_path].
|
||||
</member>
|
||||
<member name="start_location" type="Vector2" setter="set_start_location" getter="get_start_location" default="Vector2(0, 0)">
|
||||
Starting position of the link.
|
||||
This position will search out the nearest polygon in the navigation mesh to attach to.
|
||||
The distance the link will search is controlled by [method NavigationServer2D.map_set_link_connection_radius].
|
||||
</member>
|
||||
<member name="travel_cost" type="float" setter="set_travel_cost" getter="get_travel_cost" default="1.0">
|
||||
When pathfinding moves along the link the traveled distance is multiplied with [code]travel_cost[/code] for determining the shortest path.
|
||||
</member>
|
||||
</members>
|
||||
</class>
|
||||
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="NavigationLink3D" inherits="Node3D" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
|
||||
<brief_description>
|
||||
Creates a link between two locations that [NavigationServer3D] can route agents through.
|
||||
</brief_description>
|
||||
<description>
|
||||
Creates a link between two locations that [NavigationServer3D] can route agents through. Links can be used to express navigation methods that aren't just traveling along the surface of the navigation mesh, like zip-lines, teleporters, or jumping across gaps.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_navigation_layer_value" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="layer_number" type="int" />
|
||||
<description>
|
||||
Returns whether or not the specified layer of the [member navigation_layers] bitmask is enabled, given a [code]layer_number[/code] between 1 and 32.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_navigation_layer_value">
|
||||
<return type="void" />
|
||||
<param index="0" name="layer_number" type="int" />
|
||||
<param index="1" name="value" type="bool" />
|
||||
<description>
|
||||
Based on [code]value[/code], enables or disables the specified layer in the [member navigation_layers] bitmask, given a [code]layer_number[/code] between 1 and 32.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="bidirectional" type="bool" setter="set_bidirectional" getter="is_bidirectional" default="true">
|
||||
Whether this link can be traveled in both directions or only from [member start_location] to [member end_location].
|
||||
</member>
|
||||
<member name="enabled" type="bool" setter="set_enabled" getter="is_enabled" default="true">
|
||||
Whether this link is currently active. If [code]false[/code], [method NavigationServer3D.map_get_path] will ignore this link.
|
||||
</member>
|
||||
<member name="end_location" type="Vector3" setter="set_end_location" getter="get_end_location" default="Vector3(0, 0, 0)">
|
||||
Ending position of the link.
|
||||
This position will search out the nearest polygon in the navigation mesh to attach to.
|
||||
The distance the link will search is controlled by [method NavigationServer3D.map_set_link_connection_radius].
|
||||
</member>
|
||||
<member name="enter_cost" type="float" setter="set_enter_cost" getter="get_enter_cost" default="0.0">
|
||||
When pathfinding enters this link from another regions navmesh the [code]enter_cost[/code] value is added to the path distance for determining the shortest path.
|
||||
</member>
|
||||
<member name="navigation_layers" type="int" setter="set_navigation_layers" getter="get_navigation_layers" default="1">
|
||||
A bitfield determining all navigation layers the link belongs to. These navigation layers will be checked when requesting a path with [method NavigationServer3D.map_get_path].
|
||||
</member>
|
||||
<member name="start_location" type="Vector3" setter="set_start_location" getter="get_start_location" default="Vector3(0, 0, 0)">
|
||||
Starting position of the link.
|
||||
This position will search out the nearest polygon in the navigation mesh to attach to.
|
||||
The distance the link will search is controlled by [method NavigationServer3D.map_set_link_connection_radius].
|
||||
</member>
|
||||
<member name="travel_cost" type="float" setter="set_travel_cost" getter="get_travel_cost" default="1.0">
|
||||
When pathfinding moves along the link the traveled distance is multiplied with [code]travel_cost[/code] for determining the shortest path.
|
||||
</member>
|
||||
</members>
|
||||
</class>
|
||||
@ -0,0 +1,4 @@
|
||||
<svg version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="m12.386 5.3097c-0.69157-0.021112-1.3071 0.36382-1.7492 0.86685-0.58 0.58-1.16 1.16-1.74 1.74 0.4588-0.28502 1.0599-0.064948 1.4771-0.037996 0.45549-0.44357 0.89024-0.91006 1.3596-1.3383 0.56256-0.44564 1.4906-0.15731 1.7028 0.52802 0.18967 0.4871-0.049221 1.0098-0.43284 1.3208-0.70048 0.68896-1.3789 1.4022-2.0935 2.0755-0.47999 0.3725-1.2044 0.226-1.5679-0.24034-0.38763-0.38194-1.0641 0.16031-0.78317 0.6241 0.6767 0.94379 2.1573 1.1282 3.0411 0.36751 0.80287-0.7704 1.5793-1.5696 2.3665-2.3564 0.79925-0.83719 0.70104-2.3112-0.19552-3.0393-0.38108-0.32877-0.8822-0.5119-1.385-0.51049zm-3.051 3.051c-0.69157-0.021106-1.3071 0.36382-1.7492 0.86685-0.67513 0.68452-1.37 1.3506-2.0319 2.0474-0.75433 0.87744-0.58087 2.3428 0.34933 3.0252 0.84748 0.68613 2.192 0.54839 2.8998-0.27341 0.63032-0.63031 1.2606-1.2606 1.8909-1.8909-0.4587 0.28554-1.0602 0.0659-1.477 0.038069-0.45445 0.44348-0.88773 0.91034-1.3564 1.3383-0.56256 0.44565-1.4906 0.15731-1.7028-0.52802-0.18967-0.4871 0.049229-1.0098 0.43284-1.3208 0.70048-0.68896 1.3789-1.4022 2.0935-2.0755 0.48-0.3725 1.2044-0.22601 1.5679 0.24036 0.38733 0.38325 1.064-0.16067 0.78313-0.6241-0.39353-0.52481-1.0429-0.84871-1.7002-0.8434z" fill="#8ea6f4" fill-opacity=".99608" stroke-linecap="round" stroke-linejoin="round" stroke-width=".013911"/>
|
||||
<path d="m2 1c-0.61942-0.0066969-1.0877 0.60314-1 1.198 0.00345 3.968-0.006897 7.9364 0.00517 11.904 0.043388 0.62851 0.69346 0.98513 1.272 0.89776h2.5896c-0.77174-0.5015-1.2078-1.2613-1.3143-2.3356-0.11601-1.1701 0.63729-2.024 1.6748-3.1566 0.65335-0.71326 1.4757-1.5822 2.3587-2.3316 0.76308-0.64765 1.7509-1.679 2.9376-2.578 0.91259-0.69136 2.2893-0.74691 3.1014-0.33143 0.91184 0.46649 1.2635 1.1209 1.4067 1.3826-0.0052-2.335-0.02135-1.3526-0.03955-3.6863 5e-3 -0.64349-0.67497-1.0568-1.2694-0.96289z" fill="#8ea6f4" fill-opacity=".99608"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
@ -0,0 +1,4 @@
|
||||
<svg version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="m12.386 5.3097c-0.69157-0.021112-1.3071 0.36382-1.7492 0.86685-0.58 0.58-1.16 1.16-1.74 1.74 0.4588-0.28502 1.0599-0.064948 1.4771-0.037996 0.45549-0.44357 0.89024-0.91006 1.3596-1.3383 0.56256-0.44564 1.4906-0.15731 1.7028 0.52802 0.18967 0.4871-0.049221 1.0098-0.43284 1.3208-0.70048 0.68896-1.3789 1.4022-2.0935 2.0755-0.47999 0.3725-1.2044 0.226-1.5679-0.24034-0.38763-0.38194-1.0641 0.16031-0.78317 0.6241 0.6767 0.94379 2.1573 1.1282 3.0411 0.36751 0.80287-0.7704 1.5793-1.5696 2.3665-2.3564 0.79925-0.83719 0.70104-2.3112-0.19552-3.0393-0.38108-0.32877-0.8822-0.5119-1.385-0.51049zm-3.051 3.051c-0.69157-0.021106-1.3071 0.36382-1.7492 0.86685-0.67513 0.68452-1.37 1.3506-2.0319 2.0474-0.75433 0.87744-0.58087 2.3428 0.34933 3.0252 0.84748 0.68613 2.192 0.54839 2.8998-0.27341 0.63032-0.63031 1.2606-1.2606 1.8909-1.8909-0.4587 0.28554-1.0602 0.0659-1.477 0.038069-0.45445 0.44348-0.88773 0.91034-1.3564 1.3383-0.56256 0.44565-1.4906 0.15731-1.7028-0.52802-0.18967-0.4871 0.049229-1.0098 0.43284-1.3208 0.70048-0.68896 1.3789-1.4022 2.0935-2.0755 0.48-0.3725 1.2044-0.22601 1.5679 0.24036 0.38733 0.38325 1.064-0.16067 0.78313-0.6241-0.39353-0.52481-1.0429-0.84871-1.7002-0.8434z" fill="#fc7e7e" fill-opacity=".99608" stroke-linecap="round" stroke-linejoin="round" stroke-width=".013911"/>
|
||||
<path d="m2 1c-0.61942-0.0066969-1.0877 0.60314-1 1.198 0.00345 3.968-0.006897 7.9364 0.00517 11.904 0.043388 0.62851 0.69346 0.98513 1.272 0.89776h2.5896c-0.77174-0.5015-1.2078-1.2613-1.3143-2.3356-0.11601-1.1701 0.63729-2.024 1.6748-3.1566 0.65335-0.71326 1.4757-1.5822 2.3587-2.3316 0.76308-0.64765 1.7509-1.679 2.9376-2.578 0.91259-0.69136 2.2893-0.74691 3.1014-0.33143 0.91184 0.46649 1.2635 1.1209 1.4067 1.3826-0.0052-2.335-0.02135-1.3526-0.03955-3.6863 5e-3 -0.64349-0.67497-1.0568-1.2694-0.96289z" fill="#fc7d7d" fill-opacity=".99608"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
@ -0,0 +1,191 @@
|
||||
/*************************************************************************/
|
||||
/* navigation_link_2d_editor_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "navigation_link_2d_editor_plugin.h"
|
||||
|
||||
#include "canvas_item_editor_plugin.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "editor/editor_undo_redo_manager.h"
|
||||
#include "servers/navigation_server_3d.h"
|
||||
|
||||
void NavigationLink2DEditor::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
get_tree()->connect("node_removed", callable_mp(this, &NavigationLink2DEditor::_node_removed));
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
get_tree()->disconnect("node_removed", callable_mp(this, &NavigationLink2DEditor::_node_removed));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationLink2DEditor::_node_removed(Node *p_node) {
|
||||
if (p_node == node) {
|
||||
node = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NavigationLink2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
|
||||
if (!node || !node->is_visible_in_tree()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
|
||||
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
|
||||
|
||||
Ref<InputEventMouseButton> mb = p_event;
|
||||
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT) {
|
||||
if (mb->is_pressed()) {
|
||||
// Start location
|
||||
if (xform.xform(node->get_start_location()).distance_to(mb->get_position()) < grab_threshold) {
|
||||
start_grabbed = true;
|
||||
original_start_location = node->get_start_location();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
start_grabbed = false;
|
||||
}
|
||||
|
||||
// End location
|
||||
if (xform.xform(node->get_end_location()).distance_to(mb->get_position()) < grab_threshold) {
|
||||
end_grabbed = true;
|
||||
original_end_location = node->get_end_location();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
end_grabbed = false;
|
||||
}
|
||||
} else {
|
||||
if (start_grabbed) {
|
||||
undo_redo->create_action(TTR("Set start_location"));
|
||||
undo_redo->add_do_method(node, "set_start_location", node->get_start_location());
|
||||
undo_redo->add_do_method(canvas_item_editor, "update_viewport");
|
||||
undo_redo->add_undo_method(node, "set_start_location", original_start_location);
|
||||
undo_redo->add_undo_method(canvas_item_editor, "update_viewport");
|
||||
undo_redo->commit_action();
|
||||
|
||||
start_grabbed = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (end_grabbed) {
|
||||
undo_redo->create_action(TTR("Set end_location"));
|
||||
undo_redo->add_do_method(node, "set_end_location", node->get_end_location());
|
||||
undo_redo->add_do_method(canvas_item_editor, "update_viewport");
|
||||
undo_redo->add_undo_method(node, "set_end_location", original_end_location);
|
||||
undo_redo->add_undo_method(canvas_item_editor, "update_viewport");
|
||||
undo_redo->commit_action();
|
||||
|
||||
end_grabbed = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<InputEventMouseMotion> mm = p_event;
|
||||
if (mm.is_valid()) {
|
||||
Vector2 point = canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position()));
|
||||
point = node->get_global_transform().affine_inverse().xform(point);
|
||||
|
||||
if (start_grabbed) {
|
||||
node->set_start_location(point);
|
||||
canvas_item_editor->update_viewport();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (end_grabbed) {
|
||||
node->set_end_location(point);
|
||||
canvas_item_editor->update_viewport();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NavigationLink2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
|
||||
if (!node || !node->is_visible_in_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
|
||||
Vector2 global_start_location = gt.xform(node->get_start_location());
|
||||
Vector2 global_end_location = gt.xform(node->get_end_location());
|
||||
|
||||
// Only drawing the handles here, since the debug rendering will fill in the rest.
|
||||
const Ref<Texture2D> handle = get_theme_icon(SNAME("EditorHandle"), SNAME("EditorIcons"));
|
||||
p_overlay->draw_texture(handle, global_start_location - handle->get_size() / 2);
|
||||
p_overlay->draw_texture(handle, global_end_location - handle->get_size() / 2);
|
||||
}
|
||||
|
||||
void NavigationLink2DEditor::edit(NavigationLink2D *p_node) {
|
||||
if (!canvas_item_editor) {
|
||||
canvas_item_editor = CanvasItemEditor::get_singleton();
|
||||
}
|
||||
|
||||
if (p_node) {
|
||||
node = p_node;
|
||||
} else {
|
||||
node = nullptr;
|
||||
}
|
||||
|
||||
canvas_item_editor->update_viewport();
|
||||
}
|
||||
|
||||
NavigationLink2DEditor::NavigationLink2DEditor() {
|
||||
undo_redo = EditorNode::get_undo_redo();
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
|
||||
void NavigationLink2DEditorPlugin::edit(Object *p_object) {
|
||||
editor->edit(Object::cast_to<NavigationLink2D>(p_object));
|
||||
}
|
||||
|
||||
bool NavigationLink2DEditorPlugin::handles(Object *p_object) const {
|
||||
return Object::cast_to<NavigationLink2D>(p_object) != nullptr;
|
||||
}
|
||||
|
||||
void NavigationLink2DEditorPlugin::make_visible(bool p_visible) {
|
||||
if (!p_visible) {
|
||||
edit(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
NavigationLink2DEditorPlugin::NavigationLink2DEditorPlugin() {
|
||||
editor = memnew(NavigationLink2DEditor);
|
||||
EditorNode::get_singleton()->get_gui_base()->add_child(editor);
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
/*************************************************************************/
|
||||
/* navigation_link_2d_editor_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef NAVIGATION_LINK_2D_EDITOR_PLUGIN_H
|
||||
#define NAVIGATION_LINK_2D_EDITOR_PLUGIN_H
|
||||
|
||||
#include "editor/editor_plugin.h"
|
||||
#include "scene/2d/navigation_link_2d.h"
|
||||
|
||||
class CanvasItemEditor;
|
||||
class EditorUndoRedoManager;
|
||||
|
||||
class NavigationLink2DEditor : public Control {
|
||||
GDCLASS(NavigationLink2DEditor, Control);
|
||||
|
||||
Ref<EditorUndoRedoManager> undo_redo;
|
||||
CanvasItemEditor *canvas_item_editor = nullptr;
|
||||
NavigationLink2D *node;
|
||||
|
||||
bool start_grabbed = false;
|
||||
Vector2 original_start_location;
|
||||
|
||||
bool end_grabbed = false;
|
||||
Vector2 original_end_location;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
void _node_removed(Node *p_node);
|
||||
|
||||
public:
|
||||
bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
|
||||
void forward_canvas_draw_over_viewport(Control *p_overlay);
|
||||
void edit(NavigationLink2D *p_node);
|
||||
|
||||
NavigationLink2DEditor();
|
||||
};
|
||||
|
||||
class NavigationLink2DEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(NavigationLink2DEditorPlugin, EditorPlugin);
|
||||
|
||||
NavigationLink2DEditor *editor = nullptr;
|
||||
|
||||
public:
|
||||
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override { return editor->forward_canvas_gui_input(p_event); }
|
||||
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override { editor->forward_canvas_draw_over_viewport(p_overlay); }
|
||||
|
||||
virtual String get_name() const override { return "NavigationLink2D"; }
|
||||
bool has_main_screen() const override { return false; }
|
||||
virtual void edit(Object *p_object) override;
|
||||
virtual bool handles(Object *p_object) const override;
|
||||
virtual void make_visible(bool p_visible) override;
|
||||
|
||||
NavigationLink2DEditorPlugin();
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_LINK_2D_EDITOR_PLUGIN_H
|
||||
@ -0,0 +1,56 @@
|
||||
/*************************************************************************/
|
||||
/* nav_base.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef NAV_BASE_H
|
||||
#define NAV_BASE_H
|
||||
|
||||
#include "nav_rid.h"
|
||||
#include "nav_utils.h"
|
||||
|
||||
class NavMap;
|
||||
|
||||
class NavBase : public NavRid {
|
||||
protected:
|
||||
uint32_t navigation_layers = 1;
|
||||
float enter_cost = 0.0;
|
||||
float travel_cost = 1.0;
|
||||
|
||||
public:
|
||||
void set_navigation_layers(uint32_t p_navigation_layers) { navigation_layers = p_navigation_layers; }
|
||||
uint32_t get_navigation_layers() const { return navigation_layers; }
|
||||
|
||||
void set_enter_cost(float p_enter_cost) { enter_cost = MAX(p_enter_cost, 0.0); }
|
||||
float get_enter_cost() const { return enter_cost; }
|
||||
|
||||
void set_travel_cost(float p_travel_cost) { travel_cost = MAX(p_travel_cost, 0.0); }
|
||||
float get_travel_cost() const { return travel_cost; }
|
||||
};
|
||||
|
||||
#endif // NAV_BASE_H
|
||||
@ -0,0 +1,60 @@
|
||||
/*************************************************************************/
|
||||
/* nav_link.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "nav_link.h"
|
||||
|
||||
#include "nav_map.h"
|
||||
|
||||
void NavLink::set_map(NavMap *p_map) {
|
||||
map = p_map;
|
||||
link_dirty = true;
|
||||
}
|
||||
|
||||
void NavLink::set_bidirectional(bool p_bidirectional) {
|
||||
bidirectional = p_bidirectional;
|
||||
link_dirty = true;
|
||||
}
|
||||
|
||||
void NavLink::set_start_location(const Vector3 p_location) {
|
||||
start_location = p_location;
|
||||
link_dirty = true;
|
||||
}
|
||||
|
||||
void NavLink::set_end_location(const Vector3 p_location) {
|
||||
end_location = p_location;
|
||||
link_dirty = true;
|
||||
}
|
||||
|
||||
bool NavLink::check_dirty() {
|
||||
const bool was_dirty = link_dirty;
|
||||
|
||||
link_dirty = false;
|
||||
return was_dirty;
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
/*************************************************************************/
|
||||
/* nav_link.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef NAV_LINK_H
|
||||
#define NAV_LINK_H
|
||||
|
||||
#include "nav_base.h"
|
||||
#include "nav_utils.h"
|
||||
|
||||
class NavLink : public NavBase {
|
||||
NavMap *map = nullptr;
|
||||
bool bidirectional = true;
|
||||
Vector3 start_location = Vector3();
|
||||
Vector3 end_location = Vector3();
|
||||
|
||||
bool link_dirty = true;
|
||||
|
||||
public:
|
||||
void set_map(NavMap *p_map);
|
||||
NavMap *get_map() const {
|
||||
return map;
|
||||
}
|
||||
|
||||
void set_bidirectional(bool p_bidirectional);
|
||||
bool is_bidirectional() const {
|
||||
return bidirectional;
|
||||
}
|
||||
|
||||
void set_start_location(Vector3 p_location);
|
||||
Vector3 get_start_location() const {
|
||||
return start_location;
|
||||
}
|
||||
|
||||
void set_end_location(Vector3 p_location);
|
||||
Vector3 get_end_location() const {
|
||||
return end_location;
|
||||
}
|
||||
|
||||
bool check_dirty();
|
||||
};
|
||||
|
||||
#endif // NAV_LINK_H
|
||||
@ -0,0 +1,284 @@
|
||||
/*************************************************************************/
|
||||
/* navigation_link_2d.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "navigation_link_2d.h"
|
||||
|
||||
#include "core/math/geometry_2d.h"
|
||||
#include "scene/resources/world_2d.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
#include "servers/navigation_server_3d.h"
|
||||
|
||||
void NavigationLink2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationLink2D::set_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationLink2D::is_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_bidirectional", "bidirectional"), &NavigationLink2D::set_bidirectional);
|
||||
ClassDB::bind_method(D_METHOD("is_bidirectional"), &NavigationLink2D::is_bidirectional);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationLink2D::set_navigation_layers);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationLink2D::get_navigation_layers);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_layer_value", "layer_number", "value"), &NavigationLink2D::set_navigation_layer_value);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_layer_value", "layer_number"), &NavigationLink2D::get_navigation_layer_value);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_start_location", "location"), &NavigationLink2D::set_start_location);
|
||||
ClassDB::bind_method(D_METHOD("get_start_location"), &NavigationLink2D::get_start_location);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_end_location", "location"), &NavigationLink2D::set_end_location);
|
||||
ClassDB::bind_method(D_METHOD("get_end_location"), &NavigationLink2D::get_end_location);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_enter_cost", "enter_cost"), &NavigationLink2D::set_enter_cost);
|
||||
ClassDB::bind_method(D_METHOD("get_enter_cost"), &NavigationLink2D::get_enter_cost);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_travel_cost", "travel_cost"), &NavigationLink2D::set_travel_cost);
|
||||
ClassDB::bind_method(D_METHOD("get_travel_cost"), &NavigationLink2D::get_travel_cost);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bidirectional"), "set_bidirectional", "is_bidirectional");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "start_location"), "set_start_location", "get_start_location");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "end_location"), "set_end_location", "get_end_location");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "enter_cost"), "set_enter_cost", "get_enter_cost");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "travel_cost"), "set_travel_cost", "get_travel_cost");
|
||||
}
|
||||
|
||||
void NavigationLink2D::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
if (enabled) {
|
||||
NavigationServer2D::get_singleton()->link_set_map(link, get_world_2d()->get_navigation_map());
|
||||
|
||||
// Update global positions for the link.
|
||||
Transform2D gt = get_global_transform();
|
||||
NavigationServer2D::get_singleton()->link_set_start_location(link, gt.xform(start_location));
|
||||
NavigationServer2D::get_singleton()->link_set_end_location(link, gt.xform(end_location));
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||
// Update global positions for the link.
|
||||
Transform2D gt = get_global_transform();
|
||||
NavigationServer2D::get_singleton()->link_set_start_location(link, gt.xform(start_location));
|
||||
NavigationServer2D::get_singleton()->link_set_end_location(link, gt.xform(end_location));
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
NavigationServer2D::get_singleton()->link_set_map(link, RID());
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled())) {
|
||||
Color color;
|
||||
if (enabled) {
|
||||
color = NavigationServer2D::get_singleton()->get_debug_navigation_link_connection_color();
|
||||
} else {
|
||||
color = NavigationServer2D::get_singleton()->get_debug_navigation_link_connection_disabled_color();
|
||||
}
|
||||
|
||||
real_t radius = NavigationServer2D::get_singleton()->map_get_link_connection_radius(get_world_2d()->get_navigation_map());
|
||||
|
||||
draw_line(get_start_location(), get_end_location(), color);
|
||||
draw_arc(get_start_location(), radius, 0, Math_TAU, 10, color);
|
||||
draw_arc(get_end_location(), radius, 0, Math_TAU, 10, color);
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
Rect2 NavigationLink2D::_edit_get_rect() const {
|
||||
real_t radius = NavigationServer2D::get_singleton()->map_get_link_connection_radius(get_world_2d()->get_navigation_map());
|
||||
|
||||
Rect2 rect(get_start_location(), Size2());
|
||||
rect.expand_to(get_end_location());
|
||||
rect.grow_by(radius);
|
||||
return rect;
|
||||
}
|
||||
|
||||
bool NavigationLink2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
|
||||
Point2 segment[2] = { get_start_location(), get_end_location() };
|
||||
|
||||
Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, segment);
|
||||
return p_point.distance_to(closest_point) < p_tolerance;
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
void NavigationLink2D::set_enabled(bool p_enabled) {
|
||||
if (enabled == p_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
enabled = p_enabled;
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
NavigationServer2D::get_singleton()->link_set_map(link, RID());
|
||||
} else {
|
||||
NavigationServer2D::get_singleton()->link_set_map(link, get_world_2d()->get_navigation_map());
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) {
|
||||
update();
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
void NavigationLink2D::set_bidirectional(bool p_bidirectional) {
|
||||
if (bidirectional == p_bidirectional) {
|
||||
return;
|
||||
}
|
||||
|
||||
bidirectional = p_bidirectional;
|
||||
|
||||
NavigationServer2D::get_singleton()->link_set_bidirectional(link, bidirectional);
|
||||
}
|
||||
|
||||
void NavigationLink2D::set_navigation_layers(uint32_t p_navigation_layers) {
|
||||
if (navigation_layers == p_navigation_layers) {
|
||||
return;
|
||||
}
|
||||
|
||||
navigation_layers = p_navigation_layers;
|
||||
|
||||
NavigationServer2D::get_singleton()->link_set_navigation_layers(link, navigation_layers);
|
||||
}
|
||||
|
||||
void NavigationLink2D::set_navigation_layer_value(int p_layer_number, bool p_value) {
|
||||
ERR_FAIL_COND_MSG(p_layer_number < 1, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
ERR_FAIL_COND_MSG(p_layer_number > 32, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
|
||||
uint32_t _navigation_layers = get_navigation_layers();
|
||||
|
||||
if (p_value) {
|
||||
_navigation_layers |= 1 << (p_layer_number - 1);
|
||||
} else {
|
||||
_navigation_layers &= ~(1 << (p_layer_number - 1));
|
||||
}
|
||||
|
||||
set_navigation_layers(_navigation_layers);
|
||||
}
|
||||
|
||||
bool NavigationLink2D::get_navigation_layer_value(int p_layer_number) const {
|
||||
ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
|
||||
return get_navigation_layers() & (1 << (p_layer_number - 1));
|
||||
}
|
||||
|
||||
void NavigationLink2D::set_start_location(Vector2 p_location) {
|
||||
if (start_location.is_equal_approx(p_location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
start_location = p_location;
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Transform2D gt = get_global_transform();
|
||||
NavigationServer2D::get_singleton()->link_set_start_location(link, gt.xform(start_location));
|
||||
|
||||
update_configuration_warnings();
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) {
|
||||
update();
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
void NavigationLink2D::set_end_location(Vector2 p_location) {
|
||||
if (end_location.is_equal_approx(p_location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
end_location = p_location;
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Transform2D gt = get_global_transform();
|
||||
NavigationServer2D::get_singleton()->link_set_end_location(link, gt.xform(end_location));
|
||||
|
||||
update_configuration_warnings();
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) {
|
||||
update();
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
void NavigationLink2D::set_enter_cost(real_t p_enter_cost) {
|
||||
ERR_FAIL_COND_MSG(p_enter_cost < 0.0, "The enter_cost must be positive.");
|
||||
if (Math::is_equal_approx(enter_cost, p_enter_cost)) {
|
||||
return;
|
||||
}
|
||||
|
||||
enter_cost = p_enter_cost;
|
||||
|
||||
NavigationServer2D::get_singleton()->link_set_enter_cost(link, enter_cost);
|
||||
}
|
||||
|
||||
void NavigationLink2D::set_travel_cost(real_t p_travel_cost) {
|
||||
ERR_FAIL_COND_MSG(p_travel_cost < 0.0, "The travel_cost must be positive.");
|
||||
if (Math::is_equal_approx(travel_cost, p_travel_cost)) {
|
||||
return;
|
||||
}
|
||||
|
||||
travel_cost = p_travel_cost;
|
||||
|
||||
NavigationServer2D::get_singleton()->link_set_travel_cost(link, travel_cost);
|
||||
}
|
||||
|
||||
TypedArray<String> NavigationLink2D::get_configuration_warnings() const {
|
||||
TypedArray<String> warnings = Node::get_configuration_warnings();
|
||||
|
||||
if (start_location.is_equal_approx(end_location)) {
|
||||
warnings.push_back(RTR("NavigationLink2D start location should be different than the end location to be useful."));
|
||||
}
|
||||
|
||||
return warnings;
|
||||
}
|
||||
|
||||
NavigationLink2D::NavigationLink2D() {
|
||||
link = NavigationServer2D::get_singleton()->link_create();
|
||||
set_notify_transform(true);
|
||||
}
|
||||
|
||||
NavigationLink2D::~NavigationLink2D() {
|
||||
NavigationServer2D::get_singleton()->free(link);
|
||||
link = RID();
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
/*************************************************************************/
|
||||
/* navigation_link_2d.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef NAVIGATION_LINK_2D_H
|
||||
#define NAVIGATION_LINK_2D_H
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
class NavigationLink2D : public Node2D {
|
||||
GDCLASS(NavigationLink2D, Node2D);
|
||||
|
||||
bool enabled = true;
|
||||
RID link = RID();
|
||||
bool bidirectional = true;
|
||||
uint32_t navigation_layers = 1;
|
||||
Vector2 end_location = Vector2();
|
||||
Vector2 start_location = Vector2();
|
||||
real_t enter_cost = 0.0;
|
||||
real_t travel_cost = 1.0;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual Rect2 _edit_get_rect() const override;
|
||||
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
|
||||
#endif
|
||||
|
||||
void set_enabled(bool p_enabled);
|
||||
bool is_enabled() const { return enabled; }
|
||||
|
||||
void set_bidirectional(bool p_bidirectional);
|
||||
bool is_bidirectional() const { return bidirectional; }
|
||||
|
||||
void set_navigation_layers(uint32_t p_navigation_layers);
|
||||
uint32_t get_navigation_layers() const { return navigation_layers; }
|
||||
|
||||
void set_navigation_layer_value(int p_layer_number, bool p_value);
|
||||
bool get_navigation_layer_value(int p_layer_number) const;
|
||||
|
||||
void set_start_location(Vector2 p_location);
|
||||
Vector2 get_start_location() const { return start_location; }
|
||||
|
||||
void set_end_location(Vector2 p_location);
|
||||
Vector2 get_end_location() const { return end_location; }
|
||||
|
||||
void set_enter_cost(real_t p_enter_cost);
|
||||
real_t get_enter_cost() const { return enter_cost; }
|
||||
|
||||
void set_travel_cost(real_t p_travel_cost);
|
||||
real_t get_travel_cost() const { return travel_cost; }
|
||||
|
||||
TypedArray<String> get_configuration_warnings() const override;
|
||||
|
||||
NavigationLink2D();
|
||||
~NavigationLink2D();
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_LINK_2D_H
|
||||
@ -0,0 +1,389 @@
|
||||
/*************************************************************************/
|
||||
/* navigation_link_3d.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "navigation_link_3d.h"
|
||||
|
||||
#include "mesh_instance_3d.h"
|
||||
#include "servers/navigation_server_3d.h"
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
void NavigationLink3D::_update_debug_mesh() {
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
// don't update inside Editor as node 3d gizmo takes care of this
|
||||
// as collisions and selections for Editor Viewport need to be updated
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NavigationServer3D::get_singleton()->get_debug_enabled()) {
|
||||
if (debug_instance.is_valid()) {
|
||||
RS::get_singleton()->instance_set_visible(debug_instance, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!debug_instance.is_valid()) {
|
||||
debug_instance = RenderingServer::get_singleton()->instance_create();
|
||||
}
|
||||
|
||||
if (!debug_mesh.is_valid()) {
|
||||
debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
}
|
||||
|
||||
RID nav_map = get_world_3d()->get_navigation_map();
|
||||
real_t search_radius = NavigationServer3D::get_singleton()->map_get_link_connection_radius(nav_map);
|
||||
Vector3 up_vector = NavigationServer3D::get_singleton()->map_get_up(nav_map);
|
||||
Vector3::Axis up_axis = up_vector.max_axis_index();
|
||||
|
||||
debug_mesh->clear_surfaces();
|
||||
|
||||
Vector<Vector3> lines;
|
||||
|
||||
// Draw line between the points.
|
||||
lines.push_back(start_location);
|
||||
lines.push_back(end_location);
|
||||
|
||||
// Draw start location search radius
|
||||
for (int i = 0; i < 30; i++) {
|
||||
// Create a circle
|
||||
const float ra = Math::deg_to_rad((float)(i * 12));
|
||||
const float rb = Math::deg_to_rad((float)((i + 1) * 12));
|
||||
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * search_radius;
|
||||
const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * search_radius;
|
||||
|
||||
// Draw axis-aligned circle
|
||||
switch (up_axis) {
|
||||
case Vector3::AXIS_X:
|
||||
lines.append(start_location + Vector3(0, a.x, a.y));
|
||||
lines.append(start_location + Vector3(0, b.x, b.y));
|
||||
break;
|
||||
case Vector3::AXIS_Y:
|
||||
lines.append(start_location + Vector3(a.x, 0, a.y));
|
||||
lines.append(start_location + Vector3(b.x, 0, b.y));
|
||||
break;
|
||||
case Vector3::AXIS_Z:
|
||||
lines.append(start_location + Vector3(a.x, a.y, 0));
|
||||
lines.append(start_location + Vector3(b.x, b.y, 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw end location search radius
|
||||
for (int i = 0; i < 30; i++) {
|
||||
// Create a circle
|
||||
const float ra = Math::deg_to_rad((float)(i * 12));
|
||||
const float rb = Math::deg_to_rad((float)((i + 1) * 12));
|
||||
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * search_radius;
|
||||
const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * search_radius;
|
||||
|
||||
// Draw axis-aligned circle
|
||||
switch (up_axis) {
|
||||
case Vector3::AXIS_X:
|
||||
lines.append(end_location + Vector3(0, a.x, a.y));
|
||||
lines.append(end_location + Vector3(0, b.x, b.y));
|
||||
break;
|
||||
case Vector3::AXIS_Y:
|
||||
lines.append(end_location + Vector3(a.x, 0, a.y));
|
||||
lines.append(end_location + Vector3(b.x, 0, b.y));
|
||||
break;
|
||||
case Vector3::AXIS_Z:
|
||||
lines.append(end_location + Vector3(a.x, a.y, 0));
|
||||
lines.append(end_location + Vector3(b.x, b.y, 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Array mesh_array;
|
||||
mesh_array.resize(Mesh::ARRAY_MAX);
|
||||
mesh_array[Mesh::ARRAY_VERTEX] = lines;
|
||||
|
||||
debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, mesh_array);
|
||||
|
||||
RS::get_singleton()->instance_set_base(debug_instance, debug_mesh->get_rid());
|
||||
RS::get_singleton()->instance_set_scenario(debug_instance, get_world_3d()->get_scenario());
|
||||
RS::get_singleton()->instance_set_visible(debug_instance, is_visible_in_tree());
|
||||
|
||||
Ref<StandardMaterial3D> link_material = NavigationServer3D::get_singleton_mut()->get_debug_navigation_link_connections_material();
|
||||
Ref<StandardMaterial3D> disabled_link_material = NavigationServer3D::get_singleton_mut()->get_debug_navigation_link_connections_disabled_material();
|
||||
|
||||
if (enabled) {
|
||||
RS::get_singleton()->instance_set_surface_override_material(debug_instance, 0, link_material->get_rid());
|
||||
} else {
|
||||
RS::get_singleton()->instance_set_surface_override_material(debug_instance, 0, disabled_link_material->get_rid());
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void NavigationLink3D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationLink3D::set_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationLink3D::is_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_bidirectional", "bidirectional"), &NavigationLink3D::set_bidirectional);
|
||||
ClassDB::bind_method(D_METHOD("is_bidirectional"), &NavigationLink3D::is_bidirectional);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationLink3D::set_navigation_layers);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationLink3D::get_navigation_layers);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_layer_value", "layer_number", "value"), &NavigationLink3D::set_navigation_layer_value);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_layer_value", "layer_number"), &NavigationLink3D::get_navigation_layer_value);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_start_location", "location"), &NavigationLink3D::set_start_location);
|
||||
ClassDB::bind_method(D_METHOD("get_start_location"), &NavigationLink3D::get_start_location);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_end_location", "location"), &NavigationLink3D::set_end_location);
|
||||
ClassDB::bind_method(D_METHOD("get_end_location"), &NavigationLink3D::get_end_location);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_enter_cost", "enter_cost"), &NavigationLink3D::set_enter_cost);
|
||||
ClassDB::bind_method(D_METHOD("get_enter_cost"), &NavigationLink3D::get_enter_cost);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_travel_cost", "travel_cost"), &NavigationLink3D::set_travel_cost);
|
||||
ClassDB::bind_method(D_METHOD("get_travel_cost"), &NavigationLink3D::get_travel_cost);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bidirectional"), "set_bidirectional", "is_bidirectional");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_3D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "start_location"), "set_start_location", "get_start_location");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "end_location"), "set_end_location", "get_end_location");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "enter_cost"), "set_enter_cost", "get_enter_cost");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "travel_cost"), "set_travel_cost", "get_travel_cost");
|
||||
}
|
||||
|
||||
void NavigationLink3D::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
if (enabled) {
|
||||
NavigationServer3D::get_singleton()->link_set_map(link, get_world_3d()->get_navigation_map());
|
||||
|
||||
// Update global positions for the link.
|
||||
Transform3D gt = get_global_transform();
|
||||
NavigationServer3D::get_singleton()->link_set_start_location(link, gt.xform(start_location));
|
||||
NavigationServer3D::get_singleton()->link_set_end_location(link, gt.xform(end_location));
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
_update_debug_mesh();
|
||||
#endif // DEBUG_ENABLED
|
||||
} break;
|
||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||
// Update global positions for the link.
|
||||
Transform3D gt = get_global_transform();
|
||||
NavigationServer3D::get_singleton()->link_set_start_location(link, gt.xform(start_location));
|
||||
NavigationServer3D::get_singleton()->link_set_end_location(link, gt.xform(end_location));
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (is_inside_tree() && debug_instance.is_valid()) {
|
||||
RS::get_singleton()->instance_set_transform(debug_instance, get_global_transform());
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
NavigationServer3D::get_singleton()->link_set_map(link, RID());
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (debug_instance.is_valid()) {
|
||||
RS::get_singleton()->instance_set_scenario(debug_instance, RID());
|
||||
RS::get_singleton()->instance_set_visible(debug_instance, false);
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
NavigationLink3D::NavigationLink3D() {
|
||||
link = NavigationServer3D::get_singleton()->link_create();
|
||||
set_notify_transform(true);
|
||||
}
|
||||
|
||||
NavigationLink3D::~NavigationLink3D() {
|
||||
NavigationServer3D::get_singleton()->free(link);
|
||||
link = RID();
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (debug_instance.is_valid()) {
|
||||
RenderingServer::get_singleton()->free(debug_instance);
|
||||
}
|
||||
if (debug_mesh.is_valid()) {
|
||||
RenderingServer::get_singleton()->free(debug_mesh->get_rid());
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
void NavigationLink3D::set_enabled(bool p_enabled) {
|
||||
if (enabled == p_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
enabled = p_enabled;
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
NavigationServer3D::get_singleton()->link_set_map(link, get_world_3d()->get_navigation_map());
|
||||
} else {
|
||||
NavigationServer3D::get_singleton()->link_set_map(link, RID());
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (debug_instance.is_valid() && debug_mesh.is_valid()) {
|
||||
if (enabled) {
|
||||
Ref<StandardMaterial3D> link_material = NavigationServer3D::get_singleton_mut()->get_debug_navigation_link_connections_material();
|
||||
RS::get_singleton()->instance_set_surface_override_material(debug_instance, 0, link_material->get_rid());
|
||||
} else {
|
||||
Ref<StandardMaterial3D> disabled_link_material = NavigationServer3D::get_singleton_mut()->get_debug_navigation_link_connections_disabled_material();
|
||||
RS::get_singleton()->instance_set_surface_override_material(debug_instance, 0, disabled_link_material->get_rid());
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
update_gizmos();
|
||||
}
|
||||
|
||||
void NavigationLink3D::set_bidirectional(bool p_bidirectional) {
|
||||
if (bidirectional == p_bidirectional) {
|
||||
return;
|
||||
}
|
||||
|
||||
bidirectional = p_bidirectional;
|
||||
|
||||
NavigationServer3D::get_singleton()->link_set_bidirectional(link, bidirectional);
|
||||
}
|
||||
|
||||
void NavigationLink3D::set_navigation_layers(uint32_t p_navigation_layers) {
|
||||
if (navigation_layers == p_navigation_layers) {
|
||||
return;
|
||||
}
|
||||
|
||||
navigation_layers = p_navigation_layers;
|
||||
|
||||
NavigationServer3D::get_singleton()->link_set_navigation_layers(link, navigation_layers);
|
||||
}
|
||||
|
||||
void NavigationLink3D::set_navigation_layer_value(int p_layer_number, bool p_value) {
|
||||
ERR_FAIL_COND_MSG(p_layer_number < 1, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
ERR_FAIL_COND_MSG(p_layer_number > 32, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
|
||||
uint32_t _navigation_layers = get_navigation_layers();
|
||||
|
||||
if (p_value) {
|
||||
_navigation_layers |= 1 << (p_layer_number - 1);
|
||||
} else {
|
||||
_navigation_layers &= ~(1 << (p_layer_number - 1));
|
||||
}
|
||||
|
||||
set_navigation_layers(_navigation_layers);
|
||||
}
|
||||
|
||||
bool NavigationLink3D::get_navigation_layer_value(int p_layer_number) const {
|
||||
ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
|
||||
return get_navigation_layers() & (1 << (p_layer_number - 1));
|
||||
}
|
||||
|
||||
void NavigationLink3D::set_start_location(Vector3 p_location) {
|
||||
if (start_location.is_equal_approx(p_location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
start_location = p_location;
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Transform3D gt = get_global_transform();
|
||||
NavigationServer3D::get_singleton()->link_set_start_location(link, gt.xform(start_location));
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
_update_debug_mesh();
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
update_gizmos();
|
||||
update_configuration_warnings();
|
||||
}
|
||||
|
||||
void NavigationLink3D::set_end_location(Vector3 p_location) {
|
||||
if (end_location.is_equal_approx(p_location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
end_location = p_location;
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Transform3D gt = get_global_transform();
|
||||
NavigationServer3D::get_singleton()->link_set_end_location(link, gt.xform(end_location));
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
_update_debug_mesh();
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
update_gizmos();
|
||||
update_configuration_warnings();
|
||||
}
|
||||
|
||||
void NavigationLink3D::set_enter_cost(real_t p_enter_cost) {
|
||||
ERR_FAIL_COND_MSG(p_enter_cost < 0.0, "The enter_cost must be positive.");
|
||||
if (Math::is_equal_approx(enter_cost, p_enter_cost)) {
|
||||
return;
|
||||
}
|
||||
|
||||
enter_cost = p_enter_cost;
|
||||
|
||||
NavigationServer3D::get_singleton()->link_set_enter_cost(link, enter_cost);
|
||||
}
|
||||
|
||||
void NavigationLink3D::set_travel_cost(real_t p_travel_cost) {
|
||||
ERR_FAIL_COND_MSG(p_travel_cost < 0.0, "The travel_cost must be positive.");
|
||||
if (Math::is_equal_approx(travel_cost, p_travel_cost)) {
|
||||
return;
|
||||
}
|
||||
|
||||
travel_cost = p_travel_cost;
|
||||
|
||||
NavigationServer3D::get_singleton()->link_set_travel_cost(link, travel_cost);
|
||||
}
|
||||
|
||||
TypedArray<String> NavigationLink3D::get_configuration_warnings() const {
|
||||
TypedArray<String> warnings = Node::get_configuration_warnings();
|
||||
|
||||
if (start_location.is_equal_approx(end_location)) {
|
||||
warnings.push_back(RTR("NavigationLink3D start location should be different than the end location to be useful."));
|
||||
}
|
||||
|
||||
return warnings;
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
/*************************************************************************/
|
||||
/* navigation_link_3d.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef NAVIGATION_LINK_3D_H
|
||||
#define NAVIGATION_LINK_3D_H
|
||||
|
||||
#include "scene/3d/node_3d.h"
|
||||
|
||||
class NavigationLink3D : public Node3D {
|
||||
GDCLASS(NavigationLink3D, Node3D);
|
||||
|
||||
bool enabled = true;
|
||||
RID link = RID();
|
||||
bool bidirectional = true;
|
||||
uint32_t navigation_layers = 1;
|
||||
Vector3 end_location = Vector3();
|
||||
Vector3 start_location = Vector3();
|
||||
real_t enter_cost = 0.0;
|
||||
real_t travel_cost = 1.0;
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
RID debug_instance;
|
||||
Ref<ArrayMesh> debug_mesh;
|
||||
|
||||
void _update_debug_mesh();
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
NavigationLink3D();
|
||||
~NavigationLink3D();
|
||||
|
||||
void set_enabled(bool p_enabled);
|
||||
bool is_enabled() const { return enabled; }
|
||||
|
||||
void set_bidirectional(bool p_bidirectional);
|
||||
bool is_bidirectional() const { return bidirectional; }
|
||||
|
||||
void set_navigation_layers(uint32_t p_navigation_layers);
|
||||
uint32_t get_navigation_layers() const { return navigation_layers; }
|
||||
|
||||
void set_navigation_layer_value(int p_layer_number, bool p_value);
|
||||
bool get_navigation_layer_value(int p_layer_number) const;
|
||||
|
||||
void set_start_location(Vector3 p_location);
|
||||
Vector3 get_start_location() const { return start_location; }
|
||||
|
||||
void set_end_location(Vector3 p_location);
|
||||
Vector3 get_end_location() const { return end_location; }
|
||||
|
||||
void set_enter_cost(real_t p_enter_cost);
|
||||
real_t get_enter_cost() const { return enter_cost; }
|
||||
|
||||
void set_travel_cost(real_t p_travel_cost);
|
||||
real_t get_travel_cost() const { return travel_cost; }
|
||||
|
||||
TypedArray<String> get_configuration_warnings() const override;
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_LINK_3D_H
|
||||
Loading…
Reference in New Issue