animation_player.cpp 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. /**************************************************************************/
  2. /* animation_player.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "animation_player.h"
  31. #include "animation_player.compat.inc"
  32. #include "core/config/engine.h"
  33. bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) {
  34. String name = p_name;
  35. if (name.begins_with("playback/play")) { // For backward compatibility.
  36. set_current_animation(p_value);
  37. } else if (name.begins_with("next/")) {
  38. String which = name.get_slicec('/', 1);
  39. animation_set_next(which, p_value);
  40. } else if (p_name == SceneStringName(blend_times)) {
  41. Array array = p_value;
  42. int len = array.size();
  43. ERR_FAIL_COND_V(len % 3, false);
  44. for (int i = 0; i < len / 3; i++) {
  45. StringName from = array[i * 3 + 0];
  46. StringName to = array[i * 3 + 1];
  47. float time = array[i * 3 + 2];
  48. set_blend_time(from, to, time);
  49. }
  50. #ifndef DISABLE_DEPRECATED
  51. } else if (p_name == "method_call_mode") {
  52. set_callback_mode_method(static_cast<AnimationCallbackModeMethod>((int)p_value));
  53. } else if (p_name == "playback_process_mode") {
  54. set_callback_mode_process(static_cast<AnimationCallbackModeProcess>((int)p_value));
  55. } else if (p_name == "playback_active") {
  56. set_active(p_value);
  57. #endif // DISABLE_DEPRECATED
  58. } else {
  59. return false;
  60. }
  61. return true;
  62. }
  63. bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {
  64. String name = p_name;
  65. if (name == "playback/play") { // For backward compatibility.
  66. r_ret = get_current_animation();
  67. } else if (name.begins_with("next/")) {
  68. String which = name.get_slicec('/', 1);
  69. r_ret = animation_get_next(which);
  70. } else if (p_name == SceneStringName(blend_times)) {
  71. Vector<BlendKey> keys;
  72. for (const KeyValue<BlendKey, double> &E : blend_times) {
  73. keys.ordered_insert(E.key);
  74. }
  75. Array array;
  76. for (int i = 0; i < keys.size(); i++) {
  77. array.push_back(keys[i].from);
  78. array.push_back(keys[i].to);
  79. array.push_back(blend_times.get(keys[i]));
  80. }
  81. r_ret = array;
  82. #ifndef DISABLE_DEPRECATED
  83. } else if (name == "method_call_mode") {
  84. r_ret = get_callback_mode_method();
  85. } else if (name == "playback_process_mode") {
  86. r_ret = get_callback_mode_process();
  87. } else if (name == "playback_active") {
  88. r_ret = is_active();
  89. #endif // DISABLE_DEPRECATED
  90. } else {
  91. return false;
  92. }
  93. return true;
  94. }
  95. void AnimationPlayer::_validate_property(PropertyInfo &p_property) const {
  96. if (Engine::get_singleton()->is_editor_hint() && p_property.name == "current_animation") {
  97. List<String> names;
  98. for (const KeyValue<StringName, AnimationData> &E : animation_set) {
  99. names.push_back(E.key);
  100. }
  101. names.push_front("[stop]");
  102. String hint;
  103. for (List<String>::Element *E = names.front(); E; E = E->next()) {
  104. if (E != names.front()) {
  105. hint += ",";
  106. }
  107. hint += E->get();
  108. }
  109. p_property.hint_string = hint;
  110. } else if (!auto_capture && p_property.name.begins_with("playback_auto_capture_")) {
  111. p_property.usage = PROPERTY_USAGE_NONE;
  112. }
  113. }
  114. void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const {
  115. List<PropertyInfo> anim_names;
  116. for (const KeyValue<StringName, AnimationData> &E : animation_set) {
  117. AHashMap<StringName, StringName>::ConstIterator F = animation_next_set.find(E.key);
  118. if (F && F->value != StringName()) {
  119. anim_names.push_back(PropertyInfo(Variant::STRING, "next/" + String(E.key), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
  120. }
  121. }
  122. for (const PropertyInfo &E : anim_names) {
  123. p_list->push_back(E);
  124. }
  125. p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
  126. }
  127. void AnimationPlayer::_notification(int p_what) {
  128. switch (p_what) {
  129. case NOTIFICATION_READY: {
  130. if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) {
  131. set_active(active);
  132. play(autoplay);
  133. _check_immediately_after_start();
  134. }
  135. } break;
  136. }
  137. }
  138. void AnimationPlayer::_process_playback_data(PlaybackData &cd, double p_delta, float p_blend, bool p_seeked, bool p_internal_seeked, bool p_started, bool p_is_current) {
  139. double speed = speed_scale * cd.speed_scale;
  140. bool backwards = std::signbit(speed); // Negative zero means playing backwards too.
  141. double delta = p_started ? 0 : p_delta * speed;
  142. double next_pos = cd.pos + delta;
  143. double start = cd.get_start_time();
  144. double end = cd.get_end_time();
  145. Animation::LoopedFlag looped_flag = Animation::LOOPED_FLAG_NONE;
  146. switch (cd.from->animation->get_loop_mode()) {
  147. case Animation::LOOP_NONE: {
  148. if (Animation::is_less_approx(next_pos, start)) {
  149. next_pos = start;
  150. } else if (Animation::is_greater_approx(next_pos, end)) {
  151. next_pos = end;
  152. }
  153. delta = next_pos - cd.pos; // Fix delta (after determination of backwards because negative zero is lost here).
  154. } break;
  155. case Animation::LOOP_LINEAR: {
  156. if (Animation::is_less_approx(next_pos, start) && Animation::is_greater_or_equal_approx(cd.pos, start)) {
  157. looped_flag = Animation::LOOPED_FLAG_START;
  158. }
  159. if (Animation::is_greater_approx(next_pos, end) && Animation::is_less_or_equal_approx(cd.pos, end)) {
  160. looped_flag = Animation::LOOPED_FLAG_END;
  161. }
  162. next_pos = Math::fposmod(next_pos - start, end - start) + start;
  163. } break;
  164. case Animation::LOOP_PINGPONG: {
  165. if (Animation::is_less_approx(next_pos, start) && Animation::is_greater_or_equal_approx(cd.pos, start)) {
  166. cd.speed_scale *= -1.0;
  167. looped_flag = Animation::LOOPED_FLAG_START;
  168. }
  169. if (Animation::is_greater_approx(next_pos, end) && Animation::is_less_or_equal_approx(cd.pos, end)) {
  170. cd.speed_scale *= -1.0;
  171. looped_flag = Animation::LOOPED_FLAG_END;
  172. }
  173. next_pos = Math::pingpong(next_pos - start, end - start) + start;
  174. } break;
  175. default:
  176. break;
  177. }
  178. double prev_pos = cd.pos; // The animation may be changed during process, so it is safer that the state is changed before process.
  179. // End detection.
  180. if (p_is_current) {
  181. if (cd.from->animation->get_loop_mode() == Animation::LOOP_NONE) {
  182. if (!backwards && Animation::is_less_or_equal_approx(prev_pos, end) && Math::is_equal_approx(next_pos, end)) {
  183. // Playback finished.
  184. next_pos = end; // Snap to the edge.
  185. end_reached = true;
  186. end_notify = Animation::is_less_approx(prev_pos, end); // Notify only if not already at the end.
  187. p_blend = 1.0;
  188. }
  189. if (backwards && Animation::is_greater_or_equal_approx(prev_pos, start) && Math::is_equal_approx(next_pos, start)) {
  190. // Playback finished.
  191. next_pos = start; // Snap to the edge.
  192. end_reached = true;
  193. end_notify = Animation::is_greater_approx(prev_pos, start); // Notify only if not already at the beginning.
  194. p_blend = 1.0;
  195. }
  196. }
  197. }
  198. cd.pos = next_pos;
  199. PlaybackInfo pi;
  200. if (p_started) {
  201. pi.time = prev_pos;
  202. pi.delta = 0;
  203. pi.start = start;
  204. pi.end = end;
  205. pi.seeked = true;
  206. } else {
  207. pi.time = next_pos;
  208. pi.delta = delta;
  209. pi.start = start;
  210. pi.end = end;
  211. pi.seeked = p_seeked;
  212. }
  213. if (Math::is_zero_approx(pi.delta) && backwards) {
  214. pi.delta = -0.0; // Sign is needed to handle converted Continuous track from Discrete track correctly.
  215. }
  216. // Immediately after playback, discrete keys should be retrieved with EXACT mode since behind keys must be ignored at that time.
  217. pi.is_external_seeking = !p_internal_seeked && !p_started;
  218. pi.looped_flag = looped_flag;
  219. pi.weight = p_blend;
  220. make_animation_instance(cd.from->name, pi);
  221. }
  222. float AnimationPlayer::get_current_blend_amount() {
  223. Playback &c = playback;
  224. float blend = 1.0;
  225. for (const Blend &b : c.blend) {
  226. blend = blend - b.blend_left;
  227. }
  228. return MAX(0, blend);
  229. }
  230. void AnimationPlayer::_blend_playback_data(double p_delta, bool p_started) {
  231. Playback &c = playback;
  232. bool seeked = c.seeked; // The animation may be changed during process, so it is safer that the state is changed before process.
  233. bool internal_seeked = c.internal_seeked;
  234. if (!Math::is_zero_approx(p_delta)) {
  235. c.seeked = false;
  236. c.internal_seeked = false;
  237. }
  238. // Second, process current animation to check if the animation end reached.
  239. _process_playback_data(c.current, p_delta, get_current_blend_amount(), seeked, internal_seeked, p_started, true);
  240. // Finally, if not end the animation, do blending.
  241. if (end_reached) {
  242. playback.blend.clear();
  243. if (end_notify) {
  244. finished_anim = playback.assigned;
  245. }
  246. return;
  247. }
  248. List<List<Blend>::Element *> to_erase;
  249. for (List<Blend>::Element *E = c.blend.front(); E; E = E->next()) {
  250. Blend &b = E->get();
  251. b.blend_left = MAX(0, b.blend_left - Math::abs(speed_scale * p_delta) / b.blend_time);
  252. if (Animation::is_less_or_equal_approx(b.blend_left, 0)) {
  253. to_erase.push_back(E);
  254. b.blend_left = CMP_EPSILON; // May want to play last frame.
  255. }
  256. // Note: There may be issues if an animation event triggers an animation change while this blend is active,
  257. // so it is best to use "deferred" calls instead of "immediate" for animation events that can trigger new animations.
  258. _process_playback_data(b.data, p_delta, b.blend_left, false, false, false);
  259. }
  260. for (List<Blend>::Element *&E : to_erase) {
  261. c.blend.erase(E);
  262. }
  263. }
  264. bool AnimationPlayer::_blend_pre_process(double p_delta, int p_track_count, const AHashMap<NodePath, int> &p_track_map) {
  265. if (!playback.current.from) {
  266. _set_process(false);
  267. return false;
  268. }
  269. tmp_from = playback.current.from->animation->get_instance_id();
  270. end_reached = false;
  271. end_notify = false;
  272. finished_anim = StringName();
  273. bool started = playback.started; // The animation may be changed during process, so it is safer that the state is changed before process.
  274. if (playback.started) {
  275. playback.started = false;
  276. }
  277. AnimationData *prev_from = playback.current.from;
  278. _blend_playback_data(p_delta, started);
  279. if (prev_from != playback.current.from) {
  280. return false; // Animation has been changed in the process (may be caused by method track), abort process.
  281. }
  282. return true;
  283. }
  284. void AnimationPlayer::_blend_capture(double p_delta) {
  285. blend_capture(p_delta * Math::abs(speed_scale));
  286. }
  287. void AnimationPlayer::_blend_post_process() {
  288. if (end_reached) {
  289. // If the method track changes current animation, the animation is not finished.
  290. if (tmp_from == playback.current.from->animation->get_instance_id()) {
  291. if (playback_queue.size()) {
  292. if (!finished_anim.is_empty()) {
  293. emit_signal(SceneStringName(animation_finished), finished_anim);
  294. }
  295. String old = playback.assigned;
  296. play(playback_queue.front()->get());
  297. String new_name = playback.assigned;
  298. playback_queue.pop_front();
  299. if (end_notify) {
  300. emit_signal(SceneStringName(animation_changed), old, new_name);
  301. }
  302. } else {
  303. _clear_caches();
  304. playing = false;
  305. _set_process(false);
  306. if (end_notify) {
  307. if (!finished_anim.is_empty()) {
  308. emit_signal(SceneStringName(animation_finished), finished_anim);
  309. }
  310. emit_signal(SNAME("current_animation_changed"), "");
  311. if (movie_quit_on_finish && OS::get_singleton()->has_feature("movie")) {
  312. print_line(vformat("Movie Maker mode is enabled. Quitting on animation finish as requested by: %s", get_path()));
  313. get_tree()->quit();
  314. }
  315. }
  316. }
  317. }
  318. end_reached = false;
  319. end_notify = false;
  320. }
  321. tmp_from = ObjectID();
  322. }
  323. void AnimationPlayer::queue(const StringName &p_name) {
  324. if (!is_playing()) {
  325. play(p_name);
  326. } else {
  327. playback_queue.push_back(p_name);
  328. }
  329. }
  330. TypedArray<StringName> AnimationPlayer::get_queue() {
  331. TypedArray<StringName> ret;
  332. for (const StringName &E : playback_queue) {
  333. ret.push_back(E);
  334. }
  335. return ret;
  336. }
  337. void AnimationPlayer::clear_queue() {
  338. playback_queue.clear();
  339. }
  340. void AnimationPlayer::play_backwards(const StringName &p_name, double p_custom_blend) {
  341. play(p_name, p_custom_blend, -1, true);
  342. }
  343. void AnimationPlayer::play_section_with_markers_backwards(const StringName &p_name, const StringName &p_start_marker, const StringName &p_end_marker, double p_custom_blend) {
  344. play_section_with_markers(p_name, p_start_marker, p_end_marker, p_custom_blend, -1, true);
  345. }
  346. void AnimationPlayer::play_section_backwards(const StringName &p_name, double p_start_time, double p_end_time, double p_custom_blend) {
  347. play_section(p_name, p_start_time, p_end_time, p_custom_blend, -1, true);
  348. }
  349. void AnimationPlayer::play(const StringName &p_name, double p_custom_blend, float p_custom_scale, bool p_from_end) {
  350. if (auto_capture) {
  351. 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);
  352. } else {
  353. _play(p_name, p_custom_blend, p_custom_scale, p_from_end);
  354. }
  355. }
  356. void AnimationPlayer::_play(const StringName &p_name, double p_custom_blend, float p_custom_scale, bool p_from_end) {
  357. play_section_with_markers(p_name, StringName(), StringName(), p_custom_blend, p_custom_scale, p_from_end);
  358. }
  359. void AnimationPlayer::play_section_with_markers(const StringName &p_name, const StringName &p_start_marker, const StringName &p_end_marker, double p_custom_blend, float p_custom_scale, bool p_from_end) {
  360. StringName name = p_name;
  361. if (name == StringName()) {
  362. name = playback.assigned;
  363. }
  364. ERR_FAIL_COND_MSG(!animation_set.has(name), vformat("Animation not found: %s.", name));
  365. Ref<Animation> animation = animation_set[name].animation;
  366. ERR_FAIL_COND_MSG(p_start_marker == p_end_marker && p_start_marker, vformat("Start marker and end marker cannot be the same marker: %s.", p_start_marker));
  367. ERR_FAIL_COND_MSG(p_start_marker && !animation->has_marker(p_start_marker), vformat("Marker %s not found in animation: %s.", p_start_marker, name));
  368. ERR_FAIL_COND_MSG(p_end_marker && !animation->has_marker(p_end_marker), vformat("Marker %s not found in animation: %s.", p_end_marker, name));
  369. double start_time = p_start_marker ? animation->get_marker_time(p_start_marker) : -1;
  370. double end_time = p_end_marker ? animation->get_marker_time(p_end_marker) : -1;
  371. ERR_FAIL_COND_MSG(p_start_marker && p_end_marker && Animation::is_greater_approx(start_time, end_time), vformat("End marker %s is placed earlier than start marker %s in animation: %s.", p_end_marker, p_start_marker, name));
  372. if (p_start_marker && Animation::is_less_approx(start_time, 0)) {
  373. WARN_PRINT_ED(vformat("Negative time start marker: %s is invalid in the section, so the start of the animation: %s is used instead.", p_start_marker, playback.current.from->animation->get_name()));
  374. }
  375. if (p_end_marker && Animation::is_less_approx(end_time, 0)) {
  376. WARN_PRINT_ED(vformat("Negative time end marker: %s is invalid in the section, so the end of the animation: %s is used instead.", p_end_marker, playback.current.from->animation->get_name()));
  377. }
  378. play_section(name, start_time, end_time, p_custom_blend, p_custom_scale, p_from_end);
  379. }
  380. void AnimationPlayer::play_section(const StringName &p_name, double p_start_time, double p_end_time, double p_custom_blend, float p_custom_scale, bool p_from_end) {
  381. StringName name = p_name;
  382. if (name == StringName()) {
  383. name = playback.assigned;
  384. }
  385. ERR_FAIL_COND_MSG(!animation_set.has(name), vformat("Animation not found: %s.", name));
  386. ERR_FAIL_COND_MSG(p_start_time >= 0 && p_end_time >= 0 && Math::is_equal_approx(p_start_time, p_end_time), "Start time and end time must not equal to each other.");
  387. ERR_FAIL_COND_MSG(p_start_time >= 0 && p_end_time >= 0 && Animation::is_greater_approx(p_start_time, p_end_time), vformat("Start time %f is greater than end time %f.", p_start_time, p_end_time));
  388. Playback &c = playback;
  389. if (c.current.from) {
  390. double blend_time = 0.0;
  391. // Find if it can blend.
  392. BlendKey bk;
  393. bk.from = c.current.from->name;
  394. bk.to = name;
  395. if (Animation::is_greater_or_equal_approx(p_custom_blend, 0)) {
  396. blend_time = p_custom_blend;
  397. } else if (blend_times.has(bk)) {
  398. blend_time = blend_times[bk];
  399. } else {
  400. bk.from = "*";
  401. if (blend_times.has(bk)) {
  402. blend_time = blend_times[bk];
  403. } else {
  404. bk.from = c.current.from->name;
  405. bk.to = "*";
  406. if (blend_times.has(bk)) {
  407. blend_time = blend_times[bk];
  408. }
  409. }
  410. }
  411. if (Animation::is_less_approx(p_custom_blend, 0) && Math::is_zero_approx(blend_time) && default_blend_time) {
  412. blend_time = default_blend_time;
  413. }
  414. if (Animation::is_greater_approx(blend_time, 0)) {
  415. Blend b;
  416. b.data = c.current;
  417. b.blend_left = get_current_blend_amount();
  418. b.blend_time = blend_time;
  419. c.blend.push_back(b);
  420. } else {
  421. c.blend.clear();
  422. }
  423. }
  424. if (get_current_animation() != p_name) {
  425. _clear_playing_caches();
  426. }
  427. c.current.from = &animation_set[name];
  428. c.current.speed_scale = p_custom_scale;
  429. c.current.start_time = p_start_time;
  430. c.current.end_time = p_end_time;
  431. double start = playback.current.get_start_time();
  432. double end = playback.current.get_end_time();
  433. if (!end_reached) {
  434. playback_queue.clear();
  435. }
  436. if (c.assigned != name) { // Reset.
  437. c.current.pos = p_from_end ? end : start;
  438. c.assigned = name;
  439. emit_signal(SNAME("current_animation_changed"), c.assigned);
  440. } else {
  441. if (p_from_end && Animation::is_less_or_equal_approx(c.current.pos, start)) {
  442. // Animation reset but played backwards, set position to the end.
  443. seek_internal(end, true, true, true);
  444. } else if (!p_from_end && Animation::is_greater_or_equal_approx(c.current.pos, end)) {
  445. // Animation resumed but already ended, set position to the beginning.
  446. seek_internal(start, true, true, true);
  447. } else if (playing) {
  448. return;
  449. }
  450. }
  451. c.seeked = false;
  452. c.started = true;
  453. _set_process(true); // Always process when starting an animation.
  454. playing = true;
  455. emit_signal(SceneStringName(animation_started), c.assigned);
  456. if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
  457. return; // No next in this case.
  458. }
  459. StringName next = animation_get_next(p_name);
  460. if (next != StringName() && animation_set.has(next)) {
  461. queue(next);
  462. }
  463. }
  464. void AnimationPlayer::_capture(const StringName &p_name, bool p_from_end, double p_duration, Tween::TransitionType p_trans_type, Tween::EaseType p_ease_type) {
  465. StringName name = p_name;
  466. if (name == StringName()) {
  467. name = playback.assigned;
  468. }
  469. Ref<Animation> anim = get_animation(name);
  470. if (anim.is_null() || !anim->is_capture_included()) {
  471. return;
  472. }
  473. if (std::signbit(p_duration)) {
  474. double max_dur = 0;
  475. double current_pos = playback.current.pos;
  476. if (playback.assigned != name) {
  477. current_pos = p_from_end ? anim->get_length() : 0;
  478. }
  479. for (int i = 0; i < anim->get_track_count(); i++) {
  480. if (anim->track_get_type(i) != Animation::TYPE_VALUE) {
  481. continue;
  482. }
  483. if (anim->value_track_get_update_mode(i) != Animation::UPDATE_CAPTURE) {
  484. continue;
  485. }
  486. if (anim->track_get_key_count(i) == 0) {
  487. continue;
  488. }
  489. max_dur = MAX(max_dur, p_from_end ? current_pos - anim->track_get_key_time(i, anim->track_get_key_count(i) - 1) : anim->track_get_key_time(i, 0) - current_pos);
  490. }
  491. p_duration = max_dur;
  492. }
  493. if (Math::is_zero_approx(p_duration)) {
  494. return;
  495. }
  496. capture(name, p_duration, p_trans_type, p_ease_type);
  497. }
  498. void AnimationPlayer::play_with_capture(const StringName &p_name, double p_duration, double p_custom_blend, float p_custom_scale, bool p_from_end, Tween::TransitionType p_trans_type, Tween::EaseType p_ease_type) {
  499. _capture(p_name, p_from_end, p_duration, p_trans_type, p_ease_type);
  500. _play(p_name, p_custom_blend, p_custom_scale, p_from_end);
  501. }
  502. bool AnimationPlayer::is_playing() const {
  503. return playing;
  504. }
  505. void AnimationPlayer::set_current_animation(const StringName &p_animation) {
  506. if (p_animation == SNAME("[stop]") || p_animation.is_empty()) {
  507. stop();
  508. } else if (!is_playing()) {
  509. play(p_animation);
  510. } else if (playback.assigned != p_animation) {
  511. float speed = playback.current.speed_scale;
  512. play(p_animation, -1.0, speed, std::signbit(speed));
  513. } else {
  514. // Same animation, do not replay from start.
  515. }
  516. }
  517. StringName AnimationPlayer::get_current_animation() const {
  518. return (is_playing() ? playback.assigned : StringName());
  519. }
  520. void AnimationPlayer::set_assigned_animation(const StringName &p_animation) {
  521. if (is_playing()) {
  522. float speed = playback.current.speed_scale;
  523. play(p_animation, -1.0, speed, std::signbit(speed));
  524. } else {
  525. ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation.operator String()));
  526. playback.current.pos = 0;
  527. playback.current.from = &animation_set[p_animation];
  528. playback.current.start_time = -1;
  529. playback.current.end_time = -1;
  530. playback.assigned = p_animation;
  531. emit_signal(SNAME("current_animation_changed"), playback.assigned);
  532. }
  533. }
  534. StringName AnimationPlayer::get_assigned_animation() const {
  535. return playback.assigned;
  536. }
  537. void AnimationPlayer::pause() {
  538. _stop_internal(false, false);
  539. }
  540. void AnimationPlayer::stop(bool p_keep_state) {
  541. _stop_internal(true, p_keep_state);
  542. }
  543. void AnimationPlayer::set_speed_scale(float p_speed) {
  544. speed_scale = p_speed;
  545. }
  546. float AnimationPlayer::get_speed_scale() const {
  547. return speed_scale;
  548. }
  549. float AnimationPlayer::get_playing_speed() const {
  550. if (!playing) {
  551. return 0;
  552. }
  553. return speed_scale * playback.current.speed_scale;
  554. }
  555. void AnimationPlayer::seek_internal(double p_time, bool p_update, bool p_update_only, bool p_is_internal_seek) {
  556. if (!active) {
  557. return;
  558. }
  559. bool is_backward = Animation::is_less_approx(p_time, playback.current.pos);
  560. _check_immediately_after_start();
  561. playback.current.pos = p_time;
  562. if (!playback.current.from) {
  563. if (playback.assigned) {
  564. ERR_FAIL_COND_MSG(!animation_set.has(playback.assigned), vformat("Animation not found: %s.", playback.assigned));
  565. playback.current.from = &animation_set[playback.assigned];
  566. }
  567. if (!playback.current.from) {
  568. return; // There is no animation.
  569. }
  570. }
  571. double start = playback.current.get_start_time();
  572. double end = playback.current.get_end_time();
  573. // Clamp the seek position.
  574. p_time = CLAMP(p_time, start, end);
  575. playback.seeked = true;
  576. playback.internal_seeked = p_is_internal_seek;
  577. if (p_update) {
  578. _process_animation(is_backward ? -0.0 : 0.0, p_update_only);
  579. playback.seeked = false; // If animation was proceeded here, no more seek in internal process.
  580. }
  581. }
  582. void AnimationPlayer::seek(double p_time, bool p_update, bool p_update_only) {
  583. seek_internal(p_time, p_update, p_update_only);
  584. }
  585. void AnimationPlayer::advance(double p_time) {
  586. _check_immediately_after_start();
  587. AnimationMixer::advance(p_time);
  588. }
  589. void AnimationPlayer::_check_immediately_after_start() {
  590. if (playback.started) {
  591. _process_animation(0); // Force process current key for Discrete/Method/Audio/AnimationPlayback. Then, started flag is cleared.
  592. }
  593. }
  594. bool AnimationPlayer::is_valid() const {
  595. return (playback.current.from);
  596. }
  597. double AnimationPlayer::get_current_animation_position() const {
  598. ERR_FAIL_NULL_V_MSG(playback.current.from, 0, "AnimationPlayer has no current animation.");
  599. return playback.current.pos;
  600. }
  601. double AnimationPlayer::get_current_animation_length() const {
  602. ERR_FAIL_NULL_V_MSG(playback.current.from, 0, "AnimationPlayer has no current animation.");
  603. return playback.current.from->animation->get_length();
  604. }
  605. void AnimationPlayer::set_section_with_markers(const StringName &p_start_marker, const StringName &p_end_marker) {
  606. ERR_FAIL_NULL_MSG(playback.current.from, "AnimationPlayer has no current animation.");
  607. ERR_FAIL_COND_MSG(p_start_marker == p_end_marker && p_start_marker, vformat("Start marker and end marker cannot be the same marker: %s.", p_start_marker));
  608. ERR_FAIL_COND_MSG(p_start_marker && !playback.current.from->animation->has_marker(p_start_marker), vformat("Marker %s not found in animation: %s.", p_start_marker, playback.current.from->animation->get_name()));
  609. ERR_FAIL_COND_MSG(p_end_marker && !playback.current.from->animation->has_marker(p_end_marker), vformat("Marker %s not found in animation: %s.", p_end_marker, playback.current.from->animation->get_name()));
  610. double start_time = p_start_marker ? playback.current.from->animation->get_marker_time(p_start_marker) : -1;
  611. double end_time = p_end_marker ? playback.current.from->animation->get_marker_time(p_end_marker) : -1;
  612. if (p_start_marker && Animation::is_less_approx(start_time, 0)) {
  613. WARN_PRINT_ONCE_ED(vformat("Marker %s time must be positive in animation: %s.", p_start_marker, playback.current.from->animation->get_name()));
  614. }
  615. if (p_end_marker && Animation::is_less_approx(end_time, 0)) {
  616. WARN_PRINT_ONCE_ED(vformat("Marker %s time must be positive in animation: %s.", p_end_marker, playback.current.from->animation->get_name()));
  617. }
  618. set_section(start_time, end_time);
  619. }
  620. void AnimationPlayer::set_section(double p_start_time, double p_end_time) {
  621. ERR_FAIL_NULL_MSG(playback.current.from, "AnimationPlayer has no current animation.");
  622. ERR_FAIL_COND_MSG(Animation::is_greater_or_equal_approx(p_start_time, 0) && Animation::is_greater_or_equal_approx(p_end_time, 0) && Animation::is_greater_or_equal_approx(p_start_time, p_end_time), vformat("Start time %f is greater than end time %f.", p_start_time, p_end_time));
  623. playback.current.start_time = p_start_time;
  624. playback.current.end_time = p_end_time;
  625. playback.current.pos = CLAMP(playback.current.pos, playback.current.get_start_time(), playback.current.get_end_time());
  626. }
  627. void AnimationPlayer::reset_section() {
  628. playback.current.start_time = -1;
  629. playback.current.end_time = -1;
  630. }
  631. double AnimationPlayer::get_section_start_time() const {
  632. ERR_FAIL_NULL_V_MSG(playback.current.from, playback.current.start_time, "AnimationPlayer has no current animation.");
  633. return playback.current.get_start_time();
  634. }
  635. double AnimationPlayer::get_section_end_time() const {
  636. ERR_FAIL_NULL_V_MSG(playback.current.from, playback.current.end_time, "AnimationPlayer has no current animation.");
  637. return playback.current.get_end_time();
  638. }
  639. bool AnimationPlayer::has_section() const {
  640. return Animation::is_greater_or_equal_approx(playback.current.start_time, 0) || Animation::is_greater_or_equal_approx(playback.current.end_time, 0);
  641. }
  642. void AnimationPlayer::set_autoplay(const StringName &p_name) {
  643. if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
  644. WARN_PRINT("Setting autoplay after the node has been added to the scene has no effect.");
  645. }
  646. autoplay = p_name;
  647. }
  648. StringName AnimationPlayer::get_autoplay() const {
  649. return autoplay;
  650. }
  651. void AnimationPlayer::set_movie_quit_on_finish_enabled(bool p_enabled) {
  652. movie_quit_on_finish = p_enabled;
  653. }
  654. bool AnimationPlayer::is_movie_quit_on_finish_enabled() const {
  655. return movie_quit_on_finish;
  656. }
  657. void AnimationPlayer::_stop_internal(bool p_reset, bool p_keep_state) {
  658. _clear_caches();
  659. Playback &c = playback;
  660. // c.blend.clear();
  661. double start = c.current.from ? playback.current.get_start_time() : 0;
  662. if (p_reset) {
  663. c.blend.clear();
  664. if (p_keep_state) {
  665. c.current.pos = start;
  666. } else {
  667. is_stopping = true;
  668. seek_internal(start, true, true, true);
  669. is_stopping = false;
  670. }
  671. c.current.from = nullptr;
  672. c.current.speed_scale = 1;
  673. emit_signal(SNAME("current_animation_changed"), "");
  674. }
  675. _set_process(false);
  676. playback_queue.clear();
  677. playing = false;
  678. }
  679. void AnimationPlayer::animation_set_next(const StringName &p_animation, const StringName &p_next) {
  680. ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation));
  681. animation_next_set[p_animation] = p_next;
  682. }
  683. StringName AnimationPlayer::animation_get_next(const StringName &p_animation) const {
  684. if (!animation_next_set.has(p_animation)) {
  685. return StringName();
  686. }
  687. return animation_next_set[p_animation];
  688. }
  689. void AnimationPlayer::set_default_blend_time(double p_default) {
  690. default_blend_time = p_default;
  691. }
  692. double AnimationPlayer::get_default_blend_time() const {
  693. return default_blend_time;
  694. }
  695. void AnimationPlayer::set_blend_time(const StringName &p_animation1, const StringName &p_animation2, double p_time) {
  696. ERR_FAIL_COND_MSG(!animation_set.has(p_animation1), vformat("Animation not found: %s.", p_animation1));
  697. ERR_FAIL_COND_MSG(!animation_set.has(p_animation2), vformat("Animation not found: %s.", p_animation2));
  698. ERR_FAIL_COND_MSG(p_time < 0, "Blend time cannot be smaller than 0.");
  699. BlendKey bk;
  700. bk.from = p_animation1;
  701. bk.to = p_animation2;
  702. if (Math::is_zero_approx(p_time)) {
  703. blend_times.erase(bk);
  704. } else {
  705. blend_times[bk] = p_time;
  706. }
  707. }
  708. double AnimationPlayer::get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const {
  709. BlendKey bk;
  710. bk.from = p_animation1;
  711. bk.to = p_animation2;
  712. if (blend_times.has(bk)) {
  713. return blend_times[bk];
  714. } else {
  715. return 0;
  716. }
  717. }
  718. void AnimationPlayer::set_auto_capture(bool p_auto_capture) {
  719. auto_capture = p_auto_capture;
  720. notify_property_list_changed();
  721. }
  722. bool AnimationPlayer::is_auto_capture() const {
  723. return auto_capture;
  724. }
  725. void AnimationPlayer::set_auto_capture_duration(double p_auto_capture_duration) {
  726. auto_capture_duration = p_auto_capture_duration;
  727. }
  728. double AnimationPlayer::get_auto_capture_duration() const {
  729. return auto_capture_duration;
  730. }
  731. void AnimationPlayer::set_auto_capture_transition_type(Tween::TransitionType p_auto_capture_transition_type) {
  732. auto_capture_transition_type = p_auto_capture_transition_type;
  733. }
  734. Tween::TransitionType AnimationPlayer::get_auto_capture_transition_type() const {
  735. return auto_capture_transition_type;
  736. }
  737. void AnimationPlayer::set_auto_capture_ease_type(Tween::EaseType p_auto_capture_ease_type) {
  738. auto_capture_ease_type = p_auto_capture_ease_type;
  739. }
  740. Tween::EaseType AnimationPlayer::get_auto_capture_ease_type() const {
  741. return auto_capture_ease_type;
  742. }
  743. #ifdef TOOLS_ENABLED
  744. void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  745. const String pf = p_function;
  746. if (p_idx == 0 && (pf == "play" || pf == "play_backwards" || pf == "has_animation" || pf == "queue")) {
  747. List<StringName> al;
  748. get_animation_list(&al);
  749. for (const StringName &name : al) {
  750. r_options->push_back(String(name).quote());
  751. }
  752. }
  753. AnimationMixer::get_argument_options(p_function, p_idx, r_options);
  754. }
  755. #endif
  756. void AnimationPlayer::_animation_removed(const StringName &p_name, const StringName &p_library) {
  757. AnimationMixer::_animation_removed(p_name, p_library);
  758. StringName name = p_library == StringName() ? p_name : StringName(String(p_library) + "/" + String(p_name));
  759. if (!animation_set.has(name)) {
  760. return; // No need to update because not the one from the library being used.
  761. }
  762. _animation_set_cache_update();
  763. // Erase blends if needed
  764. List<BlendKey> to_erase;
  765. for (const KeyValue<BlendKey, double> &E : blend_times) {
  766. BlendKey bk = E.key;
  767. if (bk.from == name || bk.to == name) {
  768. to_erase.push_back(bk);
  769. }
  770. }
  771. while (to_erase.size()) {
  772. blend_times.erase(to_erase.front()->get());
  773. to_erase.pop_front();
  774. }
  775. }
  776. void AnimationPlayer::_rename_animation(const StringName &p_from_name, const StringName &p_to_name) {
  777. AnimationMixer::_rename_animation(p_from_name, p_to_name);
  778. // Rename autoplay or blends if needed.
  779. List<BlendKey> to_erase;
  780. HashMap<BlendKey, double, BlendKey> to_insert;
  781. for (const KeyValue<BlendKey, double> &E : blend_times) {
  782. BlendKey bk = E.key;
  783. BlendKey new_bk = bk;
  784. bool erase = false;
  785. if (bk.from == p_from_name) {
  786. new_bk.from = p_to_name;
  787. erase = true;
  788. }
  789. if (bk.to == p_from_name) {
  790. new_bk.to = p_to_name;
  791. erase = true;
  792. }
  793. if (erase) {
  794. to_erase.push_back(bk);
  795. to_insert[new_bk] = E.value;
  796. }
  797. }
  798. while (to_erase.size()) {
  799. blend_times.erase(to_erase.front()->get());
  800. to_erase.pop_front();
  801. }
  802. while (to_insert.size()) {
  803. blend_times[to_insert.begin()->key] = to_insert.begin()->value;
  804. to_insert.remove(to_insert.begin());
  805. }
  806. if (autoplay == p_from_name) {
  807. autoplay = p_to_name;
  808. }
  809. }
  810. void AnimationPlayer::_bind_methods() {
  811. ClassDB::bind_method(D_METHOD("animation_set_next", "animation_from", "animation_to"), &AnimationPlayer::animation_set_next);
  812. ClassDB::bind_method(D_METHOD("animation_get_next", "animation_from"), &AnimationPlayer::animation_get_next);
  813. ClassDB::bind_method(D_METHOD("set_blend_time", "animation_from", "animation_to", "sec"), &AnimationPlayer::set_blend_time);
  814. ClassDB::bind_method(D_METHOD("get_blend_time", "animation_from", "animation_to"), &AnimationPlayer::get_blend_time);
  815. ClassDB::bind_method(D_METHOD("set_default_blend_time", "sec"), &AnimationPlayer::set_default_blend_time);
  816. ClassDB::bind_method(D_METHOD("get_default_blend_time"), &AnimationPlayer::get_default_blend_time);
  817. ClassDB::bind_method(D_METHOD("set_auto_capture", "auto_capture"), &AnimationPlayer::set_auto_capture);
  818. ClassDB::bind_method(D_METHOD("is_auto_capture"), &AnimationPlayer::is_auto_capture);
  819. ClassDB::bind_method(D_METHOD("set_auto_capture_duration", "auto_capture_duration"), &AnimationPlayer::set_auto_capture_duration);
  820. ClassDB::bind_method(D_METHOD("get_auto_capture_duration"), &AnimationPlayer::get_auto_capture_duration);
  821. ClassDB::bind_method(D_METHOD("set_auto_capture_transition_type", "auto_capture_transition_type"), &AnimationPlayer::set_auto_capture_transition_type);
  822. ClassDB::bind_method(D_METHOD("get_auto_capture_transition_type"), &AnimationPlayer::get_auto_capture_transition_type);
  823. ClassDB::bind_method(D_METHOD("set_auto_capture_ease_type", "auto_capture_ease_type"), &AnimationPlayer::set_auto_capture_ease_type);
  824. ClassDB::bind_method(D_METHOD("get_auto_capture_ease_type"), &AnimationPlayer::get_auto_capture_ease_type);
  825. ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(StringName()), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
  826. ClassDB::bind_method(D_METHOD("play_section_with_markers", "name", "start_marker", "end_marker", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play_section_with_markers, DEFVAL(StringName()), DEFVAL(StringName()), DEFVAL(StringName()), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
  827. ClassDB::bind_method(D_METHOD("play_section", "name", "start_time", "end_time", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play_section, DEFVAL(StringName()), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
  828. ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(StringName()), DEFVAL(-1));
  829. ClassDB::bind_method(D_METHOD("play_section_with_markers_backwards", "name", "start_marker", "end_marker", "custom_blend"), &AnimationPlayer::play_section_with_markers_backwards, DEFVAL(StringName()), DEFVAL(StringName()), DEFVAL(StringName()), DEFVAL(-1));
  830. ClassDB::bind_method(D_METHOD("play_section_backwards", "name", "start_time", "end_time", "custom_blend"), &AnimationPlayer::play_section_backwards, DEFVAL(StringName()), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1));
  831. ClassDB::bind_method(D_METHOD("play_with_capture", "name", "duration", "custom_blend", "custom_speed", "from_end", "trans_type", "ease_type"), &AnimationPlayer::play_with_capture, DEFVAL(StringName()), DEFVAL(-1.0), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false), DEFVAL(Tween::TRANS_LINEAR), DEFVAL(Tween::EASE_IN));
  832. ClassDB::bind_method(D_METHOD("pause"), &AnimationPlayer::pause);
  833. ClassDB::bind_method(D_METHOD("stop", "keep_state"), &AnimationPlayer::stop, DEFVAL(false));
  834. ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing);
  835. ClassDB::bind_method(D_METHOD("is_animation_active"), &AnimationPlayer::is_valid);
  836. ClassDB::bind_method(D_METHOD("set_current_animation", "animation"), &AnimationPlayer::set_current_animation);
  837. ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation);
  838. ClassDB::bind_method(D_METHOD("set_assigned_animation", "animation"), &AnimationPlayer::set_assigned_animation);
  839. ClassDB::bind_method(D_METHOD("get_assigned_animation"), &AnimationPlayer::get_assigned_animation);
  840. ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue);
  841. ClassDB::bind_method(D_METHOD("get_queue"), &AnimationPlayer::get_queue);
  842. ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue);
  843. ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &AnimationPlayer::set_speed_scale);
  844. ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimationPlayer::get_speed_scale);
  845. ClassDB::bind_method(D_METHOD("get_playing_speed"), &AnimationPlayer::get_playing_speed);
  846. ClassDB::bind_method(D_METHOD("set_autoplay", "name"), &AnimationPlayer::set_autoplay);
  847. ClassDB::bind_method(D_METHOD("get_autoplay"), &AnimationPlayer::get_autoplay);
  848. ClassDB::bind_method(D_METHOD("find_animation", "animation"), &AnimationPlayer::find_animation);
  849. ClassDB::bind_method(D_METHOD("find_animation_library", "animation"), &AnimationPlayer::find_animation_library);
  850. ClassDB::bind_method(D_METHOD("set_movie_quit_on_finish_enabled", "enabled"), &AnimationPlayer::set_movie_quit_on_finish_enabled);
  851. ClassDB::bind_method(D_METHOD("is_movie_quit_on_finish_enabled"), &AnimationPlayer::is_movie_quit_on_finish_enabled);
  852. ClassDB::bind_method(D_METHOD("get_current_animation_position"), &AnimationPlayer::get_current_animation_position);
  853. ClassDB::bind_method(D_METHOD("get_current_animation_length"), &AnimationPlayer::get_current_animation_length);
  854. ClassDB::bind_method(D_METHOD("set_section_with_markers", "start_marker", "end_marker"), &AnimationPlayer::set_section_with_markers, DEFVAL(StringName()), DEFVAL(StringName()));
  855. ClassDB::bind_method(D_METHOD("set_section", "start_time", "end_time"), &AnimationPlayer::set_section, DEFVAL(-1), DEFVAL(-1));
  856. ClassDB::bind_method(D_METHOD("reset_section"), &AnimationPlayer::reset_section);
  857. ClassDB::bind_method(D_METHOD("get_section_start_time"), &AnimationPlayer::get_section_start_time);
  858. ClassDB::bind_method(D_METHOD("get_section_end_time"), &AnimationPlayer::get_section_end_time);
  859. ClassDB::bind_method(D_METHOD("has_section"), &AnimationPlayer::has_section);
  860. ClassDB::bind_method(D_METHOD("seek", "seconds", "update", "update_only"), &AnimationPlayer::seek, DEFVAL(false), DEFVAL(false));
  861. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR), "set_current_animation", "get_current_animation");
  862. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "assigned_animation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_assigned_animation", "get_assigned_animation");
  863. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_autoplay", "get_autoplay");
  864. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "current_animation_length", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_current_animation_length");
  865. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "current_animation_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_current_animation_position");
  866. ADD_GROUP("Playback Options", "playback_");
  867. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_auto_capture"), "set_auto_capture", "is_auto_capture");
  868. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_auto_capture_duration", PROPERTY_HINT_NONE, "suffix:s"), "set_auto_capture_duration", "get_auto_capture_duration");
  869. ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_auto_capture_transition_type", PROPERTY_HINT_ENUM, "Linear,Sine,Quint,Quart,Quad,Expo,Elastic,Cubic,Circ,Bounce,Back,Spring"), "set_auto_capture_transition_type", "get_auto_capture_transition_type");
  870. 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");
  871. 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");
  872. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "-4,4,0.001,or_less,or_greater"), "set_speed_scale", "get_speed_scale");
  873. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "movie_quit_on_finish"), "set_movie_quit_on_finish_enabled", "is_movie_quit_on_finish_enabled");
  874. ADD_SIGNAL(MethodInfo(SNAME("current_animation_changed"), PropertyInfo(Variant::STRING_NAME, "name")));
  875. ADD_SIGNAL(MethodInfo(SNAME("animation_changed"), PropertyInfo(Variant::STRING_NAME, "old_name"), PropertyInfo(Variant::STRING_NAME, "new_name")));
  876. }
  877. AnimationPlayer::AnimationPlayer() {
  878. }
  879. AnimationPlayer::~AnimationPlayer() {
  880. }