animation_player.cpp 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712
  1. /*************************************************************************/
  2. /* animation_player.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 "core/engine.h"
  32. #include "core/message_queue.h"
  33. #include "scene/scene_string_names.h"
  34. #include "servers/audio/audio_stream.h"
  35. #ifdef TOOLS_ENABLED
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_settings.h"
  38. #include "scene/2d/skeleton_2d.h"
  39. void AnimatedValuesBackup::update_skeletons() {
  40. for (int i = 0; i < entries.size(); i++) {
  41. if (entries[i].bone_idx != -1) {
  42. // 3D bone
  43. Object::cast_to<Skeleton>(entries[i].object)->notification(Skeleton::NOTIFICATION_UPDATE_SKELETON);
  44. } else {
  45. Bone2D *bone = Object::cast_to<Bone2D>(entries[i].object);
  46. if (bone && bone->skeleton) {
  47. // 2D bone
  48. bone->skeleton->_update_transform();
  49. }
  50. }
  51. }
  52. }
  53. void AnimatedValuesBackup::restore() const {
  54. for (int i = 0; i < entries.size(); i++) {
  55. const AnimatedValuesBackup::Entry *entry = &entries[i];
  56. if (entry->bone_idx == -1) {
  57. entry->object->set_indexed(entry->subpath, entry->value);
  58. } else {
  59. Object::cast_to<Skeleton>(entry->object)->set_bone_pose(entry->bone_idx, entry->value);
  60. }
  61. }
  62. }
  63. void AnimatedValuesBackup::_bind_methods() {
  64. ClassDB::bind_method(D_METHOD("restore"), &AnimatedValuesBackup::restore);
  65. }
  66. #endif
  67. bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) {
  68. String name = p_name;
  69. if (name.begins_with("playback/play")) { // bw compatibility
  70. set_current_animation(p_value);
  71. } else if (name.begins_with("anims/")) {
  72. String which = name.get_slicec('/', 1);
  73. add_animation(which, p_value);
  74. } else if (name.begins_with("next/")) {
  75. String which = name.get_slicec('/', 1);
  76. animation_set_next(which, p_value);
  77. } else if (p_name == SceneStringNames::get_singleton()->blend_times) {
  78. Array array = p_value;
  79. int len = array.size();
  80. ERR_FAIL_COND_V(len % 3, false);
  81. for (int i = 0; i < len / 3; i++) {
  82. StringName from = array[i * 3 + 0];
  83. StringName to = array[i * 3 + 1];
  84. float time = array[i * 3 + 2];
  85. set_blend_time(from, to, time);
  86. }
  87. } else {
  88. return false;
  89. }
  90. return true;
  91. }
  92. bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {
  93. String name = p_name;
  94. if (name == "playback/play") { // bw compatibility
  95. r_ret = get_current_animation();
  96. } else if (name.begins_with("anims/")) {
  97. String which = name.get_slicec('/', 1);
  98. r_ret = get_animation(which).get_ref_ptr();
  99. } else if (name.begins_with("next/")) {
  100. String which = name.get_slicec('/', 1);
  101. r_ret = animation_get_next(which);
  102. } else if (name == "blend_times") {
  103. Vector<BlendKey> keys;
  104. for (Map<BlendKey, float>::Element *E = blend_times.front(); E; E = E->next()) {
  105. keys.ordered_insert(E->key());
  106. }
  107. Array array;
  108. for (int i = 0; i < keys.size(); i++) {
  109. array.push_back(keys[i].from);
  110. array.push_back(keys[i].to);
  111. array.push_back(blend_times[keys[i]]);
  112. }
  113. r_ret = array;
  114. } else {
  115. return false;
  116. }
  117. return true;
  118. }
  119. void AnimationPlayer::_validate_property(PropertyInfo &property) const {
  120. if (property.name == "current_animation") {
  121. List<String> names;
  122. for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
  123. names.push_back(E->key());
  124. }
  125. names.sort();
  126. names.push_front("[stop]");
  127. String hint;
  128. for (List<String>::Element *E = names.front(); E; E = E->next()) {
  129. if (E != names.front()) {
  130. hint += ",";
  131. }
  132. hint += E->get();
  133. }
  134. property.hint_string = hint;
  135. }
  136. }
  137. void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const {
  138. List<PropertyInfo> anim_names;
  139. for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
  140. anim_names.push_back(PropertyInfo(Variant::OBJECT, "anims/" + String(E->key()), PROPERTY_HINT_RESOURCE_TYPE, "Animation", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE));
  141. if (E->get().next != StringName()) {
  142. anim_names.push_back(PropertyInfo(Variant::STRING, "next/" + String(E->key()), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  143. }
  144. }
  145. anim_names.sort();
  146. for (List<PropertyInfo>::Element *E = anim_names.front(); E; E = E->next()) {
  147. p_list->push_back(E->get());
  148. }
  149. p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  150. }
  151. void AnimationPlayer::advance(float p_time) {
  152. _animation_process(p_time);
  153. }
  154. void AnimationPlayer::_notification(int p_what) {
  155. switch (p_what) {
  156. case NOTIFICATION_ENTER_TREE: {
  157. if (!processing) {
  158. //make sure that a previous process state was not saved
  159. //only process if "processing" is set
  160. set_physics_process_internal(false);
  161. set_process_internal(false);
  162. }
  163. //_set_process(false);
  164. clear_caches();
  165. } break;
  166. case NOTIFICATION_READY: {
  167. if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) {
  168. play(autoplay);
  169. _animation_process(0);
  170. }
  171. } break;
  172. case NOTIFICATION_INTERNAL_PROCESS: {
  173. if (animation_process_mode == ANIMATION_PROCESS_PHYSICS) {
  174. break;
  175. }
  176. if (processing) {
  177. _animation_process(get_process_delta_time());
  178. }
  179. } break;
  180. case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
  181. if (animation_process_mode == ANIMATION_PROCESS_IDLE) {
  182. break;
  183. }
  184. if (processing) {
  185. _animation_process(get_physics_process_delta_time());
  186. }
  187. } break;
  188. case NOTIFICATION_EXIT_TREE: {
  189. clear_caches();
  190. } break;
  191. }
  192. }
  193. void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim, Node *p_root_override) {
  194. // Already cached?
  195. if (p_anim->node_cache.size() == p_anim->animation->get_track_count()) {
  196. return;
  197. }
  198. Node *parent = p_root_override ? p_root_override : get_node(root);
  199. ERR_FAIL_COND(!parent);
  200. Animation *a = p_anim->animation.operator->();
  201. p_anim->node_cache.resize(a->get_track_count());
  202. for (int i = 0; i < a->get_track_count(); i++) {
  203. p_anim->node_cache.write[i] = NULL;
  204. RES resource;
  205. Vector<StringName> leftover_path;
  206. Node *child = parent->get_node_and_resource(a->track_get_path(i), resource, leftover_path);
  207. ERR_CONTINUE_MSG(!child, "On Animation: '" + p_anim->name + "', couldn't resolve track: '" + String(a->track_get_path(i)) + "'."); // couldn't find the child node
  208. uint32_t id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id();
  209. int bone_idx = -1;
  210. if (a->track_get_path(i).get_subname_count() == 1 && Object::cast_to<Skeleton>(child)) {
  211. Skeleton *sk = Object::cast_to<Skeleton>(child);
  212. bone_idx = sk->find_bone(a->track_get_path(i).get_subname(0));
  213. if (bone_idx == -1) {
  214. continue;
  215. }
  216. }
  217. {
  218. if (!child->is_connected("tree_exiting", this, "_node_removed")) {
  219. child->connect("tree_exiting", this, "_node_removed", make_binds(child), CONNECT_ONESHOT);
  220. }
  221. }
  222. TrackNodeCacheKey key;
  223. key.id = id;
  224. key.bone_idx = bone_idx;
  225. if (!node_cache_map.has(key)) {
  226. node_cache_map[key] = TrackNodeCache();
  227. }
  228. p_anim->node_cache.write[i] = &node_cache_map[key];
  229. p_anim->node_cache[i]->path = a->track_get_path(i);
  230. p_anim->node_cache[i]->node = child;
  231. p_anim->node_cache[i]->resource = resource;
  232. p_anim->node_cache[i]->node_2d = Object::cast_to<Node2D>(child);
  233. if (a->track_get_type(i) == Animation::TYPE_TRANSFORM) {
  234. // special cases and caches for transform tracks
  235. // cache spatial
  236. p_anim->node_cache[i]->spatial = Object::cast_to<Spatial>(child);
  237. // cache skeleton
  238. p_anim->node_cache[i]->skeleton = Object::cast_to<Skeleton>(child);
  239. if (p_anim->node_cache[i]->skeleton) {
  240. if (a->track_get_path(i).get_subname_count() == 1) {
  241. StringName bone_name = a->track_get_path(i).get_subname(0);
  242. p_anim->node_cache[i]->bone_idx = p_anim->node_cache[i]->skeleton->find_bone(bone_name);
  243. if (p_anim->node_cache[i]->bone_idx < 0) {
  244. // broken track (nonexistent bone)
  245. p_anim->node_cache[i]->skeleton = nullptr;
  246. p_anim->node_cache[i]->spatial = nullptr;
  247. ERR_CONTINUE(p_anim->node_cache[i]->bone_idx < 0);
  248. }
  249. } else {
  250. // no property, just use spatialnode
  251. p_anim->node_cache[i]->skeleton = nullptr;
  252. }
  253. }
  254. }
  255. if (a->track_get_type(i) == Animation::TYPE_VALUE) {
  256. if (!p_anim->node_cache[i]->property_anim.has(a->track_get_path(i).get_concatenated_subnames())) {
  257. TrackNodeCache::PropertyAnim pa;
  258. pa.subpath = leftover_path;
  259. pa.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child;
  260. pa.special = SP_NONE;
  261. pa.owner = p_anim->node_cache[i];
  262. if (false && p_anim->node_cache[i]->node_2d) {
  263. if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_pos) {
  264. pa.special = SP_NODE2D_POS;
  265. } else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_rot) {
  266. pa.special = SP_NODE2D_ROT;
  267. } else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_scale) {
  268. pa.special = SP_NODE2D_SCALE;
  269. }
  270. }
  271. p_anim->node_cache[i]->property_anim[a->track_get_path(i).get_concatenated_subnames()] = pa;
  272. }
  273. }
  274. if (a->track_get_type(i) == Animation::TYPE_BEZIER && leftover_path.size()) {
  275. if (!p_anim->node_cache[i]->bezier_anim.has(a->track_get_path(i).get_concatenated_subnames())) {
  276. TrackNodeCache::BezierAnim ba;
  277. ba.bezier_property = leftover_path;
  278. ba.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child;
  279. ba.owner = p_anim->node_cache[i];
  280. p_anim->node_cache[i]->bezier_anim[a->track_get_path(i).get_concatenated_subnames()] = ba;
  281. }
  282. }
  283. }
  284. }
  285. void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float p_time, float p_delta, float p_interp, bool p_is_current, bool p_seeked, bool p_started) {
  286. _ensure_node_caches(p_anim);
  287. ERR_FAIL_COND(p_anim->node_cache.size() != p_anim->animation->get_track_count());
  288. Animation *a = p_anim->animation.operator->();
  289. bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
  290. for (int i = 0; i < a->get_track_count(); i++) {
  291. // If an animation changes this animation (or it animates itself)
  292. // we need to recreate our animation cache
  293. if (p_anim->node_cache.size() != a->get_track_count()) {
  294. _ensure_node_caches(p_anim);
  295. }
  296. TrackNodeCache *nc = p_anim->node_cache[i];
  297. if (!nc) {
  298. continue; // no node cache for this track, skip it
  299. }
  300. if (!a->track_is_enabled(i)) {
  301. continue; // do nothing if the track is disabled
  302. }
  303. if (a->track_get_key_count(i) == 0) {
  304. continue; // do nothing if track is empty
  305. }
  306. switch (a->track_get_type(i)) {
  307. case Animation::TYPE_TRANSFORM: {
  308. if (!nc->spatial) {
  309. continue;
  310. }
  311. Vector3 loc;
  312. Quat rot;
  313. Vector3 scale;
  314. Error err = a->transform_track_interpolate(i, p_time, &loc, &rot, &scale);
  315. //ERR_CONTINUE(err!=OK); //used for testing, should be removed
  316. if (err != OK) {
  317. continue;
  318. }
  319. if (nc->accum_pass != accum_pass) {
  320. ERR_CONTINUE(cache_update_size >= NODE_CACHE_UPDATE_MAX);
  321. cache_update[cache_update_size++] = nc;
  322. nc->accum_pass = accum_pass;
  323. nc->loc_accum = loc;
  324. nc->rot_accum = rot;
  325. nc->scale_accum = scale;
  326. } else {
  327. nc->loc_accum = nc->loc_accum.linear_interpolate(loc, p_interp);
  328. nc->rot_accum = nc->rot_accum.slerp(rot, p_interp);
  329. nc->scale_accum = nc->scale_accum.linear_interpolate(scale, p_interp);
  330. }
  331. } break;
  332. case Animation::TYPE_VALUE: {
  333. if (!nc->node) {
  334. continue;
  335. }
  336. //StringName property=a->track_get_path(i).get_property();
  337. Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.find(a->track_get_path(i).get_concatenated_subnames());
  338. ERR_CONTINUE(!E); //should it continue, or create a new one?
  339. TrackNodeCache::PropertyAnim *pa = &E->get();
  340. Animation::UpdateMode update_mode = a->value_track_get_update_mode(i);
  341. if (update_mode == Animation::UPDATE_CAPTURE) {
  342. if (p_started || pa->capture == Variant()) {
  343. pa->capture = pa->object->get_indexed(pa->subpath);
  344. }
  345. int key_count = a->track_get_key_count(i);
  346. if (key_count == 0) {
  347. continue; //eeh not worth it
  348. }
  349. float first_key_time = a->track_get_key_time(i, 0);
  350. float transition = 1.0;
  351. int first_key = 0;
  352. if (first_key_time == 0.0) {
  353. //ignore, use for transition
  354. if (key_count == 1) {
  355. continue; //with one key we can't do anything
  356. }
  357. transition = a->track_get_key_transition(i, 0);
  358. first_key_time = a->track_get_key_time(i, 1);
  359. first_key = 1;
  360. }
  361. if (p_time < first_key_time) {
  362. float c = Math::ease(p_time / first_key_time, transition);
  363. Variant first_value = a->track_get_key_value(i, first_key);
  364. Variant interp_value;
  365. Variant::interpolate(pa->capture, first_value, c, interp_value);
  366. if (pa->accum_pass != accum_pass) {
  367. ERR_CONTINUE(cache_update_prop_size >= NODE_CACHE_UPDATE_MAX);
  368. cache_update_prop[cache_update_prop_size++] = pa;
  369. pa->value_accum = interp_value;
  370. pa->accum_pass = accum_pass;
  371. } else {
  372. Variant::interpolate(pa->value_accum, interp_value, p_interp, pa->value_accum);
  373. }
  374. continue; //handled
  375. }
  376. }
  377. if (update_mode == Animation::UPDATE_CONTINUOUS || update_mode == Animation::UPDATE_CAPTURE || (p_delta == 0 && update_mode == Animation::UPDATE_DISCRETE)) { //delta == 0 means seek
  378. Variant value = a->value_track_interpolate(i, p_time);
  379. if (value == Variant()) {
  380. continue;
  381. }
  382. //thanks to trigger mode, this should be solved now..
  383. /*
  384. if (p_delta==0 && value.get_type()==Variant::STRING)
  385. continue; // doing this with strings is messy, should find another way
  386. */
  387. if (pa->accum_pass != accum_pass) {
  388. ERR_CONTINUE(cache_update_prop_size >= NODE_CACHE_UPDATE_MAX);
  389. cache_update_prop[cache_update_prop_size++] = pa;
  390. pa->value_accum = value;
  391. pa->accum_pass = accum_pass;
  392. } else {
  393. Variant::interpolate(pa->value_accum, value, p_interp, pa->value_accum);
  394. }
  395. } else if (p_is_current && p_delta != 0) {
  396. List<int> indices;
  397. a->value_track_get_key_indices(i, p_time, p_delta, &indices);
  398. for (List<int>::Element *F = indices.front(); F; F = F->next()) {
  399. Variant value = a->track_get_key_value(i, F->get());
  400. switch (pa->special) {
  401. case SP_NONE: {
  402. bool valid;
  403. pa->object->set_indexed(pa->subpath, value, &valid); //you are not speshul
  404. #ifdef DEBUG_ENABLED
  405. if (!valid) {
  406. ERR_PRINT("Failed setting track value '" + String(pa->owner->path) + "'. Check if property exists or the type of key is valid. Animation '" + a->get_name() + "' at node '" + get_path() + "'.");
  407. }
  408. #endif
  409. } break;
  410. case SP_NODE2D_POS: {
  411. #ifdef DEBUG_ENABLED
  412. if (value.get_type() != Variant::VECTOR2) {
  413. ERR_PRINT("Position key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2(). Animation '" + a->get_name() + "' at node '" + get_path() + "'.");
  414. }
  415. #endif
  416. static_cast<Node2D *>(pa->object)->set_position(value);
  417. } break;
  418. case SP_NODE2D_ROT: {
  419. #ifdef DEBUG_ENABLED
  420. if (value.is_num()) {
  421. ERR_PRINT("Rotation key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not numerical. Animation '" + a->get_name() + "' at node '" + get_path() + "'.");
  422. }
  423. #endif
  424. static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)value));
  425. } break;
  426. case SP_NODE2D_SCALE: {
  427. #ifdef DEBUG_ENABLED
  428. if (value.get_type() != Variant::VECTOR2) {
  429. ERR_PRINT("Scale key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2()." + a->get_name() + "' at node '" + get_path() + "'.");
  430. }
  431. #endif
  432. static_cast<Node2D *>(pa->object)->set_scale(value);
  433. } break;
  434. }
  435. }
  436. }
  437. } break;
  438. case Animation::TYPE_METHOD: {
  439. if (!nc->node) {
  440. continue;
  441. }
  442. if (p_delta == 0) {
  443. continue;
  444. }
  445. if (!p_is_current) {
  446. break;
  447. }
  448. List<int> indices;
  449. a->method_track_get_key_indices(i, p_time, p_delta, &indices);
  450. for (List<int>::Element *E = indices.front(); E; E = E->next()) {
  451. StringName method = a->method_track_get_name(i, E->get());
  452. Vector<Variant> params = a->method_track_get_params(i, E->get());
  453. int s = params.size();
  454. ERR_CONTINUE(s > VARIANT_ARG_MAX);
  455. #ifdef DEBUG_ENABLED
  456. if (!nc->node->has_method(method)) {
  457. ERR_PRINT("Invalid method call '" + method + "'. '" + a->get_name() + "' at node '" + get_path() + "'.");
  458. }
  459. #endif
  460. if (can_call) {
  461. if (method_call_mode == ANIMATION_METHOD_CALL_DEFERRED) {
  462. MessageQueue::get_singleton()->push_call(
  463. nc->node,
  464. method,
  465. s >= 1 ? params[0] : Variant(),
  466. s >= 2 ? params[1] : Variant(),
  467. s >= 3 ? params[2] : Variant(),
  468. s >= 4 ? params[3] : Variant(),
  469. s >= 5 ? params[4] : Variant());
  470. } else {
  471. nc->node->call(
  472. method,
  473. s >= 1 ? params[0] : Variant(),
  474. s >= 2 ? params[1] : Variant(),
  475. s >= 3 ? params[2] : Variant(),
  476. s >= 4 ? params[3] : Variant(),
  477. s >= 5 ? params[4] : Variant());
  478. }
  479. }
  480. }
  481. } break;
  482. case Animation::TYPE_BEZIER: {
  483. if (!nc->node) {
  484. continue;
  485. }
  486. Map<StringName, TrackNodeCache::BezierAnim>::Element *E = nc->bezier_anim.find(a->track_get_path(i).get_concatenated_subnames());
  487. ERR_CONTINUE(!E); //should it continue, or create a new one?
  488. TrackNodeCache::BezierAnim *ba = &E->get();
  489. float bezier = a->bezier_track_interpolate(i, p_time);
  490. if (ba->accum_pass != accum_pass) {
  491. ERR_CONTINUE(cache_update_bezier_size >= NODE_CACHE_UPDATE_MAX);
  492. cache_update_bezier[cache_update_bezier_size++] = ba;
  493. ba->bezier_accum = bezier;
  494. ba->accum_pass = accum_pass;
  495. } else {
  496. ba->bezier_accum = Math::lerp(ba->bezier_accum, bezier, p_interp);
  497. }
  498. } break;
  499. case Animation::TYPE_AUDIO: {
  500. if (!nc->node) {
  501. continue;
  502. }
  503. if (p_delta == 0) {
  504. continue;
  505. }
  506. if (p_seeked) {
  507. //find whatever should be playing
  508. int idx = a->track_find_key(i, p_time);
  509. if (idx < 0) {
  510. continue;
  511. }
  512. Ref<AudioStream> stream = a->audio_track_get_key_stream(i, idx);
  513. if (!stream.is_valid()) {
  514. nc->node->call("stop");
  515. nc->audio_playing = false;
  516. playing_caches.erase(nc);
  517. } else {
  518. float start_ofs = a->audio_track_get_key_start_offset(i, idx);
  519. start_ofs += p_time - a->track_get_key_time(i, idx);
  520. float end_ofs = a->audio_track_get_key_end_offset(i, idx);
  521. float len = stream->get_length();
  522. if (start_ofs > len - end_ofs) {
  523. nc->node->call("stop");
  524. nc->audio_playing = false;
  525. playing_caches.erase(nc);
  526. continue;
  527. }
  528. nc->node->call("set_stream", stream);
  529. nc->node->call("play", start_ofs);
  530. nc->audio_playing = true;
  531. playing_caches.insert(nc);
  532. if (len && end_ofs > 0) { //force a end at a time
  533. nc->audio_len = len - start_ofs - end_ofs;
  534. } else {
  535. nc->audio_len = 0;
  536. }
  537. nc->audio_start = p_time;
  538. }
  539. } else {
  540. //find stuff to play
  541. List<int> to_play;
  542. a->track_get_key_indices_in_range(i, p_time, p_delta, &to_play);
  543. if (to_play.size()) {
  544. int idx = to_play.back()->get();
  545. Ref<AudioStream> stream = a->audio_track_get_key_stream(i, idx);
  546. if (!stream.is_valid()) {
  547. nc->node->call("stop");
  548. nc->audio_playing = false;
  549. playing_caches.erase(nc);
  550. } else {
  551. float start_ofs = a->audio_track_get_key_start_offset(i, idx);
  552. float end_ofs = a->audio_track_get_key_end_offset(i, idx);
  553. float len = stream->get_length();
  554. nc->node->call("set_stream", stream);
  555. nc->node->call("play", start_ofs);
  556. nc->audio_playing = true;
  557. playing_caches.insert(nc);
  558. if (len && end_ofs > 0) { //force a end at a time
  559. nc->audio_len = len - start_ofs - end_ofs;
  560. } else {
  561. nc->audio_len = 0;
  562. }
  563. nc->audio_start = p_time;
  564. }
  565. } else if (nc->audio_playing) {
  566. bool loop = a->has_loop();
  567. bool stop = false;
  568. if (!loop && p_time < nc->audio_start) {
  569. stop = true;
  570. } else if (nc->audio_len > 0) {
  571. float len = nc->audio_start > p_time ? (a->get_length() - nc->audio_start) + p_time : p_time - nc->audio_start;
  572. if (len > nc->audio_len) {
  573. stop = true;
  574. }
  575. }
  576. if (stop) {
  577. //time to stop
  578. nc->node->call("stop");
  579. nc->audio_playing = false;
  580. playing_caches.erase(nc);
  581. }
  582. }
  583. }
  584. } break;
  585. case Animation::TYPE_ANIMATION: {
  586. AnimationPlayer *player = Object::cast_to<AnimationPlayer>(nc->node);
  587. if (!player) {
  588. continue;
  589. }
  590. if (p_delta == 0 || p_seeked) {
  591. //seek
  592. int idx = a->track_find_key(i, p_time);
  593. if (idx < 0) {
  594. continue;
  595. }
  596. float pos = a->track_get_key_time(i, idx);
  597. StringName anim_name = a->animation_track_get_key_animation(i, idx);
  598. if (String(anim_name) == "[stop]" || !player->has_animation(anim_name)) {
  599. continue;
  600. }
  601. Ref<Animation> anim = player->get_animation(anim_name);
  602. float at_anim_pos;
  603. if (anim->has_loop()) {
  604. at_anim_pos = Math::fposmod(p_time - pos, anim->get_length()); //seek to loop
  605. } else {
  606. at_anim_pos = MIN(anim->get_length(), p_time - pos); //seek to end
  607. }
  608. if (player->is_playing() || p_seeked) {
  609. player->play(anim_name);
  610. player->seek(at_anim_pos);
  611. nc->animation_playing = true;
  612. playing_caches.insert(nc);
  613. } else {
  614. player->set_assigned_animation(anim_name);
  615. player->seek(at_anim_pos, true);
  616. }
  617. } else {
  618. //find stuff to play
  619. List<int> to_play;
  620. a->track_get_key_indices_in_range(i, p_time, p_delta, &to_play);
  621. if (to_play.size()) {
  622. int idx = to_play.back()->get();
  623. StringName anim_name = a->animation_track_get_key_animation(i, idx);
  624. if (String(anim_name) == "[stop]" || !player->has_animation(anim_name)) {
  625. if (playing_caches.has(nc)) {
  626. playing_caches.erase(nc);
  627. player->stop();
  628. nc->animation_playing = false;
  629. }
  630. } else {
  631. player->play(anim_name);
  632. player->seek(0.0, true);
  633. nc->animation_playing = true;
  634. playing_caches.insert(nc);
  635. }
  636. }
  637. }
  638. } break;
  639. }
  640. }
  641. }
  642. void AnimationPlayer::_animation_process_data(PlaybackData &cd, float p_delta, float p_blend, bool p_seeked, bool p_started) {
  643. float delta = p_delta * speed_scale * cd.speed_scale;
  644. float next_pos = cd.pos + delta;
  645. float len = cd.from->animation->get_length();
  646. bool loop = cd.from->animation->has_loop();
  647. if (!loop) {
  648. if (next_pos < 0) {
  649. next_pos = 0;
  650. } else if (next_pos > len) {
  651. next_pos = len;
  652. }
  653. bool backwards = signbit(delta); // Negative zero means playing backwards too
  654. delta = next_pos - cd.pos; // Fix delta (after determination of backwards because negative zero is lost here)
  655. if (&cd == &playback.current) {
  656. if (!backwards && cd.pos <= len && next_pos == len /*&& playback.blend.empty()*/) {
  657. //playback finished
  658. end_reached = true;
  659. end_notify = cd.pos < len; // Notify only if not already at the end
  660. }
  661. if (backwards && cd.pos >= 0 && next_pos == 0 /*&& playback.blend.empty()*/) {
  662. //playback finished
  663. end_reached = true;
  664. end_notify = cd.pos > 0; // Notify only if not already at the beginning
  665. }
  666. }
  667. } else {
  668. float looped_next_pos = Math::fposmod(next_pos, len);
  669. if (looped_next_pos == 0 && next_pos != 0) {
  670. // Loop multiples of the length to it, rather than 0
  671. // so state at time=length is previewable in the editor
  672. next_pos = len;
  673. } else {
  674. next_pos = looped_next_pos;
  675. }
  676. }
  677. cd.pos = next_pos;
  678. _animation_process_animation(cd.from, cd.pos, delta, p_blend, &cd == &playback.current, p_seeked, p_started);
  679. }
  680. void AnimationPlayer::_animation_process2(float p_delta, bool p_started) {
  681. Playback &c = playback;
  682. accum_pass++;
  683. _animation_process_data(c.current, p_delta, 1.0f, c.seeked && p_delta != 0, p_started);
  684. if (p_delta != 0) {
  685. c.seeked = false;
  686. }
  687. List<Blend>::Element *prev = nullptr;
  688. for (List<Blend>::Element *E = c.blend.back(); E; E = prev) {
  689. Blend &b = E->get();
  690. float blend = b.blend_left / b.blend_time;
  691. _animation_process_data(b.data, p_delta, blend, false, false);
  692. b.blend_left -= Math::absf(speed_scale * p_delta);
  693. prev = E->prev();
  694. if (b.blend_left < 0) {
  695. c.blend.erase(E);
  696. }
  697. }
  698. }
  699. void AnimationPlayer::_animation_update_transforms() {
  700. {
  701. Transform t;
  702. for (int i = 0; i < cache_update_size; i++) {
  703. TrackNodeCache *nc = cache_update[i];
  704. ERR_CONTINUE(nc->accum_pass != accum_pass);
  705. t.origin = nc->loc_accum;
  706. t.basis.set_quat_scale(nc->rot_accum, nc->scale_accum);
  707. if (nc->skeleton && nc->bone_idx >= 0) {
  708. nc->skeleton->set_bone_pose(nc->bone_idx, t);
  709. } else if (nc->spatial) {
  710. nc->spatial->set_transform(t);
  711. }
  712. }
  713. }
  714. cache_update_size = 0;
  715. for (int i = 0; i < cache_update_prop_size; i++) {
  716. TrackNodeCache::PropertyAnim *pa = cache_update_prop[i];
  717. ERR_CONTINUE(pa->accum_pass != accum_pass);
  718. switch (pa->special) {
  719. case SP_NONE: {
  720. bool valid;
  721. pa->object->set_indexed(pa->subpath, pa->value_accum, &valid); //you are not speshul
  722. #ifdef DEBUG_ENABLED
  723. if (!valid) {
  724. ERR_PRINT("Failed setting key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "'. Check if property exists or the type of key is right for the property");
  725. }
  726. #endif
  727. } break;
  728. case SP_NODE2D_POS: {
  729. #ifdef DEBUG_ENABLED
  730. if (pa->value_accum.get_type() != Variant::VECTOR2) {
  731. ERR_PRINT("Position key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()");
  732. }
  733. #endif
  734. static_cast<Node2D *>(pa->object)->set_position(pa->value_accum);
  735. } break;
  736. case SP_NODE2D_ROT: {
  737. #ifdef DEBUG_ENABLED
  738. if (pa->value_accum.is_num()) {
  739. ERR_PRINT("Rotation key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not numerical");
  740. }
  741. #endif
  742. static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)pa->value_accum));
  743. } break;
  744. case SP_NODE2D_SCALE: {
  745. #ifdef DEBUG_ENABLED
  746. if (pa->value_accum.get_type() != Variant::VECTOR2) {
  747. ERR_PRINT("Scale key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()");
  748. }
  749. #endif
  750. static_cast<Node2D *>(pa->object)->set_scale(pa->value_accum);
  751. } break;
  752. }
  753. }
  754. cache_update_prop_size = 0;
  755. for (int i = 0; i < cache_update_bezier_size; i++) {
  756. TrackNodeCache::BezierAnim *ba = cache_update_bezier[i];
  757. ERR_CONTINUE(ba->accum_pass != accum_pass);
  758. ba->object->set_indexed(ba->bezier_property, ba->bezier_accum);
  759. }
  760. cache_update_bezier_size = 0;
  761. }
  762. void AnimationPlayer::_animation_process(float p_delta) {
  763. if (playback.current.from) {
  764. end_reached = false;
  765. end_notify = false;
  766. _animation_process2(p_delta, playback.started);
  767. if (playback.started) {
  768. playback.started = false;
  769. }
  770. _animation_update_transforms();
  771. if (end_reached) {
  772. if (queued.size()) {
  773. String old = playback.assigned;
  774. play(queued.front()->get());
  775. String new_name = playback.assigned;
  776. queued.pop_front();
  777. if (end_notify) {
  778. emit_signal(SceneStringNames::get_singleton()->animation_changed, old, new_name);
  779. }
  780. } else {
  781. //stop();
  782. playing = false;
  783. _set_process(false);
  784. if (end_notify) {
  785. emit_signal(SceneStringNames::get_singleton()->animation_finished, playback.assigned);
  786. }
  787. }
  788. end_reached = false;
  789. }
  790. } else {
  791. _set_process(false);
  792. }
  793. }
  794. Error AnimationPlayer::add_animation(const StringName &p_name, const Ref<Animation> &p_animation) {
  795. #ifdef DEBUG_ENABLED
  796. ERR_FAIL_COND_V_MSG(String(p_name).find("/") != -1 || String(p_name).find(":") != -1 || String(p_name).find(",") != -1 || String(p_name).find("[") != -1, ERR_INVALID_PARAMETER, "Invalid animation name: " + String(p_name) + ".");
  797. #endif
  798. ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER);
  799. if (animation_set.has(p_name)) {
  800. _unref_anim(animation_set[p_name].animation);
  801. animation_set[p_name].animation = p_animation;
  802. clear_caches();
  803. } else {
  804. AnimationData ad;
  805. ad.animation = p_animation;
  806. ad.name = p_name;
  807. animation_set[p_name] = ad;
  808. }
  809. _ref_anim(p_animation);
  810. _change_notify();
  811. return OK;
  812. }
  813. void AnimationPlayer::remove_animation(const StringName &p_name) {
  814. ERR_FAIL_COND(!animation_set.has(p_name));
  815. stop();
  816. _unref_anim(animation_set[p_name].animation);
  817. animation_set.erase(p_name);
  818. clear_caches();
  819. _change_notify();
  820. }
  821. void AnimationPlayer::_ref_anim(const Ref<Animation> &p_anim) {
  822. Ref<Animation>(p_anim)->connect(SceneStringNames::get_singleton()->tracks_changed, this, "_animation_changed", varray(), CONNECT_REFERENCE_COUNTED);
  823. }
  824. void AnimationPlayer::_unref_anim(const Ref<Animation> &p_anim) {
  825. Ref<Animation>(p_anim)->disconnect(SceneStringNames::get_singleton()->tracks_changed, this, "_animation_changed");
  826. }
  827. void AnimationPlayer::rename_animation(const StringName &p_name, const StringName &p_new_name) {
  828. ERR_FAIL_COND(!animation_set.has(p_name));
  829. ERR_FAIL_COND(String(p_new_name).find("/") != -1 || String(p_new_name).find(":") != -1);
  830. ERR_FAIL_COND(animation_set.has(p_new_name));
  831. stop();
  832. AnimationData ad = animation_set[p_name];
  833. ad.name = p_new_name;
  834. animation_set.erase(p_name);
  835. animation_set[p_new_name] = ad;
  836. List<BlendKey> to_erase;
  837. Map<BlendKey, float> to_insert;
  838. for (Map<BlendKey, float>::Element *E = blend_times.front(); E; E = E->next()) {
  839. BlendKey bk = E->key();
  840. BlendKey new_bk = bk;
  841. bool erase = false;
  842. if (bk.from == p_name) {
  843. new_bk.from = p_new_name;
  844. erase = true;
  845. }
  846. if (bk.to == p_name) {
  847. new_bk.to = p_new_name;
  848. erase = true;
  849. }
  850. if (erase) {
  851. to_erase.push_back(bk);
  852. to_insert[new_bk] = E->get();
  853. }
  854. }
  855. while (to_erase.size()) {
  856. blend_times.erase(to_erase.front()->get());
  857. to_erase.pop_front();
  858. }
  859. while (to_insert.size()) {
  860. blend_times[to_insert.front()->key()] = to_insert.front()->get();
  861. to_insert.erase(to_insert.front());
  862. }
  863. if (autoplay == p_name) {
  864. autoplay = p_new_name;
  865. }
  866. clear_caches();
  867. _change_notify();
  868. }
  869. bool AnimationPlayer::has_animation(const StringName &p_name) const {
  870. return animation_set.has(p_name);
  871. }
  872. Ref<Animation> AnimationPlayer::get_animation(const StringName &p_name) const {
  873. ERR_FAIL_COND_V(!animation_set.has(p_name), Ref<Animation>());
  874. const AnimationData &data = animation_set[p_name];
  875. return data.animation;
  876. }
  877. void AnimationPlayer::get_animation_list(List<StringName> *p_animations) const {
  878. List<String> anims;
  879. for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
  880. anims.push_back(E->key());
  881. }
  882. anims.sort();
  883. for (List<String>::Element *E = anims.front(); E; E = E->next()) {
  884. p_animations->push_back(E->get());
  885. }
  886. }
  887. void AnimationPlayer::set_blend_time(const StringName &p_animation1, const StringName &p_animation2, float p_time) {
  888. ERR_FAIL_COND(!animation_set.has(p_animation1));
  889. ERR_FAIL_COND(!animation_set.has(p_animation2));
  890. ERR_FAIL_COND_MSG(p_time < 0, "Blend time cannot be smaller than 0.");
  891. BlendKey bk;
  892. bk.from = p_animation1;
  893. bk.to = p_animation2;
  894. if (p_time == 0) {
  895. blend_times.erase(bk);
  896. } else {
  897. blend_times[bk] = p_time;
  898. }
  899. }
  900. float AnimationPlayer::get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const {
  901. BlendKey bk;
  902. bk.from = p_animation1;
  903. bk.to = p_animation2;
  904. if (blend_times.has(bk)) {
  905. return blend_times[bk];
  906. } else {
  907. return 0;
  908. }
  909. }
  910. void AnimationPlayer::queue(const StringName &p_name) {
  911. if (!is_playing()) {
  912. play(p_name);
  913. } else {
  914. queued.push_back(p_name);
  915. }
  916. }
  917. PoolVector<String> AnimationPlayer::get_queue() {
  918. PoolVector<String> ret;
  919. for (List<StringName>::Element *E = queued.front(); E; E = E->next()) {
  920. ret.push_back(E->get());
  921. }
  922. return ret;
  923. }
  924. void AnimationPlayer::clear_queue() {
  925. queued.clear();
  926. }
  927. void AnimationPlayer::play_backwards(const StringName &p_name, float p_custom_blend) {
  928. play(p_name, p_custom_blend, -1, true);
  929. }
  930. void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float p_custom_scale, bool p_from_end) {
  931. StringName name = p_name;
  932. if (String(name) == "") {
  933. name = playback.assigned;
  934. }
  935. ERR_FAIL_COND_MSG(!animation_set.has(name), "Animation not found: " + name + ".");
  936. Playback &c = playback;
  937. if (c.current.from) {
  938. float blend_time = 0;
  939. // find if it can blend
  940. BlendKey bk;
  941. bk.from = c.current.from->name;
  942. bk.to = name;
  943. if (p_custom_blend >= 0) {
  944. blend_time = p_custom_blend;
  945. } else if (blend_times.has(bk)) {
  946. blend_time = blend_times[bk];
  947. } else {
  948. bk.from = "*";
  949. if (blend_times.has(bk)) {
  950. blend_time = blend_times[bk];
  951. } else {
  952. bk.from = c.current.from->name;
  953. bk.to = "*";
  954. if (blend_times.has(bk)) {
  955. blend_time = blend_times[bk];
  956. }
  957. }
  958. }
  959. if (p_custom_blend < 0 && blend_time == 0 && default_blend_time) {
  960. blend_time = default_blend_time;
  961. }
  962. if (blend_time > 0) {
  963. Blend b;
  964. b.data = c.current;
  965. b.blend_time = b.blend_left = blend_time;
  966. c.blend.push_back(b);
  967. }
  968. }
  969. if (get_current_animation() != p_name) {
  970. _stop_playing_caches();
  971. }
  972. c.current.from = &animation_set[name];
  973. if (c.assigned != name) { // reset
  974. c.current.pos = p_from_end ? c.current.from->animation->get_length() : 0;
  975. } else {
  976. if (p_from_end && c.current.pos == 0) {
  977. // Animation reset BUT played backwards, set position to the end
  978. c.current.pos = c.current.from->animation->get_length();
  979. } else if (!p_from_end && c.current.pos == c.current.from->animation->get_length()) {
  980. // Animation resumed but already ended, set position to the beginning
  981. c.current.pos = 0;
  982. }
  983. }
  984. c.current.speed_scale = p_custom_scale;
  985. c.assigned = name;
  986. c.seeked = false;
  987. c.started = true;
  988. if (!end_reached) {
  989. queued.clear();
  990. }
  991. _set_process(true); // always process when starting an animation
  992. playing = true;
  993. emit_signal(SceneStringNames::get_singleton()->animation_started, c.assigned);
  994. if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
  995. return; // no next in this case
  996. }
  997. StringName next = animation_get_next(p_name);
  998. if (next != StringName() && animation_set.has(next)) {
  999. queue(next);
  1000. }
  1001. }
  1002. bool AnimationPlayer::is_playing() const {
  1003. return playing;
  1004. /*
  1005. if (playback.current.from==NULL)
  1006. return false;
  1007. float len=playback.current.from->animation->get_length();
  1008. float pos = playback.current.pos;
  1009. bool loop=playback.current.from->animation->has_loop();
  1010. if (!loop && pos >= len) {
  1011. return false;
  1012. };
  1013. return true;
  1014. */
  1015. }
  1016. void AnimationPlayer::set_current_animation(const String &p_anim) {
  1017. if (p_anim == "[stop]" || p_anim == "") {
  1018. stop();
  1019. } else if (!is_playing() || playback.assigned != p_anim) {
  1020. play(p_anim);
  1021. } else {
  1022. // Same animation, do not replay from start
  1023. }
  1024. }
  1025. String AnimationPlayer::get_current_animation() const {
  1026. return (is_playing() ? playback.assigned : "");
  1027. }
  1028. void AnimationPlayer::set_assigned_animation(const String &p_anim) {
  1029. if (is_playing()) {
  1030. play(p_anim);
  1031. } else {
  1032. ERR_FAIL_COND(!animation_set.has(p_anim));
  1033. playback.current.pos = 0;
  1034. playback.current.from = &animation_set[p_anim];
  1035. playback.assigned = p_anim;
  1036. }
  1037. }
  1038. String AnimationPlayer::get_assigned_animation() const {
  1039. return playback.assigned;
  1040. }
  1041. void AnimationPlayer::stop(bool p_reset) {
  1042. _stop_playing_caches();
  1043. Playback &c = playback;
  1044. c.blend.clear();
  1045. if (p_reset) {
  1046. c.current.from = nullptr;
  1047. c.current.speed_scale = 1;
  1048. c.current.pos = 0;
  1049. }
  1050. _set_process(false);
  1051. queued.clear();
  1052. playing = false;
  1053. }
  1054. void AnimationPlayer::set_speed_scale(float p_speed) {
  1055. speed_scale = p_speed;
  1056. }
  1057. float AnimationPlayer::get_speed_scale() const {
  1058. return speed_scale;
  1059. }
  1060. float AnimationPlayer::get_playing_speed() const {
  1061. if (!playing) {
  1062. return 0;
  1063. }
  1064. return speed_scale * playback.current.speed_scale;
  1065. }
  1066. void AnimationPlayer::seek(float p_time, bool p_update) {
  1067. if (!playback.current.from) {
  1068. if (playback.assigned) {
  1069. ERR_FAIL_COND(!animation_set.has(playback.assigned));
  1070. playback.current.from = &animation_set[playback.assigned];
  1071. }
  1072. ERR_FAIL_COND(!playback.current.from);
  1073. }
  1074. playback.current.pos = p_time;
  1075. playback.seeked = true;
  1076. if (p_update) {
  1077. _animation_process(0);
  1078. }
  1079. }
  1080. void AnimationPlayer::seek_delta(float p_time, float p_delta) {
  1081. if (!playback.current.from) {
  1082. if (playback.assigned) {
  1083. ERR_FAIL_COND(!animation_set.has(playback.assigned));
  1084. playback.current.from = &animation_set[playback.assigned];
  1085. }
  1086. ERR_FAIL_COND(!playback.current.from);
  1087. }
  1088. playback.current.pos = p_time - p_delta;
  1089. if (speed_scale != 0.0) {
  1090. p_delta /= speed_scale;
  1091. }
  1092. _animation_process(p_delta);
  1093. //playback.current.pos=p_time;
  1094. }
  1095. bool AnimationPlayer::is_valid() const {
  1096. return (playback.current.from);
  1097. }
  1098. float AnimationPlayer::get_current_animation_position() const {
  1099. ERR_FAIL_COND_V_MSG(!playback.current.from, 0, "AnimationPlayer has no current animation");
  1100. return playback.current.pos;
  1101. }
  1102. float AnimationPlayer::get_current_animation_length() const {
  1103. ERR_FAIL_COND_V_MSG(!playback.current.from, 0, "AnimationPlayer has no current animation");
  1104. return playback.current.from->animation->get_length();
  1105. }
  1106. void AnimationPlayer::_animation_changed() {
  1107. clear_caches();
  1108. emit_signal("caches_cleared");
  1109. if (is_playing()) {
  1110. playback.seeked = true; //need to restart stuff, like audio
  1111. }
  1112. }
  1113. void AnimationPlayer::_stop_playing_caches() {
  1114. for (Set<TrackNodeCache *>::Element *E = playing_caches.front(); E; E = E->next()) {
  1115. if (E->get()->node && E->get()->audio_playing) {
  1116. E->get()->node->call("stop");
  1117. }
  1118. if (E->get()->node && E->get()->animation_playing) {
  1119. AnimationPlayer *player = Object::cast_to<AnimationPlayer>(E->get()->node);
  1120. if (!player) {
  1121. continue;
  1122. }
  1123. player->stop();
  1124. }
  1125. }
  1126. playing_caches.clear();
  1127. }
  1128. void AnimationPlayer::_node_removed(Node *p_node) {
  1129. clear_caches(); // nodes contained here ar being removed, clear the caches
  1130. }
  1131. void AnimationPlayer::clear_caches() {
  1132. _stop_playing_caches();
  1133. node_cache_map.clear();
  1134. for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
  1135. E->get().node_cache.clear();
  1136. }
  1137. cache_update_size = 0;
  1138. cache_update_prop_size = 0;
  1139. cache_update_bezier_size = 0;
  1140. }
  1141. void AnimationPlayer::set_active(bool p_active) {
  1142. if (active == p_active) {
  1143. return;
  1144. }
  1145. active = p_active;
  1146. _set_process(processing, true);
  1147. }
  1148. bool AnimationPlayer::is_active() const {
  1149. return active;
  1150. }
  1151. StringName AnimationPlayer::find_animation(const Ref<Animation> &p_animation) const {
  1152. for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
  1153. if (E->get().animation == p_animation) {
  1154. return E->key();
  1155. }
  1156. }
  1157. return "";
  1158. }
  1159. void AnimationPlayer::set_autoplay(const String &p_name) {
  1160. if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint())
  1161. WARN_PRINT("Setting autoplay after the node has been added to the scene has no effect.");
  1162. autoplay = p_name;
  1163. }
  1164. String AnimationPlayer::get_autoplay() const {
  1165. return autoplay;
  1166. }
  1167. void AnimationPlayer::set_reset_on_save_enabled(bool p_enabled) {
  1168. reset_on_save = p_enabled;
  1169. }
  1170. bool AnimationPlayer::is_reset_on_save_enabled() const {
  1171. return reset_on_save;
  1172. }
  1173. void AnimationPlayer::set_animation_process_mode(AnimationProcessMode p_mode) {
  1174. if (animation_process_mode == p_mode) {
  1175. return;
  1176. }
  1177. bool pr = processing;
  1178. if (pr) {
  1179. _set_process(false);
  1180. }
  1181. animation_process_mode = p_mode;
  1182. if (pr) {
  1183. _set_process(true);
  1184. }
  1185. }
  1186. AnimationPlayer::AnimationProcessMode AnimationPlayer::get_animation_process_mode() const {
  1187. return animation_process_mode;
  1188. }
  1189. void AnimationPlayer::set_method_call_mode(AnimationMethodCallMode p_mode) {
  1190. method_call_mode = p_mode;
  1191. }
  1192. AnimationPlayer::AnimationMethodCallMode AnimationPlayer::get_method_call_mode() const {
  1193. return method_call_mode;
  1194. }
  1195. void AnimationPlayer::_set_process(bool p_process, bool p_force) {
  1196. if (processing == p_process && !p_force) {
  1197. return;
  1198. }
  1199. switch (animation_process_mode) {
  1200. case ANIMATION_PROCESS_PHYSICS:
  1201. set_physics_process_internal(p_process && active);
  1202. break;
  1203. case ANIMATION_PROCESS_IDLE:
  1204. set_process_internal(p_process && active);
  1205. break;
  1206. case ANIMATION_PROCESS_MANUAL:
  1207. break;
  1208. }
  1209. processing = p_process;
  1210. }
  1211. void AnimationPlayer::animation_set_next(const StringName &p_animation, const StringName &p_next) {
  1212. ERR_FAIL_COND(!animation_set.has(p_animation));
  1213. animation_set[p_animation].next = p_next;
  1214. }
  1215. StringName AnimationPlayer::animation_get_next(const StringName &p_animation) const {
  1216. if (!animation_set.has(p_animation)) {
  1217. return StringName();
  1218. }
  1219. return animation_set[p_animation].next;
  1220. }
  1221. void AnimationPlayer::set_default_blend_time(float p_default) {
  1222. default_blend_time = p_default;
  1223. }
  1224. float AnimationPlayer::get_default_blend_time() const {
  1225. return default_blend_time;
  1226. }
  1227. void AnimationPlayer::set_root(const NodePath &p_root) {
  1228. root = p_root;
  1229. clear_caches();
  1230. }
  1231. NodePath AnimationPlayer::get_root() const {
  1232. return root;
  1233. }
  1234. void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1235. #ifdef TOOLS_ENABLED
  1236. const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
  1237. #else
  1238. const String quote_style = "\"";
  1239. #endif
  1240. String pf = p_function;
  1241. if (p_idx == 0 && (p_function == "play" || p_function == "play_backwards" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue")) {
  1242. List<StringName> al;
  1243. get_animation_list(&al);
  1244. for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
  1245. r_options->push_back(quote_style + String(E->get()) + quote_style);
  1246. }
  1247. }
  1248. Node::get_argument_options(p_function, p_idx, r_options);
  1249. }
  1250. #ifdef TOOLS_ENABLED
  1251. Ref<AnimatedValuesBackup> AnimationPlayer::backup_animated_values(Node *p_root_override) {
  1252. Ref<AnimatedValuesBackup> backup;
  1253. if (!playback.current.from) {
  1254. return backup;
  1255. }
  1256. _ensure_node_caches(playback.current.from, p_root_override);
  1257. backup.instance();
  1258. for (int i = 0; i < playback.current.from->node_cache.size(); i++) {
  1259. TrackNodeCache *nc = playback.current.from->node_cache[i];
  1260. if (!nc) {
  1261. continue;
  1262. }
  1263. if (nc->skeleton) {
  1264. if (nc->bone_idx == -1) {
  1265. continue;
  1266. }
  1267. AnimatedValuesBackup::Entry entry;
  1268. entry.object = nc->skeleton;
  1269. entry.bone_idx = nc->bone_idx;
  1270. entry.value = nc->skeleton->get_bone_pose(nc->bone_idx);
  1271. backup->entries.push_back(entry);
  1272. } else {
  1273. if (nc->spatial) {
  1274. AnimatedValuesBackup::Entry entry;
  1275. entry.object = nc->spatial;
  1276. entry.subpath.push_back("transform");
  1277. entry.value = nc->spatial->get_transform();
  1278. entry.bone_idx = -1;
  1279. backup->entries.push_back(entry);
  1280. } else {
  1281. for (Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.front(); E; E = E->next()) {
  1282. AnimatedValuesBackup::Entry entry;
  1283. entry.object = E->value().object;
  1284. entry.subpath = E->value().subpath;
  1285. bool valid;
  1286. entry.value = E->value().object->get_indexed(E->value().subpath, &valid);
  1287. entry.bone_idx = -1;
  1288. if (valid) {
  1289. backup->entries.push_back(entry);
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. return backup;
  1296. }
  1297. Ref<AnimatedValuesBackup> AnimationPlayer::apply_reset(bool p_user_initiated) {
  1298. ERR_FAIL_COND_V(!can_apply_reset(), Ref<AnimatedValuesBackup>());
  1299. Ref<Animation> reset_anim = animation_set["RESET"].animation;
  1300. Node *root_node = get_node_or_null(root);
  1301. ERR_FAIL_COND_V(!root_node, Ref<AnimatedValuesBackup>());
  1302. AnimationPlayer *aux_player = memnew(AnimationPlayer);
  1303. EditorNode::get_singleton()->add_child(aux_player);
  1304. aux_player->add_animation("RESET", reset_anim);
  1305. aux_player->set_assigned_animation("RESET");
  1306. // Forcing the use of the original root because the scene where original player belongs may be not the active one
  1307. Node *root = get_node(get_root());
  1308. Ref<AnimatedValuesBackup> old_values = aux_player->backup_animated_values(root);
  1309. aux_player->seek(0.0f, true);
  1310. aux_player->queue_delete();
  1311. if (p_user_initiated) {
  1312. Ref<AnimatedValuesBackup> new_values = aux_player->backup_animated_values();
  1313. old_values->restore();
  1314. UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
  1315. ur->create_action(TTR("Anim Apply Reset"));
  1316. ur->add_do_method(new_values.ptr(), "restore");
  1317. ur->add_undo_method(old_values.ptr(), "restore");
  1318. ur->commit_action();
  1319. }
  1320. return old_values;
  1321. }
  1322. bool AnimationPlayer::can_apply_reset() const {
  1323. return has_animation("RESET") && playback.assigned != StringName("RESET");
  1324. }
  1325. #endif
  1326. void AnimationPlayer::_bind_methods() {
  1327. ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationPlayer::_node_removed);
  1328. ClassDB::bind_method(D_METHOD("_animation_changed"), &AnimationPlayer::_animation_changed);
  1329. ClassDB::bind_method(D_METHOD("add_animation", "name", "animation"), &AnimationPlayer::add_animation);
  1330. ClassDB::bind_method(D_METHOD("remove_animation", "name"), &AnimationPlayer::remove_animation);
  1331. ClassDB::bind_method(D_METHOD("rename_animation", "name", "newname"), &AnimationPlayer::rename_animation);
  1332. ClassDB::bind_method(D_METHOD("has_animation", "name"), &AnimationPlayer::has_animation);
  1333. ClassDB::bind_method(D_METHOD("get_animation", "name"), &AnimationPlayer::get_animation);
  1334. ClassDB::bind_method(D_METHOD("get_animation_list"), &AnimationPlayer::_get_animation_list);
  1335. ClassDB::bind_method(D_METHOD("animation_set_next", "anim_from", "anim_to"), &AnimationPlayer::animation_set_next);
  1336. ClassDB::bind_method(D_METHOD("animation_get_next", "anim_from"), &AnimationPlayer::animation_get_next);
  1337. ClassDB::bind_method(D_METHOD("set_blend_time", "anim_from", "anim_to", "sec"), &AnimationPlayer::set_blend_time);
  1338. ClassDB::bind_method(D_METHOD("get_blend_time", "anim_from", "anim_to"), &AnimationPlayer::get_blend_time);
  1339. ClassDB::bind_method(D_METHOD("set_default_blend_time", "sec"), &AnimationPlayer::set_default_blend_time);
  1340. ClassDB::bind_method(D_METHOD("get_default_blend_time"), &AnimationPlayer::get_default_blend_time);
  1341. ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
  1342. ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(""), DEFVAL(-1));
  1343. ClassDB::bind_method(D_METHOD("stop", "reset"), &AnimationPlayer::stop, DEFVAL(true));
  1344. ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing);
  1345. ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation);
  1346. ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation);
  1347. ClassDB::bind_method(D_METHOD("set_assigned_animation", "anim"), &AnimationPlayer::set_assigned_animation);
  1348. ClassDB::bind_method(D_METHOD("get_assigned_animation"), &AnimationPlayer::get_assigned_animation);
  1349. ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue);
  1350. ClassDB::bind_method(D_METHOD("get_queue"), &AnimationPlayer::get_queue);
  1351. ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue);
  1352. ClassDB::bind_method(D_METHOD("set_active", "active"), &AnimationPlayer::set_active);
  1353. ClassDB::bind_method(D_METHOD("is_active"), &AnimationPlayer::is_active);
  1354. ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &AnimationPlayer::set_speed_scale);
  1355. ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimationPlayer::get_speed_scale);
  1356. ClassDB::bind_method(D_METHOD("get_playing_speed"), &AnimationPlayer::get_playing_speed);
  1357. ClassDB::bind_method(D_METHOD("set_autoplay", "name"), &AnimationPlayer::set_autoplay);
  1358. ClassDB::bind_method(D_METHOD("get_autoplay"), &AnimationPlayer::get_autoplay);
  1359. ClassDB::bind_method(D_METHOD("set_reset_on_save_enabled", "enabled"), &AnimationPlayer::set_reset_on_save_enabled);
  1360. ClassDB::bind_method(D_METHOD("is_reset_on_save_enabled"), &AnimationPlayer::is_reset_on_save_enabled);
  1361. ClassDB::bind_method(D_METHOD("set_root", "path"), &AnimationPlayer::set_root);
  1362. ClassDB::bind_method(D_METHOD("get_root"), &AnimationPlayer::get_root);
  1363. ClassDB::bind_method(D_METHOD("find_animation", "animation"), &AnimationPlayer::find_animation);
  1364. ClassDB::bind_method(D_METHOD("clear_caches"), &AnimationPlayer::clear_caches);
  1365. ClassDB::bind_method(D_METHOD("set_animation_process_mode", "mode"), &AnimationPlayer::set_animation_process_mode);
  1366. ClassDB::bind_method(D_METHOD("get_animation_process_mode"), &AnimationPlayer::get_animation_process_mode);
  1367. ClassDB::bind_method(D_METHOD("set_method_call_mode", "mode"), &AnimationPlayer::set_method_call_mode);
  1368. ClassDB::bind_method(D_METHOD("get_method_call_mode"), &AnimationPlayer::get_method_call_mode);
  1369. ClassDB::bind_method(D_METHOD("get_current_animation_position"), &AnimationPlayer::get_current_animation_position);
  1370. ClassDB::bind_method(D_METHOD("get_current_animation_length"), &AnimationPlayer::get_current_animation_length);
  1371. ClassDB::bind_method(D_METHOD("seek", "seconds", "update"), &AnimationPlayer::seek, DEFVAL(false));
  1372. ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationPlayer::advance);
  1373. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root");
  1374. ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER), "set_current_animation", "get_current_animation");
  1375. ADD_PROPERTY(PropertyInfo(Variant::STRING, "assigned_animation", PROPERTY_HINT_NONE, "", 0), "set_assigned_animation", "get_assigned_animation");
  1376. ADD_PROPERTY(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_autoplay", "get_autoplay");
  1377. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reset_on_save", PROPERTY_HINT_NONE, ""), "set_reset_on_save_enabled", "is_reset_on_save_enabled");
  1378. ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_length", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_length");
  1379. ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position");
  1380. ADD_GROUP("Playback Options", "playback_");
  1381. ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_animation_process_mode", "get_animation_process_mode");
  1382. ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_default_blend_time", "get_default_blend_time");
  1383. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_active", PROPERTY_HINT_NONE, "", 0), "set_active", "is_active");
  1384. ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale");
  1385. ADD_PROPERTY(PropertyInfo(Variant::INT, "method_call_mode", PROPERTY_HINT_ENUM, "Deferred,Immediate"), "set_method_call_mode", "get_method_call_mode");
  1386. ADD_SIGNAL(MethodInfo("animation_finished", PropertyInfo(Variant::STRING, "anim_name")));
  1387. ADD_SIGNAL(MethodInfo("animation_changed", PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name")));
  1388. ADD_SIGNAL(MethodInfo("animation_started", PropertyInfo(Variant::STRING, "anim_name")));
  1389. ADD_SIGNAL(MethodInfo("caches_cleared"));
  1390. BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS);
  1391. BIND_ENUM_CONSTANT(ANIMATION_PROCESS_IDLE);
  1392. BIND_ENUM_CONSTANT(ANIMATION_PROCESS_MANUAL);
  1393. BIND_ENUM_CONSTANT(ANIMATION_METHOD_CALL_DEFERRED);
  1394. BIND_ENUM_CONSTANT(ANIMATION_METHOD_CALL_IMMEDIATE);
  1395. }
  1396. AnimationPlayer::AnimationPlayer() {
  1397. accum_pass = 1;
  1398. cache_update_size = 0;
  1399. cache_update_prop_size = 0;
  1400. cache_update_bezier_size = 0;
  1401. speed_scale = 1;
  1402. end_reached = false;
  1403. end_notify = false;
  1404. reset_on_save = true;
  1405. animation_process_mode = ANIMATION_PROCESS_IDLE;
  1406. method_call_mode = ANIMATION_METHOD_CALL_DEFERRED;
  1407. processing = false;
  1408. default_blend_time = 0;
  1409. root = SceneStringNames::get_singleton()->path_pp;
  1410. playing = false;
  1411. active = true;
  1412. playback.seeked = false;
  1413. playback.started = false;
  1414. }
  1415. AnimationPlayer::~AnimationPlayer() {
  1416. }