animation_tree_player.cpp 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  1. /*************************************************************************/
  2. /* animation_tree_player.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "animation_tree_player.h"
  30. #include "animation_player.h"
  31. #include "scene/scene_string_names.h"
  32. void AnimationTreePlayer::set_animation_process_mode(AnimationProcessMode p_mode) {
  33. if (animation_process_mode == p_mode)
  34. return;
  35. bool pr = processing;
  36. if (pr)
  37. _set_process(false);
  38. animation_process_mode = p_mode;
  39. if (pr)
  40. _set_process(true);
  41. }
  42. AnimationTreePlayer::AnimationProcessMode AnimationTreePlayer::get_animation_process_mode() const{
  43. return animation_process_mode;
  44. }
  45. void AnimationTreePlayer::_set_process(bool p_process, bool p_force)
  46. {
  47. if (processing == p_process && !p_force)
  48. return;
  49. switch (animation_process_mode) {
  50. case ANIMATION_PROCESS_FIXED: set_fixed_process_internal(p_process && active); break;
  51. case ANIMATION_PROCESS_IDLE: set_process_internal(p_process && active); break;
  52. }
  53. processing = p_process;
  54. }
  55. bool AnimationTreePlayer::_set(const StringName& p_name, const Variant& p_value) {
  56. if (String(p_name)=="base_path") {
  57. set_base_path(p_value);
  58. return true;
  59. }
  60. if (String(p_name)=="master_player") {
  61. set_master_player(p_value);
  62. return true;
  63. }
  64. if(String(p_name) == SceneStringNames::get_singleton()->playback_active) {
  65. set_active(p_value);
  66. return true;
  67. }
  68. if (String(p_name)!="data")
  69. return false;
  70. Dictionary data=p_value;
  71. Array nodes=data.get_valid("nodes");
  72. for(int i=0;i<nodes.size();i++) {
  73. Dictionary node = nodes[i];
  74. StringName id = node.get_valid("id");
  75. Point2 pos = node.get_valid("pos");
  76. NodeType nt=NODE_MAX;
  77. String type = node.get_valid("type");
  78. if (type=="output")
  79. nt=NODE_OUTPUT;
  80. else if (type=="animation")
  81. nt=NODE_ANIMATION;
  82. else if (type=="oneshot")
  83. nt=NODE_ONESHOT;
  84. else if (type=="mix")
  85. nt=NODE_MIX;
  86. else if (type=="blend2")
  87. nt=NODE_BLEND2;
  88. else if (type=="blend3")
  89. nt=NODE_BLEND3;
  90. else if (type=="blend4")
  91. nt=NODE_BLEND4;
  92. else if (type=="timescale")
  93. nt=NODE_TIMESCALE;
  94. else if (type=="timeseek")
  95. nt=NODE_TIMESEEK;
  96. else if (type=="transition")
  97. nt=NODE_TRANSITION;
  98. ERR_FAIL_COND_V(nt==NODE_MAX,false);
  99. if (nt!=NODE_OUTPUT)
  100. add_node(nt,id);
  101. node_set_pos(id,pos);
  102. switch(nt) {
  103. case NODE_OUTPUT: {
  104. } break;
  105. case NODE_ANIMATION: {
  106. if (node.has("from"))
  107. animation_node_set_master_animation(id,node.get_valid("from"));
  108. else
  109. animation_node_set_animation(id,node.get_valid("animation"));
  110. Array filters= node.get_valid("filter");
  111. for(int i=0;i<filters.size();i++) {
  112. animation_node_set_filter_path(id,filters[i],true);
  113. }
  114. } break;
  115. case NODE_ONESHOT: {
  116. oneshot_node_set_fadein_time(id,node.get_valid("fade_in"));
  117. oneshot_node_set_fadeout_time(id,node.get_valid("fade_out"));
  118. oneshot_node_set_mix_mode(id,node.get_valid("mix"));
  119. oneshot_node_set_autorestart(id,node.get_valid("autorestart"));
  120. oneshot_node_set_autorestart_delay(id,node.get_valid("autorestart_delay"));
  121. oneshot_node_set_autorestart_random_delay(id,node.get_valid("autorestart_random_delay"));
  122. Array filters= node.get_valid("filter");
  123. for(int i=0;i<filters.size();i++) {
  124. oneshot_node_set_filter_path(id,filters[i],true);
  125. }
  126. } break;
  127. case NODE_MIX: {
  128. mix_node_set_amount(id,node.get_valid("mix"));
  129. } break;
  130. case NODE_BLEND2: {
  131. blend2_node_set_amount(id,node.get_valid("blend"));
  132. Array filters= node.get_valid("filter");
  133. for(int i=0;i<filters.size();i++) {
  134. blend2_node_set_filter_path(id,filters[i],true);
  135. }
  136. } break;
  137. case NODE_BLEND3: {
  138. blend3_node_set_amount(id,node.get_valid("blend"));
  139. } break;
  140. case NODE_BLEND4: {
  141. blend4_node_set_amount(id,node.get_valid("blend"));
  142. } break;
  143. case NODE_TIMESCALE: {
  144. timescale_node_set_scale(id,node.get_valid("scale"));
  145. } break;
  146. case NODE_TIMESEEK: {
  147. } break;
  148. case NODE_TRANSITION: {
  149. transition_node_set_xfade_time(id,node.get_valid("xfade"));
  150. Array transitions = node.get_valid("transitions");
  151. transition_node_set_input_count(id,transitions.size());
  152. for(int x=0;x<transitions.size();x++) {
  153. Dictionary d =transitions[x];
  154. bool aa = d.get_valid("auto_advance");
  155. transition_node_set_input_auto_advance(id,x,aa);
  156. }
  157. } break;
  158. default: {};
  159. }
  160. }
  161. Array connections = data.get_valid("connections");
  162. ERR_FAIL_COND_V(connections.size()%3,false);
  163. int cc=connections.size()/3;
  164. for(int i=0;i<cc;i++) {
  165. StringName src = connections[i*3+0];
  166. StringName dst = connections[i*3+1];
  167. int dst_in = connections[i*3+2];
  168. connect_nodes(src,dst,dst_in);
  169. }
  170. set_active(data.get_valid("active"));
  171. set_master_player(data.get_valid("master"));
  172. return true;
  173. }
  174. bool AnimationTreePlayer::_get(const StringName& p_name,Variant &r_ret) const {
  175. if (String(p_name)=="base_path") {
  176. r_ret=base_path;
  177. return true;
  178. }
  179. if (String(p_name)=="master_player") {
  180. r_ret=master;
  181. return true;
  182. }
  183. if (String(p_name) == "playback/active") {
  184. r_ret=is_active();
  185. return true;
  186. }
  187. if (String(p_name)!="data")
  188. return false;
  189. Dictionary data;
  190. Array nodes;
  191. for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
  192. NodeBase *n = node_map[E->key()];
  193. Dictionary node;
  194. node["id"]=E->key();
  195. node["pos"]=n->pos;
  196. switch(n->type) {
  197. case NODE_OUTPUT: node["type"]= "output"; break;
  198. case NODE_ANIMATION: node["type"]= "animation"; break;
  199. case NODE_ONESHOT: node["type"]= "oneshot"; break;
  200. case NODE_MIX: node["type"]= "mix"; break;
  201. case NODE_BLEND2: node["type"]= "blend2"; break;
  202. case NODE_BLEND3: node["type"]= "blend3"; break;
  203. case NODE_BLEND4: node["type"]= "blend4"; break;
  204. case NODE_TIMESCALE: node["type"]= "timescale"; break;
  205. case NODE_TIMESEEK: node["type"]= "timeseek"; break;
  206. case NODE_TRANSITION: node["type"]= "transition"; break;
  207. default: node["type"]= ""; break;
  208. }
  209. switch(n->type) {
  210. case NODE_OUTPUT: {
  211. } break;
  212. case NODE_ANIMATION: {
  213. AnimationNode *an = static_cast<AnimationNode*>(n);
  214. if (master!=NodePath() && an->from!="") {
  215. node["from"]=an->from;
  216. } else {
  217. node["animation"]=an->animation;
  218. }
  219. Array k;
  220. List<NodePath> keys;
  221. an->filter.get_key_list(&keys);
  222. k.resize(keys.size());
  223. int i=0;
  224. for(List<NodePath>::Element *E=keys.front();E;E=E->next()) {
  225. k[i++]=E->get();
  226. }
  227. node["filter"]=k;
  228. } break;
  229. case NODE_ONESHOT: {
  230. OneShotNode *osn = static_cast<OneShotNode*>(n);
  231. node["fade_in"]=osn->fade_in;
  232. node["fade_out"]=osn->fade_out;
  233. node["mix"]=osn->mix;
  234. node["autorestart"]=osn->autorestart;
  235. node["autorestart_delay"]=osn->autorestart_delay;
  236. node["autorestart_random_delay"]=osn->autorestart_random_delay;
  237. Array k;
  238. List<NodePath> keys;
  239. osn->filter.get_key_list(&keys);
  240. k.resize(keys.size());
  241. int i=0;
  242. for(List<NodePath>::Element *E=keys.front();E;E=E->next()) {
  243. k[i++]=E->get();
  244. }
  245. node["filter"]=k;
  246. } break;
  247. case NODE_MIX: {
  248. MixNode *mn = static_cast<MixNode*>(n);
  249. node["mix"]=mn->amount;
  250. } break;
  251. case NODE_BLEND2: {
  252. Blend2Node *bn = static_cast<Blend2Node*>(n);
  253. node["blend"]=bn->value;
  254. Array k;
  255. List<NodePath> keys;
  256. bn->filter.get_key_list(&keys);
  257. k.resize(keys.size());
  258. int i=0;
  259. for(List<NodePath>::Element *E=keys.front();E;E=E->next()) {
  260. k[i++]=E->get();
  261. }
  262. node["filter"]=k;
  263. } break;
  264. case NODE_BLEND3: {
  265. Blend3Node *bn = static_cast<Blend3Node*>(n);
  266. node["blend"]=bn->value;
  267. } break;
  268. case NODE_BLEND4: {
  269. Blend4Node *bn = static_cast<Blend4Node*>(n);
  270. node["blend"]=bn->value;
  271. } break;
  272. case NODE_TIMESCALE: {
  273. TimeScaleNode *tsn = static_cast<TimeScaleNode*>(n);
  274. node["scale"]=tsn->scale;
  275. } break;
  276. case NODE_TIMESEEK: {
  277. } break;
  278. case NODE_TRANSITION: {
  279. TransitionNode *tn = static_cast<TransitionNode*>(n);
  280. node["xfade"]=tn->xfade;
  281. Array transitions;
  282. for(int i=0;i<tn->input_data.size();i++) {
  283. Dictionary d;
  284. d["auto_advance"]=tn->input_data[i].auto_advance;
  285. transitions.push_back(d);
  286. }
  287. node["transitions"]=transitions;
  288. } break;
  289. default: {};
  290. }
  291. nodes.push_back(node);
  292. }
  293. data["nodes"]=nodes;
  294. //connectiosn
  295. List<Connection> connections;
  296. get_connection_list(&connections);
  297. Array connections_arr;
  298. connections_arr.resize(connections.size()*3);
  299. int idx=0;
  300. for (List<Connection>::Element *E=connections.front();E;E=E->next()) {
  301. connections_arr.set(idx+0,E->get().src_node);
  302. connections_arr.set(idx+1,E->get().dst_node);
  303. connections_arr.set(idx+2,E->get().dst_input);
  304. idx+=3;
  305. }
  306. data["connections"]=connections_arr;
  307. data["active"]=active;
  308. data["master"]=master;
  309. r_ret=data;
  310. return true;
  311. }
  312. void AnimationTreePlayer::_get_property_list( List<PropertyInfo> *p_list) const {
  313. p_list->push_back( PropertyInfo(Variant::NODE_PATH,"base_path" ) );
  314. p_list->push_back( PropertyInfo(Variant::NODE_PATH,"master_player" ) );
  315. p_list->push_back( PropertyInfo(Variant::DICTIONARY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_NETWORK) );
  316. }
  317. void AnimationTreePlayer::advance(float p_time) {
  318. _process_animation(p_time);
  319. }
  320. void AnimationTreePlayer::_notification(int p_what) {
  321. switch(p_what) {
  322. case NOTIFICATION_ENTER_TREE: {
  323. if (!processing) {
  324. //make sure that a previous process state was not saved
  325. //only process if "processing" is set
  326. set_fixed_process_internal(false);
  327. set_process_internal(false);
  328. }
  329. } break;
  330. case NOTIFICATION_READY: {
  331. dirty_caches=true;
  332. if (master!=NodePath()) {
  333. _update_sources();
  334. }
  335. } break;
  336. case NOTIFICATION_INTERNAL_PROCESS: {
  337. if (animation_process_mode==ANIMATION_PROCESS_FIXED)
  338. break;
  339. if (processing)
  340. _process_animation( get_process_delta_time() );
  341. } break;
  342. case NOTIFICATION_INTERNAL_FIXED_PROCESS: {
  343. if (animation_process_mode==ANIMATION_PROCESS_IDLE)
  344. break;
  345. if (processing)
  346. _process_animation(get_fixed_process_delta_time());
  347. } break;
  348. }
  349. }
  350. void AnimationTreePlayer::_compute_weights(float *p_fallback_weight, HashMap<NodePath,float> *p_weights, float p_coeff, const HashMap<NodePath,bool> *p_filter, float p_filtered_coeff) {
  351. if (p_filter != NULL) {
  352. List<NodePath> key_list;
  353. p_filter->get_key_list(&key_list);
  354. for (List<NodePath>::Element *E = key_list.front();E; E=E->next()) {
  355. if ((*p_filter)[E->get()]) {
  356. if (p_weights->has(E->get())) {
  357. (*p_weights)[E->get()] *= p_filtered_coeff;
  358. } else {
  359. p_weights->set(E->get(), *p_fallback_weight * p_filtered_coeff);
  360. }
  361. } else if (p_weights->has(E->get())) {
  362. (*p_weights)[E->get()] *= p_coeff;
  363. }
  364. }
  365. }
  366. List<NodePath> key_list;
  367. p_weights->get_key_list(&key_list);
  368. for (List<NodePath>::Element *E = key_list.front();E;E=E->next()) {
  369. if (p_filter == NULL || !p_filter->has(E->get())) {
  370. (*p_weights)[E->get()] *= p_coeff;
  371. }
  372. }
  373. *p_fallback_weight *= p_coeff;
  374. }
  375. float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode **r_prev_anim, float p_time, bool p_seek, float p_fallback_weight, HashMap<NodePath,float>* p_weights) {
  376. ERR_FAIL_COND_V(!node_map.has(p_node), 0);
  377. NodeBase *nb=node_map[p_node];
  378. //transform to seconds...
  379. switch(nb->type) {
  380. case NODE_OUTPUT: {
  381. NodeOut *on = static_cast<NodeOut*>(nb);
  382. HashMap<NodePath, float> weights;
  383. return _process_node(on->inputs[0].node,r_prev_anim,p_time,p_seek, p_fallback_weight, &weights);
  384. } break;
  385. case NODE_ANIMATION: {
  386. AnimationNode *an = static_cast<AnimationNode*>(nb);
  387. float rem = 0;
  388. if (!an->animation.is_null()) {
  389. //float pos = an->time;
  390. //float delta = p_time;
  391. //const Animation *a = an->animation.operator->();
  392. if (p_seek) {
  393. an->time=p_time;
  394. an->step=0;
  395. } else {
  396. an->time=MAX(0,an->time+p_time);
  397. an->step=p_time;
  398. }
  399. float anim_size = an->animation->get_length();
  400. if (an->animation->has_loop()) {
  401. if (anim_size)
  402. an->time=Math::fposmod(an->time,anim_size);
  403. } else if (an->time > anim_size) {
  404. an->time=anim_size;
  405. }
  406. an->skip=true;
  407. for (List<AnimationNode::TrackRef>::Element *E=an->tref.front();E;E=E->next()) {
  408. NodePath track_path = an->animation->track_get_path(E->get().local_track);
  409. if (an->filter.has(track_path) && an->filter[track_path]) {
  410. E->get().weight = 0;
  411. } else {
  412. if (p_weights->has(track_path)) {
  413. float weight = (*p_weights)[track_path];
  414. E->get().weight = weight;
  415. } else {
  416. E->get().weight = p_fallback_weight;
  417. }
  418. }
  419. if (E->get().weight>CMP_EPSILON)
  420. an->skip=false;
  421. }
  422. rem = anim_size - an->time;
  423. }
  424. if (!(*r_prev_anim))
  425. active_list=an;
  426. else
  427. (*r_prev_anim)->next=an;
  428. an->next=NULL;
  429. *r_prev_anim=an;
  430. return rem;
  431. } break;
  432. case NODE_ONESHOT: {
  433. OneShotNode *osn = static_cast<OneShotNode*>(nb);
  434. if (!osn->active) {
  435. //make it as if this node doesn't exist, pass input 0 by.
  436. return _process_node(osn->inputs[0].node,r_prev_anim,p_time,p_seek, p_fallback_weight, p_weights);
  437. }
  438. float os_seek = p_seek;
  439. if (p_seek)
  440. osn->time=p_time;
  441. if (osn->start) {
  442. osn->time=0;
  443. os_seek = true;
  444. }
  445. float blend;
  446. if (osn->time<osn->fade_in) {
  447. if (osn->fade_in>0)
  448. blend = osn->time/osn->fade_in;
  449. else
  450. blend=0; //wtf
  451. } else if (!osn->start && osn->remaining<osn->fade_out) {
  452. if (osn->fade_out)
  453. blend=(osn->remaining/osn->fade_out);
  454. else
  455. blend=1.0;
  456. } else
  457. blend=1.0;
  458. float main_rem;
  459. float os_rem;
  460. HashMap<NodePath, float> os_weights(*p_weights);
  461. float os_fallback_weight = p_fallback_weight;
  462. _compute_weights(&p_fallback_weight, p_weights, osn->mix?1.0 : 1.0 - blend, &osn->filter, 1.0);
  463. _compute_weights(&os_fallback_weight, &os_weights, blend, &osn->filter, 0.0);
  464. main_rem = _process_node(osn->inputs[0].node,r_prev_anim,p_time,p_seek, p_fallback_weight, p_weights);
  465. os_rem = _process_node(osn->inputs[1].node,r_prev_anim,p_time,os_seek, os_fallback_weight, &os_weights);
  466. if (osn->start) {
  467. osn->remaining=os_rem;
  468. osn->start=false;
  469. }
  470. if (!p_seek) {
  471. osn->time+=p_time;
  472. osn->remaining=os_rem;
  473. if (osn->remaining<=0)
  474. osn->active=false;
  475. }
  476. return MAX(main_rem,osn->remaining);
  477. } break;
  478. case NODE_MIX: {
  479. MixNode *mn = static_cast<MixNode*>(nb);
  480. HashMap<NodePath, float> mn_weights(*p_weights);
  481. float mn_fallback_weight = p_fallback_weight;
  482. _compute_weights(&mn_fallback_weight, &mn_weights, mn->amount);
  483. float rem = _process_node(mn->inputs[0].node,r_prev_anim, p_time,p_seek,p_fallback_weight,p_weights);
  484. _process_node(mn->inputs[1].node,r_prev_anim,p_time,p_seek,mn_fallback_weight,&mn_weights);
  485. return rem;
  486. } break;
  487. case NODE_BLEND2: {
  488. Blend2Node *bn = static_cast<Blend2Node*>(nb);
  489. HashMap<NodePath, float> bn_weights(*p_weights);
  490. float bn_fallback_weight = p_fallback_weight;
  491. _compute_weights(&p_fallback_weight,p_weights, 1.0 - bn->value, &bn->filter, 1.0);
  492. _compute_weights(&bn_fallback_weight,&bn_weights, bn->value, &bn->filter, 0.0);
  493. float rem = _process_node(bn->inputs[0].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
  494. _process_node(bn->inputs[1].node,r_prev_anim,p_time,p_seek,bn_fallback_weight,&bn_weights);
  495. return rem;
  496. } break;
  497. case NODE_BLEND3: {
  498. Blend3Node *bn = static_cast<Blend3Node*>(nb);
  499. float rem;
  500. float blend, lower_blend, upper_blend;
  501. if (bn->value < 0) {
  502. lower_blend = -bn->value;
  503. blend = 1.0 - lower_blend;
  504. upper_blend = 0;
  505. } else {
  506. lower_blend = 0;
  507. blend = 1.0 - bn->value;
  508. upper_blend = bn->value;
  509. }
  510. HashMap<NodePath, float> upper_weights(*p_weights);
  511. float upper_fallback_weight = p_fallback_weight;
  512. HashMap<NodePath, float> lower_weights(*p_weights);
  513. float lower_fallback_weight = p_fallback_weight;
  514. _compute_weights(&upper_fallback_weight,&upper_weights, upper_blend);
  515. _compute_weights(&p_fallback_weight,p_weights, blend);
  516. _compute_weights(&lower_fallback_weight,&lower_weights, lower_blend);
  517. rem = _process_node(bn->inputs[1].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
  518. _process_node(bn->inputs[0].node,r_prev_anim,p_time,p_seek,lower_fallback_weight,&lower_weights);
  519. _process_node(bn->inputs[2].node,r_prev_anim,p_time,p_seek,upper_fallback_weight,&upper_weights);
  520. return rem;
  521. } break;
  522. case NODE_BLEND4: {
  523. Blend4Node *bn = static_cast<Blend4Node*>(nb);
  524. HashMap<NodePath, float> weights1(*p_weights);
  525. float fallback_weight1 = p_fallback_weight;
  526. HashMap<NodePath, float> weights2(*p_weights);
  527. float fallback_weight2 = p_fallback_weight;
  528. HashMap<NodePath, float> weights3(*p_weights);
  529. float fallback_weight3 = p_fallback_weight;
  530. _compute_weights(&p_fallback_weight,p_weights, 1.0-bn->value.x);
  531. _compute_weights(&fallback_weight1,&weights1, bn->value.x);
  532. _compute_weights(&fallback_weight2,&weights2, 1.0-bn->value.y);
  533. _compute_weights(&fallback_weight3,&weights3, bn->value.y);
  534. float rem = _process_node(bn->inputs[0].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
  535. _process_node(bn->inputs[1].node,r_prev_anim,p_time,p_seek,fallback_weight1,&weights1);
  536. float rem2 = _process_node(bn->inputs[2].node,r_prev_anim,p_time,p_seek,fallback_weight2,&weights2);
  537. _process_node(bn->inputs[3].node,r_prev_anim,p_time,p_seek,fallback_weight3,&weights3);
  538. return MAX(rem,rem2);
  539. } break;
  540. case NODE_TIMESCALE: {
  541. TimeScaleNode *tsn = static_cast<TimeScaleNode*>(nb);
  542. float rem;
  543. if (p_seek)
  544. rem = _process_node(tsn->inputs[0].node,r_prev_anim,p_time,true,p_fallback_weight,p_weights);
  545. else
  546. rem = _process_node(tsn->inputs[0].node,r_prev_anim,p_time*tsn->scale,false,p_fallback_weight,p_weights);
  547. if (tsn->scale == 0)
  548. return INFINITY;
  549. else
  550. return rem / tsn->scale;
  551. } break;
  552. case NODE_TIMESEEK: {
  553. TimeSeekNode *tsn = static_cast<TimeSeekNode*>(nb);
  554. if (tsn->seek_pos>=0 && !p_seek) {
  555. p_time = tsn->seek_pos;
  556. p_seek = true;
  557. }
  558. tsn->seek_pos=-1;
  559. return _process_node(tsn->inputs[0].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
  560. } break;
  561. case NODE_TRANSITION: {
  562. TransitionNode *tn = static_cast<TransitionNode*>(nb);
  563. HashMap<NodePath, float> prev_weights(*p_weights);
  564. float prev_fallback_weight = p_fallback_weight;
  565. if (tn->prev<0) { // process current animation, check for transition
  566. float rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
  567. if (p_seek)
  568. tn->time=p_time;
  569. else
  570. tn->time+=p_time;
  571. if (tn->input_data[tn->current].auto_advance && rem <= tn->xfade) {
  572. tn->set_current((tn->current+1) % tn->inputs.size());
  573. }
  574. return rem;
  575. } else { // cross-fading from tn->prev to tn->current
  576. float blend = tn->xfade? (tn->prev_xfading/tn->xfade) : 1;
  577. float rem;
  578. _compute_weights(&p_fallback_weight,p_weights, 1.0-blend);
  579. _compute_weights(&prev_fallback_weight,&prev_weights, blend);
  580. if (!p_seek && tn->switched) { //just switched, seek to start of current
  581. rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,0,true,p_fallback_weight,p_weights);
  582. } else {
  583. rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
  584. }
  585. tn->switched=false;
  586. if (p_seek) { // don't seek prev animation
  587. _process_node(tn->inputs[tn->prev].node,r_prev_anim,0,false,prev_fallback_weight,&prev_weights);
  588. tn->time=p_time;
  589. } else {
  590. _process_node(tn->inputs[tn->prev].node,r_prev_anim,p_time,false,prev_fallback_weight,&prev_weights);
  591. tn->time+=p_time;
  592. tn->prev_xfading-=p_time;
  593. if (tn->prev_xfading<0) {
  594. tn->prev=-1;
  595. }
  596. }
  597. return rem;
  598. }
  599. } break;
  600. default: {}
  601. }
  602. return 0;
  603. }
  604. void AnimationTreePlayer::_process_animation(float p_delta) {
  605. if (last_error!=CONNECT_OK)
  606. return;
  607. if (dirty_caches)
  608. _recompute_caches();
  609. active_list=NULL;
  610. AnimationNode *prev=NULL;
  611. if (reset_request) {
  612. _process_node(out_name,&prev, 0, true);
  613. reset_request=false;
  614. } else
  615. _process_node(out_name,&prev, p_delta);
  616. if (dirty_caches) {
  617. //some animation changed.. ignore this pass
  618. return;
  619. }
  620. //update the tracks..
  621. /* STEP 1 CLEAR TRACKS */
  622. for(TrackMap::Element *E=track_map.front();E;E=E->next()) {
  623. Track &t = E->get();
  624. t.loc.zero();
  625. t.rot=Quat();
  626. t.scale.x=0;
  627. t.scale.y=0;
  628. t.scale.z=0;
  629. t.value = t.object->get(t.property);
  630. t.value.zero();
  631. t.skip = false;
  632. }
  633. /* STEP 2 PROCESS ANIMATIONS */
  634. AnimationNode *anim_list=active_list;
  635. Quat empty_rot;
  636. while(anim_list) {
  637. if (!anim_list->animation.is_null() && !anim_list->skip) {
  638. //check if animation is meaningful
  639. Animation *a = anim_list->animation.operator->();
  640. for(List<AnimationNode::TrackRef>::Element *E=anim_list->tref.front();E;E=E->next()) {
  641. AnimationNode::TrackRef &tr = E->get();
  642. if (tr.track==NULL || tr.local_track<0 || tr.weight < CMP_EPSILON)
  643. continue;
  644. switch(a->track_get_type(tr.local_track)) {
  645. case Animation::TYPE_TRANSFORM: { ///< Transform a node or a bone.
  646. Vector3 loc;
  647. Quat rot;
  648. Vector3 scale;
  649. a->transform_track_interpolate(tr.local_track,anim_list->time,&loc,&rot,&scale);
  650. tr.track->loc+=loc*tr.weight;
  651. scale.x-=1.0;
  652. scale.y-=1.0;
  653. scale.z-=1.0;
  654. tr.track->scale+=scale*tr.weight;
  655. tr.track->rot = tr.track->rot * empty_rot.slerp(rot,tr.weight);
  656. } break;
  657. case Animation::TYPE_VALUE: { ///< Set a value in a property, can be interpolated.
  658. if (a->value_track_get_update_mode(tr.local_track)==Animation::UPDATE_CONTINUOUS) {
  659. Variant value = a->value_track_interpolate(tr.local_track,anim_list->time);
  660. Variant::blend(tr.track->value,value,tr.weight,tr.track->value);
  661. } else {
  662. int index = a->track_find_key(tr.local_track,anim_list->time);
  663. tr.track->value = a->track_get_key_value(tr.local_track, index);
  664. }
  665. } break;
  666. case Animation::TYPE_METHOD: { ///< Call any method on a specific node.
  667. List<int> indices;
  668. a->method_track_get_key_indices(tr.local_track,anim_list->time,anim_list->step,&indices);
  669. for(List<int>::Element *E=indices.front();E;E=E->next()) {
  670. StringName method = a->method_track_get_name(tr.local_track,E->get());
  671. Vector<Variant> args=a->method_track_get_params(tr.local_track,E->get());
  672. args.resize(VARIANT_ARG_MAX);
  673. tr.track->object->call(method,args[0],args[1],args[2],args[3],args[4]);
  674. }
  675. } break;
  676. }
  677. }
  678. }
  679. anim_list=anim_list->next;
  680. }
  681. /* STEP 3 APPLY TRACKS */
  682. for(TrackMap::Element *E=track_map.front();E;E=E->next()) {
  683. Track &t = E->get();
  684. if (t.skip || !t.object)
  685. continue;
  686. if(t.property) { // value track
  687. t.object->set(t.property,t.value);
  688. continue;
  689. }
  690. Transform xform;
  691. xform.basis=t.rot;
  692. xform.origin=t.loc;
  693. t.scale.x+=1.0;
  694. t.scale.y+=1.0;
  695. t.scale.z+=1.0;
  696. xform.basis.scale(t.scale);
  697. if (t.bone_idx>=0) {
  698. if (t.skeleton)
  699. t.skeleton->set_bone_pose(t.bone_idx,xform);
  700. } else if (t.spatial) {
  701. t.spatial->set_transform(xform);
  702. }
  703. }
  704. }
  705. void AnimationTreePlayer::add_node(NodeType p_type, const StringName& p_node) {
  706. ERR_FAIL_COND( p_type == NODE_OUTPUT );
  707. ERR_FAIL_COND( node_map.has(p_node));
  708. NodeBase *n=NULL;
  709. switch(p_type) {
  710. case NODE_ANIMATION: {
  711. n = memnew( AnimationNode );
  712. } break;
  713. case NODE_ONESHOT: {
  714. n = memnew( OneShotNode );
  715. } break;
  716. case NODE_MIX: {
  717. n = memnew( MixNode );
  718. } break;
  719. case NODE_BLEND2: {
  720. n = memnew( Blend2Node );
  721. } break;
  722. case NODE_BLEND3: {
  723. n = memnew( Blend3Node );
  724. } break;
  725. case NODE_BLEND4: {
  726. n = memnew( Blend4Node );
  727. } break;
  728. case NODE_TIMESCALE: {
  729. n = memnew( TimeScaleNode );
  730. } break;
  731. case NODE_TIMESEEK: {
  732. n = memnew( TimeSeekNode );
  733. } break;
  734. case NODE_TRANSITION: {
  735. n = memnew( TransitionNode );
  736. } break;
  737. default: {}
  738. }
  739. //n->name+=" "+itos(p_node);
  740. node_map[p_node]=n;
  741. }
  742. StringName AnimationTreePlayer::node_get_input_source(const StringName& p_node,int p_input) const {
  743. ERR_FAIL_COND_V(!node_map.has(p_node),StringName());
  744. ERR_FAIL_INDEX_V( p_input,node_map[p_node]->inputs.size(),StringName() );
  745. return node_map[p_node]->inputs[p_input].node;
  746. }
  747. int AnimationTreePlayer::node_get_input_count(const StringName& p_node) const {
  748. ERR_FAIL_COND_V(!node_map.has(p_node),-1);
  749. return node_map[p_node]->inputs.size();
  750. }
  751. #define GET_NODE( m_type, m_cast )\
  752. ERR_FAIL_COND(!node_map.has(p_node));\
  753. ERR_EXPLAIN("Invalid parameter for node type.");\
  754. ERR_FAIL_COND(node_map[p_node]->type!=m_type);\
  755. m_cast *n = static_cast<m_cast*>( node_map[p_node] );\
  756. void AnimationTreePlayer::animation_node_set_animation(const StringName& p_node,const Ref<Animation>& p_animation) {
  757. GET_NODE( NODE_ANIMATION, AnimationNode );
  758. n->animation=p_animation;
  759. dirty_caches=true;
  760. }
  761. void AnimationTreePlayer::animation_node_set_master_animation(const StringName& p_node,const String& p_master_animation) {
  762. GET_NODE( NODE_ANIMATION, AnimationNode );
  763. n->from=p_master_animation;
  764. dirty_caches=true;
  765. if (master!=NodePath())
  766. _update_sources();
  767. }
  768. void AnimationTreePlayer::animation_node_set_filter_path(const StringName& p_node,const NodePath& p_track_path,bool p_filter) {
  769. GET_NODE( NODE_ANIMATION, AnimationNode );
  770. if (p_filter)
  771. n->filter[p_track_path]=true;
  772. else
  773. n->filter.erase(p_track_path);
  774. }
  775. void AnimationTreePlayer::animation_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const{
  776. GET_NODE( NODE_ANIMATION, AnimationNode );
  777. n->filter.get_key_list(r_paths);
  778. }
  779. void AnimationTreePlayer::oneshot_node_set_fadein_time(const StringName& p_node,float p_time) {
  780. GET_NODE( NODE_ONESHOT, OneShotNode );
  781. n->fade_in=p_time;
  782. }
  783. void AnimationTreePlayer::oneshot_node_set_fadeout_time(const StringName& p_node,float p_time) {
  784. GET_NODE( NODE_ONESHOT, OneShotNode );
  785. n->fade_out=p_time;
  786. }
  787. void AnimationTreePlayer::oneshot_node_set_mix_mode(const StringName& p_node,bool p_mix) {
  788. GET_NODE( NODE_ONESHOT, OneShotNode );
  789. n->mix=p_mix;
  790. }
  791. void AnimationTreePlayer::oneshot_node_set_autorestart(const StringName& p_node,bool p_active) {
  792. GET_NODE( NODE_ONESHOT, OneShotNode );
  793. n->autorestart=p_active;
  794. }
  795. void AnimationTreePlayer::oneshot_node_set_autorestart_delay(const StringName& p_node,float p_time) {
  796. GET_NODE( NODE_ONESHOT, OneShotNode );
  797. n->autorestart_delay=p_time;
  798. }
  799. void AnimationTreePlayer::oneshot_node_set_autorestart_random_delay(const StringName& p_node,float p_time) {
  800. GET_NODE( NODE_ONESHOT, OneShotNode );
  801. n->autorestart_random_delay=p_time;
  802. }
  803. void AnimationTreePlayer::oneshot_node_start(const StringName& p_node) {
  804. GET_NODE( NODE_ONESHOT, OneShotNode );
  805. n->active=true;
  806. n->start=true;
  807. }
  808. void AnimationTreePlayer::oneshot_node_stop(const StringName& p_node) {
  809. GET_NODE( NODE_ONESHOT, OneShotNode );
  810. n->active=false;
  811. }
  812. void AnimationTreePlayer::oneshot_node_set_filter_path(const StringName& p_node,const NodePath& p_filter,bool p_enable) {
  813. GET_NODE( NODE_ONESHOT, OneShotNode );
  814. if (p_enable)
  815. n->filter[p_filter]=true;
  816. else
  817. n->filter.erase(p_filter);
  818. }
  819. void AnimationTreePlayer::oneshot_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const{
  820. GET_NODE( NODE_ONESHOT, OneShotNode );
  821. n->filter.get_key_list(r_paths);
  822. }
  823. void AnimationTreePlayer::mix_node_set_amount(const StringName& p_node,float p_amount) {
  824. GET_NODE( NODE_MIX, MixNode );
  825. n->amount=p_amount;
  826. }
  827. void AnimationTreePlayer::blend2_node_set_amount(const StringName& p_node,float p_amount) {
  828. GET_NODE( NODE_BLEND2, Blend2Node );
  829. n->value=p_amount;
  830. }
  831. void AnimationTreePlayer::blend2_node_set_filter_path(const StringName& p_node,const NodePath& p_filter,bool p_enable) {
  832. GET_NODE( NODE_BLEND2, Blend2Node );
  833. if (p_enable)
  834. n->filter[p_filter]=true;
  835. else
  836. n->filter.erase(p_filter);
  837. }
  838. void AnimationTreePlayer::blend2_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const{
  839. GET_NODE( NODE_BLEND2, Blend2Node );
  840. n->filter.get_key_list(r_paths);
  841. }
  842. void AnimationTreePlayer::blend3_node_set_amount(const StringName& p_node,float p_amount) {
  843. GET_NODE( NODE_BLEND3, Blend3Node );
  844. n->value=p_amount;
  845. }
  846. void AnimationTreePlayer::blend4_node_set_amount(const StringName& p_node,const Vector2& p_amount) {
  847. GET_NODE( NODE_BLEND4, Blend4Node );
  848. n->value=p_amount;
  849. }
  850. void AnimationTreePlayer::timescale_node_set_scale(const StringName& p_node,float p_scale) {
  851. GET_NODE( NODE_TIMESCALE, TimeScaleNode );
  852. n->scale=p_scale;
  853. }
  854. void AnimationTreePlayer::timeseek_node_seek(const StringName& p_node,float p_pos) {
  855. GET_NODE( NODE_TIMESEEK, TimeSeekNode );
  856. n->seek_pos=p_pos;
  857. }
  858. void AnimationTreePlayer::transition_node_set_input_count(const StringName& p_node, int p_inputs) {
  859. GET_NODE( NODE_TRANSITION, TransitionNode );
  860. ERR_FAIL_COND(p_inputs<1);
  861. n->inputs.resize(p_inputs);
  862. n->input_data.resize(p_inputs);
  863. last_error=_cycle_test(out_name);
  864. }
  865. void AnimationTreePlayer::transition_node_set_input_auto_advance(const StringName& p_node, int p_input,bool p_auto_advance) {
  866. GET_NODE( NODE_TRANSITION, TransitionNode );
  867. ERR_FAIL_INDEX(p_input,n->input_data.size());
  868. n->input_data[p_input].auto_advance=p_auto_advance;
  869. }
  870. void AnimationTreePlayer::transition_node_set_xfade_time(const StringName& p_node, float p_time) {
  871. GET_NODE( NODE_TRANSITION, TransitionNode );
  872. n->xfade=p_time;
  873. }
  874. void AnimationTreePlayer::TransitionNode::set_current(int p_current) {
  875. ERR_FAIL_INDEX(p_current,inputs.size());
  876. if (current==p_current)
  877. return;
  878. prev=current;
  879. prev_xfading=xfade;
  880. prev_time=time;
  881. time=0;
  882. current=p_current;
  883. switched=true;
  884. }
  885. void AnimationTreePlayer::transition_node_set_current(const StringName& p_node, int p_current) {
  886. GET_NODE( NODE_TRANSITION, TransitionNode );
  887. n->set_current(p_current);
  888. }
  889. void AnimationTreePlayer::node_set_pos(const StringName& p_node, const Vector2& p_pos) {
  890. ERR_FAIL_COND(!node_map.has(p_node));
  891. node_map[p_node]->pos=p_pos;
  892. }
  893. AnimationTreePlayer::NodeType AnimationTreePlayer::node_get_type(const StringName& p_node) const {
  894. ERR_FAIL_COND_V(!node_map.has(p_node),NODE_OUTPUT);
  895. return node_map[p_node]->type;
  896. }
  897. Point2 AnimationTreePlayer::node_get_pos(const StringName& p_node) const {
  898. ERR_FAIL_COND_V(!node_map.has(p_node),Point2());
  899. return node_map[p_node]->pos;
  900. }
  901. #define GET_NODE_V( m_type, m_cast, m_ret )\
  902. ERR_FAIL_COND_V(!node_map.has(p_node),m_ret);\
  903. ERR_EXPLAIN("Invalid parameter for node type.");\
  904. ERR_FAIL_COND_V(node_map[p_node]->type!=m_type,m_ret);\
  905. m_cast *n = static_cast<m_cast*>( node_map[p_node] );\
  906. Ref<Animation> AnimationTreePlayer::animation_node_get_animation(const StringName& p_node) const {
  907. GET_NODE_V(NODE_ANIMATION, AnimationNode, Ref<Animation>());
  908. return n->animation;
  909. }
  910. String AnimationTreePlayer::animation_node_get_master_animation(const StringName& p_node) const {
  911. GET_NODE_V(NODE_ANIMATION, AnimationNode, String());
  912. return n->from;
  913. }
  914. bool AnimationTreePlayer::animation_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const {
  915. GET_NODE_V(NODE_ANIMATION, AnimationNode, 0 );
  916. return n->filter.has(p_path);
  917. }
  918. float AnimationTreePlayer::oneshot_node_get_fadein_time(const StringName& p_node) const {
  919. GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
  920. return n->fade_in;
  921. }
  922. float AnimationTreePlayer::oneshot_node_get_fadeout_time(const StringName& p_node) const {
  923. GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
  924. return n->fade_out;
  925. }
  926. bool AnimationTreePlayer::oneshot_node_get_mix_mode(const StringName& p_node) const {
  927. GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
  928. return n->mix;
  929. }
  930. bool AnimationTreePlayer::oneshot_node_has_autorestart(const StringName& p_node) const {
  931. GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
  932. return n->autorestart;
  933. }
  934. float AnimationTreePlayer::oneshot_node_get_autorestart_delay(const StringName& p_node) const {
  935. GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
  936. return n->autorestart_delay;
  937. }
  938. float AnimationTreePlayer::oneshot_node_get_autorestart_random_delay(const StringName& p_node) const {
  939. GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
  940. return n->autorestart_random_delay;
  941. }
  942. bool AnimationTreePlayer::oneshot_node_is_active(const StringName& p_node) const {
  943. GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
  944. return n->active;
  945. }
  946. bool AnimationTreePlayer::oneshot_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const {
  947. GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
  948. return n->filter.has(p_path);
  949. }
  950. float AnimationTreePlayer::mix_node_get_amount(const StringName& p_node) const {
  951. GET_NODE_V(NODE_MIX, MixNode, 0 );
  952. return n->amount;
  953. }
  954. float AnimationTreePlayer::blend2_node_get_amount(const StringName& p_node) const {
  955. GET_NODE_V(NODE_BLEND2, Blend2Node, 0 );
  956. return n->value;
  957. }
  958. bool AnimationTreePlayer::blend2_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const {
  959. GET_NODE_V(NODE_BLEND2, Blend2Node, 0 );
  960. return n->filter.has(p_path);
  961. }
  962. float AnimationTreePlayer::blend3_node_get_amount(const StringName& p_node) const {
  963. GET_NODE_V(NODE_BLEND3, Blend3Node, 0 );
  964. return n->value;
  965. }
  966. Vector2 AnimationTreePlayer::blend4_node_get_amount(const StringName& p_node) const {
  967. GET_NODE_V(NODE_BLEND4, Blend4Node, Vector2() );
  968. return n->value;
  969. }
  970. float AnimationTreePlayer::timescale_node_get_scale(const StringName& p_node) const {
  971. GET_NODE_V(NODE_TIMESCALE, TimeScaleNode, 0 );
  972. return n->scale;
  973. }
  974. void AnimationTreePlayer::transition_node_delete_input(const StringName& p_node, int p_input) {
  975. GET_NODE(NODE_TRANSITION, TransitionNode);
  976. ERR_FAIL_INDEX(p_input,n->inputs.size());
  977. if (n->inputs.size()<=1)
  978. return;
  979. n->inputs.remove(p_input);
  980. n->input_data.remove(p_input);
  981. last_error=_cycle_test(out_name);
  982. }
  983. int AnimationTreePlayer::transition_node_get_input_count(const StringName& p_node) const {
  984. GET_NODE_V(NODE_TRANSITION, TransitionNode, 0 );
  985. return n->inputs.size();
  986. }
  987. bool AnimationTreePlayer::transition_node_has_input_auto_advance(const StringName& p_node, int p_input) const {
  988. GET_NODE_V(NODE_TRANSITION, TransitionNode, false );
  989. ERR_FAIL_INDEX_V(p_input,n->inputs.size(),false);
  990. return n->input_data[p_input].auto_advance;
  991. }
  992. float AnimationTreePlayer::transition_node_get_xfade_time(const StringName& p_node) const {
  993. GET_NODE_V(NODE_TRANSITION, TransitionNode, 0 );
  994. return n->xfade;
  995. }
  996. int AnimationTreePlayer::transition_node_get_current(const StringName& p_node) const {
  997. GET_NODE_V(NODE_TRANSITION, TransitionNode, -1 );
  998. return n->current;
  999. }
  1000. /*misc */
  1001. void AnimationTreePlayer::get_node_list(List<StringName> *p_node_list) const {
  1002. for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
  1003. p_node_list->push_back( E->key() );
  1004. }
  1005. }
  1006. void AnimationTreePlayer::remove_node(const StringName& p_node) {
  1007. ERR_FAIL_COND( !node_map.has(p_node) );
  1008. ERR_EXPLAIN("Node 0 (output) can't be removed.");
  1009. ERR_FAIL_COND( p_node == out_name );
  1010. for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
  1011. NodeBase *nb = E->get();
  1012. for(int i=0;i<nb->inputs.size();i++) {
  1013. if (nb->inputs[i].node==p_node)
  1014. nb->inputs[i].node=StringName();
  1015. }
  1016. }
  1017. node_map.erase(p_node);
  1018. // compute last error again, just in case
  1019. last_error=_cycle_test(out_name);
  1020. dirty_caches=true;
  1021. }
  1022. AnimationTreePlayer::ConnectError AnimationTreePlayer::_cycle_test(const StringName& p_at_node) {
  1023. ERR_FAIL_COND_V(!node_map.has(p_at_node), CONNECT_INCOMPLETE);
  1024. NodeBase *nb = node_map[p_at_node];
  1025. if (nb->cycletest)
  1026. return CONNECT_CYCLE;
  1027. nb->cycletest=true;
  1028. for(int i=0;i<nb->inputs.size();i++) {
  1029. if (nb->inputs[i].node==StringName())
  1030. return CONNECT_INCOMPLETE;
  1031. ConnectError _err = _cycle_test(nb->inputs[i].node);
  1032. if (_err)
  1033. return _err;
  1034. }
  1035. return CONNECT_OK;
  1036. }
  1037. Error AnimationTreePlayer::connect_nodes(const StringName& p_src_node,const StringName& p_dst_node, int p_dst_input) {
  1038. ERR_FAIL_COND_V( !node_map.has(p_src_node) , ERR_INVALID_PARAMETER);
  1039. ERR_FAIL_COND_V( !node_map.has(p_dst_node) , ERR_INVALID_PARAMETER);
  1040. ERR_FAIL_COND_V( p_src_node==p_dst_node , ERR_INVALID_PARAMETER);
  1041. //NodeBase *src = node_map[p_src_node];
  1042. NodeBase *dst = node_map[p_dst_node];
  1043. ERR_FAIL_INDEX_V( p_dst_input, dst->inputs.size(), ERR_INVALID_PARAMETER);
  1044. //int oldval = dst->inputs[p_dst_input].node;
  1045. for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
  1046. NodeBase *nb = E->get();
  1047. for(int i=0;i<nb->inputs.size();i++) {
  1048. if (nb->inputs[i].node==p_src_node)
  1049. nb->inputs[i].node=StringName();
  1050. }
  1051. }
  1052. dst->inputs[p_dst_input].node=p_src_node;
  1053. for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
  1054. NodeBase *nb = E->get();
  1055. nb->cycletest=false;
  1056. }
  1057. last_error=_cycle_test(out_name);
  1058. if (last_error) {
  1059. if (last_error==CONNECT_INCOMPLETE)
  1060. return ERR_UNCONFIGURED;
  1061. else if (last_error==CONNECT_CYCLE)
  1062. return ERR_CYCLIC_LINK;
  1063. }
  1064. dirty_caches=true;
  1065. return OK;
  1066. }
  1067. bool AnimationTreePlayer::are_nodes_connected(const StringName& p_src_node,const StringName& p_dst_node, int p_dst_input) const {
  1068. ERR_FAIL_COND_V( !node_map.has(p_src_node) , false);
  1069. ERR_FAIL_COND_V( !node_map.has(p_dst_node) , false);
  1070. ERR_FAIL_COND_V( p_src_node==p_dst_node , false);
  1071. NodeBase *dst = node_map[p_dst_node];
  1072. return dst->inputs[p_dst_input].node==p_src_node;
  1073. }
  1074. void AnimationTreePlayer::disconnect_nodes(const StringName& p_node, int p_input) {
  1075. ERR_FAIL_COND( !node_map.has(p_node));
  1076. NodeBase *dst = node_map[p_node];
  1077. ERR_FAIL_INDEX(p_input,dst->inputs.size());
  1078. dst->inputs[p_input].node=StringName();
  1079. last_error=CONNECT_INCOMPLETE;
  1080. dirty_caches=true;
  1081. }
  1082. void AnimationTreePlayer::get_connection_list( List<Connection> *p_connections) const {
  1083. for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
  1084. NodeBase *nb = E->get();
  1085. for(int i=0;i<nb->inputs.size();i++) {
  1086. if (nb->inputs[i].node!=StringName()) {
  1087. Connection c;
  1088. c.src_node=nb->inputs[i].node;
  1089. c.dst_node=E->key();
  1090. c.dst_input=i;
  1091. p_connections->push_back(c);
  1092. }
  1093. }
  1094. }
  1095. }
  1096. AnimationTreePlayer::Track* AnimationTreePlayer::_find_track(const NodePath& p_path) {
  1097. Node *parent=get_node(base_path);
  1098. ERR_FAIL_COND_V(!parent,NULL);
  1099. RES resource;
  1100. Node *child=parent->get_node_and_resource(p_path,resource);
  1101. if (!child) {
  1102. String err = "Animation track references unknown Node: '"+String(p_path)+"'.";
  1103. WARN_PRINT(err.ascii().get_data());
  1104. return NULL;
  1105. }
  1106. ObjectID id=child->get_instance_ID();
  1107. StringName property;
  1108. int bone_idx=-1;
  1109. if (p_path.get_property()) {
  1110. if (child->cast_to<Skeleton>())
  1111. bone_idx = child->cast_to<Skeleton>()->find_bone( p_path.get_property() );
  1112. if (bone_idx==-1)
  1113. property=p_path.get_property();
  1114. }
  1115. TrackKey key;
  1116. key.id=id;
  1117. key.bone_idx=bone_idx;
  1118. key.property=property;
  1119. if (!track_map.has(key)) {
  1120. Track tr;
  1121. tr.id=id;
  1122. tr.object=resource.is_valid()?(Object*)resource.ptr():(Object*)child;
  1123. tr.skeleton=child->cast_to<Skeleton>();
  1124. tr.spatial=child->cast_to<Spatial>();
  1125. tr.bone_idx=bone_idx;
  1126. tr.property=property;
  1127. track_map[key]=tr;
  1128. }
  1129. return &track_map[key];
  1130. }
  1131. void AnimationTreePlayer::_recompute_caches() {
  1132. track_map.clear();
  1133. _recompute_caches(out_name);
  1134. dirty_caches=false;
  1135. }
  1136. void AnimationTreePlayer::_recompute_caches(const StringName& p_node) {
  1137. ERR_FAIL_COND( !node_map.has(p_node) );
  1138. NodeBase *nb = node_map[p_node];
  1139. if (nb->type==NODE_ANIMATION) {
  1140. AnimationNode *an = static_cast<AnimationNode*>(nb);
  1141. an->tref.clear();;
  1142. if (!an->animation.is_null()) {
  1143. Ref<Animation> a = an->animation;
  1144. for(int i=0;i<an->animation->get_track_count();i++) {
  1145. Track *tr = _find_track(a->track_get_path(i));
  1146. if (!tr)
  1147. continue;
  1148. AnimationNode::TrackRef tref;
  1149. tref.local_track=i;
  1150. tref.track=tr;
  1151. tref.weight=0;
  1152. an->tref.push_back(tref);
  1153. }
  1154. }
  1155. }
  1156. for(int i=0;i<nb->inputs.size();i++) {
  1157. _recompute_caches(nb->inputs[i].node);
  1158. }
  1159. }
  1160. void AnimationTreePlayer::recompute_caches() {
  1161. dirty_caches=true;
  1162. }
  1163. /* playback */
  1164. void AnimationTreePlayer::set_active(bool p_active) {
  1165. if (active == p_active)
  1166. return;
  1167. active = p_active;
  1168. processing = active;
  1169. reset_request = p_active;
  1170. _set_process(processing, true);
  1171. }
  1172. bool AnimationTreePlayer::is_active() const {
  1173. return active;
  1174. }
  1175. AnimationTreePlayer::ConnectError AnimationTreePlayer::get_last_error() const {
  1176. return last_error;
  1177. }
  1178. void AnimationTreePlayer::reset() {
  1179. reset_request=true;
  1180. }
  1181. void AnimationTreePlayer::set_base_path(const NodePath& p_path) {
  1182. base_path=p_path;
  1183. recompute_caches();
  1184. }
  1185. NodePath AnimationTreePlayer::get_base_path() const{
  1186. return base_path;
  1187. }
  1188. void AnimationTreePlayer::set_master_player(const NodePath& p_path) {
  1189. if (p_path==master)
  1190. return;
  1191. master=p_path;
  1192. _update_sources();
  1193. recompute_caches();
  1194. }
  1195. NodePath AnimationTreePlayer::get_master_player() const{
  1196. return master;
  1197. }
  1198. PoolVector<String> AnimationTreePlayer::_get_node_list() {
  1199. List<StringName> nl;
  1200. get_node_list(&nl);
  1201. PoolVector<String> ret;
  1202. ret.resize(nl.size());
  1203. int idx=0;
  1204. for(List<StringName>::Element *E=nl.front();E;E=E->next()) {
  1205. ret.set(idx++,E->get());
  1206. }
  1207. return ret;
  1208. }
  1209. void AnimationTreePlayer::_update_sources() {
  1210. if (master==NodePath())
  1211. return;
  1212. if (!is_inside_tree())
  1213. return;
  1214. Node *m = get_node(master);
  1215. if (!m) {
  1216. master=NodePath();
  1217. ERR_FAIL_COND(!m);
  1218. }
  1219. AnimationPlayer *ap = m->cast_to<AnimationPlayer>();
  1220. if (!ap) {
  1221. master=NodePath();
  1222. ERR_FAIL_COND(!ap);
  1223. }
  1224. for (Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
  1225. if (E->get()->type==NODE_ANIMATION) {
  1226. AnimationNode *an = static_cast<AnimationNode*>(E->get());
  1227. if (an->from!="") {
  1228. an->animation = ap->get_animation(an->from);
  1229. }
  1230. }
  1231. }
  1232. }
  1233. bool AnimationTreePlayer::node_exists(const StringName& p_name) const {
  1234. return (node_map.has(p_name));
  1235. }
  1236. Error AnimationTreePlayer::node_rename(const StringName& p_node,const StringName& p_new_name) {
  1237. if (p_new_name==p_node)
  1238. return OK;
  1239. ERR_FAIL_COND_V(!node_map.has(p_node),ERR_ALREADY_EXISTS);
  1240. ERR_FAIL_COND_V(node_map.has(p_new_name),ERR_ALREADY_EXISTS);
  1241. ERR_FAIL_COND_V(p_new_name==StringName(),ERR_INVALID_DATA);
  1242. ERR_FAIL_COND_V(p_node==out_name,ERR_INVALID_DATA);
  1243. ERR_FAIL_COND_V(p_new_name==out_name,ERR_INVALID_DATA);
  1244. for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
  1245. NodeBase *nb = E->get();
  1246. for(int i=0;i<nb->inputs.size();i++) {
  1247. if (nb->inputs[i].node==p_node) {
  1248. nb->inputs[i].node=p_new_name;
  1249. }
  1250. }
  1251. }
  1252. node_map[p_new_name]=node_map[p_node];
  1253. node_map.erase(p_node);
  1254. return OK;
  1255. }
  1256. void AnimationTreePlayer::_bind_methods() {
  1257. ClassDB::bind_method(_MD("add_node","type","id"),&AnimationTreePlayer::add_node);
  1258. ClassDB::bind_method(_MD("node_exists","node"),&AnimationTreePlayer::node_exists);
  1259. ClassDB::bind_method(_MD("node_rename","node","new_name"),&AnimationTreePlayer::node_rename);
  1260. ClassDB::bind_method(_MD("node_get_type","id"),&AnimationTreePlayer::node_get_type);
  1261. ClassDB::bind_method(_MD("node_get_input_count","id"),&AnimationTreePlayer::node_get_input_count);
  1262. ClassDB::bind_method(_MD("node_get_input_source","id","idx"),&AnimationTreePlayer::node_get_input_source);
  1263. ClassDB::bind_method(_MD("animation_node_set_animation","id","animation:Animation"),&AnimationTreePlayer::animation_node_set_animation);
  1264. ClassDB::bind_method(_MD("animation_node_get_animation:Animation","id"),&AnimationTreePlayer::animation_node_get_animation);
  1265. ClassDB::bind_method(_MD("animation_node_set_master_animation","id","source"),&AnimationTreePlayer::animation_node_set_master_animation);
  1266. ClassDB::bind_method(_MD("animation_node_get_master_animation","id"),&AnimationTreePlayer::animation_node_get_master_animation);
  1267. ClassDB::bind_method(_MD("animation_node_set_filter_path","id","path","enable"),&AnimationTreePlayer::animation_node_set_filter_path);
  1268. ClassDB::bind_method(_MD("oneshot_node_set_fadein_time","id","time_sec"),&AnimationTreePlayer::oneshot_node_set_fadein_time);
  1269. ClassDB::bind_method(_MD("oneshot_node_get_fadein_time","id"),&AnimationTreePlayer::oneshot_node_get_fadein_time);
  1270. ClassDB::bind_method(_MD("oneshot_node_set_fadeout_time","id","time_sec"),&AnimationTreePlayer::oneshot_node_set_fadeout_time);
  1271. ClassDB::bind_method(_MD("oneshot_node_get_fadeout_time","id"),&AnimationTreePlayer::oneshot_node_get_fadeout_time);
  1272. ClassDB::bind_method(_MD("oneshot_node_set_autorestart","id","enable"),&AnimationTreePlayer::oneshot_node_set_autorestart);
  1273. ClassDB::bind_method(_MD("oneshot_node_set_autorestart_delay","id","delay_sec"),&AnimationTreePlayer::oneshot_node_set_autorestart_delay);
  1274. ClassDB::bind_method(_MD("oneshot_node_set_autorestart_random_delay","id","rand_sec"),&AnimationTreePlayer::oneshot_node_set_autorestart_random_delay);
  1275. ClassDB::bind_method(_MD("oneshot_node_has_autorestart","id"),&AnimationTreePlayer::oneshot_node_has_autorestart);
  1276. ClassDB::bind_method(_MD("oneshot_node_get_autorestart_delay","id"),&AnimationTreePlayer::oneshot_node_get_autorestart_delay);
  1277. ClassDB::bind_method(_MD("oneshot_node_get_autorestart_random_delay","id"),&AnimationTreePlayer::oneshot_node_get_autorestart_random_delay);
  1278. ClassDB::bind_method(_MD("oneshot_node_start","id"),&AnimationTreePlayer::oneshot_node_start);
  1279. ClassDB::bind_method(_MD("oneshot_node_stop","id"),&AnimationTreePlayer::oneshot_node_stop);
  1280. ClassDB::bind_method(_MD("oneshot_node_is_active","id"),&AnimationTreePlayer::oneshot_node_is_active);
  1281. ClassDB::bind_method(_MD("oneshot_node_set_filter_path","id","path","enable"),&AnimationTreePlayer::oneshot_node_set_filter_path);
  1282. ClassDB::bind_method(_MD("mix_node_set_amount","id","ratio"),&AnimationTreePlayer::mix_node_set_amount);
  1283. ClassDB::bind_method(_MD("mix_node_get_amount","id"),&AnimationTreePlayer::mix_node_get_amount);
  1284. ClassDB::bind_method(_MD("blend2_node_set_amount","id","blend"),&AnimationTreePlayer::blend2_node_set_amount);
  1285. ClassDB::bind_method(_MD("blend2_node_get_amount","id"),&AnimationTreePlayer::blend2_node_get_amount);
  1286. ClassDB::bind_method(_MD("blend2_node_set_filter_path","id","path","enable"),&AnimationTreePlayer::blend2_node_set_filter_path);
  1287. ClassDB::bind_method(_MD("blend3_node_set_amount","id","blend"),&AnimationTreePlayer::blend3_node_set_amount);
  1288. ClassDB::bind_method(_MD("blend3_node_get_amount","id"),&AnimationTreePlayer::blend3_node_get_amount);
  1289. ClassDB::bind_method(_MD("blend4_node_set_amount","id","blend"),&AnimationTreePlayer::blend4_node_set_amount);
  1290. ClassDB::bind_method(_MD("blend4_node_get_amount","id"),&AnimationTreePlayer::blend4_node_get_amount);
  1291. ClassDB::bind_method(_MD("timescale_node_set_scale","id","scale"),&AnimationTreePlayer::timescale_node_set_scale);
  1292. ClassDB::bind_method(_MD("timescale_node_get_scale","id"),&AnimationTreePlayer::timescale_node_get_scale);
  1293. ClassDB::bind_method(_MD("timeseek_node_seek","id","pos_sec"),&AnimationTreePlayer::timeseek_node_seek);
  1294. ClassDB::bind_method(_MD("transition_node_set_input_count","id","count"),&AnimationTreePlayer::transition_node_set_input_count);
  1295. ClassDB::bind_method(_MD("transition_node_get_input_count","id"),&AnimationTreePlayer::transition_node_get_input_count);
  1296. ClassDB::bind_method(_MD("transition_node_delete_input","id","input_idx"),&AnimationTreePlayer::transition_node_delete_input);
  1297. ClassDB::bind_method(_MD("transition_node_set_input_auto_advance","id","input_idx","enable"),&AnimationTreePlayer::transition_node_set_input_auto_advance);
  1298. ClassDB::bind_method(_MD("transition_node_has_input_auto_advance","id","input_idx"),&AnimationTreePlayer::transition_node_has_input_auto_advance);
  1299. ClassDB::bind_method(_MD("transition_node_set_xfade_time","id","time_sec"),&AnimationTreePlayer::transition_node_set_xfade_time);
  1300. ClassDB::bind_method(_MD("transition_node_get_xfade_time","id"),&AnimationTreePlayer::transition_node_get_xfade_time);
  1301. ClassDB::bind_method(_MD("transition_node_set_current","id","input_idx"),&AnimationTreePlayer::transition_node_set_current);
  1302. ClassDB::bind_method(_MD("transition_node_get_current","id"),&AnimationTreePlayer::transition_node_get_current);
  1303. ClassDB::bind_method(_MD("node_set_pos","id","screen_pos"),&AnimationTreePlayer::node_set_pos);
  1304. ClassDB::bind_method(_MD("node_get_pos","id"),&AnimationTreePlayer::node_get_pos);
  1305. ClassDB::bind_method(_MD("remove_node","id"),&AnimationTreePlayer::remove_node);
  1306. ClassDB::bind_method(_MD("connect_nodes","id","dst_id","dst_input_idx"),&AnimationTreePlayer::connect_nodes);
  1307. ClassDB::bind_method(_MD("are_nodes_connected","id","dst_id","dst_input_idx"),&AnimationTreePlayer::are_nodes_connected);
  1308. ClassDB::bind_method(_MD("disconnect_nodes","id","dst_input_idx"),&AnimationTreePlayer::disconnect_nodes);
  1309. ClassDB::bind_method(_MD("set_active","enabled"),&AnimationTreePlayer::set_active);
  1310. ClassDB::bind_method(_MD("is_active"),&AnimationTreePlayer::is_active);
  1311. ClassDB::bind_method(_MD("set_base_path","path"),&AnimationTreePlayer::set_base_path);
  1312. ClassDB::bind_method(_MD("get_base_path"),&AnimationTreePlayer::get_base_path);
  1313. ClassDB::bind_method(_MD("set_master_player","nodepath"),&AnimationTreePlayer::set_master_player);
  1314. ClassDB::bind_method(_MD("get_master_player"),&AnimationTreePlayer::get_master_player);
  1315. ClassDB::bind_method(_MD("get_node_list"),&AnimationTreePlayer::_get_node_list);
  1316. ClassDB::bind_method(_MD("set_animation_process_mode","mode"),&AnimationTreePlayer::set_animation_process_mode);
  1317. ClassDB::bind_method(_MD("get_animation_process_mode"),&AnimationTreePlayer::get_animation_process_mode);
  1318. ClassDB::bind_method(_MD("advance", "delta"), &AnimationTreePlayer::advance);
  1319. ClassDB::bind_method(_MD("reset"),&AnimationTreePlayer::reset);
  1320. ClassDB::bind_method(_MD("recompute_caches"),&AnimationTreePlayer::recompute_caches);
  1321. ADD_GROUP("Playback","playback_");
  1322. ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_animation_process_mode"), _SCS("get_animation_process_mode"));
  1323. BIND_CONSTANT( NODE_OUTPUT );
  1324. BIND_CONSTANT( NODE_ANIMATION );
  1325. BIND_CONSTANT( NODE_ONESHOT );
  1326. BIND_CONSTANT( NODE_MIX );
  1327. BIND_CONSTANT( NODE_BLEND2 );
  1328. BIND_CONSTANT( NODE_BLEND3 );
  1329. BIND_CONSTANT( NODE_BLEND4 );
  1330. BIND_CONSTANT( NODE_TIMESCALE );
  1331. BIND_CONSTANT( NODE_TIMESEEK );
  1332. BIND_CONSTANT( NODE_TRANSITION );
  1333. }
  1334. AnimationTreePlayer::AnimationTreePlayer() {
  1335. active_list=NULL;
  1336. out = memnew( NodeOut ) ;
  1337. out_name="out";
  1338. out->pos=Point2(40,40);
  1339. node_map.insert( out_name , out);
  1340. animation_process_mode = ANIMATION_PROCESS_IDLE;
  1341. processing = false;
  1342. active=false;
  1343. dirty_caches=true;
  1344. reset_request=true;
  1345. last_error=CONNECT_INCOMPLETE;
  1346. base_path=String("..");
  1347. }
  1348. AnimationTreePlayer::~AnimationTreePlayer() {
  1349. while(node_map.size()) {
  1350. memdelete( node_map.front()->get() );
  1351. node_map.erase( node_map.front() );
  1352. }
  1353. }