Skip to content

Commit 34b5e8f

Browse files
committed
Merge pull request #91481 from TokageItLab/auto-capture-option
Add argument options to AnimationPlayer for auto capture
2 parents 4d43fe1 + 6fd8b25 commit 34b5e8f

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

doc/classes/AnimationPlayer.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@
213213
</member>
214214
<member name="playback_auto_capture" type="bool" setter="set_auto_capture" getter="is_auto_capture" default="true">
215215
If [code]true[/code], performs [method AnimationMixer.capture] before playback automatically. This means just [method play_with_capture] is executed with default arguments instead of [method play].
216+
[b]Note:[/b] Capture interpolation is only performed if the animation contains a capture track. See also [constant Animation.UPDATE_CAPTURE].
217+
</member>
218+
<member name="playback_auto_capture_duration" type="float" setter="set_auto_capture_duration" getter="get_auto_capture_duration" default="-1.0">
219+
See also [method play_with_capture] and [method AnimationMixer.capture].
220+
If [member playback_auto_capture_duration] is negative value, the duration is set to the interval between the current position and the first key.
221+
</member>
222+
<member name="playback_auto_capture_ease_type" type="int" setter="set_auto_capture_ease_type" getter="get_auto_capture_ease_type" enum="Tween.EaseType" default="0">
223+
The ease type of the capture interpolation. See also [enum Tween.EaseType].
224+
</member>
225+
<member name="playback_auto_capture_transition_type" type="int" setter="set_auto_capture_transition_type" getter="get_auto_capture_transition_type" enum="Tween.TransitionType" default="0">
226+
The transition type of the capture interpolation. See also [enum Tween.TransitionType].
216227
</member>
217228
<member name="playback_default_blend_time" type="float" setter="set_default_blend_time" getter="get_default_blend_time" default="0.0">
218229
The default time in which to blend animations. Ranges from 0 to 4096 with 0.01 precision.

scene/animation/animation_player.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ void AnimationPlayer::_validate_property(PropertyInfo &p_property) const {
125125
}
126126

127127
p_property.hint_string = hint;
128+
} else if (!auto_capture && p_property.name.begins_with("playback_auto_capture_")) {
129+
p_property.usage = PROPERTY_USAGE_NONE;
128130
}
129131
}
130132

