Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gltf/structures/gltf_animation.cpp
10278 views
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
void GLTFAnimation::_bind_methods() {
34
ClassDB::bind_method(D_METHOD("get_original_name"), &GLTFAnimation::get_original_name);
35
ClassDB::bind_method(D_METHOD("set_original_name", "original_name"), &GLTFAnimation::set_original_name);
36
ClassDB::bind_method(D_METHOD("get_loop"), &GLTFAnimation::get_loop);
37
ClassDB::bind_method(D_METHOD("set_loop", "loop"), &GLTFAnimation::set_loop);
38
ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFAnimation::get_additional_data);
39
ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFAnimation::set_additional_data);
40
41
ADD_PROPERTY(PropertyInfo(Variant::STRING, "original_name"), "set_original_name", "get_original_name"); // String
42
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "get_loop"); // bool
43
}
44
45
GLTFAnimation::Interpolation GLTFAnimation::godot_to_gltf_interpolation(const Ref<Animation> &p_godot_animation, int32_t p_godot_anim_track_index) {
46
Animation::InterpolationType interpolation = p_godot_animation->track_get_interpolation_type(p_godot_anim_track_index);
47
switch (interpolation) {
48
case Animation::INTERPOLATION_LINEAR:
49
case Animation::INTERPOLATION_LINEAR_ANGLE:
50
return INTERP_LINEAR;
51
case Animation::INTERPOLATION_NEAREST:
52
return INTERP_STEP;
53
case Animation::INTERPOLATION_CUBIC:
54
case Animation::INTERPOLATION_CUBIC_ANGLE:
55
return INTERP_CUBIC_SPLINE;
56
}
57
return INTERP_LINEAR;
58
}
59
60
Animation::InterpolationType GLTFAnimation::gltf_to_godot_interpolation(Interpolation p_gltf_interpolation) {
61
switch (p_gltf_interpolation) {
62
case INTERP_LINEAR:
63
return Animation::INTERPOLATION_LINEAR;
64
case INTERP_STEP:
65
return Animation::INTERPOLATION_NEAREST;
66
case INTERP_CATMULLROMSPLINE:
67
case INTERP_CUBIC_SPLINE:
68
return Animation::INTERPOLATION_CUBIC;
69
}
70
return Animation::INTERPOLATION_LINEAR;
71
}
72
73
String GLTFAnimation::get_original_name() {
74
return original_name;
75
}
76
77
void GLTFAnimation::set_original_name(String p_name) {
78
original_name = p_name;
79
}
80
81
bool GLTFAnimation::get_loop() const {
82
return loop;
83
}
84
85
void GLTFAnimation::set_loop(bool p_val) {
86
loop = p_val;
87
}
88
89
HashMap<int, GLTFAnimation::NodeTrack> &GLTFAnimation::get_node_tracks() {
90
return node_tracks;
91
}
92
93
HashMap<String, GLTFAnimation::Channel<Variant>> &GLTFAnimation::get_pointer_tracks() {
94
return pointer_tracks;
95
}
96
97
bool GLTFAnimation::is_empty_of_tracks() const {
98
return node_tracks.is_empty() && pointer_tracks.is_empty();
99
}
100
101
GLTFAnimation::GLTFAnimation() {
102
}
103
104
Variant GLTFAnimation::get_additional_data(const StringName &p_extension_name) {
105
return additional_data[p_extension_name];
106
}
107
108
void GLTFAnimation::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {
109
additional_data[p_extension_name] = p_additional_data;
110
}
111
112