animation_blend_tree.cpp 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590
  1. /**************************************************************************/
  2. /* animation_blend_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_blend_tree.h"
  31. #include "scene/resources/animation.h"
  32. #include "scene/scene_string_names.h"
  33. void AnimationNodeAnimation::set_animation(const StringName &p_name) {
  34. animation = p_name;
  35. }
  36. StringName AnimationNodeAnimation::get_animation() const {
  37. return animation;
  38. }
  39. Vector<String> (*AnimationNodeAnimation::get_editable_animation_list)() = nullptr;
  40. void AnimationNodeAnimation::get_parameter_list(List<PropertyInfo> *r_list) const {
  41. r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));
  42. }
  43. void AnimationNodeAnimation::_validate_property(PropertyInfo &p_property) const {
  44. if (p_property.name == "animation" && get_editable_animation_list) {
  45. Vector<String> names = get_editable_animation_list();
  46. String anims;
  47. for (int i = 0; i < names.size(); i++) {
  48. if (i > 0) {
  49. anims += ",";
  50. }
  51. anims += String(names[i]);
  52. }
  53. if (!anims.is_empty()) {
  54. p_property.hint = PROPERTY_HINT_ENUM;
  55. p_property.hint_string = anims;
  56. }
  57. }
  58. }
  59. double AnimationNodeAnimation::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  60. double cur_time = get_parameter(time);
  61. if (!process_state->tree->has_animation(animation)) {
  62. AnimationNodeBlendTree *tree = Object::cast_to<AnimationNodeBlendTree>(node_state.parent);
  63. if (tree) {
  64. String node_name = tree->get_node_name(Ref<AnimationNodeAnimation>(this));
  65. make_invalid(vformat(RTR("On BlendTree node '%s', animation not found: '%s'"), node_name, animation));
  66. } else {
  67. make_invalid(vformat(RTR("Animation not found: '%s'"), animation));
  68. }
  69. return 0;
  70. }
  71. Ref<Animation> anim = process_state->tree->get_animation(animation);
  72. double anim_size = (double)anim->get_length();
  73. double step = 0.0;
  74. double prev_time = cur_time;
  75. Animation::LoopedFlag looped_flag = Animation::LOOPED_FLAG_NONE;
  76. bool node_backward = play_mode == PLAY_MODE_BACKWARD;
  77. double p_time = p_playback_info.time;
  78. bool p_seek = p_playback_info.seeked;
  79. bool p_is_external_seeking = p_playback_info.is_external_seeking;
  80. if (p_playback_info.seeked) {
  81. step = p_time - cur_time;
  82. cur_time = p_time;
  83. } else {
  84. p_time *= backward ? -1.0 : 1.0;
  85. cur_time = cur_time + p_time;
  86. step = p_time;
  87. }
  88. bool is_looping = false;
  89. if (anim->get_loop_mode() == Animation::LOOP_PINGPONG) {
  90. if (!Math::is_zero_approx(anim_size)) {
  91. if (prev_time >= 0 && cur_time < 0) {
  92. backward = !backward;
  93. looped_flag = node_backward ? Animation::LOOPED_FLAG_END : Animation::LOOPED_FLAG_START;
  94. }
  95. if (prev_time <= anim_size && cur_time > anim_size) {
  96. backward = !backward;
  97. looped_flag = node_backward ? Animation::LOOPED_FLAG_START : Animation::LOOPED_FLAG_END;
  98. }
  99. cur_time = Math::pingpong(cur_time, anim_size);
  100. }
  101. is_looping = true;
  102. } else if (anim->get_loop_mode() == Animation::LOOP_LINEAR) {
  103. if (!Math::is_zero_approx(anim_size)) {
  104. if (prev_time >= 0 && cur_time < 0) {
  105. looped_flag = node_backward ? Animation::LOOPED_FLAG_END : Animation::LOOPED_FLAG_START;
  106. }
  107. if (prev_time <= anim_size && cur_time > anim_size) {
  108. looped_flag = node_backward ? Animation::LOOPED_FLAG_START : Animation::LOOPED_FLAG_END;
  109. }
  110. cur_time = Math::fposmod(cur_time, anim_size);
  111. }
  112. backward = false;
  113. is_looping = true;
  114. } else {
  115. if (cur_time < 0) {
  116. step += cur_time;
  117. cur_time = 0;
  118. } else if (cur_time > anim_size) {
  119. step += anim_size - cur_time;
  120. cur_time = anim_size;
  121. }
  122. backward = false;
  123. // If ended, don't progress animation. So set delta to 0.
  124. if (p_time > 0) {
  125. if (play_mode == PLAY_MODE_FORWARD) {
  126. if (prev_time >= anim_size) {
  127. step = 0;
  128. }
  129. } else {
  130. if (prev_time <= 0) {
  131. step = 0;
  132. }
  133. }
  134. }
  135. // Emit start & finish signal. Internally, the detections are the same for backward.
  136. // We should use call_deferred since the track keys are still being processed.
  137. if (process_state->tree && !p_test_only) {
  138. // AnimationTree uses seek to 0 "internally" to process the first key of the animation, which is used as the start detection.
  139. if (p_seek && !p_is_external_seeking && cur_time == 0) {
  140. process_state->tree->call_deferred(SNAME("emit_signal"), "animation_started", animation);
  141. }
  142. // Finished.
  143. if (prev_time < anim_size && cur_time >= anim_size) {
  144. process_state->tree->call_deferred(SNAME("emit_signal"), "animation_finished", animation);
  145. }
  146. }
  147. }
  148. if (!p_test_only) {
  149. AnimationMixer::PlaybackInfo pi = p_playback_info;
  150. if (play_mode == PLAY_MODE_FORWARD) {
  151. pi.time = cur_time;
  152. pi.delta = step;
  153. } else {
  154. pi.time = anim_size - cur_time;
  155. pi.delta = -step;
  156. }
  157. pi.weight = 1.0;
  158. pi.looped_flag = looped_flag;
  159. blend_animation(animation, pi);
  160. }
  161. set_parameter(time, cur_time);
  162. return is_looping ? HUGE_LENGTH : anim_size - cur_time;
  163. }
  164. String AnimationNodeAnimation::get_caption() const {
  165. return "Animation";
  166. }
  167. void AnimationNodeAnimation::set_play_mode(PlayMode p_play_mode) {
  168. play_mode = p_play_mode;
  169. }
  170. AnimationNodeAnimation::PlayMode AnimationNodeAnimation::get_play_mode() const {
  171. return play_mode;
  172. }
  173. void AnimationNodeAnimation::set_backward(bool p_backward) {
  174. backward = p_backward;
  175. }
  176. bool AnimationNodeAnimation::is_backward() const {
  177. return backward;
  178. }
  179. void AnimationNodeAnimation::_bind_methods() {
  180. ClassDB::bind_method(D_METHOD("set_animation", "name"), &AnimationNodeAnimation::set_animation);
  181. ClassDB::bind_method(D_METHOD("get_animation"), &AnimationNodeAnimation::get_animation);
  182. ClassDB::bind_method(D_METHOD("set_play_mode", "mode"), &AnimationNodeAnimation::set_play_mode);
  183. ClassDB::bind_method(D_METHOD("get_play_mode"), &AnimationNodeAnimation::get_play_mode);
  184. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "animation"), "set_animation", "get_animation");
  185. ADD_PROPERTY(PropertyInfo(Variant::INT, "play_mode", PROPERTY_HINT_ENUM, "Forward,Backward"), "set_play_mode", "get_play_mode");
  186. BIND_ENUM_CONSTANT(PLAY_MODE_FORWARD);
  187. BIND_ENUM_CONSTANT(PLAY_MODE_BACKWARD);
  188. }
  189. AnimationNodeAnimation::AnimationNodeAnimation() {
  190. }
  191. ////////////////////////////////////////////////////////
  192. void AnimationNodeSync::_bind_methods() {
  193. ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeSync::set_use_sync);
  194. ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeSync::is_using_sync);
  195. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync"), "set_use_sync", "is_using_sync");
  196. }
  197. void AnimationNodeSync::set_use_sync(bool p_sync) {
  198. sync = p_sync;
  199. }
  200. bool AnimationNodeSync::is_using_sync() const {
  201. return sync;
  202. }
  203. AnimationNodeSync::AnimationNodeSync() {
  204. }
  205. ////////////////////////////////////////////////////////
  206. void AnimationNodeOneShot::get_parameter_list(List<PropertyInfo> *r_list) const {
  207. r_list->push_back(PropertyInfo(Variant::BOOL, active, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_READ_ONLY));
  208. r_list->push_back(PropertyInfo(Variant::BOOL, internal_active, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_READ_ONLY));
  209. r_list->push_back(PropertyInfo(Variant::INT, request, PROPERTY_HINT_ENUM, ",Fire,Abort,Fade Out"));
  210. r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));
  211. r_list->push_back(PropertyInfo(Variant::FLOAT, remaining, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));
  212. r_list->push_back(PropertyInfo(Variant::FLOAT, fade_out_remaining, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));
  213. r_list->push_back(PropertyInfo(Variant::FLOAT, time_to_restart, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));
  214. }
  215. Variant AnimationNodeOneShot::get_parameter_default_value(const StringName &p_parameter) const {
  216. if (p_parameter == request) {
  217. return ONE_SHOT_REQUEST_NONE;
  218. } else if (p_parameter == active || p_parameter == internal_active) {
  219. return false;
  220. } else if (p_parameter == time_to_restart) {
  221. return -1;
  222. } else {
  223. return 0.0;
  224. }
  225. }
  226. bool AnimationNodeOneShot::is_parameter_read_only(const StringName &p_parameter) const {
  227. if (p_parameter == active || p_parameter == internal_active) {
  228. return true;
  229. }
  230. return false;
  231. }
  232. void AnimationNodeOneShot::set_fade_in_time(double p_time) {
  233. fade_in = p_time;
  234. }
  235. double AnimationNodeOneShot::get_fade_in_time() const {
  236. return fade_in;
  237. }
  238. void AnimationNodeOneShot::set_fade_out_time(double p_time) {
  239. fade_out = p_time;
  240. }
  241. double AnimationNodeOneShot::get_fade_out_time() const {
  242. return fade_out;
  243. }
  244. void AnimationNodeOneShot::set_fade_in_curve(const Ref<Curve> &p_curve) {
  245. fade_in_curve = p_curve;
  246. }
  247. Ref<Curve> AnimationNodeOneShot::get_fade_in_curve() const {
  248. return fade_in_curve;
  249. }
  250. void AnimationNodeOneShot::set_fade_out_curve(const Ref<Curve> &p_curve) {
  251. fade_out_curve = p_curve;
  252. }
  253. Ref<Curve> AnimationNodeOneShot::get_fade_out_curve() const {
  254. return fade_out_curve;
  255. }
  256. void AnimationNodeOneShot::set_auto_restart_enabled(bool p_enabled) {
  257. auto_restart = p_enabled;
  258. }
  259. void AnimationNodeOneShot::set_auto_restart_delay(double p_time) {
  260. auto_restart_delay = p_time;
  261. }
  262. void AnimationNodeOneShot::set_auto_restart_random_delay(double p_time) {
  263. auto_restart_random_delay = p_time;
  264. }
  265. bool AnimationNodeOneShot::is_auto_restart_enabled() const {
  266. return auto_restart;
  267. }
  268. double AnimationNodeOneShot::get_auto_restart_delay() const {
  269. return auto_restart_delay;
  270. }
  271. double AnimationNodeOneShot::get_auto_restart_random_delay() const {
  272. return auto_restart_random_delay;
  273. }
  274. void AnimationNodeOneShot::set_mix_mode(MixMode p_mix) {
  275. mix = p_mix;
  276. }
  277. AnimationNodeOneShot::MixMode AnimationNodeOneShot::get_mix_mode() const {
  278. return mix;
  279. }
  280. String AnimationNodeOneShot::get_caption() const {
  281. return "OneShot";
  282. }
  283. bool AnimationNodeOneShot::has_filter() const {
  284. return true;
  285. }
  286. double AnimationNodeOneShot::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  287. OneShotRequest cur_request = static_cast<OneShotRequest>((int)get_parameter(request));
  288. bool cur_active = get_parameter(active);
  289. bool cur_internal_active = get_parameter(internal_active);
  290. double cur_time = get_parameter(time);
  291. double cur_remaining = get_parameter(remaining);
  292. double cur_fade_out_remaining = get_parameter(fade_out_remaining);
  293. double cur_time_to_restart = get_parameter(time_to_restart);
  294. set_parameter(request, ONE_SHOT_REQUEST_NONE);
  295. bool is_shooting = true;
  296. bool clear_remaining_fade = false;
  297. bool is_fading_out = cur_active == true && cur_internal_active == false;
  298. double p_time = p_playback_info.time;
  299. bool p_seek = p_playback_info.seeked;
  300. bool p_is_external_seeking = p_playback_info.is_external_seeking;
  301. if (p_time == 0 && p_seek && !p_is_external_seeking) {
  302. clear_remaining_fade = true; // Reset occurs.
  303. }
  304. bool do_start = cur_request == ONE_SHOT_REQUEST_FIRE;
  305. if (cur_request == ONE_SHOT_REQUEST_ABORT) {
  306. set_parameter(internal_active, false);
  307. set_parameter(active, false);
  308. set_parameter(time_to_restart, -1);
  309. is_shooting = false;
  310. } else if (cur_request == ONE_SHOT_REQUEST_FADE_OUT && !is_fading_out) { // If fading, keep current fade.
  311. if (cur_active) {
  312. // Request fading.
  313. is_fading_out = true;
  314. cur_fade_out_remaining = fade_out;
  315. } else {
  316. // Shot is ended, do nothing.
  317. is_shooting = false;
  318. }
  319. set_parameter(internal_active, false);
  320. set_parameter(time_to_restart, -1);
  321. } else if (!do_start && !cur_active) {
  322. if (cur_time_to_restart >= 0.0 && !p_seek) {
  323. cur_time_to_restart -= p_time;
  324. if (cur_time_to_restart < 0) {
  325. do_start = true; // Restart.
  326. }
  327. set_parameter(time_to_restart, cur_time_to_restart);
  328. }
  329. if (!do_start) {
  330. is_shooting = false;
  331. }
  332. }
  333. bool os_seek = p_seek;
  334. if (clear_remaining_fade) {
  335. os_seek = false;
  336. cur_fade_out_remaining = 0;
  337. set_parameter(fade_out_remaining, 0);
  338. if (is_fading_out) {
  339. is_fading_out = false;
  340. set_parameter(internal_active, false);
  341. set_parameter(active, false);
  342. }
  343. }
  344. if (!is_shooting) {
  345. AnimationMixer::PlaybackInfo pi = p_playback_info;
  346. pi.weight = 1.0;
  347. return blend_input(0, pi, FILTER_IGNORE, sync, p_test_only);
  348. }
  349. if (do_start) {
  350. cur_time = 0;
  351. os_seek = true;
  352. set_parameter(request, ONE_SHOT_REQUEST_NONE);
  353. set_parameter(internal_active, true);
  354. set_parameter(active, true);
  355. }
  356. real_t blend = 1.0;
  357. bool use_blend = sync;
  358. if (cur_time < fade_in) {
  359. if (fade_in > 0) {
  360. use_blend = true;
  361. blend = cur_time / fade_in;
  362. if (fade_in_curve.is_valid()) {
  363. blend = fade_in_curve->sample(blend);
  364. }
  365. } else {
  366. blend = 0; // Should not happen.
  367. }
  368. } else if (!do_start && !is_fading_out && cur_remaining <= fade_out) {
  369. is_fading_out = true;
  370. cur_fade_out_remaining = cur_remaining;
  371. set_parameter(internal_active, false);
  372. }
  373. if (is_fading_out) {
  374. use_blend = true;
  375. if (fade_out > 0) {
  376. blend = cur_fade_out_remaining / fade_out;
  377. if (fade_out_curve.is_valid()) {
  378. blend = 1.0 - fade_out_curve->sample(1.0 - blend);
  379. }
  380. } else {
  381. blend = 0;
  382. }
  383. }
  384. AnimationMixer::PlaybackInfo pi = p_playback_info;
  385. double main_rem = 0.0;
  386. if (mix == MIX_MODE_ADD) {
  387. pi.weight = 1.0;
  388. main_rem = blend_input(0, pi, FILTER_IGNORE, sync, p_test_only);
  389. } else {
  390. pi.seeked &= use_blend;
  391. pi.weight = 1.0 - blend;
  392. main_rem = blend_input(0, pi, FILTER_BLEND, sync, p_test_only); // Unlike below, processing this edge is a corner case.
  393. }
  394. pi = p_playback_info;
  395. if (os_seek) {
  396. pi.time = cur_time;
  397. }
  398. pi.seeked = os_seek;
  399. pi.weight = Math::is_zero_approx(blend) ? CMP_EPSILON : blend;
  400. double os_rem = blend_input(1, pi, FILTER_PASS, true, p_test_only); // Blend values must be more than CMP_EPSILON to process discrete keys in edge.
  401. if (do_start) {
  402. cur_remaining = os_rem;
  403. }
  404. if (p_seek) {
  405. cur_time = p_time;
  406. } else {
  407. cur_time += p_time;
  408. cur_remaining = os_rem;
  409. cur_fade_out_remaining -= p_time;
  410. if (cur_remaining <= 0 || (is_fading_out && cur_fade_out_remaining <= 0)) {
  411. set_parameter(internal_active, false);
  412. set_parameter(active, false);
  413. if (auto_restart) {
  414. double restart_sec = auto_restart_delay + Math::randd() * auto_restart_random_delay;
  415. set_parameter(time_to_restart, restart_sec);
  416. }
  417. }
  418. }
  419. set_parameter(time, cur_time);
  420. set_parameter(remaining, cur_remaining);
  421. set_parameter(fade_out_remaining, cur_fade_out_remaining);
  422. return MAX(main_rem, cur_remaining);
  423. }
  424. void AnimationNodeOneShot::_bind_methods() {
  425. ClassDB::bind_method(D_METHOD("set_fadein_time", "time"), &AnimationNodeOneShot::set_fade_in_time);
  426. ClassDB::bind_method(D_METHOD("get_fadein_time"), &AnimationNodeOneShot::get_fade_in_time);
  427. ClassDB::bind_method(D_METHOD("set_fadein_curve", "curve"), &AnimationNodeOneShot::set_fade_in_curve);
  428. ClassDB::bind_method(D_METHOD("get_fadein_curve"), &AnimationNodeOneShot::get_fade_in_curve);
  429. ClassDB::bind_method(D_METHOD("set_fadeout_time", "time"), &AnimationNodeOneShot::set_fade_out_time);
  430. ClassDB::bind_method(D_METHOD("get_fadeout_time"), &AnimationNodeOneShot::get_fade_out_time);
  431. ClassDB::bind_method(D_METHOD("set_fadeout_curve", "curve"), &AnimationNodeOneShot::set_fade_out_curve);
  432. ClassDB::bind_method(D_METHOD("get_fadeout_curve"), &AnimationNodeOneShot::get_fade_out_curve);
  433. ClassDB::bind_method(D_METHOD("set_autorestart", "active"), &AnimationNodeOneShot::set_auto_restart_enabled);
  434. ClassDB::bind_method(D_METHOD("has_autorestart"), &AnimationNodeOneShot::is_auto_restart_enabled);
  435. ClassDB::bind_method(D_METHOD("set_autorestart_delay", "time"), &AnimationNodeOneShot::set_auto_restart_delay);
  436. ClassDB::bind_method(D_METHOD("get_autorestart_delay"), &AnimationNodeOneShot::get_auto_restart_delay);
  437. ClassDB::bind_method(D_METHOD("set_autorestart_random_delay", "time"), &AnimationNodeOneShot::set_auto_restart_random_delay);
  438. ClassDB::bind_method(D_METHOD("get_autorestart_random_delay"), &AnimationNodeOneShot::get_auto_restart_random_delay);
  439. ClassDB::bind_method(D_METHOD("set_mix_mode", "mode"), &AnimationNodeOneShot::set_mix_mode);
  440. ClassDB::bind_method(D_METHOD("get_mix_mode"), &AnimationNodeOneShot::get_mix_mode);
  441. ADD_PROPERTY(PropertyInfo(Variant::INT, "mix_mode", PROPERTY_HINT_ENUM, "Blend,Add"), "set_mix_mode", "get_mix_mode");
  442. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fadein_time", PROPERTY_HINT_RANGE, "0,60,0.01,or_greater,suffix:s"), "set_fadein_time", "get_fadein_time");
  443. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fadein_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_fadein_curve", "get_fadein_curve");
  444. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fadeout_time", PROPERTY_HINT_RANGE, "0,60,0.01,or_greater,suffix:s"), "set_fadeout_time", "get_fadeout_time");
  445. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fadeout_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_fadeout_curve", "get_fadeout_curve");
  446. ADD_GROUP("Auto Restart", "autorestart_");
  447. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autorestart"), "set_autorestart", "has_autorestart");
  448. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "autorestart_delay", PROPERTY_HINT_RANGE, "0,60,0.01,or_greater,suffix:s"), "set_autorestart_delay", "get_autorestart_delay");
  449. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "autorestart_random_delay", PROPERTY_HINT_RANGE, "0,60,0.01,or_greater,suffix:s"), "set_autorestart_random_delay", "get_autorestart_random_delay");
  450. BIND_ENUM_CONSTANT(ONE_SHOT_REQUEST_NONE);
  451. BIND_ENUM_CONSTANT(ONE_SHOT_REQUEST_FIRE);
  452. BIND_ENUM_CONSTANT(ONE_SHOT_REQUEST_ABORT);
  453. BIND_ENUM_CONSTANT(ONE_SHOT_REQUEST_FADE_OUT);
  454. BIND_ENUM_CONSTANT(MIX_MODE_BLEND);
  455. BIND_ENUM_CONSTANT(MIX_MODE_ADD);
  456. }
  457. AnimationNodeOneShot::AnimationNodeOneShot() {
  458. add_input("in");
  459. add_input("shot");
  460. }
  461. ////////////////////////////////////////////////
  462. void AnimationNodeAdd2::get_parameter_list(List<PropertyInfo> *r_list) const {
  463. r_list->push_back(PropertyInfo(Variant::FLOAT, add_amount, PROPERTY_HINT_RANGE, "0,1,0.01,or_less,or_greater"));
  464. }
  465. Variant AnimationNodeAdd2::get_parameter_default_value(const StringName &p_parameter) const {
  466. return 0;
  467. }
  468. String AnimationNodeAdd2::get_caption() const {
  469. return "Add2";
  470. }
  471. bool AnimationNodeAdd2::has_filter() const {
  472. return true;
  473. }
  474. double AnimationNodeAdd2::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  475. double amount = get_parameter(add_amount);
  476. AnimationMixer::PlaybackInfo pi = p_playback_info;
  477. pi.weight = 1.0;
  478. double rem0 = blend_input(0, pi, FILTER_IGNORE, sync, p_test_only);
  479. pi.weight = amount;
  480. blend_input(1, pi, FILTER_PASS, sync, p_test_only);
  481. return rem0;
  482. }
  483. void AnimationNodeAdd2::_bind_methods() {
  484. }
  485. AnimationNodeAdd2::AnimationNodeAdd2() {
  486. add_input("in");
  487. add_input("add");
  488. }
  489. ////////////////////////////////////////////////
  490. void AnimationNodeAdd3::get_parameter_list(List<PropertyInfo> *r_list) const {
  491. r_list->push_back(PropertyInfo(Variant::FLOAT, add_amount, PROPERTY_HINT_RANGE, "-1,1,0.01,or_less,or_greater"));
  492. }
  493. Variant AnimationNodeAdd3::get_parameter_default_value(const StringName &p_parameter) const {
  494. return 0;
  495. }
  496. String AnimationNodeAdd3::get_caption() const {
  497. return "Add3";
  498. }
  499. bool AnimationNodeAdd3::has_filter() const {
  500. return true;
  501. }
  502. double AnimationNodeAdd3::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  503. double amount = get_parameter(add_amount);
  504. AnimationMixer::PlaybackInfo pi = p_playback_info;
  505. pi.weight = MAX(0, -amount);
  506. blend_input(0, pi, FILTER_PASS, sync, p_test_only);
  507. pi.weight = 1.0;
  508. double rem0 = blend_input(1, pi, FILTER_IGNORE, sync, p_test_only);
  509. pi.weight = MAX(0, amount);
  510. blend_input(2, pi, FILTER_PASS, sync, p_test_only);
  511. return rem0;
  512. }
  513. void AnimationNodeAdd3::_bind_methods() {
  514. }
  515. AnimationNodeAdd3::AnimationNodeAdd3() {
  516. add_input("-add");
  517. add_input("in");
  518. add_input("+add");
  519. }
  520. /////////////////////////////////////////////
  521. void AnimationNodeBlend2::get_parameter_list(List<PropertyInfo> *r_list) const {
  522. r_list->push_back(PropertyInfo(Variant::FLOAT, blend_amount, PROPERTY_HINT_RANGE, "0,1,0.01,or_less,or_greater"));
  523. }
  524. Variant AnimationNodeBlend2::get_parameter_default_value(const StringName &p_parameter) const {
  525. return 0; // For blend amount.
  526. }
  527. String AnimationNodeBlend2::get_caption() const {
  528. return "Blend2";
  529. }
  530. double AnimationNodeBlend2::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  531. double amount = get_parameter(blend_amount);
  532. AnimationMixer::PlaybackInfo pi = p_playback_info;
  533. pi.weight = 1.0 - amount;
  534. double rem0 = blend_input(0, pi, FILTER_BLEND, sync, p_test_only);
  535. pi.weight = amount;
  536. double rem1 = blend_input(1, pi, FILTER_PASS, sync, p_test_only);
  537. return amount > 0.5 ? rem1 : rem0; // Hacky but good enough.
  538. }
  539. bool AnimationNodeBlend2::has_filter() const {
  540. return true;
  541. }
  542. void AnimationNodeBlend2::_bind_methods() {
  543. }
  544. AnimationNodeBlend2::AnimationNodeBlend2() {
  545. add_input("in");
  546. add_input("blend");
  547. }
  548. //////////////////////////////////////
  549. void AnimationNodeBlend3::get_parameter_list(List<PropertyInfo> *r_list) const {
  550. r_list->push_back(PropertyInfo(Variant::FLOAT, blend_amount, PROPERTY_HINT_RANGE, "-1,1,0.01,or_less,or_greater"));
  551. }
  552. Variant AnimationNodeBlend3::get_parameter_default_value(const StringName &p_parameter) const {
  553. return 0; // For blend amount.
  554. }
  555. String AnimationNodeBlend3::get_caption() const {
  556. return "Blend3";
  557. }
  558. double AnimationNodeBlend3::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  559. double amount = get_parameter(blend_amount);
  560. AnimationMixer::PlaybackInfo pi = p_playback_info;
  561. pi.weight = MAX(0, -amount);
  562. double rem0 = blend_input(0, pi, FILTER_IGNORE, sync, p_test_only);
  563. pi.weight = 1.0 - ABS(amount);
  564. double rem1 = blend_input(1, pi, FILTER_IGNORE, sync, p_test_only);
  565. pi.weight = MAX(0, amount);
  566. double rem2 = blend_input(2, pi, FILTER_IGNORE, sync, p_test_only);
  567. return amount > 0.5 ? rem2 : (amount < -0.5 ? rem0 : rem1); // Hacky but good enough.
  568. }
  569. void AnimationNodeBlend3::_bind_methods() {
  570. }
  571. AnimationNodeBlend3::AnimationNodeBlend3() {
  572. add_input("-blend");
  573. add_input("in");
  574. add_input("+blend");
  575. }
  576. ////////////////////////////////////////////////
  577. void AnimationNodeSub2::get_parameter_list(List<PropertyInfo> *r_list) const {
  578. r_list->push_back(PropertyInfo(Variant::FLOAT, sub_amount, PROPERTY_HINT_RANGE, "0,1,0.01,or_less,or_greater"));
  579. }
  580. Variant AnimationNodeSub2::get_parameter_default_value(const StringName &p_parameter) const {
  581. return 0;
  582. }
  583. String AnimationNodeSub2::get_caption() const {
  584. return "Sub2";
  585. }
  586. bool AnimationNodeSub2::has_filter() const {
  587. return true;
  588. }
  589. double AnimationNodeSub2::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  590. double amount = get_parameter(sub_amount);
  591. AnimationMixer::PlaybackInfo pi = p_playback_info;
  592. // Out = Sub.Transform3D^(-1) * In.Transform3D
  593. pi.weight = -amount;
  594. blend_input(1, pi, FILTER_PASS, sync, p_test_only);
  595. pi.weight = 1.0;
  596. return blend_input(0, pi, FILTER_IGNORE, sync, p_test_only);
  597. }
  598. void AnimationNodeSub2::_bind_methods() {
  599. }
  600. AnimationNodeSub2::AnimationNodeSub2() {
  601. add_input("in");
  602. add_input("sub");
  603. }
  604. /////////////////////////////////
  605. void AnimationNodeTimeScale::get_parameter_list(List<PropertyInfo> *r_list) const {
  606. r_list->push_back(PropertyInfo(Variant::FLOAT, scale, PROPERTY_HINT_RANGE, "-32,32,0.01,or_less,or_greater"));
  607. }
  608. Variant AnimationNodeTimeScale::get_parameter_default_value(const StringName &p_parameter) const {
  609. return 1.0; // Initial timescale.
  610. }
  611. String AnimationNodeTimeScale::get_caption() const {
  612. return "TimeScale";
  613. }
  614. double AnimationNodeTimeScale::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  615. double cur_scale = get_parameter(scale);
  616. AnimationMixer::PlaybackInfo pi = p_playback_info;
  617. pi.weight = 1.0;
  618. if (!pi.seeked) {
  619. pi.time *= cur_scale;
  620. }
  621. return blend_input(0, pi, FILTER_IGNORE, true, p_test_only);
  622. }
  623. void AnimationNodeTimeScale::_bind_methods() {
  624. }
  625. AnimationNodeTimeScale::AnimationNodeTimeScale() {
  626. add_input("in");
  627. }
  628. ////////////////////////////////////
  629. void AnimationNodeTimeSeek::get_parameter_list(List<PropertyInfo> *r_list) const {
  630. r_list->push_back(PropertyInfo(Variant::FLOAT, seek_pos_request, PROPERTY_HINT_RANGE, "-1,3600,0.01,or_greater")); // It will be reset to -1 after seeking the position immediately.
  631. }
  632. Variant AnimationNodeTimeSeek::get_parameter_default_value(const StringName &p_parameter) const {
  633. return -1.0; // Initial seek request.
  634. }
  635. String AnimationNodeTimeSeek::get_caption() const {
  636. return "TimeSeek";
  637. }
  638. double AnimationNodeTimeSeek::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  639. double cur_seek_pos = get_parameter(seek_pos_request);
  640. AnimationMixer::PlaybackInfo pi = p_playback_info;
  641. pi.weight = 1.0;
  642. if (cur_seek_pos >= 0) {
  643. pi.time = cur_seek_pos;
  644. pi.seeked = true;
  645. pi.is_external_seeking = true;
  646. set_parameter(seek_pos_request, -1.0); // Reset.
  647. }
  648. return blend_input(0, pi, FILTER_IGNORE, true, p_test_only);
  649. }
  650. void AnimationNodeTimeSeek::_bind_methods() {
  651. }
  652. AnimationNodeTimeSeek::AnimationNodeTimeSeek() {
  653. add_input("in");
  654. }
  655. /////////////////////////////////////////////////
  656. bool AnimationNodeTransition::_set(const StringName &p_path, const Variant &p_value) {
  657. String path = p_path;
  658. if (!path.begins_with("input_")) {
  659. return false;
  660. }
  661. int which = path.get_slicec('/', 0).get_slicec('_', 1).to_int();
  662. String what = path.get_slicec('/', 1);
  663. if (which == get_input_count() && what == "name") {
  664. if (add_input(p_value)) {
  665. return true;
  666. }
  667. return false;
  668. }
  669. ERR_FAIL_INDEX_V(which, get_input_count(), false);
  670. if (what == "name") {
  671. set_input_name(which, p_value);
  672. } else if (what == "auto_advance") {
  673. set_input_as_auto_advance(which, p_value);
  674. } else if (what == "reset") {
  675. set_input_reset(which, p_value);
  676. } else {
  677. return false;
  678. }
  679. return true;
  680. }
  681. bool AnimationNodeTransition::_get(const StringName &p_path, Variant &r_ret) const {
  682. String path = p_path;
  683. if (!path.begins_with("input_")) {
  684. return false;
  685. }
  686. int which = path.get_slicec('/', 0).get_slicec('_', 1).to_int();
  687. String what = path.get_slicec('/', 1);
  688. ERR_FAIL_INDEX_V(which, get_input_count(), false);
  689. if (what == "name") {
  690. r_ret = get_input_name(which);
  691. } else if (what == "auto_advance") {
  692. r_ret = is_input_set_as_auto_advance(which);
  693. } else if (what == "reset") {
  694. r_ret = is_input_reset(which);
  695. } else {
  696. return false;
  697. }
  698. return true;
  699. }
  700. void AnimationNodeTransition::get_parameter_list(List<PropertyInfo> *r_list) const {
  701. String anims;
  702. for (int i = 0; i < get_input_count(); i++) {
  703. if (i > 0) {
  704. anims += ",";
  705. }
  706. anims += inputs[i].name;
  707. }
  708. r_list->push_back(PropertyInfo(Variant::STRING, current_state, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_READ_ONLY)); // For interface.
  709. r_list->push_back(PropertyInfo(Variant::STRING, transition_request, PROPERTY_HINT_ENUM, anims)); // For transition request. It will be cleared after setting the value immediately.
  710. r_list->push_back(PropertyInfo(Variant::INT, current_index, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_READ_ONLY)); // To avoid finding the index every frame, use this internally.
  711. r_list->push_back(PropertyInfo(Variant::INT, prev_index, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));
  712. r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));
  713. r_list->push_back(PropertyInfo(Variant::FLOAT, prev_xfading, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));
  714. }
  715. Variant AnimationNodeTransition::get_parameter_default_value(const StringName &p_parameter) const {
  716. if (p_parameter == time || p_parameter == prev_xfading) {
  717. return 0.0;
  718. } else if (p_parameter == prev_index || p_parameter == current_index) {
  719. return -1;
  720. } else {
  721. return String();
  722. }
  723. }
  724. bool AnimationNodeTransition::is_parameter_read_only(const StringName &p_parameter) const {
  725. if (p_parameter == current_state || p_parameter == current_index) {
  726. return true;
  727. }
  728. return false;
  729. }
  730. String AnimationNodeTransition::get_caption() const {
  731. return "Transition";
  732. }
  733. void AnimationNodeTransition::set_input_count(int p_inputs) {
  734. for (int i = get_input_count(); i < p_inputs; i++) {
  735. add_input("state_" + itos(i));
  736. }
  737. while (get_input_count() > p_inputs) {
  738. remove_input(get_input_count() - 1);
  739. }
  740. pending_update = true;
  741. emit_signal(SNAME("tree_changed")); // For updating connect activity map.
  742. notify_property_list_changed();
  743. }
  744. bool AnimationNodeTransition::add_input(const String &p_name) {
  745. if (AnimationNode::add_input(p_name)) {
  746. input_data.push_back(InputData());
  747. return true;
  748. }
  749. return false;
  750. }
  751. void AnimationNodeTransition::remove_input(int p_index) {
  752. input_data.remove_at(p_index);
  753. AnimationNode::remove_input(p_index);
  754. }
  755. bool AnimationNodeTransition::set_input_name(int p_input, const String &p_name) {
  756. pending_update = true;
  757. return AnimationNode::set_input_name(p_input, p_name);
  758. }
  759. void AnimationNodeTransition::set_input_as_auto_advance(int p_input, bool p_enable) {
  760. ERR_FAIL_INDEX(p_input, get_input_count());
  761. input_data.write[p_input].auto_advance = p_enable;
  762. }
  763. bool AnimationNodeTransition::is_input_set_as_auto_advance(int p_input) const {
  764. ERR_FAIL_INDEX_V(p_input, get_input_count(), false);
  765. return input_data[p_input].auto_advance;
  766. }
  767. void AnimationNodeTransition::set_input_reset(int p_input, bool p_enable) {
  768. ERR_FAIL_INDEX(p_input, get_input_count());
  769. input_data.write[p_input].reset = p_enable;
  770. }
  771. bool AnimationNodeTransition::is_input_reset(int p_input) const {
  772. ERR_FAIL_INDEX_V(p_input, get_input_count(), true);
  773. return input_data[p_input].reset;
  774. }
  775. void AnimationNodeTransition::set_xfade_time(double p_fade) {
  776. xfade_time = p_fade;
  777. }
  778. double AnimationNodeTransition::get_xfade_time() const {
  779. return xfade_time;
  780. }
  781. void AnimationNodeTransition::set_xfade_curve(const Ref<Curve> &p_curve) {
  782. xfade_curve = p_curve;
  783. }
  784. Ref<Curve> AnimationNodeTransition::get_xfade_curve() const {
  785. return xfade_curve;
  786. }
  787. void AnimationNodeTransition::set_allow_transition_to_self(bool p_enable) {
  788. allow_transition_to_self = p_enable;
  789. }
  790. bool AnimationNodeTransition::is_allow_transition_to_self() const {
  791. return allow_transition_to_self;
  792. }
  793. double AnimationNodeTransition::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  794. String cur_transition_request = get_parameter(transition_request);
  795. int cur_current_index = get_parameter(current_index);
  796. int cur_prev_index = get_parameter(prev_index);
  797. double cur_time = get_parameter(time);
  798. double cur_prev_xfading = get_parameter(prev_xfading);
  799. bool switched = false;
  800. bool restart = false;
  801. bool clear_remaining_fade = false;
  802. if (pending_update) {
  803. if (cur_current_index < 0 || cur_current_index >= get_input_count()) {
  804. set_parameter(prev_index, -1);
  805. if (get_input_count() > 0) {
  806. set_parameter(current_index, 0);
  807. set_parameter(current_state, get_input_name(0));
  808. } else {
  809. set_parameter(current_index, -1);
  810. set_parameter(current_state, StringName());
  811. }
  812. } else {
  813. set_parameter(current_state, get_input_name(cur_current_index));
  814. }
  815. pending_update = false;
  816. }
  817. double p_time = p_playback_info.time;
  818. bool p_seek = p_playback_info.seeked;
  819. bool p_is_external_seeking = p_playback_info.is_external_seeking;
  820. if (p_time == 0 && p_seek && !p_is_external_seeking) {
  821. clear_remaining_fade = true; // Reset occurs.
  822. }
  823. if (!cur_transition_request.is_empty()) {
  824. int new_idx = find_input(cur_transition_request);
  825. if (new_idx >= 0) {
  826. if (cur_current_index == new_idx) {
  827. if (allow_transition_to_self) {
  828. // Transition to same state.
  829. restart = input_data[cur_current_index].reset;
  830. clear_remaining_fade = true;
  831. }
  832. } else {
  833. switched = true;
  834. cur_prev_index = cur_current_index;
  835. set_parameter(prev_index, cur_current_index);
  836. cur_current_index = new_idx;
  837. set_parameter(current_index, cur_current_index);
  838. set_parameter(current_state, cur_transition_request);
  839. }
  840. } else {
  841. ERR_PRINT("No such input: '" + cur_transition_request + "'");
  842. }
  843. cur_transition_request = String();
  844. set_parameter(transition_request, cur_transition_request);
  845. }
  846. if (clear_remaining_fade) {
  847. cur_prev_xfading = 0;
  848. set_parameter(prev_xfading, 0);
  849. cur_prev_index = -1;
  850. set_parameter(prev_index, -1);
  851. }
  852. AnimationMixer::PlaybackInfo pi = p_playback_info;
  853. // Special case for restart.
  854. if (restart) {
  855. set_parameter(time, 0);
  856. pi.time = 0;
  857. pi.seeked = true;
  858. pi.weight = 1.0;
  859. return blend_input(cur_current_index, pi, FILTER_IGNORE, true, p_test_only);
  860. }
  861. if (switched) {
  862. cur_prev_xfading = xfade_time;
  863. cur_time = 0;
  864. }
  865. if (cur_current_index < 0 || cur_current_index >= get_input_count() || cur_prev_index >= get_input_count()) {
  866. return 0;
  867. }
  868. double rem = 0.0;
  869. double abs_time = Math::abs(p_time);
  870. if (sync) {
  871. pi.weight = 0;
  872. for (int i = 0; i < get_input_count(); i++) {
  873. if (i != cur_current_index && i != cur_prev_index) {
  874. blend_input(i, pi, FILTER_IGNORE, true, p_test_only);
  875. }
  876. }
  877. }
  878. if (cur_prev_index < 0) { // Process current animation, check for transition.
  879. pi.weight = 1.0;
  880. rem = blend_input(cur_current_index, pi, FILTER_IGNORE, true, p_test_only);
  881. if (p_seek) {
  882. cur_time = abs_time;
  883. } else {
  884. cur_time += abs_time;
  885. }
  886. if (input_data[cur_current_index].auto_advance && rem <= xfade_time) {
  887. set_parameter(transition_request, get_input_name((cur_current_index + 1) % get_input_count()));
  888. }
  889. } else { // Cross-fading from prev to current.
  890. real_t blend = 0.0;
  891. real_t blend_inv = 1.0;
  892. bool use_blend = sync;
  893. if (xfade_time > 0) {
  894. use_blend = true;
  895. blend = cur_prev_xfading / xfade_time;
  896. if (xfade_curve.is_valid()) {
  897. blend = xfade_curve->sample(blend);
  898. }
  899. blend_inv = 1.0 - blend;
  900. blend = Math::is_zero_approx(blend) ? CMP_EPSILON : blend;
  901. blend_inv = Math::is_zero_approx(blend_inv) ? CMP_EPSILON : blend_inv;
  902. }
  903. // Blend values must be more than CMP_EPSILON to process discrete keys in edge.
  904. pi.weight = blend_inv;
  905. if (input_data[cur_current_index].reset && !p_seek && switched) { // Just switched, seek to start of current.
  906. pi.time = 0;
  907. pi.seeked = true;
  908. }
  909. rem = blend_input(cur_current_index, pi, FILTER_IGNORE, true, p_test_only);
  910. pi = p_playback_info;
  911. pi.seeked &= use_blend;
  912. pi.weight = blend;
  913. blend_input(cur_prev_index, pi, FILTER_IGNORE, true, p_test_only);
  914. if (p_seek) {
  915. cur_time = abs_time;
  916. } else {
  917. cur_time += abs_time;
  918. cur_prev_xfading -= abs_time;
  919. if (cur_prev_xfading < 0) {
  920. set_parameter(prev_index, -1);
  921. }
  922. }
  923. }
  924. set_parameter(time, cur_time);
  925. set_parameter(prev_xfading, cur_prev_xfading);
  926. return rem;
  927. }
  928. void AnimationNodeTransition::_get_property_list(List<PropertyInfo> *p_list) const {
  929. for (int i = 0; i < get_input_count(); i++) {
  930. p_list->push_back(PropertyInfo(Variant::STRING, "input_" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
  931. p_list->push_back(PropertyInfo(Variant::BOOL, "input_" + itos(i) + "/auto_advance", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
  932. p_list->push_back(PropertyInfo(Variant::BOOL, "input_" + itos(i) + "/reset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
  933. }
  934. }
  935. void AnimationNodeTransition::_bind_methods() {
  936. ClassDB::bind_method(D_METHOD("set_input_count", "input_count"), &AnimationNodeTransition::set_input_count);
  937. ClassDB::bind_method(D_METHOD("set_input_as_auto_advance", "input", "enable"), &AnimationNodeTransition::set_input_as_auto_advance);
  938. ClassDB::bind_method(D_METHOD("is_input_set_as_auto_advance", "input"), &AnimationNodeTransition::is_input_set_as_auto_advance);
  939. ClassDB::bind_method(D_METHOD("set_input_reset", "input", "enable"), &AnimationNodeTransition::set_input_reset);
  940. ClassDB::bind_method(D_METHOD("is_input_reset", "input"), &AnimationNodeTransition::is_input_reset);
  941. ClassDB::bind_method(D_METHOD("set_xfade_time", "time"), &AnimationNodeTransition::set_xfade_time);
  942. ClassDB::bind_method(D_METHOD("get_xfade_time"), &AnimationNodeTransition::get_xfade_time);
  943. ClassDB::bind_method(D_METHOD("set_xfade_curve", "curve"), &AnimationNodeTransition::set_xfade_curve);
  944. ClassDB::bind_method(D_METHOD("get_xfade_curve"), &AnimationNodeTransition::get_xfade_curve);
  945. ClassDB::bind_method(D_METHOD("set_allow_transition_to_self", "enable"), &AnimationNodeTransition::set_allow_transition_to_self);
  946. ClassDB::bind_method(D_METHOD("is_allow_transition_to_self"), &AnimationNodeTransition::is_allow_transition_to_self);
  947. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "xfade_time", PROPERTY_HINT_RANGE, "0,120,0.01,suffix:s"), "set_xfade_time", "get_xfade_time");
  948. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "xfade_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_xfade_curve", "get_xfade_curve");
  949. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_transition_to_self"), "set_allow_transition_to_self", "is_allow_transition_to_self");
  950. ADD_PROPERTY(PropertyInfo(Variant::INT, "input_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ARRAY | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED, "Inputs,input_"), "set_input_count", "get_input_count");
  951. }
  952. AnimationNodeTransition::AnimationNodeTransition() {
  953. }
  954. /////////////////////
  955. String AnimationNodeOutput::get_caption() const {
  956. return "Output";
  957. }
  958. double AnimationNodeOutput::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  959. AnimationMixer::PlaybackInfo pi = p_playback_info;
  960. pi.weight = 1.0;
  961. return blend_input(0, pi, FILTER_IGNORE, true, p_test_only);
  962. }
  963. AnimationNodeOutput::AnimationNodeOutput() {
  964. add_input("output");
  965. }
  966. ///////////////////////////////////////////////////////
  967. void AnimationNodeBlendTree::add_node(const StringName &p_name, Ref<AnimationNode> p_node, const Vector2 &p_position) {
  968. ERR_FAIL_COND(nodes.has(p_name));
  969. ERR_FAIL_COND(p_node.is_null());
  970. ERR_FAIL_COND(p_name == SceneStringNames::get_singleton()->output);
  971. ERR_FAIL_COND(String(p_name).contains("/"));
  972. Node n;
  973. n.node = p_node;
  974. n.position = p_position;
  975. n.connections.resize(n.node->get_input_count());
  976. nodes[p_name] = n;
  977. emit_changed();
  978. emit_signal(SNAME("tree_changed"));
  979. p_node->connect(SNAME("tree_changed"), callable_mp(this, &AnimationNodeBlendTree::_tree_changed), CONNECT_REFERENCE_COUNTED);
  980. p_node->connect(SNAME("animation_node_renamed"), callable_mp(this, &AnimationNodeBlendTree::_animation_node_renamed), CONNECT_REFERENCE_COUNTED);
  981. p_node->connect(SNAME("animation_node_removed"), callable_mp(this, &AnimationNodeBlendTree::_animation_node_removed), CONNECT_REFERENCE_COUNTED);
  982. p_node->connect_changed(callable_mp(this, &AnimationNodeBlendTree::_node_changed).bind(p_name), CONNECT_REFERENCE_COUNTED);
  983. }
  984. Ref<AnimationNode> AnimationNodeBlendTree::get_node(const StringName &p_name) const {
  985. ERR_FAIL_COND_V(!nodes.has(p_name), Ref<AnimationNode>());
  986. return nodes[p_name].node;
  987. }
  988. StringName AnimationNodeBlendTree::get_node_name(const Ref<AnimationNode> &p_node) const {
  989. for (const KeyValue<StringName, Node> &E : nodes) {
  990. if (E.value.node == p_node) {
  991. return E.key;
  992. }
  993. }
  994. ERR_FAIL_V(StringName());
  995. }
  996. void AnimationNodeBlendTree::set_node_position(const StringName &p_node, const Vector2 &p_position) {
  997. ERR_FAIL_COND(!nodes.has(p_node));
  998. nodes[p_node].position = p_position;
  999. }
  1000. Vector2 AnimationNodeBlendTree::get_node_position(const StringName &p_node) const {
  1001. ERR_FAIL_COND_V(!nodes.has(p_node), Vector2());
  1002. return nodes[p_node].position;
  1003. }
  1004. void AnimationNodeBlendTree::get_child_nodes(List<ChildNode> *r_child_nodes) {
  1005. Vector<StringName> ns;
  1006. for (const KeyValue<StringName, Node> &E : nodes) {
  1007. ns.push_back(E.key);
  1008. }
  1009. for (int i = 0; i < ns.size(); i++) {
  1010. ChildNode cn;
  1011. cn.name = ns[i];
  1012. cn.node = nodes[cn.name].node;
  1013. r_child_nodes->push_back(cn);
  1014. }
  1015. }
  1016. bool AnimationNodeBlendTree::has_node(const StringName &p_name) const {
  1017. return nodes.has(p_name);
  1018. }
  1019. Vector<StringName> AnimationNodeBlendTree::get_node_connection_array(const StringName &p_name) const {
  1020. ERR_FAIL_COND_V(!nodes.has(p_name), Vector<StringName>());
  1021. return nodes[p_name].connections;
  1022. }
  1023. void AnimationNodeBlendTree::remove_node(const StringName &p_name) {
  1024. ERR_FAIL_COND(!nodes.has(p_name));
  1025. ERR_FAIL_COND(p_name == SceneStringNames::get_singleton()->output); //can't delete output
  1026. {
  1027. Ref<AnimationNode> node = nodes[p_name].node;
  1028. node->disconnect(SNAME("tree_changed"), callable_mp(this, &AnimationNodeBlendTree::_tree_changed));
  1029. node->disconnect(SNAME("animation_node_renamed"), callable_mp(this, &AnimationNodeBlendTree::_animation_node_renamed));
  1030. node->disconnect(SNAME("animation_node_removed"), callable_mp(this, &AnimationNodeBlendTree::_animation_node_removed));
  1031. node->disconnect_changed(callable_mp(this, &AnimationNodeBlendTree::_node_changed));
  1032. }
  1033. nodes.erase(p_name);
  1034. // Erase connections to name.
  1035. for (KeyValue<StringName, Node> &E : nodes) {
  1036. for (int i = 0; i < E.value.connections.size(); i++) {
  1037. if (E.value.connections[i] == p_name) {
  1038. E.value.connections.write[i] = StringName();
  1039. }
  1040. }
  1041. }
  1042. emit_signal(SNAME("animation_node_removed"), get_instance_id(), p_name);
  1043. emit_changed();
  1044. emit_signal(SNAME("tree_changed"));
  1045. }
  1046. void AnimationNodeBlendTree::rename_node(const StringName &p_name, const StringName &p_new_name) {
  1047. ERR_FAIL_COND(!nodes.has(p_name));
  1048. ERR_FAIL_COND(nodes.has(p_new_name));
  1049. ERR_FAIL_COND(p_name == SceneStringNames::get_singleton()->output);
  1050. ERR_FAIL_COND(p_new_name == SceneStringNames::get_singleton()->output);
  1051. nodes[p_name].node->disconnect_changed(callable_mp(this, &AnimationNodeBlendTree::_node_changed));
  1052. nodes[p_new_name] = nodes[p_name];
  1053. nodes.erase(p_name);
  1054. // Rename connections.
  1055. for (KeyValue<StringName, Node> &E : nodes) {
  1056. for (int i = 0; i < E.value.connections.size(); i++) {
  1057. if (E.value.connections[i] == p_name) {
  1058. E.value.connections.write[i] = p_new_name;
  1059. }
  1060. }
  1061. }
  1062. // Connection must be done with new name.
  1063. nodes[p_new_name].node->connect_changed(callable_mp(this, &AnimationNodeBlendTree::_node_changed).bind(p_new_name), CONNECT_REFERENCE_COUNTED);
  1064. emit_signal(SNAME("animation_node_renamed"), get_instance_id(), p_name, p_new_name);
  1065. emit_signal(SNAME("tree_changed"));
  1066. }
  1067. void AnimationNodeBlendTree::connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) {
  1068. ERR_FAIL_COND(!nodes.has(p_output_node));
  1069. ERR_FAIL_COND(!nodes.has(p_input_node));
  1070. ERR_FAIL_COND(p_output_node == SceneStringNames::get_singleton()->output);
  1071. ERR_FAIL_COND(p_input_node == p_output_node);
  1072. Ref<AnimationNode> input = nodes[p_input_node].node;
  1073. ERR_FAIL_INDEX(p_input_index, nodes[p_input_node].connections.size());
  1074. for (KeyValue<StringName, Node> &E : nodes) {
  1075. for (int i = 0; i < E.value.connections.size(); i++) {
  1076. StringName output = E.value.connections[i];
  1077. ERR_FAIL_COND(output == p_output_node);
  1078. }
  1079. }
  1080. nodes[p_input_node].connections.write[p_input_index] = p_output_node;
  1081. emit_changed();
  1082. }
  1083. void AnimationNodeBlendTree::disconnect_node(const StringName &p_node, int p_input_index) {
  1084. ERR_FAIL_COND(!nodes.has(p_node));
  1085. Ref<AnimationNode> input = nodes[p_node].node;
  1086. ERR_FAIL_INDEX(p_input_index, nodes[p_node].connections.size());
  1087. nodes[p_node].connections.write[p_input_index] = StringName();
  1088. }
  1089. AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) const {
  1090. if (!nodes.has(p_output_node) || p_output_node == SceneStringNames::get_singleton()->output) {
  1091. return CONNECTION_ERROR_NO_OUTPUT;
  1092. }
  1093. if (!nodes.has(p_input_node)) {
  1094. return CONNECTION_ERROR_NO_INPUT;
  1095. }
  1096. if (p_input_node == p_output_node) {
  1097. return CONNECTION_ERROR_SAME_NODE;
  1098. }
  1099. Ref<AnimationNode> input = nodes[p_input_node].node;
  1100. if (p_input_index < 0 || p_input_index >= nodes[p_input_node].connections.size()) {
  1101. return CONNECTION_ERROR_NO_INPUT_INDEX;
  1102. }
  1103. if (nodes[p_input_node].connections[p_input_index] != StringName()) {
  1104. return CONNECTION_ERROR_CONNECTION_EXISTS;
  1105. }
  1106. for (const KeyValue<StringName, Node> &E : nodes) {
  1107. for (int i = 0; i < E.value.connections.size(); i++) {
  1108. const StringName output = E.value.connections[i];
  1109. if (output == p_output_node) {
  1110. return CONNECTION_ERROR_CONNECTION_EXISTS;
  1111. }
  1112. }
  1113. }
  1114. return CONNECTION_OK;
  1115. }
  1116. void AnimationNodeBlendTree::get_node_connections(List<NodeConnection> *r_connections) const {
  1117. for (const KeyValue<StringName, Node> &E : nodes) {
  1118. for (int i = 0; i < E.value.connections.size(); i++) {
  1119. const StringName output = E.value.connections[i];
  1120. if (output != StringName()) {
  1121. NodeConnection nc;
  1122. nc.input_node = E.key;
  1123. nc.input_index = i;
  1124. nc.output_node = output;
  1125. r_connections->push_back(nc);
  1126. }
  1127. }
  1128. }
  1129. }
  1130. String AnimationNodeBlendTree::get_caption() const {
  1131. return "BlendTree";
  1132. }
  1133. double AnimationNodeBlendTree::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  1134. Ref<AnimationNodeOutput> output = nodes[SceneStringNames::get_singleton()->output].node;
  1135. node_state.connections = nodes[SceneStringNames::get_singleton()->output].connections;
  1136. AnimationMixer::PlaybackInfo pi = p_playback_info;
  1137. pi.weight = 1.0;
  1138. return _blend_node(output, "output", this, pi, FILTER_IGNORE, true, p_test_only, nullptr);
  1139. }
  1140. void AnimationNodeBlendTree::get_node_list(List<StringName> *r_list) {
  1141. for (const KeyValue<StringName, Node> &E : nodes) {
  1142. r_list->push_back(E.key);
  1143. }
  1144. }
  1145. void AnimationNodeBlendTree::set_graph_offset(const Vector2 &p_graph_offset) {
  1146. graph_offset = p_graph_offset;
  1147. }
  1148. Vector2 AnimationNodeBlendTree::get_graph_offset() const {
  1149. return graph_offset;
  1150. }
  1151. Ref<AnimationNode> AnimationNodeBlendTree::get_child_by_name(const StringName &p_name) const {
  1152. return get_node(p_name);
  1153. }
  1154. bool AnimationNodeBlendTree::_set(const StringName &p_name, const Variant &p_value) {
  1155. String prop_name = p_name;
  1156. if (prop_name.begins_with("nodes/")) {
  1157. String node_name = prop_name.get_slicec('/', 1);
  1158. String what = prop_name.get_slicec('/', 2);
  1159. if (what == "node") {
  1160. Ref<AnimationNode> anode = p_value;
  1161. if (anode.is_valid()) {
  1162. add_node(node_name, p_value);
  1163. }
  1164. return true;
  1165. }
  1166. if (what == "position") {
  1167. if (nodes.has(node_name)) {
  1168. nodes[node_name].position = p_value;
  1169. }
  1170. return true;
  1171. }
  1172. } else if (prop_name == "node_connections") {
  1173. Array conns = p_value;
  1174. ERR_FAIL_COND_V(conns.size() % 3 != 0, false);
  1175. for (int i = 0; i < conns.size(); i += 3) {
  1176. connect_node(conns[i], conns[i + 1], conns[i + 2]);
  1177. }
  1178. return true;
  1179. }
  1180. return false;
  1181. }
  1182. bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) const {
  1183. String prop_name = p_name;
  1184. if (prop_name.begins_with("nodes/")) {
  1185. String node_name = prop_name.get_slicec('/', 1);
  1186. String what = prop_name.get_slicec('/', 2);
  1187. if (what == "node") {
  1188. if (nodes.has(node_name)) {
  1189. r_ret = nodes[node_name].node;
  1190. return true;
  1191. }
  1192. }
  1193. if (what == "position") {
  1194. if (nodes.has(node_name)) {
  1195. r_ret = nodes[node_name].position;
  1196. return true;
  1197. }
  1198. }
  1199. } else if (prop_name == "node_connections") {
  1200. List<NodeConnection> nc;
  1201. get_node_connections(&nc);
  1202. Array conns;
  1203. conns.resize(nc.size() * 3);
  1204. int idx = 0;
  1205. for (const NodeConnection &E : nc) {
  1206. conns[idx * 3 + 0] = E.input_node;
  1207. conns[idx * 3 + 1] = E.input_index;
  1208. conns[idx * 3 + 2] = E.output_node;
  1209. idx++;
  1210. }
  1211. r_ret = conns;
  1212. return true;
  1213. }
  1214. return false;
  1215. }
  1216. void AnimationNodeBlendTree::_get_property_list(List<PropertyInfo> *p_list) const {
  1217. List<StringName> names;
  1218. for (const KeyValue<StringName, Node> &E : nodes) {
  1219. names.push_back(E.key);
  1220. }
  1221. for (const StringName &E : names) {
  1222. String prop_name = E;
  1223. if (prop_name != "output") {
  1224. p_list->push_back(PropertyInfo(Variant::OBJECT, "nodes/" + prop_name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NO_EDITOR));
  1225. }
  1226. p_list->push_back(PropertyInfo(Variant::VECTOR2, "nodes/" + prop_name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR));
  1227. }
  1228. p_list->push_back(PropertyInfo(Variant::ARRAY, "node_connections", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR));
  1229. }
  1230. void AnimationNodeBlendTree::_tree_changed() {
  1231. AnimationRootNode::_tree_changed();
  1232. }
  1233. void AnimationNodeBlendTree::_animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) {
  1234. AnimationRootNode::_animation_node_renamed(p_oid, p_old_name, p_new_name);
  1235. }
  1236. void AnimationNodeBlendTree::_animation_node_removed(const ObjectID &p_oid, const StringName &p_node) {
  1237. AnimationRootNode::_animation_node_removed(p_oid, p_node);
  1238. }
  1239. void AnimationNodeBlendTree::reset_state() {
  1240. graph_offset = Vector2();
  1241. nodes.clear();
  1242. _initialize_node_tree();
  1243. emit_changed();
  1244. emit_signal(SNAME("tree_changed"));
  1245. }
  1246. void AnimationNodeBlendTree::_node_changed(const StringName &p_node) {
  1247. ERR_FAIL_COND(!nodes.has(p_node));
  1248. nodes[p_node].connections.resize(nodes[p_node].node->get_input_count());
  1249. emit_signal(SNAME("node_changed"), p_node);
  1250. }
  1251. void AnimationNodeBlendTree::_bind_methods() {
  1252. ClassDB::bind_method(D_METHOD("add_node", "name", "node", "position"), &AnimationNodeBlendTree::add_node, DEFVAL(Vector2()));
  1253. ClassDB::bind_method(D_METHOD("get_node", "name"), &AnimationNodeBlendTree::get_node);
  1254. ClassDB::bind_method(D_METHOD("remove_node", "name"), &AnimationNodeBlendTree::remove_node);
  1255. ClassDB::bind_method(D_METHOD("rename_node", "name", "new_name"), &AnimationNodeBlendTree::rename_node);
  1256. ClassDB::bind_method(D_METHOD("has_node", "name"), &AnimationNodeBlendTree::has_node);
  1257. ClassDB::bind_method(D_METHOD("connect_node", "input_node", "input_index", "output_node"), &AnimationNodeBlendTree::connect_node);
  1258. ClassDB::bind_method(D_METHOD("disconnect_node", "input_node", "input_index"), &AnimationNodeBlendTree::disconnect_node);
  1259. ClassDB::bind_method(D_METHOD("set_node_position", "name", "position"), &AnimationNodeBlendTree::set_node_position);
  1260. ClassDB::bind_method(D_METHOD("get_node_position", "name"), &AnimationNodeBlendTree::get_node_position);
  1261. ClassDB::bind_method(D_METHOD("set_graph_offset", "offset"), &AnimationNodeBlendTree::set_graph_offset);
  1262. ClassDB::bind_method(D_METHOD("get_graph_offset"), &AnimationNodeBlendTree::get_graph_offset);
  1263. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "graph_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_graph_offset", "get_graph_offset");
  1264. BIND_CONSTANT(CONNECTION_OK);
  1265. BIND_CONSTANT(CONNECTION_ERROR_NO_INPUT);
  1266. BIND_CONSTANT(CONNECTION_ERROR_NO_INPUT_INDEX);
  1267. BIND_CONSTANT(CONNECTION_ERROR_NO_OUTPUT);
  1268. BIND_CONSTANT(CONNECTION_ERROR_SAME_NODE);
  1269. BIND_CONSTANT(CONNECTION_ERROR_CONNECTION_EXISTS);
  1270. ADD_SIGNAL(MethodInfo(SNAME("node_changed"), PropertyInfo(Variant::STRING_NAME, "node_name")));
  1271. }
  1272. void AnimationNodeBlendTree::_initialize_node_tree() {
  1273. Ref<AnimationNodeOutput> output;
  1274. output.instantiate();
  1275. Node n;
  1276. n.node = output;
  1277. n.position = Vector2(300, 150);
  1278. n.connections.resize(1);
  1279. nodes["output"] = n;
  1280. }
  1281. AnimationNodeBlendTree::AnimationNodeBlendTree() {
  1282. _initialize_node_tree();
  1283. }
  1284. AnimationNodeBlendTree::~AnimationNodeBlendTree() {
  1285. }