@@ -372,7 +374,7 @@ void AnimationPlayer::play_backwards(const StringName &p_name, double p_custom_b
372374

373375
void AnimationPlayer::play(const StringName &p_name, double p_custom_blend, float p_custom_scale, bool p_from_end) {
374376
if (auto_capture) {
375-
play_with_capture(p_name, -1.0, p_custom_blend, p_custom_scale, p_from_end);
377+
play_with_capture(p_name, auto_capture_duration, p_custom_blend, p_custom_scale, p_from_end, auto_capture_transition_type, auto_capture_ease_type);
376378
} else {
377379
_play(p_name, p_custom_blend, p_custom_scale, p_from_end);
378380
}
@@ -716,12 +718,37 @@ double AnimationPlayer::get_blend_time(const StringName &p_animation1, const Str
716718

717719
void AnimationPlayer::set_auto_capture(bool p_auto_capture) {
718720
auto_capture = p_auto_capture;
721+
notify_property_list_changed();
719722
}
720723

721724
bool AnimationPlayer::is_auto_capture() const {
722725
return auto_capture;
723726
}
724727

728+
void AnimationPlayer::set_auto_capture_duration(double p_auto_capture_duration) {
729+
auto_capture_duration = p_auto_capture_duration;
730+
}
731+
732+
double AnimationPlayer::get_auto_capture_duration() const {
733+
return auto_capture_duration;
734+
}
735+
736+
void AnimationPlayer::set_auto_capture_transition_type(Tween::TransitionType p_auto_capture_transition_type) {
737+
auto_capture_transition_type = p_auto_capture_transition_type;
738+
}
739+
740+
Tween::TransitionType AnimationPlayer::get_auto_capture_transition_type() const {
741+
return auto_capture_transition_type;
742+
}
743+
744+
void AnimationPlayer::set_auto_capture_ease_type(Tween::EaseType p_auto_capture_ease_type) {
745+
auto_capture_ease_type = p_auto_capture_ease_type;
746+
}
747+
748+
Tween::EaseType AnimationPlayer::get_auto_capture_ease_type() const {
749+
return auto_capture_ease_type;
750+
}
751+
725752
#ifdef TOOLS_ENABLED
726753
void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
727754
const String pf = p_function;
@@ -814,6 +841,12 @@ void AnimationPlayer::_bind_methods() {
814841

815842
ClassDB::bind_method(D_METHOD("set_auto_capture", "auto_capture"), &AnimationPlayer::set_auto_capture);
816843
ClassDB::bind_method(D_METHOD("is_auto_capture"), &AnimationPlayer::is_auto_capture);
844+
ClassDB::bind_method(D_METHOD("set_auto_capture_duration", "auto_capture_duration"), &AnimationPlayer::set_auto_capture_duration);
845+
ClassDB::bind_method(D_METHOD("get_auto_capture_duration"), &AnimationPlayer::get_auto_capture_duration);
846+
ClassDB::bind_method(D_METHOD("set_auto_capture_transition_type", "auto_capture_transition_type"), &AnimationPlayer::set_auto_capture_transition_type);
847+
ClassDB::bind_method(D_METHOD("get_auto_capture_transition_type"), &AnimationPlayer::get_auto_capture_transition_type);
848+
ClassDB::bind_method(D_METHOD("set_auto_capture_ease_type", "auto_capture_ease_type"), &AnimationPlayer::set_auto_capture_ease_type);
849+
ClassDB::bind_method(D_METHOD("get_auto_capture_ease_type"), &AnimationPlayer::get_auto_capture_ease_type);
817850

818851
ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(StringName()), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
819852
ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(StringName()), DEFVAL(-1));
@@ -856,6 +889,9 @@ void AnimationPlayer::_bind_methods() {
856889

857890
ADD_GROUP("Playback Options", "playback_");
858891
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_auto_capture"), "set_auto_capture", "is_auto_capture");
892+
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_auto_capture_duration", PROPERTY_HINT_NONE, "suffix:s"), "set_auto_capture_duration", "get_auto_capture_duration");
893+
ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_auto_capture_transition_type", PROPERTY_HINT_ENUM, "Linear,Sine,Quint,Quart,Expo,Elastic,Cubic,Circ,Bounce,Back,Spring"), "set_auto_capture_transition_type", "get_auto_capture_transition_type");
894+
ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_auto_capture_ease_type", PROPERTY_HINT_ENUM, "In,Out,InOut,OutIn"), "set_auto_capture_ease_type", "get_auto_capture_ease_type");
859895
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01,suffix:s"), "set_default_blend_time", "get_default_blend_time");
860896

861897
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "-4,4,0.001,or_less,or_greater"), "set_speed_scale", "get_speed_scale");

scene/animation/animation_player.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ class AnimationPlayer : public AnimationMixer {
5656

5757
float speed_scale = 1.0;
5858
double default_blend_time = 0.0;
59+
5960
bool auto_capture = true;
61+
double auto_capture_duration = -1.0;
62+
Tween::TransitionType auto_capture_transition_type = Tween::TRANS_LINEAR;
63+
Tween::EaseType auto_capture_ease_type = Tween::EASE_IN;
64+
6065
bool is_stopping = false;
6166

6267
struct PlaybackData {
@@ -163,6 +168,12 @@ class AnimationPlayer : public AnimationMixer {
163168

164169
void set_auto_capture(bool p_auto_capture);
165170
bool is_auto_capture() const;
171+
void set_auto_capture_duration(double p_auto_capture_duration);
172+
double get_auto_capture_duration() const;
173+
void set_auto_capture_transition_type(Tween::TransitionType p_auto_capture_transition_type);
174+
Tween::TransitionType get_auto_capture_transition_type() const;
175+
void set_auto_capture_ease_type(Tween::EaseType p_auto_capture_ease_type);
176+
Tween::EaseType get_auto_capture_ease_type() const;
166177

167178
void play(const StringName &p_name = StringName(), double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);
168179
void play_backwards(const StringName &p_name = StringName(), double p_custom_blend = -1);

scene/resources/animation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ void Animation::value_track_set_update_mode(int p_track, UpdateMode p_mode) {
27052705
ValueTrack *vt = static_cast<ValueTrack *>(t);
27062706
vt->update_mode = p_mode;
27072707

2708-
capture_included = capture_included || (p_mode == UPDATE_CAPTURE);
2708+
_check_capture_included();
27092709
emit_changed();
27102710
}
27112711

@@ -3901,7 +3901,7 @@ void Animation::_bind_methods() {
39013901
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_RANGE, "0.001,99999,0.001,suffix:s"), "set_length", "get_length");
39023902
ADD_PROPERTY(PropertyInfo(Variant::INT, "loop_mode", PROPERTY_HINT_ENUM, "None,Linear,Ping-Pong"), "set_loop_mode", "get_loop_mode");
39033903
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "step", PROPERTY_HINT_RANGE, "0,4096,0.001,suffix:s"), "set_step", "get_step");
3904-
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "capture_included", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_NO_EDITOR), "_set_capture_included", "is_capture_included");
3904+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "capture_included", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_NO_EDITOR), "_set_capture_included", "is_capture_included");
39053905

39063906
BIND_ENUM_CONSTANT(TYPE_VALUE);
39073907
BIND_ENUM_CONSTANT(TYPE_POSITION_3D);

0 commit comments

Comments
 (0)