Path: blob/master/modules/gltf/structures/gltf_animation.cpp
10278 views
/**************************************************************************/1/* gltf_animation.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 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/**************************************************************************/2930#include "gltf_animation.h"3132void GLTFAnimation::_bind_methods() {33ClassDB::bind_method(D_METHOD("get_original_name"), &GLTFAnimation::get_original_name);34ClassDB::bind_method(D_METHOD("set_original_name", "original_name"), &GLTFAnimation::set_original_name);35ClassDB::bind_method(D_METHOD("get_loop"), &GLTFAnimation::get_loop);36ClassDB::bind_method(D_METHOD("set_loop", "loop"), &GLTFAnimation::set_loop);37ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFAnimation::get_additional_data);38ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFAnimation::set_additional_data);3940ADD_PROPERTY(PropertyInfo(Variant::STRING, "original_name"), "set_original_name", "get_original_name"); // String41ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "get_loop"); // bool42}4344GLTFAnimation::Interpolation GLTFAnimation::godot_to_gltf_interpolation(const Ref<Animation> &p_godot_animation, int32_t p_godot_anim_track_index) {45Animation::InterpolationType interpolation = p_godot_animation->track_get_interpolation_type(p_godot_anim_track_index);46switch (interpolation) {47case Animation::INTERPOLATION_LINEAR:48case Animation::INTERPOLATION_LINEAR_ANGLE:49return INTERP_LINEAR;50case Animation::INTERPOLATION_NEAREST:51return INTERP_STEP;52case Animation::INTERPOLATION_CUBIC:53case Animation::INTERPOLATION_CUBIC_ANGLE:54return INTERP_CUBIC_SPLINE;55}56return INTERP_LINEAR;57}5859Animation::InterpolationType GLTFAnimation::gltf_to_godot_interpolation(Interpolation p_gltf_interpolation) {60switch (p_gltf_interpolation) {61case INTERP_LINEAR:62return Animation::INTERPOLATION_LINEAR;63case INTERP_STEP:64return Animation::INTERPOLATION_NEAREST;65case INTERP_CATMULLROMSPLINE:66case INTERP_CUBIC_SPLINE:67return Animation::INTERPOLATION_CUBIC;68}69return Animation::INTERPOLATION_LINEAR;70}7172String GLTFAnimation::get_original_name() {73return original_name;74}7576void GLTFAnimation::set_original_name(String p_name) {77original_name = p_name;78}7980bool GLTFAnimation::get_loop() const {81return loop;82}8384void GLTFAnimation::set_loop(bool p_val) {85loop = p_val;86}8788HashMap<int, GLTFAnimation::NodeTrack> &GLTFAnimation::get_node_tracks() {89return node_tracks;90}9192HashMap<String, GLTFAnimation::Channel<Variant>> &GLTFAnimation::get_pointer_tracks() {93return pointer_tracks;94}9596bool GLTFAnimation::is_empty_of_tracks() const {97return node_tracks.is_empty() && pointer_tracks.is_empty();98}99100GLTFAnimation::GLTFAnimation() {101}102103Variant GLTFAnimation::get_additional_data(const StringName &p_extension_name) {104return additional_data[p_extension_name];105}106107void GLTFAnimation::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {108additional_data[p_extension_name] = p_additional_data;109}110111112