summaryrefslogtreecommitdiffstats
path: root/scene/resources
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-07-04 17:12:22 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-07-04 17:12:22 +0200
commit4d984b63697d840f2c823608d2c46740fb44651a (patch)
treef2f0147594b9697a0fee0f6dcb1cae4715d546df /scene/resources
parent0452cbee7512daefe1a01ab63f339397af751c34 (diff)
parent7c6f32ddbff4186bc91db68aad7460b2d932924d (diff)
downloadredot-engine-4d984b63697d840f2c823608d2c46740fb44651a.tar.gz
Merge pull request #93930 from Arnklit/short-animation-length-bezier-handle-fix
Clamp bezier handle length to half the length of animation
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/animation.cpp14
-rw-r--r--scene/resources/animation.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index 254bd38be7..c0ab636adc 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -3189,6 +3189,20 @@ StringName Animation::method_track_get_name(int p_track, int p_key_idx) const {
return pm->methods[p_key_idx].method;
}
+Array Animation::make_default_bezier_key(float p_value) {
+ const double max_width = length / 2.0;
+ Array new_point;
+ new_point.resize(5);
+
+ new_point[0] = p_value;
+ new_point[1] = MAX(-0.25, -max_width);
+ new_point[2] = 0;
+ new_point[3] = MIN(0.25, max_width);
+ new_point[4] = 0;
+
+ return new_point;
+}
+
int Animation::bezier_track_insert_key(int p_track, double p_time, real_t p_value, const Vector2 &p_in_handle, const Vector2 &p_out_handle) {
ERR_FAIL_INDEX_V(p_track, tracks.size(), -1);
Track *t = tracks[p_track];
diff --git a/scene/resources/animation.h b/scene/resources/animation.h
index e9bfc298a5..cb12b12c0e 100644
--- a/scene/resources/animation.h
+++ b/scene/resources/animation.h
@@ -455,6 +455,7 @@ public:
void track_set_interpolation_type(int p_track, InterpolationType p_interp);
InterpolationType track_get_interpolation_type(int p_track) const;
+ Array make_default_bezier_key(float p_value);
int bezier_track_insert_key(int p_track, double p_time, real_t p_value, const Vector2 &p_in_handle, const Vector2 &p_out_handle);
void bezier_track_set_key_value(int p_track, int p_index, real_t p_value);
void bezier_track_set_key_in_handle(int p_track, int p_index, const Vector2 &p_handle, real_t p_balanced_value_time_ratio = 1.0);