summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-26 22:57:03 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-26 22:57:03 +0100
commit91ad92657ed0ca76151880abec53f7b157d9f3f6 (patch)
tree50b1ead16d11707a841907805d10aa1f9a905a66 /scene/3d
parent3cacc835266af9446e3a51020c4ce1d36e4ad327 (diff)
parentbf1571979cd3cd90b2b5c4581b2947450aa4cd9d (diff)
Merge pull request #69689 from smix8/navagent_rename_location_4.x
Rename Navigation uses of 'location' to 'position'
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/navigation_agent_3d.cpp32
-rw-r--r--scene/3d/navigation_agent_3d.h10
-rw-r--r--scene/3d/navigation_link_3d.cpp98
-rw-r--r--scene/3d/navigation_link_3d.h17
4 files changed, 94 insertions, 63 deletions
diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp
index 0034bf78b9..fe7ddcb06e 100644
--- a/scene/3d/navigation_agent_3d.cpp
+++ b/scene/3d/navigation_agent_3d.cpp
@@ -80,10 +80,10 @@ void NavigationAgent3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &NavigationAgent3D::set_navigation_map);
ClassDB::bind_method(D_METHOD("get_navigation_map"), &NavigationAgent3D::get_navigation_map);
- ClassDB::bind_method(D_METHOD("set_target_location", "location"), &NavigationAgent3D::set_target_location);
- ClassDB::bind_method(D_METHOD("get_target_location"), &NavigationAgent3D::get_target_location);
+ ClassDB::bind_method(D_METHOD("set_target_position", "position"), &NavigationAgent3D::set_target_position);
+ ClassDB::bind_method(D_METHOD("get_target_position"), &NavigationAgent3D::get_target_position);
- ClassDB::bind_method(D_METHOD("get_next_location"), &NavigationAgent3D::get_next_location);
+ ClassDB::bind_method(D_METHOD("get_next_path_position"), &NavigationAgent3D::get_next_path_position);
ClassDB::bind_method(D_METHOD("distance_to_target"), &NavigationAgent3D::distance_to_target);
ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &NavigationAgent3D::set_velocity);
ClassDB::bind_method(D_METHOD("get_current_navigation_result"), &NavigationAgent3D::get_current_navigation_result);
@@ -92,12 +92,12 @@ void NavigationAgent3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_target_reached"), &NavigationAgent3D::is_target_reached);
ClassDB::bind_method(D_METHOD("is_target_reachable"), &NavigationAgent3D::is_target_reachable);
ClassDB::bind_method(D_METHOD("is_navigation_finished"), &NavigationAgent3D::is_navigation_finished);
- ClassDB::bind_method(D_METHOD("get_final_location"), &NavigationAgent3D::get_final_location);
+ ClassDB::bind_method(D_METHOD("get_final_position"), &NavigationAgent3D::get_final_position);
ClassDB::bind_method(D_METHOD("_avoidance_done", "new_velocity"), &NavigationAgent3D::_avoidance_done);
ADD_GROUP("Pathfinding", "");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "target_location", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_target_location", "get_target_location");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "target_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_target_position", "get_target_position");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_desired_distance", PROPERTY_HINT_RANGE, "0.1,100,0.01,suffix:m"), "set_path_desired_distance", "get_path_desired_distance");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "target_desired_distance", PROPERTY_HINT_RANGE, "0.1,100,0.01,suffix:m"), "set_target_desired_distance", "get_target_desired_distance");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent_height_offset", PROPERTY_HINT_RANGE, "-100.0,100,0.01,suffix:m"), "set_agent_height_offset", "get_agent_height_offset");
@@ -344,17 +344,17 @@ real_t NavigationAgent3D::get_path_max_distance() {
return path_max_distance;
}
-void NavigationAgent3D::set_target_location(Vector3 p_location) {
- target_location = p_location;
+void NavigationAgent3D::set_target_position(Vector3 p_position) {
+ target_position = p_position;
target_position_submitted = true;
_request_repath();
}
-Vector3 NavigationAgent3D::get_target_location() const {
- return target_location;
+Vector3 NavigationAgent3D::get_target_position() const {
+ return target_position;
}
-Vector3 NavigationAgent3D::get_next_location() {
+Vector3 NavigationAgent3D::get_next_path_position() {
update_navigation();
const Vector<Vector3> &navigation_path = navigation_result->get_path();
@@ -368,7 +368,7 @@ Vector3 NavigationAgent3D::get_next_location() {
real_t NavigationAgent3D::distance_to_target() const {
ERR_FAIL_COND_V_MSG(agent_parent == nullptr, 0.0, "The agent has no parent.");
- return agent_parent->get_global_transform().origin.distance_to(target_location);
+ return agent_parent->get_global_transform().origin.distance_to(target_position);
}
bool NavigationAgent3D::is_target_reached() const {
@@ -376,7 +376,7 @@ bool NavigationAgent3D::is_target_reached() const {
}
bool NavigationAgent3D::is_target_reachable() {
- return target_desired_distance >= get_final_location().distance_to(target_location);
+ return target_desired_distance >= get_final_position().distance_to(target_position);
}
bool NavigationAgent3D::is_navigation_finished() {
@@ -384,7 +384,7 @@ bool NavigationAgent3D::is_navigation_finished() {
return navigation_finished;
}
-Vector3 NavigationAgent3D::get_final_location() {
+Vector3 NavigationAgent3D::get_final_position() {
update_navigation();
const Vector<Vector3> &navigation_path = navigation_result->get_path();
@@ -467,7 +467,7 @@ void NavigationAgent3D::update_navigation() {
if (reload_path) {
navigation_query->set_start_position(origin);
- navigation_query->set_target_position(target_location);
+ navigation_query->set_target_position(target_position);
navigation_query->set_navigation_layers(navigation_layers);
navigation_query->set_metadata_flags(path_metadata_flags);
@@ -489,7 +489,7 @@ void NavigationAgent3D::update_navigation() {
// Check if we can advance the navigation path
if (navigation_finished == false) {
- // Advances to the next far away location.
+ // Advances to the next far away position.
const Vector<Vector3> &navigation_path = navigation_result->get_path();
const Vector<int32_t> &navigation_path_types = navigation_result->get_path_types();
const TypedArray<RID> &navigation_path_rids = navigation_result->get_path_rids();
@@ -499,7 +499,7 @@ void NavigationAgent3D::update_navigation() {
Dictionary details;
const Vector3 waypoint = navigation_path[navigation_path_index];
- details[SNAME("location")] = waypoint;
+ details[SNAME("position")] = waypoint;
int waypoint_type = -1;
if (path_metadata_flags.has_flag(NavigationPathQueryParameters3D::PathMetadataFlags::PATH_METADATA_INCLUDE_TYPES)) {
diff --git a/scene/3d/navigation_agent_3d.h b/scene/3d/navigation_agent_3d.h
index 91be068392..12f83ce6a8 100644
--- a/scene/3d/navigation_agent_3d.h
+++ b/scene/3d/navigation_agent_3d.h
@@ -62,7 +62,7 @@ class NavigationAgent3D : public Node {
real_t path_max_distance = 3.0;
- Vector3 target_location;
+ Vector3 target_position;
bool target_position_submitted = false;
Ref<NavigationPathQueryParameters3D> navigation_query;
Ref<NavigationPathQueryResult3D> navigation_result;
@@ -155,10 +155,10 @@ public:
void set_path_max_distance(real_t p_pmd);
real_t get_path_max_distance();
- void set_target_location(Vector3 p_location);
- Vector3 get_target_location() const;
+ void set_target_position(Vector3 p_position);
+ Vector3 get_target_position() const;
- Vector3 get_next_location();
+ Vector3 get_next_path_position();
Ref<NavigationPathQueryResult3D> get_current_navigation_result() const {
return navigation_result;
@@ -174,7 +174,7 @@ public:
bool is_target_reached() const;
bool is_target_reachable();
bool is_navigation_finished();
- Vector3 get_final_location();
+ Vector3 get_final_position();
void set_velocity(Vector3 p_velocity);
void _avoidance_done(Vector3 p_new_velocity);
diff --git a/scene/3d/navigation_link_3d.cpp b/scene/3d/navigation_link_3d.cpp
index e058ef62d0..f47fcfaf51 100644
--- a/scene/3d/navigation_link_3d.cpp
+++ b/scene/3d/navigation_link_3d.cpp
@@ -70,10 +70,10 @@ void NavigationLink3D::_update_debug_mesh() {
Vector<Vector3> lines;
// Draw line between the points.
- lines.push_back(start_location);
- lines.push_back(end_location);
+ lines.push_back(start_position);
+ lines.push_back(end_position);
- // Draw start location search radius
+ // Draw start position search radius
for (int i = 0; i < 30; i++) {
// Create a circle
const float ra = Math::deg_to_rad((float)(i * 12));
@@ -84,21 +84,21 @@ void NavigationLink3D::_update_debug_mesh() {
// 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));
+ lines.append(start_position + Vector3(0, a.x, a.y));
+ lines.append(start_position + 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));
+ lines.append(start_position + Vector3(a.x, 0, a.y));
+ lines.append(start_position + 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));
+ lines.append(start_position + Vector3(a.x, a.y, 0));
+ lines.append(start_position + Vector3(b.x, b.y, 0));
break;
}
}
- // Draw end location search radius
+ // Draw end position search radius
for (int i = 0; i < 30; i++) {
// Create a circle
const float ra = Math::deg_to_rad((float)(i * 12));
@@ -109,16 +109,16 @@ void NavigationLink3D::_update_debug_mesh() {
// 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));
+ lines.append(end_position + Vector3(0, a.x, a.y));
+ lines.append(end_position + 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));
+ lines.append(end_position + Vector3(a.x, 0, a.y));
+ lines.append(end_position + 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));
+ lines.append(end_position + Vector3(a.x, a.y, 0));
+ lines.append(end_position + Vector3(b.x, b.y, 0));
break;
}
}
@@ -157,11 +157,11 @@ void NavigationLink3D::_bind_methods() {
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_start_position", "position"), &NavigationLink3D::set_start_position);
+ ClassDB::bind_method(D_METHOD("get_start_position"), &NavigationLink3D::get_start_position);
- 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_end_position", "position"), &NavigationLink3D::set_end_position);
+ ClassDB::bind_method(D_METHOD("get_end_position"), &NavigationLink3D::get_end_position);
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);
@@ -172,12 +172,38 @@ void NavigationLink3D::_bind_methods() {
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::VECTOR3, "start_position"), "set_start_position", "get_start_position");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "end_position"), "set_end_position", "get_end_position");
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");
}
+#ifndef DISABLE_DEPRECATED
+bool NavigationLink3D::_set(const StringName &p_name, const Variant &p_value) {
+ if (p_name == "start_location") {
+ set_start_position(p_value);
+ return true;
+ }
+ if (p_name == "end_location") {
+ set_end_position(p_value);
+ return true;
+ }
+ return false;
+}
+
+bool NavigationLink3D::_get(const StringName &p_name, Variant &r_ret) const {
+ if (p_name == "start_location") {
+ r_ret = get_start_position();
+ return true;
+ }
+ if (p_name == "end_location") {
+ r_ret = get_end_position();
+ return true;
+ }
+ return false;
+}
+#endif // DISABLE_DEPRECATED
+
void NavigationLink3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -186,8 +212,8 @@ void NavigationLink3D::_notification(int p_what) {
// 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));
+ NavigationServer3D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
+ NavigationServer3D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
}
#ifdef DEBUG_ENABLED
@@ -197,8 +223,8 @@ void NavigationLink3D::_notification(int p_what) {
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));
+ NavigationServer3D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
+ NavigationServer3D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
#ifdef DEBUG_ENABLED
if (is_inside_tree() && debug_instance.is_valid()) {
@@ -316,19 +342,19 @@ bool NavigationLink3D::get_navigation_layer_value(int p_layer_number) const {
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)) {
+void NavigationLink3D::set_start_position(Vector3 p_position) {
+ if (start_position.is_equal_approx(p_position)) {
return;
}
- start_location = p_location;
+ start_position = p_position;
if (!is_inside_tree()) {
return;
}
Transform3D gt = get_global_transform();
- NavigationServer3D::get_singleton()->link_set_start_location(link, gt.xform(start_location));
+ NavigationServer3D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
#ifdef DEBUG_ENABLED
_update_debug_mesh();
@@ -338,19 +364,19 @@ void NavigationLink3D::set_start_location(Vector3 p_location) {
update_configuration_warnings();
}
-void NavigationLink3D::set_end_location(Vector3 p_location) {
- if (end_location.is_equal_approx(p_location)) {
+void NavigationLink3D::set_end_position(Vector3 p_position) {
+ if (end_position.is_equal_approx(p_position)) {
return;
}
- end_location = p_location;
+ end_position = p_position;
if (!is_inside_tree()) {
return;
}
Transform3D gt = get_global_transform();
- NavigationServer3D::get_singleton()->link_set_end_location(link, gt.xform(end_location));
+ NavigationServer3D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
#ifdef DEBUG_ENABLED
_update_debug_mesh();
@@ -385,8 +411,8 @@ void NavigationLink3D::set_travel_cost(real_t p_travel_cost) {
PackedStringArray NavigationLink3D::get_configuration_warnings() const {
PackedStringArray 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."));
+ if (start_position.is_equal_approx(end_position)) {
+ warnings.push_back(RTR("NavigationLink3D start position should be different than the end position to be useful."));
}
return warnings;
diff --git a/scene/3d/navigation_link_3d.h b/scene/3d/navigation_link_3d.h
index 175c5cdd5d..5c9ec36189 100644
--- a/scene/3d/navigation_link_3d.h
+++ b/scene/3d/navigation_link_3d.h
@@ -40,8 +40,8 @@ class NavigationLink3D : public Node3D {
RID link;
bool bidirectional = true;
uint32_t navigation_layers = 1;
- Vector3 end_location;
- Vector3 start_location;
+ Vector3 end_position;
+ Vector3 start_position;
real_t enter_cost = 0.0;
real_t travel_cost = 1.0;
@@ -56,6 +56,11 @@ protected:
static void _bind_methods();
void _notification(int p_what);
+#ifndef DISABLE_DEPRECATED
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+#endif // DISABLE_DEPRECATED
+
public:
NavigationLink3D();
~NavigationLink3D();
@@ -72,11 +77,11 @@ public:
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_start_position(Vector3 p_position);
+ Vector3 get_start_position() const { return start_position; }
- void set_end_location(Vector3 p_location);
- Vector3 get_end_location() const { return end_location; }
+ void set_end_position(Vector3 p_position);
+ Vector3 get_end_position() const { return end_position; }
void set_enter_cost(real_t p_enter_cost);
real_t get_enter_cost() const { return enter_cost; }