gltf_animation.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**************************************************************************/
  2. /* gltf_animation.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 "gltf_animation.h"
  31. void GLTFAnimation::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_original_name"), &GLTFAnimation::get_original_name);
  33. ClassDB::bind_method(D_METHOD("set_original_name", "original_name"), &GLTFAnimation::set_original_name);
  34. ClassDB::bind_method(D_METHOD("get_loop"), &GLTFAnimation::get_loop);
  35. ClassDB::bind_method(D_METHOD("set_loop", "loop"), &GLTFAnimation::set_loop);
  36. ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFAnimation::get_additional_data);
  37. ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFAnimation::set_additional_data);
  38. ADD_PROPERTY(PropertyInfo(Variant::STRING, "original_name"), "set_original_name", "get_original_name"); // String
  39. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "get_loop"); // bool
  40. }
  41. GLTFAnimation::Interpolation GLTFAnimation::godot_to_gltf_interpolation(const Ref<Animation> &p_godot_animation, int32_t p_godot_anim_track_index) {
  42. Animation::InterpolationType interpolation = p_godot_animation->track_get_interpolation_type(p_godot_anim_track_index);
  43. switch (interpolation) {
  44. case Animation::INTERPOLATION_LINEAR:
  45. case Animation::INTERPOLATION_LINEAR_ANGLE:
  46. return INTERP_LINEAR;
  47. case Animation::INTERPOLATION_NEAREST:
  48. return INTERP_STEP;
  49. case Animation::INTERPOLATION_CUBIC:
  50. case Animation::INTERPOLATION_CUBIC_ANGLE:
  51. return INTERP_CUBIC_SPLINE;
  52. }
  53. return INTERP_LINEAR;
  54. }
  55. Animation::InterpolationType GLTFAnimation::gltf_to_godot_interpolation(Interpolation p_gltf_interpolation) {
  56. switch (p_gltf_interpolation) {
  57. case INTERP_LINEAR:
  58. return Animation::INTERPOLATION_LINEAR;
  59. case INTERP_STEP:
  60. return Animation::INTERPOLATION_NEAREST;
  61. case INTERP_CATMULLROMSPLINE:
  62. case INTERP_CUBIC_SPLINE:
  63. return Animation::INTERPOLATION_CUBIC;
  64. }
  65. return Animation::INTERPOLATION_LINEAR;
  66. }
  67. String GLTFAnimation::get_original_name() {
  68. return original_name;
  69. }
  70. void GLTFAnimation::set_original_name(String p_name) {
  71. original_name = p_name;
  72. }
  73. bool GLTFAnimation::get_loop() const {
  74. return loop;
  75. }
  76. void GLTFAnimation::set_loop(bool p_val) {
  77. loop = p_val;
  78. }
  79. HashMap<int, GLTFAnimation::NodeTrack> &GLTFAnimation::get_node_tracks() {
  80. return node_tracks;
  81. }
  82. HashMap<String, GLTFAnimation::Channel<Variant>> &GLTFAnimation::get_pointer_tracks() {
  83. return pointer_tracks;
  84. }
  85. bool GLTFAnimation::is_empty_of_tracks() const {
  86. return node_tracks.is_empty() && pointer_tracks.is_empty();
  87. }
  88. GLTFAnimation::GLTFAnimation() {
  89. }
  90. Variant GLTFAnimation::get_additional_data(const StringName &p_extension_name) {
  91. return additional_data[p_extension_name];
  92. }
  93. void GLTFAnimation::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {
  94. additional_data[p_extension_name] = p_additional_data;
  95. }