animation_node_extension.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**************************************************************************/
  2. /* animation_node_extension.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_node_extension.h"
  31. AnimationNode::NodeTimeInfo AnimationNodeExtension::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
  32. PackedFloat32Array r_ret;
  33. GDVIRTUAL_CALL(
  34. _process_animation_node,
  35. _playback_info_to_array(p_playback_info),
  36. p_test_only,
  37. r_ret);
  38. return _array_to_node_time_info(r_ret);
  39. }
  40. bool AnimationNodeExtension::is_looping(const PackedFloat32Array &p_node_info) {
  41. return _array_to_node_time_info(p_node_info).is_looping();
  42. }
  43. double AnimationNodeExtension::get_remaining_time(const PackedFloat32Array &p_node_info, bool p_break_loop) {
  44. return _array_to_node_time_info(p_node_info).get_remain(p_break_loop);
  45. }
  46. void AnimationNodeExtension::_bind_methods() {
  47. ClassDB::bind_static_method("AnimationNodeExtension", D_METHOD("is_looping", "node_info"), &AnimationNodeExtension::is_looping);
  48. ClassDB::bind_static_method("AnimationNodeExtension", D_METHOD("get_remaining_time", "node_info", "break_loop"), &AnimationNodeExtension::get_remaining_time);
  49. GDVIRTUAL_BIND(_process_animation_node, "playback_info", "test_only");
  50. }
  51. AnimationNode::NodeTimeInfo AnimationNodeExtension::_array_to_node_time_info(const PackedFloat32Array &p_node_info) {
  52. ERR_FAIL_COND_V_MSG(p_node_info.size() != 6, AnimationNode::NodeTimeInfo(), "Invalid node info.");
  53. AnimationNode::NodeTimeInfo ret_val;
  54. ret_val.length = p_node_info[0];
  55. ret_val.position = p_node_info[1];
  56. ret_val.delta = p_node_info[2];
  57. ret_val.loop_mode = static_cast<Animation::LoopMode>(p_node_info[3]);
  58. ret_val.will_end = p_node_info[4] > 0.0;
  59. ret_val.is_infinity = p_node_info[5] > 0.0;
  60. return ret_val;
  61. }
  62. PackedFloat64Array AnimationNodeExtension::_playback_info_to_array(const AnimationMixer::PlaybackInfo &p_playback_info) {
  63. PackedFloat64Array playback_info_array;
  64. playback_info_array.push_back(p_playback_info.time);
  65. playback_info_array.push_back(p_playback_info.delta);
  66. playback_info_array.push_back(p_playback_info.start);
  67. playback_info_array.push_back(p_playback_info.end);
  68. playback_info_array.push_back(p_playback_info.seeked);
  69. playback_info_array.push_back(p_playback_info.is_external_seeking);
  70. playback_info_array.push_back(p_playback_info.looped_flag);
  71. playback_info_array.push_back(p_playback_info.weight);
  72. return playback_info_array;
  73. }