animation_tree.cpp 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  1. /**************************************************************************/
  2. /* animation_tree.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_tree.h"
  31. #include "animation_blend_tree.h"
  32. #include "core/config/engine.h"
  33. #include "scene/resources/animation.h"
  34. #include "scene/scene_string_names.h"
  35. #include "servers/audio/audio_stream.h"
  36. void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const {
  37. Array parameters;
  38. if (GDVIRTUAL_CALL(_get_parameter_list, parameters)) {
  39. for (int i = 0; i < parameters.size(); i++) {
  40. Dictionary d = parameters[i];
  41. ERR_CONTINUE(d.is_empty());
  42. r_list->push_back(PropertyInfo::from_dict(d));
  43. }
  44. }
  45. }
  46. Variant AnimationNode::get_parameter_default_value(const StringName &p_parameter) const {
  47. Variant ret;
  48. GDVIRTUAL_CALL(_get_parameter_default_value, p_parameter, ret);
  49. return ret;
  50. }
  51. bool AnimationNode::is_parameter_read_only(const StringName &p_parameter) const {
  52. bool ret = false;
  53. GDVIRTUAL_CALL(_is_parameter_read_only, p_parameter, ret);
  54. return ret;
  55. }
  56. void AnimationNode::set_parameter(const StringName &p_name, const Variant &p_value) {
  57. ERR_FAIL_COND(!state);
  58. ERR_FAIL_COND(!state->tree->property_parent_map.has(base_path));
  59. ERR_FAIL_COND(!state->tree->property_parent_map[base_path].has(p_name));
  60. StringName path = state->tree->property_parent_map[base_path][p_name];
  61. state->tree->property_map[path].first = p_value;
  62. }
  63. Variant AnimationNode::get_parameter(const StringName &p_name) const {
  64. ERR_FAIL_COND_V(!state, Variant());
  65. ERR_FAIL_COND_V(!state->tree->property_parent_map.has(base_path), Variant());
  66. ERR_FAIL_COND_V(!state->tree->property_parent_map[base_path].has(p_name), Variant());
  67. StringName path = state->tree->property_parent_map[base_path][p_name];
  68. return state->tree->property_map[path].first;
  69. }
  70. void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) {
  71. Dictionary cn;
  72. if (GDVIRTUAL_CALL(_get_child_nodes, cn)) {
  73. List<Variant> keys;
  74. cn.get_key_list(&keys);
  75. for (const Variant &E : keys) {
  76. ChildNode child;
  77. child.name = E;
  78. child.node = cn[E];
  79. r_child_nodes->push_back(child);
  80. }
  81. }
  82. }
  83. void AnimationNode::blend_animation(const StringName &p_animation, double p_time, double p_delta, bool p_seeked, bool p_is_external_seeking, real_t p_blend, Animation::LoopedFlag p_looped_flag) {
  84. ERR_FAIL_COND(!state);
  85. ERR_FAIL_COND(!state->player->has_animation(p_animation));
  86. Ref<Animation> animation = state->player->get_animation(p_animation);
  87. if (animation.is_null()) {
  88. AnimationNodeBlendTree *btree = Object::cast_to<AnimationNodeBlendTree>(parent);
  89. if (btree) {
  90. String node_name = btree->get_node_name(Ref<AnimationNodeAnimation>(this));
  91. make_invalid(vformat(RTR("In node '%s', invalid animation: '%s'."), node_name, p_animation));
  92. } else {
  93. make_invalid(vformat(RTR("Invalid animation: '%s'."), p_animation));
  94. }
  95. return;
  96. }
  97. ERR_FAIL_COND(!animation.is_valid());
  98. AnimationState anim_state;
  99. anim_state.blend = p_blend;
  100. anim_state.track_blends = &blends;
  101. anim_state.delta = p_delta;
  102. anim_state.time = p_time;
  103. anim_state.animation = animation;
  104. anim_state.seeked = p_seeked;
  105. anim_state.looped_flag = p_looped_flag;
  106. anim_state.is_external_seeking = p_is_external_seeking;
  107. state->animation_states.push_back(anim_state);
  108. }
  109. double AnimationNode::_pre_process(const StringName &p_base_path, AnimationNode *p_parent, State *p_state, double p_time, bool p_seek, bool p_is_external_seeking, const Vector<StringName> &p_connections) {
  110. base_path = p_base_path;
  111. parent = p_parent;
  112. connections = p_connections;
  113. state = p_state;
  114. double t = process(p_time, p_seek, p_is_external_seeking);
  115. state = nullptr;
  116. parent = nullptr;
  117. base_path = StringName();
  118. connections.clear();
  119. return t;
  120. }
  121. AnimationTree *AnimationNode::get_animation_tree() const {
  122. ERR_FAIL_COND_V(!state, nullptr);
  123. return state->tree;
  124. }
  125. void AnimationNode::make_invalid(const String &p_reason) {
  126. ERR_FAIL_COND(!state);
  127. state->valid = false;
  128. if (!state->invalid_reasons.is_empty()) {
  129. state->invalid_reasons += "\n";
  130. }
  131. state->invalid_reasons += String::utf8("• ") + p_reason;
  132. }
  133. double AnimationNode::blend_input(int p_input, double p_time, bool p_seek, bool p_is_external_seeking, real_t p_blend, FilterAction p_filter, bool p_sync) {
  134. ERR_FAIL_INDEX_V(p_input, inputs.size(), 0);
  135. ERR_FAIL_COND_V(!state, 0);
  136. AnimationNodeBlendTree *blend_tree = Object::cast_to<AnimationNodeBlendTree>(parent);
  137. ERR_FAIL_COND_V(!blend_tree, 0);
  138. StringName node_name = connections[p_input];
  139. if (!blend_tree->has_node(node_name)) {
  140. String node_name2 = blend_tree->get_node_name(Ref<AnimationNode>(this));
  141. make_invalid(vformat(RTR("Nothing connected to input '%s' of node '%s'."), get_input_name(p_input), node_name2));
  142. return 0;
  143. }
  144. Ref<AnimationNode> node = blend_tree->get_node(node_name);
  145. //inputs.write[p_input].last_pass = state->last_pass;
  146. real_t activity = 0.0;
  147. double ret = _blend_node(node_name, blend_tree->get_node_connection_array(node_name), nullptr, node, p_time, p_seek, p_is_external_seeking, p_blend, p_filter, p_sync, &activity);
  148. Vector<AnimationTree::Activity> *activity_ptr = state->tree->input_activity_map.getptr(base_path);
  149. if (activity_ptr && p_input < activity_ptr->size()) {
  150. activity_ptr->write[p_input].last_pass = state->last_pass;
  151. activity_ptr->write[p_input].activity = activity;
  152. }
  153. return ret;
  154. }
  155. double AnimationNode::blend_node(const StringName &p_sub_path, Ref<AnimationNode> p_node, double p_time, bool p_seek, bool p_is_external_seeking, real_t p_blend, FilterAction p_filter, bool p_sync) {
  156. return _blend_node(p_sub_path, Vector<StringName>(), this, p_node, p_time, p_seek, p_is_external_seeking, p_blend, p_filter, p_sync);
  157. }
  158. double AnimationNode::_blend_node(const StringName &p_subpath, const Vector<StringName> &p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, double p_time, bool p_seek, bool p_is_external_seeking, real_t p_blend, FilterAction p_filter, bool p_sync, real_t *r_max) {
  159. ERR_FAIL_COND_V(!p_node.is_valid(), 0);
  160. ERR_FAIL_COND_V(!state, 0);
  161. int blend_count = blends.size();
  162. if (p_node->blends.size() != blend_count) {
  163. p_node->blends.resize(blend_count);
  164. }
  165. real_t *blendw = p_node->blends.ptrw();
  166. const real_t *blendr = blends.ptr();
  167. bool any_valid = false;
  168. if (has_filter() && is_filter_enabled() && p_filter != FILTER_IGNORE) {
  169. for (int i = 0; i < blend_count; i++) {
  170. blendw[i] = 0.0; //all to zero by default
  171. }
  172. for (const KeyValue<NodePath, bool> &E : filter) {
  173. if (!state->track_map.has(E.key)) {
  174. continue;
  175. }
  176. int idx = state->track_map[E.key];
  177. blendw[idx] = 1.0; //filtered goes to one
  178. }
  179. switch (p_filter) {
  180. case FILTER_IGNORE:
  181. break; //will not happen anyway
  182. case FILTER_PASS: {
  183. //values filtered pass, the rest don't
  184. for (int i = 0; i < blend_count; i++) {
  185. if (blendw[i] == 0) { //not filtered, does not pass
  186. continue;
  187. }
  188. blendw[i] = blendr[i] * p_blend;
  189. if (!Math::is_zero_approx(blendw[i])) {
  190. any_valid = true;
  191. }
  192. }
  193. } break;
  194. case FILTER_STOP: {
  195. //values filtered don't pass, the rest are blended
  196. for (int i = 0; i < blend_count; i++) {
  197. if (blendw[i] > 0) { //filtered, does not pass
  198. continue;
  199. }
  200. blendw[i] = blendr[i] * p_blend;
  201. if (!Math::is_zero_approx(blendw[i])) {
  202. any_valid = true;
  203. }
  204. }
  205. } break;
  206. case FILTER_BLEND: {
  207. //filtered values are blended, the rest are passed without blending
  208. for (int i = 0; i < blend_count; i++) {
  209. if (blendw[i] == 1.0) {
  210. blendw[i] = blendr[i] * p_blend; //filtered, blend
  211. } else {
  212. blendw[i] = blendr[i]; //not filtered, do not blend
  213. }
  214. if (!Math::is_zero_approx(blendw[i])) {
  215. any_valid = true;
  216. }
  217. }
  218. } break;
  219. }
  220. } else {
  221. for (int i = 0; i < blend_count; i++) {
  222. //regular blend
  223. blendw[i] = blendr[i] * p_blend;
  224. if (!Math::is_zero_approx(blendw[i])) {
  225. any_valid = true;
  226. }
  227. }
  228. }
  229. if (r_max) {
  230. *r_max = 0;
  231. for (int i = 0; i < blend_count; i++) {
  232. *r_max = MAX(*r_max, blendw[i]);
  233. }
  234. }
  235. String new_path;
  236. AnimationNode *new_parent;
  237. // This is the slowest part of processing, but as strings process in powers of 2, and the paths always exist, it will not result in that many allocations.
  238. if (p_new_parent) {
  239. new_parent = p_new_parent;
  240. new_path = String(base_path) + String(p_subpath) + "/";
  241. } else {
  242. ERR_FAIL_COND_V(!parent, 0);
  243. new_parent = parent;
  244. new_path = String(parent->base_path) + String(p_subpath) + "/";
  245. }
  246. // This process, which depends on p_sync is needed to process sync correctly in the case of
  247. // that a synced AnimationNodeSync exists under the un-synced AnimationNodeSync.
  248. if (!p_seek && !p_sync && !any_valid) {
  249. return p_node->_pre_process(new_path, new_parent, state, 0, p_seek, p_is_external_seeking, p_connections);
  250. }
  251. return p_node->_pre_process(new_path, new_parent, state, p_time, p_seek, p_is_external_seeking, p_connections);
  252. }
  253. String AnimationNode::get_caption() const {
  254. String ret = "Node";
  255. GDVIRTUAL_CALL(_get_caption, ret);
  256. return ret;
  257. }
  258. bool AnimationNode::add_input(const String &p_name) {
  259. //root nodes can't add inputs
  260. ERR_FAIL_COND_V(Object::cast_to<AnimationRootNode>(this) != nullptr, false);
  261. Input input;
  262. ERR_FAIL_COND_V(p_name.contains(".") || p_name.contains("/"), false);
  263. input.name = p_name;
  264. inputs.push_back(input);
  265. emit_changed();
  266. return true;
  267. }
  268. void AnimationNode::remove_input(int p_index) {
  269. ERR_FAIL_INDEX(p_index, inputs.size());
  270. inputs.remove_at(p_index);
  271. emit_changed();
  272. }
  273. bool AnimationNode::set_input_name(int p_input, const String &p_name) {
  274. ERR_FAIL_INDEX_V(p_input, inputs.size(), false);
  275. ERR_FAIL_COND_V(p_name.contains(".") || p_name.contains("/"), false);
  276. inputs.write[p_input].name = p_name;
  277. emit_changed();
  278. return true;
  279. }
  280. String AnimationNode::get_input_name(int p_input) const {
  281. ERR_FAIL_INDEX_V(p_input, inputs.size(), String());
  282. return inputs[p_input].name;
  283. }
  284. int AnimationNode::get_input_count() const {
  285. return inputs.size();
  286. }
  287. int AnimationNode::find_input(const String &p_name) const {
  288. int idx = -1;
  289. for (int i = 0; i < inputs.size(); i++) {
  290. if (inputs[i].name == p_name) {
  291. idx = i;
  292. break;
  293. }
  294. }
  295. return idx;
  296. }
  297. double AnimationNode::process(double p_time, bool p_seek, bool p_is_external_seeking) {
  298. double ret = 0;
  299. GDVIRTUAL_CALL(_process, p_time, p_seek, p_is_external_seeking, ret);
  300. return ret;
  301. }
  302. void AnimationNode::set_filter_path(const NodePath &p_path, bool p_enable) {
  303. if (p_enable) {
  304. filter[p_path] = true;
  305. } else {
  306. filter.erase(p_path);
  307. }
  308. }
  309. void AnimationNode::set_filter_enabled(bool p_enable) {
  310. filter_enabled = p_enable;
  311. }
  312. bool AnimationNode::is_filter_enabled() const {
  313. return filter_enabled;
  314. }
  315. bool AnimationNode::is_path_filtered(const NodePath &p_path) const {
  316. return filter.has(p_path);
  317. }
  318. bool AnimationNode::has_filter() const {
  319. bool ret = false;
  320. GDVIRTUAL_CALL(_has_filter, ret);
  321. return ret;
  322. }
  323. Array AnimationNode::_get_filters() const {
  324. Array paths;
  325. for (const KeyValue<NodePath, bool> &E : filter) {
  326. paths.push_back(String(E.key)); //use strings, so sorting is possible
  327. }
  328. paths.sort(); //done so every time the scene is saved, it does not change
  329. return paths;
  330. }
  331. void AnimationNode::_set_filters(const Array &p_filters) {
  332. filter.clear();
  333. for (int i = 0; i < p_filters.size(); i++) {
  334. set_filter_path(p_filters[i], true);
  335. }
  336. }
  337. void AnimationNode::_validate_property(PropertyInfo &p_property) const {
  338. if (!has_filter() && (p_property.name == "filter_enabled" || p_property.name == "filters")) {
  339. p_property.usage = PROPERTY_USAGE_NONE;
  340. }
  341. }
  342. Ref<AnimationNode> AnimationNode::get_child_by_name(const StringName &p_name) {
  343. Ref<AnimationNode> ret;
  344. GDVIRTUAL_CALL(_get_child_by_name, p_name, ret);
  345. return ret;
  346. }
  347. void AnimationNode::_bind_methods() {
  348. ClassDB::bind_method(D_METHOD("add_input", "name"), &AnimationNode::add_input);
  349. ClassDB::bind_method(D_METHOD("remove_input", "index"), &AnimationNode::remove_input);
  350. ClassDB::bind_method(D_METHOD("set_input_name", "input", "name"), &AnimationNode::set_input_name);
  351. ClassDB::bind_method(D_METHOD("get_input_name", "input"), &AnimationNode::get_input_name);
  352. ClassDB::bind_method(D_METHOD("get_input_count"), &AnimationNode::get_input_count);
  353. ClassDB::bind_method(D_METHOD("find_input", "name"), &AnimationNode::find_input);
  354. ClassDB::bind_method(D_METHOD("set_filter_path", "path", "enable"), &AnimationNode::set_filter_path);
  355. ClassDB::bind_method(D_METHOD("is_path_filtered", "path"), &AnimationNode::is_path_filtered);
  356. ClassDB::bind_method(D_METHOD("set_filter_enabled", "enable"), &AnimationNode::set_filter_enabled);
  357. ClassDB::bind_method(D_METHOD("is_filter_enabled"), &AnimationNode::is_filter_enabled);
  358. ClassDB::bind_method(D_METHOD("_set_filters", "filters"), &AnimationNode::_set_filters);
  359. ClassDB::bind_method(D_METHOD("_get_filters"), &AnimationNode::_get_filters);
  360. ClassDB::bind_method(D_METHOD("blend_animation", "animation", "time", "delta", "seeked", "is_external_seeking", "blend", "looped_flag"), &AnimationNode::blend_animation, DEFVAL(Animation::LOOPED_FLAG_NONE));
  361. ClassDB::bind_method(D_METHOD("blend_node", "name", "node", "time", "seek", "is_external_seeking", "blend", "filter", "sync"), &AnimationNode::blend_node, DEFVAL(FILTER_IGNORE), DEFVAL(true));
  362. ClassDB::bind_method(D_METHOD("blend_input", "input_index", "time", "seek", "is_external_seeking", "blend", "filter", "sync"), &AnimationNode::blend_input, DEFVAL(FILTER_IGNORE), DEFVAL(true));
  363. ClassDB::bind_method(D_METHOD("set_parameter", "name", "value"), &AnimationNode::set_parameter);
  364. ClassDB::bind_method(D_METHOD("get_parameter", "name"), &AnimationNode::get_parameter);
  365. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_filter_enabled", "is_filter_enabled");
  366. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "filters", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_filters", "_get_filters");
  367. GDVIRTUAL_BIND(_get_child_nodes);
  368. GDVIRTUAL_BIND(_get_parameter_list);
  369. GDVIRTUAL_BIND(_get_child_by_name, "name");
  370. GDVIRTUAL_BIND(_get_parameter_default_value, "parameter");
  371. GDVIRTUAL_BIND(_is_parameter_read_only, "parameter");
  372. GDVIRTUAL_BIND(_process, "time", "seek", "is_external_seeking");
  373. GDVIRTUAL_BIND(_get_caption);
  374. GDVIRTUAL_BIND(_has_filter);
  375. ADD_SIGNAL(MethodInfo("tree_changed"));
  376. ADD_SIGNAL(MethodInfo("animation_node_renamed", PropertyInfo(Variant::INT, "object_id"), PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name")));
  377. ADD_SIGNAL(MethodInfo("animation_node_removed", PropertyInfo(Variant::INT, "object_id"), PropertyInfo(Variant::STRING, "name")));
  378. BIND_ENUM_CONSTANT(FILTER_IGNORE);
  379. BIND_ENUM_CONSTANT(FILTER_PASS);
  380. BIND_ENUM_CONSTANT(FILTER_STOP);
  381. BIND_ENUM_CONSTANT(FILTER_BLEND);
  382. }
  383. AnimationNode::AnimationNode() {
  384. }
  385. ////////////////////
  386. void AnimationRootNode::_tree_changed() {
  387. emit_signal(SNAME("tree_changed"));
  388. }
  389. void AnimationRootNode::_animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) {
  390. emit_signal(SNAME("animation_node_renamed"), p_oid, p_old_name, p_new_name);
  391. }
  392. void AnimationRootNode::_animation_node_removed(const ObjectID &p_oid, const StringName &p_node) {
  393. emit_signal(SNAME("animation_node_removed"), p_oid, p_node);
  394. }
  395. ////////////////////
  396. void AnimationTree::set_tree_root(const Ref<AnimationNode> &p_root) {
  397. if (root.is_valid()) {
  398. root->disconnect("tree_changed", callable_mp(this, &AnimationTree::_tree_changed));
  399. root->disconnect("animation_node_renamed", callable_mp(this, &AnimationTree::_animation_node_renamed));
  400. root->disconnect("animation_node_removed", callable_mp(this, &AnimationTree::_animation_node_removed));
  401. }
  402. root = p_root;
  403. if (root.is_valid()) {
  404. root->connect("tree_changed", callable_mp(this, &AnimationTree::_tree_changed));
  405. root->connect("animation_node_renamed", callable_mp(this, &AnimationTree::_animation_node_renamed));
  406. root->connect("animation_node_removed", callable_mp(this, &AnimationTree::_animation_node_removed));
  407. }
  408. properties_dirty = true;
  409. update_configuration_warnings();
  410. }
  411. Ref<AnimationNode> AnimationTree::get_tree_root() const {
  412. return root;
  413. }
  414. void AnimationTree::set_active(bool p_active) {
  415. if (active == p_active) {
  416. return;
  417. }
  418. active = p_active;
  419. started = active;
  420. if (process_callback == ANIMATION_PROCESS_IDLE) {
  421. set_process_internal(active);
  422. } else {
  423. set_physics_process_internal(active);
  424. }
  425. if (!active && is_inside_tree()) {
  426. _clear_caches();
  427. }
  428. }
  429. bool AnimationTree::is_active() const {
  430. return active;
  431. }
  432. void AnimationTree::set_process_callback(AnimationProcessCallback p_mode) {
  433. if (process_callback == p_mode) {
  434. return;
  435. }
  436. bool was_active = is_active();
  437. if (was_active) {
  438. set_active(false);
  439. }
  440. process_callback = p_mode;
  441. if (was_active) {
  442. set_active(true);
  443. }
  444. }
  445. AnimationTree::AnimationProcessCallback AnimationTree::get_process_callback() const {
  446. return process_callback;
  447. }
  448. void AnimationTree::_node_removed(Node *p_node) {
  449. cache_valid = false;
  450. }
  451. bool AnimationTree::_update_caches(AnimationPlayer *player) {
  452. setup_pass++;
  453. if (!player->has_node(player->get_root())) {
  454. ERR_PRINT("AnimationTree: AnimationPlayer root is invalid.");
  455. set_active(false);
  456. _clear_caches();
  457. return false;
  458. }
  459. Node *parent = player->get_node(player->get_root());
  460. List<StringName> sname;
  461. player->get_animation_list(&sname);
  462. root_motion_cache.loc = Vector3(0, 0, 0);
  463. root_motion_cache.rot = Quaternion(0, 0, 0, 1);
  464. root_motion_cache.scale = Vector3(1, 1, 1);
  465. Ref<Animation> reset_anim;
  466. bool has_reset_anim = player->has_animation(SceneStringNames::get_singleton()->RESET);
  467. if (has_reset_anim) {
  468. reset_anim = player->get_animation(SceneStringNames::get_singleton()->RESET);
  469. }
  470. for (const StringName &E : sname) {
  471. Ref<Animation> anim = player->get_animation(E);
  472. for (int i = 0; i < anim->get_track_count(); i++) {
  473. NodePath path = anim->track_get_path(i);
  474. Animation::TrackType track_type = anim->track_get_type(i);
  475. Animation::TrackType track_cache_type = track_type;
  476. if (track_cache_type == Animation::TYPE_POSITION_3D || track_cache_type == Animation::TYPE_ROTATION_3D || track_cache_type == Animation::TYPE_SCALE_3D) {
  477. track_cache_type = Animation::TYPE_POSITION_3D; //reference them as position3D tracks, even if they modify rotation or scale
  478. }
  479. TrackCache *track = nullptr;
  480. if (track_cache.has(path)) {
  481. track = track_cache.get(path);
  482. }
  483. //if not valid, delete track
  484. if (track && (track->type != track_cache_type || ObjectDB::get_instance(track->object_id) == nullptr)) {
  485. playing_caches.erase(track);
  486. memdelete(track);
  487. track_cache.erase(path);
  488. track = nullptr;
  489. }
  490. if (!track) {
  491. Ref<Resource> resource;
  492. Vector<StringName> leftover_path;
  493. Node *child = parent->get_node_and_resource(path, resource, leftover_path);
  494. if (!child) {
  495. ERR_PRINT("AnimationTree: '" + String(E) + "', couldn't resolve track: '" + String(path) + "'");
  496. continue;
  497. }
  498. if (!child->is_connected("tree_exited", callable_mp(this, &AnimationTree::_node_removed))) {
  499. child->connect("tree_exited", callable_mp(this, &AnimationTree::_node_removed).bind(child));
  500. }
  501. switch (track_type) {
  502. case Animation::TYPE_VALUE: {
  503. TrackCacheValue *track_value = memnew(TrackCacheValue);
  504. if (resource.is_valid()) {
  505. track_value->object = resource.ptr();
  506. } else {
  507. track_value->object = child;
  508. }
  509. track_value->is_discrete = anim->value_track_get_update_mode(i) == Animation::UPDATE_DISCRETE;
  510. track_value->is_using_angle = anim->track_get_interpolation_type(i) == Animation::INTERPOLATION_LINEAR_ANGLE || anim->track_get_interpolation_type(i) == Animation::INTERPOLATION_CUBIC_ANGLE;
  511. track_value->subpath = leftover_path;
  512. track_value->object_id = track_value->object->get_instance_id();
  513. track = track_value;
  514. // If a value track without a key is cached first, the initial value cannot be determined.
  515. // It is a corner case, but which may cause problems with blending.
  516. ERR_CONTINUE_MSG(anim->track_get_key_count(i) == 0, "AnimationTree: '" + String(E) + "', value track: '" + String(path) + "' must have at least one key to cache for blending.");
  517. track_value->init_value = anim->track_get_key_value(i, 0);
  518. track_value->init_value.zero();
  519. // If there is a Reset Animation, it takes precedence by overwriting.
  520. if (has_reset_anim) {
  521. int rt = reset_anim->find_track(path, track_type);
  522. if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
  523. track_value->init_value = reset_anim->track_get_key_value(rt, 0);
  524. }
  525. }
  526. } break;
  527. case Animation::TYPE_POSITION_3D:
  528. case Animation::TYPE_ROTATION_3D:
  529. case Animation::TYPE_SCALE_3D: {
  530. #ifndef _3D_DISABLED
  531. Node3D *node_3d = Object::cast_to<Node3D>(child);
  532. if (!node_3d) {
  533. ERR_PRINT("AnimationTree: '" + String(E) + "', transform track does not point to Node3D: '" + String(path) + "'");
  534. continue;
  535. }
  536. TrackCacheTransform *track_xform = memnew(TrackCacheTransform);
  537. track_xform->type = Animation::TYPE_POSITION_3D;
  538. track_xform->node_3d = node_3d;
  539. track_xform->skeleton = nullptr;
  540. track_xform->bone_idx = -1;
  541. bool has_rest = false;
  542. if (path.get_subname_count() == 1 && Object::cast_to<Skeleton3D>(node_3d)) {
  543. Skeleton3D *sk = Object::cast_to<Skeleton3D>(node_3d);
  544. track_xform->skeleton = sk;
  545. int bone_idx = sk->find_bone(path.get_subname(0));
  546. if (bone_idx != -1) {
  547. has_rest = true;
  548. track_xform->bone_idx = bone_idx;
  549. Transform3D rest = sk->get_bone_rest(bone_idx);
  550. track_xform->init_loc = rest.origin;
  551. track_xform->init_rot = rest.basis.get_rotation_quaternion();
  552. track_xform->init_scale = rest.basis.get_scale();
  553. }
  554. }
  555. track_xform->object = node_3d;
  556. track_xform->object_id = track_xform->object->get_instance_id();
  557. track = track_xform;
  558. switch (track_type) {
  559. case Animation::TYPE_POSITION_3D: {
  560. track_xform->loc_used = true;
  561. } break;
  562. case Animation::TYPE_ROTATION_3D: {
  563. track_xform->rot_used = true;
  564. } break;
  565. case Animation::TYPE_SCALE_3D: {
  566. track_xform->scale_used = true;
  567. } break;
  568. default: {
  569. }
  570. }
  571. // For non Skeleton3D bone animation.
  572. if (has_reset_anim && !has_rest) {
  573. int rt = reset_anim->find_track(path, track_type);
  574. if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
  575. switch (track_type) {
  576. case Animation::TYPE_POSITION_3D: {
  577. track_xform->init_loc = reset_anim->track_get_key_value(rt, 0);
  578. } break;
  579. case Animation::TYPE_ROTATION_3D: {
  580. track_xform->init_rot = reset_anim->track_get_key_value(rt, 0);
  581. } break;
  582. case Animation::TYPE_SCALE_3D: {
  583. track_xform->init_scale = reset_anim->track_get_key_value(rt, 0);
  584. } break;
  585. default: {
  586. }
  587. }
  588. }
  589. }
  590. #endif // _3D_DISABLED
  591. } break;
  592. case Animation::TYPE_BLEND_SHAPE: {
  593. #ifndef _3D_DISABLED
  594. if (path.get_subname_count() != 1) {
  595. ERR_PRINT("AnimationTree: '" + String(E) + "', blend shape track does not contain a blend shape subname: '" + String(path) + "'");
  596. continue;
  597. }
  598. MeshInstance3D *mesh_3d = Object::cast_to<MeshInstance3D>(child);
  599. if (!mesh_3d) {
  600. ERR_PRINT("AnimationTree: '" + String(E) + "', blend shape track does not point to MeshInstance3D: '" + String(path) + "'");
  601. continue;
  602. }
  603. StringName blend_shape_name = path.get_subname(0);
  604. int blend_shape_idx = mesh_3d->find_blend_shape_by_name(blend_shape_name);
  605. if (blend_shape_idx == -1) {
  606. ERR_PRINT("AnimationTree: '" + String(E) + "', blend shape track points to a non-existing name: '" + String(blend_shape_name) + "'");
  607. continue;
  608. }
  609. TrackCacheBlendShape *track_bshape = memnew(TrackCacheBlendShape);
  610. track_bshape->mesh_3d = mesh_3d;
  611. track_bshape->shape_index = blend_shape_idx;
  612. track_bshape->object = mesh_3d;
  613. track_bshape->object_id = mesh_3d->get_instance_id();
  614. track = track_bshape;
  615. if (has_reset_anim) {
  616. int rt = reset_anim->find_track(path, track_type);
  617. if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
  618. track_bshape->init_value = reset_anim->track_get_key_value(rt, 0);
  619. }
  620. }
  621. #endif
  622. } break;
  623. case Animation::TYPE_METHOD: {
  624. TrackCacheMethod *track_method = memnew(TrackCacheMethod);
  625. if (resource.is_valid()) {
  626. track_method->object = resource.ptr();
  627. } else {
  628. track_method->object = child;
  629. }
  630. track_method->object_id = track_method->object->get_instance_id();
  631. track = track_method;
  632. } break;
  633. case Animation::TYPE_BEZIER: {
  634. TrackCacheBezier *track_bezier = memnew(TrackCacheBezier);
  635. if (resource.is_valid()) {
  636. track_bezier->object = resource.ptr();
  637. } else {
  638. track_bezier->object = child;
  639. }
  640. track_bezier->subpath = leftover_path;
  641. track_bezier->object_id = track_bezier->object->get_instance_id();
  642. track = track_bezier;
  643. if (has_reset_anim) {
  644. int rt = reset_anim->find_track(path, track_type);
  645. if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
  646. track_bezier->init_value = (reset_anim->track_get_key_value(rt, 0).operator Array())[0];
  647. }
  648. }
  649. } break;
  650. case Animation::TYPE_AUDIO: {
  651. TrackCacheAudio *track_audio = memnew(TrackCacheAudio);
  652. track_audio->object = child;
  653. track_audio->object_id = track_audio->object->get_instance_id();
  654. track_audio->audio_stream.instantiate();
  655. track_audio->audio_stream->set_polyphony(audio_max_polyphony);
  656. track = track_audio;
  657. } break;
  658. case Animation::TYPE_ANIMATION: {
  659. TrackCacheAnimation *track_animation = memnew(TrackCacheAnimation);
  660. track_animation->object = child;
  661. track_animation->object_id = track_animation->object->get_instance_id();
  662. track = track_animation;
  663. } break;
  664. default: {
  665. ERR_PRINT("Animation corrupted (invalid track type)");
  666. continue;
  667. }
  668. }
  669. track_cache[path] = track;
  670. } else if (track_cache_type == Animation::TYPE_POSITION_3D) {
  671. TrackCacheTransform *track_xform = static_cast<TrackCacheTransform *>(track);
  672. if (track->setup_pass != setup_pass) {
  673. track_xform->loc_used = false;
  674. track_xform->rot_used = false;
  675. track_xform->scale_used = false;
  676. }
  677. switch (track_type) {
  678. case Animation::TYPE_POSITION_3D: {
  679. track_xform->loc_used = true;
  680. } break;
  681. case Animation::TYPE_ROTATION_3D: {
  682. track_xform->rot_used = true;
  683. } break;
  684. case Animation::TYPE_SCALE_3D: {
  685. track_xform->scale_used = true;
  686. } break;
  687. default: {
  688. }
  689. }
  690. } else if (track_cache_type == Animation::TYPE_VALUE) {
  691. // If it has at least one angle interpolation, it also uses angle interpolation for blending.
  692. TrackCacheValue *track_value = static_cast<TrackCacheValue *>(track);
  693. bool was_discrete = track_value->is_discrete;
  694. bool was_using_angle = track_value->is_using_angle;
  695. track_value->is_discrete |= anim->value_track_get_update_mode(i) == Animation::UPDATE_DISCRETE;
  696. track_value->is_using_angle |= anim->track_get_interpolation_type(i) == Animation::INTERPOLATION_LINEAR_ANGLE || anim->track_get_interpolation_type(i) == Animation::INTERPOLATION_CUBIC_ANGLE;
  697. if (was_discrete != track_value->is_discrete) {
  698. ERR_PRINT_ED("Value track: " + String(path) + " with different update modes are blended. Blending prioritizes Discrete mode, so other update mode tracks will not be blended.");
  699. }
  700. if (was_using_angle != track_value->is_using_angle) {
  701. WARN_PRINT_ED("Value track: " + String(path) + " with different interpolation types for rotation are blended. Blending prioritizes angle interpolation, so the blending result uses the shortest path referenced to the initial (RESET animation) value.");
  702. }
  703. }
  704. track->setup_pass = setup_pass;
  705. }
  706. }
  707. List<NodePath> to_delete;
  708. for (const KeyValue<NodePath, TrackCache *> &K : track_cache) {
  709. TrackCache *tc = track_cache[K.key];
  710. if (tc->setup_pass != setup_pass) {
  711. to_delete.push_back(K.key);
  712. }
  713. }
  714. while (to_delete.front()) {
  715. NodePath np = to_delete.front()->get();
  716. memdelete(track_cache[np]);
  717. track_cache.erase(np);
  718. to_delete.pop_front();
  719. }
  720. state.track_map.clear();
  721. int idx = 0;
  722. for (const KeyValue<NodePath, TrackCache *> &K : track_cache) {
  723. state.track_map[K.key] = idx;
  724. idx++;
  725. }
  726. state.track_count = idx;
  727. cache_valid = true;
  728. return true;
  729. }
  730. void AnimationTree::_animation_player_changed() {
  731. emit_signal(SNAME("animation_player_changed"));
  732. _clear_caches();
  733. }
  734. void AnimationTree::_clear_caches() {
  735. _clear_audio_streams();
  736. _clear_playing_caches();
  737. for (KeyValue<NodePath, TrackCache *> &K : track_cache) {
  738. memdelete(K.value);
  739. }
  740. track_cache.clear();
  741. cache_valid = false;
  742. }
  743. void AnimationTree::_clear_audio_streams() {
  744. for (int i = 0; i < playing_audio_stream_players.size(); i++) {
  745. playing_audio_stream_players[i]->call(SNAME("stop"));
  746. playing_audio_stream_players[i]->call(SNAME("set_stream"), Ref<AudioStream>());
  747. }
  748. playing_audio_stream_players.clear();
  749. }
  750. void AnimationTree::_clear_playing_caches() {
  751. for (const TrackCache *E : playing_caches) {
  752. if (ObjectDB::get_instance(E->object_id)) {
  753. E->object->call(SNAME("stop"));
  754. }
  755. }
  756. playing_caches.clear();
  757. }
  758. static void _call_object(Object *p_object, const StringName &p_method, const Vector<Variant> &p_params, bool p_deferred) {
  759. // Separate function to use alloca() more efficiently
  760. const Variant **argptrs = (const Variant **)alloca(sizeof(const Variant **) * p_params.size());
  761. const Variant *args = p_params.ptr();
  762. uint32_t argcount = p_params.size();
  763. for (uint32_t i = 0; i < argcount; i++) {
  764. argptrs[i] = &args[i];
  765. }
  766. if (p_deferred) {
  767. MessageQueue::get_singleton()->push_callp(p_object, p_method, argptrs, argcount);
  768. } else {
  769. Callable::CallError ce;
  770. p_object->callp(p_method, argptrs, argcount, ce);
  771. }
  772. }
  773. void AnimationTree::_process_graph(double p_delta) {
  774. _update_properties(); //if properties need updating, update them
  775. //check all tracks, see if they need modification
  776. root_motion_position = Vector3(0, 0, 0);
  777. root_motion_rotation = Quaternion(0, 0, 0, 1);
  778. root_motion_scale = Vector3(0, 0, 0);
  779. if (!root.is_valid()) {
  780. ERR_PRINT("AnimationTree: root AnimationNode is not set, disabling playback.");
  781. set_active(false);
  782. cache_valid = false;
  783. return;
  784. }
  785. if (!has_node(animation_player)) {
  786. ERR_PRINT("AnimationTree: no valid AnimationPlayer path set, disabling playback");
  787. set_active(false);
  788. cache_valid = false;
  789. return;
  790. }
  791. AnimationPlayer *player = Object::cast_to<AnimationPlayer>(get_node(animation_player));
  792. ObjectID current_animation_player;
  793. if (player) {
  794. current_animation_player = player->get_instance_id();
  795. }
  796. if (last_animation_player != current_animation_player) {
  797. if (last_animation_player.is_valid()) {
  798. Object *old_player = ObjectDB::get_instance(last_animation_player);
  799. if (old_player) {
  800. old_player->disconnect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
  801. }
  802. }
  803. if (player) {
  804. player->connect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
  805. }
  806. last_animation_player = current_animation_player;
  807. }
  808. if (!player) {
  809. ERR_PRINT("AnimationTree: path points to a node not an AnimationPlayer, disabling playback");
  810. set_active(false);
  811. cache_valid = false;
  812. return;
  813. }
  814. if (!cache_valid) {
  815. if (!_update_caches(player)) {
  816. return;
  817. }
  818. }
  819. { //setup
  820. process_pass++;
  821. state.valid = true;
  822. state.invalid_reasons = "";
  823. state.animation_states.clear(); //will need to be re-created
  824. state.player = player;
  825. state.last_pass = process_pass;
  826. state.tree = this;
  827. // root source blends
  828. root->blends.resize(state.track_count);
  829. real_t *src_blendsw = root->blends.ptrw();
  830. for (int i = 0; i < state.track_count; i++) {
  831. src_blendsw[i] = 1.0; //by default all go to 1 for the root input
  832. }
  833. }
  834. //process
  835. {
  836. if (started) {
  837. //if started, seek
  838. root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, nullptr, &state, 0, true, false, Vector<StringName>());
  839. started = false;
  840. }
  841. root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, nullptr, &state, p_delta, false, false, Vector<StringName>());
  842. }
  843. if (!state.valid) {
  844. return; //state is not valid. do nothing.
  845. }
  846. // Init all value/transform/blend/bezier tracks that track_cache has.
  847. {
  848. for (const KeyValue<NodePath, TrackCache *> &K : track_cache) {
  849. TrackCache *track = K.value;
  850. switch (track->type) {
  851. case Animation::TYPE_POSITION_3D: {
  852. TrackCacheTransform *t = static_cast<TrackCacheTransform *>(track);
  853. if (track->root_motion) {
  854. root_motion_cache.loc = Vector3(0, 0, 0);
  855. root_motion_cache.rot = Quaternion(0, 0, 0, 1);
  856. root_motion_cache.scale = Vector3(1, 1, 1);
  857. }
  858. t->loc = t->init_loc;
  859. t->rot = t->init_rot;
  860. t->scale = t->init_scale;
  861. } break;
  862. case Animation::TYPE_BLEND_SHAPE: {
  863. TrackCacheBlendShape *t = static_cast<TrackCacheBlendShape *>(track);
  864. t->value = t->init_value;
  865. } break;
  866. case Animation::TYPE_VALUE: {
  867. TrackCacheValue *t = static_cast<TrackCacheValue *>(track);
  868. t->value = t->init_value;
  869. } break;
  870. case Animation::TYPE_BEZIER: {
  871. TrackCacheBezier *t = static_cast<TrackCacheBezier *>(track);
  872. t->value = t->init_value;
  873. } break;
  874. case Animation::TYPE_AUDIO: {
  875. TrackCacheAudio *t = static_cast<TrackCacheAudio *>(track);
  876. for (KeyValue<ObjectID, PlayingAudioTrackInfo> &L : t->playing_streams) {
  877. PlayingAudioTrackInfo &track_info = L.value;
  878. track_info.volume = 0.0;
  879. }
  880. } break;
  881. default: {
  882. } break;
  883. }
  884. }
  885. }
  886. // Apply value/transform/blend/bezier blends to track caches and execute method/audio/animation tracks.
  887. {
  888. #ifdef TOOLS_ENABLED
  889. bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
  890. #endif // TOOLS_ENABLED
  891. for (const AnimationNode::AnimationState &as : state.animation_states) {
  892. Ref<Animation> a = as.animation;
  893. double time = as.time;
  894. double delta = as.delta;
  895. real_t weight = as.blend;
  896. bool seeked = as.seeked;
  897. Animation::LoopedFlag looped_flag = as.looped_flag;
  898. bool is_external_seeking = as.is_external_seeking;
  899. bool backward = signbit(delta); // This flag is used by the root motion calculates or detecting the end of audio stream.
  900. #ifndef _3D_DISABLED
  901. bool calc_root = !seeked || is_external_seeking;
  902. #endif // _3D_DISABLED
  903. for (int i = 0; i < a->get_track_count(); i++) {
  904. if (!a->track_is_enabled(i)) {
  905. continue;
  906. }
  907. NodePath path = a->track_get_path(i);
  908. if (!track_cache.has(path)) {
  909. continue; // No path, but avoid error spamming.
  910. }
  911. TrackCache *track = track_cache[path];
  912. ERR_CONTINUE(!state.track_map.has(path));
  913. int blend_idx = state.track_map[path];
  914. ERR_CONTINUE(blend_idx < 0 || blend_idx >= state.track_count);
  915. real_t blend = (*as.track_blends)[blend_idx] * weight;
  916. Animation::TrackType ttype = a->track_get_type(i);
  917. if (ttype != Animation::TYPE_POSITION_3D && ttype != Animation::TYPE_ROTATION_3D && ttype != Animation::TYPE_SCALE_3D && track->type != ttype) {
  918. //broken animation, but avoid error spamming
  919. continue;
  920. }
  921. track->root_motion = root_motion_track == path;
  922. switch (ttype) {
  923. case Animation::TYPE_POSITION_3D: {
  924. #ifndef _3D_DISABLED
  925. if (Math::is_zero_approx(blend)) {
  926. continue; // Nothing to blend.
  927. }
  928. TrackCacheTransform *t = static_cast<TrackCacheTransform *>(track);
  929. if (track->root_motion && calc_root) {
  930. double prev_time = time - delta;
  931. if (!backward) {
  932. if (prev_time < 0) {
  933. switch (a->get_loop_mode()) {
  934. case Animation::LOOP_NONE: {
  935. prev_time = 0;
  936. } break;
  937. case Animation::LOOP_LINEAR: {
  938. prev_time = Math::fposmod(prev_time, (double)a->get_length());
  939. } break;
  940. case Animation::LOOP_PINGPONG: {
  941. prev_time = Math::pingpong(prev_time, (double)a->get_length());
  942. } break;
  943. default:
  944. break;
  945. }
  946. }
  947. } else {
  948. if (prev_time > a->get_length()) {
  949. switch (a->get_loop_mode()) {
  950. case Animation::LOOP_NONE: {
  951. prev_time = (double)a->get_length();
  952. } break;
  953. case Animation::LOOP_LINEAR: {
  954. prev_time = Math::fposmod(prev_time, (double)a->get_length());
  955. } break;
  956. case Animation::LOOP_PINGPONG: {
  957. prev_time = Math::pingpong(prev_time, (double)a->get_length());
  958. } break;
  959. default:
  960. break;
  961. }
  962. }
  963. }
  964. Vector3 loc[2];
  965. if (!backward) {
  966. if (prev_time > time) {
  967. Error err = a->position_track_interpolate(i, prev_time, &loc[0]);
  968. if (err != OK) {
  969. continue;
  970. }
  971. loc[0] = post_process_key_value(a, i, loc[0], t->object, t->bone_idx);
  972. a->position_track_interpolate(i, (double)a->get_length(), &loc[1]);
  973. loc[1] = post_process_key_value(a, i, loc[1], t->object, t->bone_idx);
  974. root_motion_cache.loc += (loc[1] - loc[0]) * blend;
  975. prev_time = 0;
  976. }
  977. } else {
  978. if (prev_time < time) {
  979. Error err = a->position_track_interpolate(i, prev_time, &loc[0]);
  980. if (err != OK) {
  981. continue;
  982. }
  983. loc[0] = post_process_key_value(a, i, loc[0], t->object, t->bone_idx);
  984. a->position_track_interpolate(i, 0, &loc[1]);
  985. loc[1] = post_process_key_value(a, i, loc[1], t->object, t->bone_idx);
  986. root_motion_cache.loc += (loc[1] - loc[0]) * blend;
  987. prev_time = (double)a->get_length();
  988. }
  989. }
  990. Error err = a->position_track_interpolate(i, prev_time, &loc[0]);
  991. if (err != OK) {
  992. continue;
  993. }
  994. loc[0] = post_process_key_value(a, i, loc[0], t->object, t->bone_idx);
  995. a->position_track_interpolate(i, time, &loc[1]);
  996. loc[1] = post_process_key_value(a, i, loc[1], t->object, t->bone_idx);
  997. root_motion_cache.loc += (loc[1] - loc[0]) * blend;
  998. prev_time = !backward ? 0 : (double)a->get_length();
  999. }
  1000. {
  1001. Vector3 loc;
  1002. Error err = a->position_track_interpolate(i, time, &loc);
  1003. if (err != OK) {
  1004. continue;
  1005. }
  1006. loc = post_process_key_value(a, i, loc, t->object, t->bone_idx);
  1007. t->loc += (loc - t->init_loc) * blend;
  1008. }
  1009. #endif // _3D_DISABLED
  1010. } break;
  1011. case Animation::TYPE_ROTATION_3D: {
  1012. #ifndef _3D_DISABLED
  1013. if (Math::is_zero_approx(blend)) {
  1014. continue; // Nothing to blend.
  1015. }
  1016. TrackCacheTransform *t = static_cast<TrackCacheTransform *>(track);
  1017. if (track->root_motion && calc_root) {
  1018. double prev_time = time - delta;
  1019. if (!backward) {
  1020. if (prev_time < 0) {
  1021. switch (a->get_loop_mode()) {
  1022. case Animation::LOOP_NONE: {
  1023. prev_time = 0;
  1024. } break;
  1025. case Animation::LOOP_LINEAR: {
  1026. prev_time = Math::fposmod(prev_time, (double)a->get_length());
  1027. } break;
  1028. case Animation::LOOP_PINGPONG: {
  1029. prev_time = Math::pingpong(prev_time, (double)a->get_length());
  1030. } break;
  1031. default:
  1032. break;
  1033. }
  1034. }
  1035. } else {
  1036. if (prev_time > a->get_length()) {
  1037. switch (a->get_loop_mode()) {
  1038. case Animation::LOOP_NONE: {
  1039. prev_time = (double)a->get_length();
  1040. } break;
  1041. case Animation::LOOP_LINEAR: {
  1042. prev_time = Math::fposmod(prev_time, (double)a->get_length());
  1043. } break;
  1044. case Animation::LOOP_PINGPONG: {
  1045. prev_time = Math::pingpong(prev_time, (double)a->get_length());
  1046. } break;
  1047. default:
  1048. break;
  1049. }
  1050. }
  1051. }
  1052. Quaternion rot[2];
  1053. if (!backward) {
  1054. if (prev_time > time) {
  1055. Error err = a->rotation_track_interpolate(i, prev_time, &rot[0]);
  1056. if (err != OK) {
  1057. continue;
  1058. }
  1059. rot[0] = post_process_key_value(a, i, rot[0], t->object, t->bone_idx);
  1060. a->rotation_track_interpolate(i, (double)a->get_length(), &rot[1]);
  1061. rot[1] = post_process_key_value(a, i, rot[1], t->object, t->bone_idx);
  1062. root_motion_cache.rot = (root_motion_cache.rot * Quaternion().slerp(rot[0].inverse() * rot[1], blend)).normalized();
  1063. prev_time = 0;
  1064. }
  1065. } else {
  1066. if (prev_time < time) {
  1067. Error err = a->rotation_track_interpolate(i, prev_time, &rot[0]);
  1068. if (err != OK) {
  1069. continue;
  1070. }
  1071. rot[0] = post_process_key_value(a, i, rot[0], t->object, t->bone_idx);
  1072. a->rotation_track_interpolate(i, 0, &rot[1]);
  1073. root_motion_cache.rot = (root_motion_cache.rot * Quaternion().slerp(rot[0].inverse() * rot[1], blend)).normalized();
  1074. prev_time = (double)a->get_length();
  1075. }
  1076. }
  1077. Error err = a->rotation_track_interpolate(i, prev_time, &rot[0]);
  1078. if (err != OK) {
  1079. continue;
  1080. }
  1081. rot[0] = post_process_key_value(a, i, rot[0], t->object, t->bone_idx);
  1082. a->rotation_track_interpolate(i, time, &rot[1]);
  1083. rot[1] = post_process_key_value(a, i, rot[1], t->object, t->bone_idx);
  1084. root_motion_cache.rot = (root_motion_cache.rot * Quaternion().slerp(rot[0].inverse() * rot[1], blend)).normalized();
  1085. prev_time = !backward ? 0 : (double)a->get_length();
  1086. }
  1087. {
  1088. Quaternion rot;
  1089. Error err = a->rotation_track_interpolate(i, time, &rot);
  1090. if (err != OK) {
  1091. continue;
  1092. }
  1093. rot = post_process_key_value(a, i, rot, t->object, t->bone_idx);
  1094. t->rot = (t->rot * Quaternion().slerp(t->init_rot.inverse() * rot, blend)).normalized();
  1095. }
  1096. #endif // _3D_DISABLED
  1097. } break;
  1098. case Animation::TYPE_SCALE_3D: {
  1099. #ifndef _3D_DISABLED
  1100. if (Math::is_zero_approx(blend)) {
  1101. continue; // Nothing to blend.
  1102. }
  1103. TrackCacheTransform *t = static_cast<TrackCacheTransform *>(track);
  1104. if (track->root_motion && calc_root) {
  1105. double prev_time = time - delta;
  1106. if (!backward) {
  1107. if (prev_time < 0) {
  1108. switch (a->get_loop_mode()) {
  1109. case Animation::LOOP_NONE: {
  1110. prev_time = 0;
  1111. } break;
  1112. case Animation::LOOP_LINEAR: {
  1113. prev_time = Math::fposmod(prev_time, (double)a->get_length());
  1114. } break;
  1115. case Animation::LOOP_PINGPONG: {
  1116. prev_time = Math::pingpong(prev_time, (double)a->get_length());
  1117. } break;
  1118. default:
  1119. break;
  1120. }
  1121. }
  1122. } else {
  1123. if (prev_time > a->get_length()) {
  1124. switch (a->get_loop_mode()) {
  1125. case Animation::LOOP_NONE: {
  1126. prev_time = (double)a->get_length();
  1127. } break;
  1128. case Animation::LOOP_LINEAR: {
  1129. prev_time = Math::fposmod(prev_time, (double)a->get_length());
  1130. } break;
  1131. case Animation::LOOP_PINGPONG: {
  1132. prev_time = Math::pingpong(prev_time, (double)a->get_length());
  1133. } break;
  1134. default:
  1135. break;
  1136. }
  1137. }
  1138. }
  1139. Vector3 scale[2];
  1140. if (!backward) {
  1141. if (prev_time > time) {
  1142. Error err = a->scale_track_interpolate(i, prev_time, &scale[0]);
  1143. if (err != OK) {
  1144. continue;
  1145. }
  1146. scale[0] = post_process_key_value(a, i, scale[0], t->object, t->bone_idx);
  1147. a->scale_track_interpolate(i, (double)a->get_length(), &scale[1]);
  1148. root_motion_cache.scale += (scale[1] - scale[0]) * blend;
  1149. scale[1] = post_process_key_value(a, i, scale[1], t->object, t->bone_idx);
  1150. prev_time = 0;
  1151. }
  1152. } else {
  1153. if (prev_time < time) {
  1154. Error err = a->scale_track_interpolate(i, prev_time, &scale[0]);
  1155. if (err != OK) {
  1156. continue;
  1157. }
  1158. scale[0] = post_process_key_value(a, i, scale[0], t->object, t->bone_idx);
  1159. a->scale_track_interpolate(i, 0, &scale[1]);
  1160. scale[1] = post_process_key_value(a, i, scale[1], t->object, t->bone_idx);
  1161. root_motion_cache.scale += (scale[1] - scale[0]) * blend;
  1162. prev_time = (double)a->get_length();
  1163. }
  1164. }
  1165. Error err = a->scale_track_interpolate(i, prev_time, &scale[0]);
  1166. if (err != OK) {
  1167. continue;
  1168. }
  1169. scale[0] = post_process_key_value(a, i, scale[0], t->object, t->bone_idx);
  1170. a->scale_track_interpolate(i, time, &scale[1]);
  1171. scale[1] = post_process_key_value(a, i, scale[1], t->object, t->bone_idx);
  1172. root_motion_cache.scale += (scale[1] - scale[0]) * blend;
  1173. prev_time = !backward ? 0 : (double)a->get_length();
  1174. }
  1175. {
  1176. Vector3 scale;
  1177. Error err = a->scale_track_interpolate(i, time, &scale);
  1178. if (err != OK) {
  1179. continue;
  1180. }
  1181. scale = post_process_key_value(a, i, scale, t->object, t->bone_idx);
  1182. t->scale += (scale - t->init_scale) * blend;
  1183. }
  1184. #endif // _3D_DISABLED
  1185. } break;
  1186. case Animation::TYPE_BLEND_SHAPE: {
  1187. #ifndef _3D_DISABLED
  1188. if (Math::is_zero_approx(blend)) {
  1189. continue; // Nothing to blend.
  1190. }
  1191. TrackCacheBlendShape *t = static_cast<TrackCacheBlendShape *>(track);
  1192. float value;
  1193. Error err = a->blend_shape_track_interpolate(i, time, &value);
  1194. //ERR_CONTINUE(err!=OK); //used for testing, should be removed
  1195. if (err != OK) {
  1196. continue;
  1197. }
  1198. value = post_process_key_value(a, i, value, t->object, t->shape_index);
  1199. t->value += (value - t->init_value) * blend;
  1200. #endif // _3D_DISABLED
  1201. } break;
  1202. case Animation::TYPE_VALUE: {
  1203. if (Math::is_zero_approx(blend)) {
  1204. continue; // Nothing to blend.
  1205. }
  1206. TrackCacheValue *t = static_cast<TrackCacheValue *>(track);
  1207. Animation::UpdateMode update_mode = a->value_track_get_update_mode(i);
  1208. if (update_mode == Animation::UPDATE_CONTINUOUS || update_mode == Animation::UPDATE_CAPTURE) {
  1209. Variant value = a->value_track_interpolate(i, time);
  1210. value = post_process_key_value(a, i, value, t->object);
  1211. if (value == Variant()) {
  1212. continue;
  1213. }
  1214. // Special case for angle interpolation.
  1215. if (t->is_using_angle) {
  1216. // For blending consistency, it prevents rotation of more than 180 degrees from init_value.
  1217. // This is the same as for Quaternion blends.
  1218. float rot_a = t->value;
  1219. float rot_b = value;
  1220. float rot_init = t->init_value;
  1221. rot_a = Math::fposmod(rot_a, (float)Math_TAU);
  1222. rot_b = Math::fposmod(rot_b, (float)Math_TAU);
  1223. rot_init = Math::fposmod(rot_init, (float)Math_TAU);
  1224. if (rot_init < Math_PI) {
  1225. rot_a = rot_a > rot_init + Math_PI ? rot_a - Math_TAU : rot_a;
  1226. rot_b = rot_b > rot_init + Math_PI ? rot_b - Math_TAU : rot_b;
  1227. } else {
  1228. rot_a = rot_a < rot_init - Math_PI ? rot_a + Math_TAU : rot_a;
  1229. rot_b = rot_b < rot_init - Math_PI ? rot_b + Math_TAU : rot_b;
  1230. }
  1231. t->value = Math::fposmod(rot_a + (rot_b - rot_init) * (float)blend, (float)Math_TAU);
  1232. } else {
  1233. if (t->init_value.get_type() == Variant::BOOL) {
  1234. value = Animation::subtract_variant(value.operator real_t(), t->init_value.operator real_t());
  1235. t->value = Animation::blend_variant(t->value.operator real_t(), value.operator real_t(), blend);
  1236. } else {
  1237. value = Animation::subtract_variant(value, t->init_value);
  1238. t->value = Animation::blend_variant(t->value, value, blend);
  1239. }
  1240. }
  1241. } else {
  1242. if (seeked) {
  1243. int idx = a->track_find_key(i, time, is_external_seeking ? Animation::FIND_MODE_NEAREST : Animation::FIND_MODE_EXACT);
  1244. if (idx < 0) {
  1245. continue;
  1246. }
  1247. Variant value = a->track_get_key_value(i, idx);
  1248. value = post_process_key_value(a, i, value, t->object);
  1249. t->object->set_indexed(t->subpath, value);
  1250. } else {
  1251. List<int> indices;
  1252. a->track_get_key_indices_in_range(i, time, delta, &indices, looped_flag);
  1253. for (int &F : indices) {
  1254. Variant value = a->track_get_key_value(i, F);
  1255. value = post_process_key_value(a, i, value, t->object);
  1256. t->object->set_indexed(t->subpath, value);
  1257. }
  1258. }
  1259. }
  1260. } break;
  1261. case Animation::TYPE_METHOD: {
  1262. #ifdef TOOLS_ENABLED
  1263. if (!can_call) {
  1264. continue;
  1265. }
  1266. #endif // TOOLS_ENABLED
  1267. if (Math::is_zero_approx(blend)) {
  1268. continue; // Nothing to blend.
  1269. }
  1270. TrackCacheMethod *t = static_cast<TrackCacheMethod *>(track);
  1271. if (seeked) {
  1272. int idx = a->track_find_key(i, time, is_external_seeking ? Animation::FIND_MODE_NEAREST : Animation::FIND_MODE_EXACT);
  1273. if (idx < 0) {
  1274. continue;
  1275. }
  1276. StringName method = a->method_track_get_name(i, idx);
  1277. Vector<Variant> params = a->method_track_get_params(i, idx);
  1278. _call_object(t->object, method, params, false);
  1279. } else {
  1280. List<int> indices;
  1281. a->track_get_key_indices_in_range(i, time, delta, &indices, looped_flag);
  1282. for (int &F : indices) {
  1283. StringName method = a->method_track_get_name(i, F);
  1284. Vector<Variant> params = a->method_track_get_params(i, F);
  1285. _call_object(t->object, method, params, true);
  1286. }
  1287. }
  1288. } break;
  1289. case Animation::TYPE_BEZIER: {
  1290. if (Math::is_zero_approx(blend)) {
  1291. continue; // Nothing to blend.
  1292. }
  1293. TrackCacheBezier *t = static_cast<TrackCacheBezier *>(track);
  1294. real_t bezier = a->bezier_track_interpolate(i, time);
  1295. bezier = post_process_key_value(a, i, bezier, t->object);
  1296. t->value += (bezier - t->init_value) * blend;
  1297. } break;
  1298. case Animation::TYPE_AUDIO: {
  1299. TrackCacheAudio *t = static_cast<TrackCacheAudio *>(track);
  1300. Node *asp = Object::cast_to<Node>(t->object);
  1301. if (!asp) {
  1302. t->playing_streams.clear();
  1303. continue;
  1304. }
  1305. ObjectID oid = a->get_instance_id();
  1306. if (!t->playing_streams.has(oid)) {
  1307. t->playing_streams[oid] = PlayingAudioTrackInfo();
  1308. }
  1309. // The end of audio should be observed even if the blend value is 0, build up the information and store to the cache for that.
  1310. PlayingAudioTrackInfo &track_info = t->playing_streams[oid];
  1311. track_info.length = a->get_length();
  1312. track_info.time = time;
  1313. track_info.volume += blend;
  1314. track_info.loop = a->get_loop_mode() != Animation::LOOP_NONE;
  1315. track_info.backward = backward;
  1316. track_info.use_blend = a->audio_track_is_use_blend(i);
  1317. HashMap<int, PlayingAudioStreamInfo> &map = track_info.stream_info;
  1318. // Find stream.
  1319. int idx = -1;
  1320. if (seeked) {
  1321. idx = a->track_find_key(i, time, is_external_seeking ? Animation::FIND_MODE_NEAREST : Animation::FIND_MODE_EXACT);
  1322. // Discard previous stream when seeking.
  1323. if (map.has(idx)) {
  1324. t->audio_stream_playback->stop_stream(map[idx].index);
  1325. map.erase(idx);
  1326. }
  1327. } else {
  1328. List<int> to_play;
  1329. a->track_get_key_indices_in_range(i, time, delta, &to_play, looped_flag);
  1330. if (to_play.size()) {
  1331. idx = to_play.back()->get();
  1332. }
  1333. }
  1334. if (idx < 0) {
  1335. continue;
  1336. }
  1337. // Play stream.
  1338. Ref<AudioStream> stream = a->audio_track_get_key_stream(i, idx);
  1339. if (stream.is_valid()) {
  1340. double start_ofs = a->audio_track_get_key_start_offset(i, idx);
  1341. double end_ofs = a->audio_track_get_key_end_offset(i, idx);
  1342. double len = stream->get_length();
  1343. if (seeked) {
  1344. start_ofs += time - a->track_get_key_time(i, idx);
  1345. }
  1346. if (t->object->call(SNAME("get_stream")) != t->audio_stream) {
  1347. t->object->call(SNAME("set_stream"), t->audio_stream);
  1348. t->audio_stream_playback.unref();
  1349. if (!playing_audio_stream_players.has(asp)) {
  1350. playing_audio_stream_players.push_back(asp);
  1351. }
  1352. }
  1353. if (!t->object->call(SNAME("is_playing"))) {
  1354. t->object->call(SNAME("play"));
  1355. }
  1356. if (!t->object->call(SNAME("has_stream_playback"))) {
  1357. t->audio_stream_playback.unref();
  1358. continue;
  1359. }
  1360. if (t->audio_stream_playback.is_null()) {
  1361. t->audio_stream_playback = t->object->call(SNAME("get_stream_playback"));
  1362. }
  1363. PlayingAudioStreamInfo pasi;
  1364. pasi.index = t->audio_stream_playback->play_stream(stream, start_ofs);
  1365. pasi.start = time;
  1366. if (len && end_ofs > 0) { // Force an end at a time.
  1367. pasi.len = len - start_ofs - end_ofs;
  1368. } else {
  1369. pasi.len = 0;
  1370. }
  1371. map[idx] = pasi;
  1372. }
  1373. } break;
  1374. case Animation::TYPE_ANIMATION: {
  1375. if (Math::is_zero_approx(blend)) {
  1376. continue; // Nothing to blend.
  1377. }
  1378. TrackCacheAnimation *t = static_cast<TrackCacheAnimation *>(track);
  1379. AnimationPlayer *player2 = Object::cast_to<AnimationPlayer>(t->object);
  1380. if (!player2) {
  1381. continue;
  1382. }
  1383. if (seeked) {
  1384. //seek
  1385. int idx = a->track_find_key(i, time, is_external_seeking ? Animation::FIND_MODE_NEAREST : Animation::FIND_MODE_EXACT);
  1386. if (idx < 0) {
  1387. continue;
  1388. }
  1389. double pos = a->track_get_key_time(i, idx);
  1390. StringName anim_name = a->animation_track_get_key_animation(i, idx);
  1391. if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) {
  1392. continue;
  1393. }
  1394. Ref<Animation> anim = player2->get_animation(anim_name);
  1395. double at_anim_pos = 0.0;
  1396. switch (anim->get_loop_mode()) {
  1397. case Animation::LOOP_NONE: {
  1398. at_anim_pos = MAX((double)anim->get_length(), time - pos); //seek to end
  1399. } break;
  1400. case Animation::LOOP_LINEAR: {
  1401. at_anim_pos = Math::fposmod(time - pos, (double)anim->get_length()); //seek to loop
  1402. } break;
  1403. case Animation::LOOP_PINGPONG: {
  1404. at_anim_pos = Math::pingpong(time - pos, (double)a->get_length());
  1405. } break;
  1406. default:
  1407. break;
  1408. }
  1409. if (player2->is_playing() || seeked) {
  1410. player2->seek(at_anim_pos);
  1411. player2->play(anim_name);
  1412. t->playing = true;
  1413. playing_caches.insert(t);
  1414. } else {
  1415. player2->set_assigned_animation(anim_name);
  1416. player2->seek(at_anim_pos, true);
  1417. }
  1418. } else {
  1419. //find stuff to play
  1420. List<int> to_play;
  1421. a->track_get_key_indices_in_range(i, time, delta, &to_play, looped_flag);
  1422. if (to_play.size()) {
  1423. int idx = to_play.back()->get();
  1424. StringName anim_name = a->animation_track_get_key_animation(i, idx);
  1425. if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) {
  1426. if (playing_caches.has(t)) {
  1427. playing_caches.erase(t);
  1428. player2->stop();
  1429. t->playing = false;
  1430. }
  1431. } else {
  1432. player2->play(anim_name);
  1433. t->playing = true;
  1434. playing_caches.insert(t);
  1435. }
  1436. }
  1437. }
  1438. } break;
  1439. }
  1440. }
  1441. }
  1442. }
  1443. {
  1444. // finally, set the tracks
  1445. for (const KeyValue<NodePath, TrackCache *> &K : track_cache) {
  1446. TrackCache *track = K.value;
  1447. switch (track->type) {
  1448. case Animation::TYPE_POSITION_3D: {
  1449. #ifndef _3D_DISABLED
  1450. TrackCacheTransform *t = static_cast<TrackCacheTransform *>(track);
  1451. if (t->root_motion) {
  1452. root_motion_position = root_motion_cache.loc;
  1453. root_motion_rotation = root_motion_cache.rot;
  1454. root_motion_scale = root_motion_cache.scale - Vector3(1, 1, 1);
  1455. root_motion_position_accumulator = t->loc;
  1456. root_motion_rotation_accumulator = t->rot;
  1457. root_motion_scale_accumulator = t->scale;
  1458. } else if (t->skeleton && t->bone_idx >= 0) {
  1459. if (t->loc_used) {
  1460. t->skeleton->set_bone_pose_position(t->bone_idx, t->loc);
  1461. }
  1462. if (t->rot_used) {
  1463. t->skeleton->set_bone_pose_rotation(t->bone_idx, t->rot);
  1464. }
  1465. if (t->scale_used) {
  1466. t->skeleton->set_bone_pose_scale(t->bone_idx, t->scale);
  1467. }
  1468. } else if (!t->skeleton) {
  1469. if (t->loc_used) {
  1470. t->node_3d->set_position(t->loc);
  1471. }
  1472. if (t->rot_used) {
  1473. t->node_3d->set_rotation(t->rot.get_euler());
  1474. }
  1475. if (t->scale_used) {
  1476. t->node_3d->set_scale(t->scale);
  1477. }
  1478. }
  1479. #endif // _3D_DISABLED
  1480. } break;
  1481. case Animation::TYPE_BLEND_SHAPE: {
  1482. #ifndef _3D_DISABLED
  1483. TrackCacheBlendShape *t = static_cast<TrackCacheBlendShape *>(track);
  1484. if (t->mesh_3d) {
  1485. t->mesh_3d->set_blend_shape_value(t->shape_index, t->value);
  1486. }
  1487. #endif // _3D_DISABLED
  1488. } break;
  1489. case Animation::TYPE_VALUE: {
  1490. TrackCacheValue *t = static_cast<TrackCacheValue *>(track);
  1491. if (t->is_discrete) {
  1492. break; // Don't overwrite the value set by UPDATE_DISCRETE.
  1493. }
  1494. if (t->init_value.get_type() == Variant::BOOL) {
  1495. t->object->set_indexed(t->subpath, t->value.operator real_t() >= 0.5);
  1496. } else {
  1497. t->object->set_indexed(t->subpath, t->value);
  1498. }
  1499. } break;
  1500. case Animation::TYPE_BEZIER: {
  1501. TrackCacheBezier *t = static_cast<TrackCacheBezier *>(track);
  1502. t->object->set_indexed(t->subpath, t->value);
  1503. } break;
  1504. case Animation::TYPE_AUDIO: {
  1505. TrackCacheAudio *t = static_cast<TrackCacheAudio *>(track);
  1506. // Audio ending process.
  1507. LocalVector<ObjectID> erase_maps;
  1508. for (KeyValue<ObjectID, PlayingAudioTrackInfo> &L : t->playing_streams) {
  1509. PlayingAudioTrackInfo &track_info = L.value;
  1510. float db = Math::linear_to_db(track_info.use_blend ? track_info.volume : 1.0);
  1511. LocalVector<int> erase_streams;
  1512. HashMap<int, PlayingAudioStreamInfo> &map = track_info.stream_info;
  1513. for (const KeyValue<int, PlayingAudioStreamInfo> &M : map) {
  1514. PlayingAudioStreamInfo pasi = M.value;
  1515. bool stop = false;
  1516. if (!t->audio_stream_playback->is_stream_playing(pasi.index)) {
  1517. stop = true;
  1518. }
  1519. if (!track_info.loop) {
  1520. if (!track_info.backward) {
  1521. if (track_info.time < pasi.start) {
  1522. stop = true;
  1523. }
  1524. } else if (track_info.backward) {
  1525. if (track_info.time > pasi.start) {
  1526. stop = true;
  1527. }
  1528. }
  1529. }
  1530. if (pasi.len > 0) {
  1531. double len = 0.0;
  1532. if (!track_info.backward) {
  1533. len = pasi.start > track_info.time ? (track_info.length - pasi.start) + track_info.time : track_info.time - pasi.start;
  1534. } else {
  1535. len = pasi.start < track_info.time ? (track_info.length - track_info.time) + pasi.start : pasi.start - track_info.time;
  1536. }
  1537. if (len > pasi.len) {
  1538. stop = true;
  1539. }
  1540. }
  1541. if (stop) {
  1542. // Time to stop.
  1543. t->audio_stream_playback->stop_stream(pasi.index);
  1544. erase_streams.push_back(M.key);
  1545. } else {
  1546. t->audio_stream_playback->set_stream_volume(pasi.index, db);
  1547. }
  1548. }
  1549. for (uint32_t erase_idx = 0; erase_idx < erase_streams.size(); erase_idx++) {
  1550. map.erase(erase_streams[erase_idx]);
  1551. }
  1552. if (map.size() == 0) {
  1553. erase_maps.push_back(L.key);
  1554. }
  1555. }
  1556. for (uint32_t erase_idx = 0; erase_idx < erase_maps.size(); erase_idx++) {
  1557. t->playing_streams.erase(erase_maps[erase_idx]);
  1558. }
  1559. } break;
  1560. default: {
  1561. } //the rest don't matter
  1562. }
  1563. }
  1564. }
  1565. }
  1566. Variant AnimationTree::post_process_key_value(const Ref<Animation> &p_anim, int p_track, Variant p_value, const Object *p_object, int p_object_idx) {
  1567. Variant res;
  1568. if (GDVIRTUAL_CALL(_post_process_key_value, p_anim, p_track, p_value, const_cast<Object *>(p_object), p_object_idx, res)) {
  1569. return res;
  1570. }
  1571. return _post_process_key_value(p_anim, p_track, p_value, p_object, p_object_idx);
  1572. }
  1573. Variant AnimationTree::_post_process_key_value(const Ref<Animation> &p_anim, int p_track, Variant p_value, const Object *p_object, int p_object_idx) {
  1574. switch (p_anim->track_get_type(p_track)) {
  1575. #ifndef _3D_DISABLED
  1576. case Animation::TYPE_POSITION_3D: {
  1577. if (p_object_idx >= 0) {
  1578. const Skeleton3D *skel = Object::cast_to<Skeleton3D>(p_object);
  1579. return Vector3(p_value) * skel->get_motion_scale();
  1580. }
  1581. return p_value;
  1582. } break;
  1583. #endif // _3D_DISABLED
  1584. default: {
  1585. } break;
  1586. }
  1587. return p_value;
  1588. }
  1589. void AnimationTree::advance(double p_time) {
  1590. _process_graph(p_time);
  1591. }
  1592. void AnimationTree::_notification(int p_what) {
  1593. switch (p_what) {
  1594. case NOTIFICATION_ENTER_TREE: {
  1595. _setup_animation_player();
  1596. if (last_animation_player.is_valid()) {
  1597. Object *player = ObjectDB::get_instance(last_animation_player);
  1598. if (player) {
  1599. player->connect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
  1600. }
  1601. }
  1602. } break;
  1603. case NOTIFICATION_EXIT_TREE: {
  1604. _clear_caches();
  1605. if (last_animation_player.is_valid()) {
  1606. Object *player = ObjectDB::get_instance(last_animation_player);
  1607. if (player) {
  1608. player->disconnect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
  1609. }
  1610. }
  1611. } break;
  1612. case NOTIFICATION_INTERNAL_PROCESS: {
  1613. if (active && process_callback == ANIMATION_PROCESS_IDLE) {
  1614. _process_graph(get_process_delta_time());
  1615. }
  1616. } break;
  1617. case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
  1618. if (active && process_callback == ANIMATION_PROCESS_PHYSICS) {
  1619. _process_graph(get_physics_process_delta_time());
  1620. }
  1621. } break;
  1622. }
  1623. }
  1624. void AnimationTree::_setup_animation_player() {
  1625. if (!is_inside_tree()) {
  1626. return;
  1627. }
  1628. cache_valid = false;
  1629. AnimationPlayer *new_player = nullptr;
  1630. if (!animation_player.is_empty()) {
  1631. new_player = Object::cast_to<AnimationPlayer>(get_node_or_null(animation_player));
  1632. if (new_player && !new_player->is_connected("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed))) {
  1633. new_player->connect("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed));
  1634. }
  1635. }
  1636. if (new_player) {
  1637. if (!last_animation_player.is_valid()) {
  1638. // Animation player set newly.
  1639. emit_signal(SNAME("animation_player_changed"));
  1640. return;
  1641. } else if (last_animation_player == new_player->get_instance_id()) {
  1642. // Animation player isn't changed.
  1643. return;
  1644. }
  1645. } else if (!last_animation_player.is_valid()) {
  1646. // Animation player is being empty.
  1647. return;
  1648. }
  1649. AnimationPlayer *old_player = Object::cast_to<AnimationPlayer>(ObjectDB::get_instance(last_animation_player));
  1650. if (old_player && old_player->is_connected("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed))) {
  1651. old_player->disconnect("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed));
  1652. }
  1653. emit_signal(SNAME("animation_player_changed"));
  1654. }
  1655. void AnimationTree::set_animation_player(const NodePath &p_player) {
  1656. animation_player = p_player;
  1657. _setup_animation_player();
  1658. update_configuration_warnings();
  1659. }
  1660. NodePath AnimationTree::get_animation_player() const {
  1661. return animation_player;
  1662. }
  1663. void AnimationTree::set_advance_expression_base_node(const NodePath &p_advance_expression_base_node) {
  1664. advance_expression_base_node = p_advance_expression_base_node;
  1665. }
  1666. NodePath AnimationTree::get_advance_expression_base_node() const {
  1667. return advance_expression_base_node;
  1668. }
  1669. void AnimationTree::set_audio_max_polyphony(int p_audio_max_polyphony) {
  1670. ERR_FAIL_COND(p_audio_max_polyphony < 0 || p_audio_max_polyphony > 128);
  1671. audio_max_polyphony = p_audio_max_polyphony;
  1672. }
  1673. int AnimationTree::get_audio_max_polyphony() const {
  1674. return audio_max_polyphony;
  1675. }
  1676. bool AnimationTree::is_state_invalid() const {
  1677. return !state.valid;
  1678. }
  1679. String AnimationTree::get_invalid_state_reason() const {
  1680. return state.invalid_reasons;
  1681. }
  1682. uint64_t AnimationTree::get_last_process_pass() const {
  1683. return process_pass;
  1684. }
  1685. PackedStringArray AnimationTree::get_configuration_warnings() const {
  1686. PackedStringArray warnings = Node::get_configuration_warnings();
  1687. if (!root.is_valid()) {
  1688. warnings.push_back(RTR("No root AnimationNode for the graph is set."));
  1689. }
  1690. if (!has_node(animation_player)) {
  1691. warnings.push_back(RTR("Path to an AnimationPlayer node containing animations is not set."));
  1692. } else {
  1693. AnimationPlayer *player = Object::cast_to<AnimationPlayer>(get_node(animation_player));
  1694. if (!player) {
  1695. warnings.push_back(RTR("Path set for AnimationPlayer does not lead to an AnimationPlayer node."));
  1696. } else if (!player->has_node(player->get_root())) {
  1697. warnings.push_back(RTR("The AnimationPlayer root node is not a valid node."));
  1698. }
  1699. }
  1700. return warnings;
  1701. }
  1702. void AnimationTree::set_root_motion_track(const NodePath &p_track) {
  1703. root_motion_track = p_track;
  1704. }
  1705. NodePath AnimationTree::get_root_motion_track() const {
  1706. return root_motion_track;
  1707. }
  1708. Vector3 AnimationTree::get_root_motion_position() const {
  1709. return root_motion_position;
  1710. }
  1711. Quaternion AnimationTree::get_root_motion_rotation() const {
  1712. return root_motion_rotation;
  1713. }
  1714. Vector3 AnimationTree::get_root_motion_scale() const {
  1715. return root_motion_scale;
  1716. }
  1717. Vector3 AnimationTree::get_root_motion_position_accumulator() const {
  1718. return root_motion_position_accumulator;
  1719. }
  1720. Quaternion AnimationTree::get_root_motion_rotation_accumulator() const {
  1721. return root_motion_rotation_accumulator;
  1722. }
  1723. Vector3 AnimationTree::get_root_motion_scale_accumulator() const {
  1724. return root_motion_scale_accumulator;
  1725. }
  1726. void AnimationTree::_tree_changed() {
  1727. if (properties_dirty) {
  1728. return;
  1729. }
  1730. call_deferred(SNAME("_update_properties"));
  1731. properties_dirty = true;
  1732. }
  1733. void AnimationTree::_animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) {
  1734. ERR_FAIL_COND(!property_reference_map.has(p_oid));
  1735. String base_path = property_reference_map[p_oid];
  1736. String old_base = base_path + p_old_name;
  1737. String new_base = base_path + p_new_name;
  1738. for (const PropertyInfo &E : properties) {
  1739. if (E.name.begins_with(old_base)) {
  1740. String new_name = E.name.replace_first(old_base, new_base);
  1741. property_map[new_name] = property_map[E.name];
  1742. property_map.erase(E.name);
  1743. }
  1744. }
  1745. //update tree second
  1746. properties_dirty = true;
  1747. _update_properties();
  1748. }
  1749. void AnimationTree::_animation_node_removed(const ObjectID &p_oid, const StringName &p_node) {
  1750. ERR_FAIL_COND(!property_reference_map.has(p_oid));
  1751. String base_path = String(property_reference_map[p_oid]) + String(p_node);
  1752. for (const PropertyInfo &E : properties) {
  1753. if (E.name.begins_with(base_path)) {
  1754. property_map.erase(E.name);
  1755. }
  1756. }
  1757. //update tree second
  1758. properties_dirty = true;
  1759. _update_properties();
  1760. }
  1761. void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node) {
  1762. ERR_FAIL_COND(node.is_null());
  1763. if (!property_parent_map.has(p_base_path)) {
  1764. property_parent_map[p_base_path] = HashMap<StringName, StringName>();
  1765. }
  1766. if (!property_reference_map.has(node->get_instance_id())) {
  1767. property_reference_map[node->get_instance_id()] = p_base_path;
  1768. }
  1769. if (node->get_input_count() && !input_activity_map.has(p_base_path)) {
  1770. Vector<Activity> activity;
  1771. for (int i = 0; i < node->get_input_count(); i++) {
  1772. Activity a;
  1773. a.activity = 0;
  1774. a.last_pass = 0;
  1775. activity.push_back(a);
  1776. }
  1777. input_activity_map[p_base_path] = activity;
  1778. input_activity_map_get[String(p_base_path).substr(0, String(p_base_path).length() - 1)] = &input_activity_map[p_base_path];
  1779. }
  1780. List<PropertyInfo> plist;
  1781. node->get_parameter_list(&plist);
  1782. for (PropertyInfo &pinfo : plist) {
  1783. StringName key = pinfo.name;
  1784. if (!property_map.has(p_base_path + key)) {
  1785. Pair<Variant, bool> param;
  1786. param.first = node->get_parameter_default_value(key);
  1787. param.second = node->is_parameter_read_only(key);
  1788. property_map[p_base_path + key] = param;
  1789. }
  1790. property_parent_map[p_base_path][key] = p_base_path + key;
  1791. pinfo.name = p_base_path + key;
  1792. properties.push_back(pinfo);
  1793. }
  1794. List<AnimationNode::ChildNode> children;
  1795. node->get_child_nodes(&children);
  1796. for (const AnimationNode::ChildNode &E : children) {
  1797. _update_properties_for_node(p_base_path + E.name + "/", E.node);
  1798. }
  1799. }
  1800. void AnimationTree::_update_properties() {
  1801. if (!properties_dirty) {
  1802. return;
  1803. }
  1804. properties.clear();
  1805. property_reference_map.clear();
  1806. property_parent_map.clear();
  1807. input_activity_map.clear();
  1808. input_activity_map_get.clear();
  1809. if (root.is_valid()) {
  1810. _update_properties_for_node(SceneStringNames::get_singleton()->parameters_base_path, root);
  1811. }
  1812. properties_dirty = false;
  1813. notify_property_list_changed();
  1814. }
  1815. bool AnimationTree::_set(const StringName &p_name, const Variant &p_value) {
  1816. if (properties_dirty) {
  1817. _update_properties();
  1818. }
  1819. if (property_map.has(p_name)) {
  1820. if (is_inside_tree() && property_map[p_name].second) {
  1821. return false; // Prevent to set property by user.
  1822. }
  1823. property_map[p_name].first = p_value;
  1824. return true;
  1825. }
  1826. return false;
  1827. }
  1828. bool AnimationTree::_get(const StringName &p_name, Variant &r_ret) const {
  1829. if (properties_dirty) {
  1830. const_cast<AnimationTree *>(this)->_update_properties();
  1831. }
  1832. if (property_map.has(p_name)) {
  1833. r_ret = property_map[p_name].first;
  1834. return true;
  1835. }
  1836. return false;
  1837. }
  1838. void AnimationTree::_get_property_list(List<PropertyInfo> *p_list) const {
  1839. if (properties_dirty) {
  1840. const_cast<AnimationTree *>(this)->_update_properties();
  1841. }
  1842. for (const PropertyInfo &E : properties) {
  1843. p_list->push_back(E);
  1844. }
  1845. }
  1846. real_t AnimationTree::get_connection_activity(const StringName &p_path, int p_connection) const {
  1847. if (!input_activity_map_get.has(p_path)) {
  1848. return 0;
  1849. }
  1850. const Vector<Activity> *activity = input_activity_map_get[p_path];
  1851. if (!activity || p_connection < 0 || p_connection >= activity->size()) {
  1852. return 0;
  1853. }
  1854. if ((*activity)[p_connection].last_pass != process_pass) {
  1855. return 0;
  1856. }
  1857. return (*activity)[p_connection].activity;
  1858. }
  1859. void AnimationTree::_bind_methods() {
  1860. ClassDB::bind_method(D_METHOD("set_active", "active"), &AnimationTree::set_active);
  1861. ClassDB::bind_method(D_METHOD("is_active"), &AnimationTree::is_active);
  1862. ClassDB::bind_method(D_METHOD("set_tree_root", "root"), &AnimationTree::set_tree_root);
  1863. ClassDB::bind_method(D_METHOD("get_tree_root"), &AnimationTree::get_tree_root);
  1864. ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &AnimationTree::set_process_callback);
  1865. ClassDB::bind_method(D_METHOD("get_process_callback"), &AnimationTree::get_process_callback);
  1866. ClassDB::bind_method(D_METHOD("set_animation_player", "root"), &AnimationTree::set_animation_player);
  1867. ClassDB::bind_method(D_METHOD("get_animation_player"), &AnimationTree::get_animation_player);
  1868. ClassDB::bind_method(D_METHOD("set_advance_expression_base_node", "node"), &AnimationTree::set_advance_expression_base_node);
  1869. ClassDB::bind_method(D_METHOD("get_advance_expression_base_node"), &AnimationTree::get_advance_expression_base_node);
  1870. ClassDB::bind_method(D_METHOD("set_root_motion_track", "path"), &AnimationTree::set_root_motion_track);
  1871. ClassDB::bind_method(D_METHOD("get_root_motion_track"), &AnimationTree::get_root_motion_track);
  1872. ClassDB::bind_method(D_METHOD("set_audio_max_polyphony", "max_polyphony"), &AnimationTree::set_audio_max_polyphony);
  1873. ClassDB::bind_method(D_METHOD("get_audio_max_polyphony"), &AnimationTree::get_audio_max_polyphony);
  1874. ClassDB::bind_method(D_METHOD("get_root_motion_position"), &AnimationTree::get_root_motion_position);
  1875. ClassDB::bind_method(D_METHOD("get_root_motion_rotation"), &AnimationTree::get_root_motion_rotation);
  1876. ClassDB::bind_method(D_METHOD("get_root_motion_scale"), &AnimationTree::get_root_motion_scale);
  1877. ClassDB::bind_method(D_METHOD("get_root_motion_position_accumulator"), &AnimationTree::get_root_motion_position_accumulator);
  1878. ClassDB::bind_method(D_METHOD("get_root_motion_rotation_accumulator"), &AnimationTree::get_root_motion_rotation_accumulator);
  1879. ClassDB::bind_method(D_METHOD("get_root_motion_scale_accumulator"), &AnimationTree::get_root_motion_scale_accumulator);
  1880. ClassDB::bind_method(D_METHOD("_update_properties"), &AnimationTree::_update_properties);
  1881. ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTree::advance);
  1882. GDVIRTUAL_BIND(_post_process_key_value, "animation", "track", "value", "object", "object_idx");
  1883. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode"), "set_tree_root", "get_tree_root");
  1884. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "anim_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player");
  1885. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "advance_expression_base_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node"), "set_advance_expression_base_node", "get_advance_expression_base_node");
  1886. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active");
  1887. ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_process_callback", "get_process_callback");
  1888. ADD_GROUP("Audio", "audio_");
  1889. ADD_PROPERTY(PropertyInfo(Variant::INT, "audio_max_polyphony", PROPERTY_HINT_RANGE, "1,127,1"), "set_audio_max_polyphony", "get_audio_max_polyphony");
  1890. ADD_GROUP("Root Motion", "root_motion_");
  1891. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_motion_track"), "set_root_motion_track", "get_root_motion_track");
  1892. BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS);
  1893. BIND_ENUM_CONSTANT(ANIMATION_PROCESS_IDLE);
  1894. BIND_ENUM_CONSTANT(ANIMATION_PROCESS_MANUAL);
  1895. ADD_SIGNAL(MethodInfo("animation_player_changed"));
  1896. // Signals from AnimationNodes.
  1897. ADD_SIGNAL(MethodInfo("animation_started", PropertyInfo(Variant::STRING_NAME, "anim_name")));
  1898. ADD_SIGNAL(MethodInfo("animation_finished", PropertyInfo(Variant::STRING_NAME, "anim_name")));
  1899. }
  1900. AnimationTree::AnimationTree() {
  1901. }
  1902. AnimationTree::~AnimationTree() {
  1903. }