0.2.0-dev Download ZIP
114 lines ·5.1 KB Raw
| 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 | |
| 31 | #include "gltf_animation.h" |
| 32 | |
| 33 | #include "core/object/class_db.h" |
| 34 | |
| 35 | void GLTFAnimation::_bind_methods() { |
| 36 | ClassDB::bind_method(D_METHOD("get_original_name"), &GLTFAnimation::get_original_name); |
| 37 | ClassDB::bind_method(D_METHOD("set_original_name", "original_name"), &GLTFAnimation::set_original_name); |
| 38 | ClassDB::bind_method(D_METHOD("get_loop"), &GLTFAnimation::get_loop); |
| 39 | ClassDB::bind_method(D_METHOD("set_loop", "loop"), &GLTFAnimation::set_loop); |
| 40 | ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFAnimation::get_additional_data); |
| 41 | ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFAnimation::set_additional_data); |
| 42 | |
| 43 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "original_name"), "set_original_name", "get_original_name"); // String |
| 44 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "get_loop"); // bool |
| 45 | } |
| 46 | |
| 47 | GLTFAnimation::Interpolation GLTFAnimation::godot_to_gltf_interpolation(const Ref<Animation> &p_godot_animation, int32_t p_godot_anim_track_index) { |
| 48 | Animation::InterpolationType interpolation = p_godot_animation->track_get_interpolation_type(p_godot_anim_track_index); |
| 49 | switch (interpolation) { |
| 50 | case Animation::INTERPOLATION_LINEAR: |
| 51 | case Animation::INTERPOLATION_LINEAR_ANGLE: |
| 52 | return INTERP_LINEAR; |
| 53 | case Animation::INTERPOLATION_NEAREST: |
| 54 | return INTERP_STEP; |
| 55 | case Animation::INTERPOLATION_CUBIC: |
| 56 | case Animation::INTERPOLATION_CUBIC_ANGLE: |
| 57 | case Animation::INTERPOLATION_MAKIMA: |
| 58 | case Animation::INTERPOLATION_MAKIMA_ANGLE: |
| 59 | return INTERP_CUBIC_SPLINE; |
| 60 | } |
| 61 | return INTERP_LINEAR; |
| 62 | } |
| 63 | |
| 64 | Animation::InterpolationType GLTFAnimation::gltf_to_godot_interpolation(Interpolation p_gltf_interpolation) { |
| 65 | switch (p_gltf_interpolation) { |
| 66 | case INTERP_LINEAR: |
| 67 | return Animation::INTERPOLATION_LINEAR; |
| 68 | case INTERP_STEP: |
| 69 | return Animation::INTERPOLATION_NEAREST; |
| 70 | case INTERP_CATMULLROMSPLINE: |
| 71 | case INTERP_CUBIC_SPLINE: |
| 72 | return Animation::INTERPOLATION_CUBIC; |
| 73 | } |
| 74 | return Animation::INTERPOLATION_LINEAR; |
| 75 | } |
| 76 | |
| 77 | String GLTFAnimation::get_original_name() { |
| 78 | return original_name; |
| 79 | } |
| 80 | |
| 81 | void GLTFAnimation::set_original_name(const String &p_name) { |
| 82 | original_name = p_name; |
| 83 | } |
| 84 | |
| 85 | bool GLTFAnimation::get_loop() const { |
| 86 | return loop; |
| 87 | } |
| 88 | |
| 89 | void GLTFAnimation::set_loop(bool p_val) { |
| 90 | loop = p_val; |
| 91 | } |
| 92 | |
| 93 | HashMap<int, GLTFAnimation::NodeTrack> &GLTFAnimation::get_node_tracks() { |
| 94 | return node_tracks; |
| 95 | } |
| 96 | |
| 97 | HashMap<String, GLTFAnimation::Channel<Variant>> &GLTFAnimation::get_pointer_tracks() { |
| 98 | return pointer_tracks; |
| 99 | } |
| 100 | |
| 101 | bool GLTFAnimation::is_empty_of_tracks() const { |
| 102 | return node_tracks.is_empty() && pointer_tracks.is_empty(); |
| 103 | } |
| 104 | |
| 105 | GLTFAnimation::GLTFAnimation() { |
| 106 | } |
| 107 | |
| 108 | Variant GLTFAnimation::get_additional_data(const StringName &p_extension_name) { |
| 109 | return additional_data.get(p_extension_name, Variant()); |
| 110 | } |
| 111 | |
| 112 | void GLTFAnimation::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) { |
| 113 | additional_data[p_extension_name] = p_additional_data; |
| 114 | } |