2020-01-31 19:39:58 +01:00
|
|
|
/*
|
|
|
|
Copyright (c) 2020 Péter Magyar
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2020-01-24 15:29:39 +01:00
|
|
|
#ifndef PROCEDURAL_ANIMATION_H
|
|
|
|
#define PROCEDURAL_ANIMATION_H
|
|
|
|
|
2020-03-26 10:27:39 +01:00
|
|
|
#include "scene/resources/animation.h"
|
2020-01-24 15:29:39 +01:00
|
|
|
|
2020-01-27 03:04:53 +01:00
|
|
|
#include "core/map.h"
|
|
|
|
#include "core/math/vector2.h"
|
2020-02-27 14:54:52 +01:00
|
|
|
#include "core/pool_vector.h"
|
|
|
|
#include "core/vector.h"
|
2020-01-24 15:29:39 +01:00
|
|
|
|
|
|
|
#include "scene/resources/animation.h"
|
2020-03-26 10:27:39 +01:00
|
|
|
#include "scene/resources/curve.h"
|
2020-01-24 15:29:39 +01:00
|
|
|
|
2020-03-26 10:27:39 +01:00
|
|
|
class ProceduralAnimation : public Animation {
|
|
|
|
GDCLASS(ProceduralAnimation, Animation);
|
2020-01-28 22:30:58 +01:00
|
|
|
|
2020-02-10 18:38:41 +01:00
|
|
|
protected:
|
2020-01-27 03:04:53 +01:00
|
|
|
struct AnimationKeyFrame {
|
|
|
|
String name;
|
|
|
|
int animation_keyframe_index;
|
|
|
|
int next_keyframe;
|
|
|
|
Vector2 position;
|
2020-04-01 02:09:42 +02:00
|
|
|
float transition;
|
2020-01-27 03:04:53 +01:00
|
|
|
|
|
|
|
AnimationKeyFrame() {
|
|
|
|
animation_keyframe_index = 0;
|
2020-04-01 02:09:42 +02:00
|
|
|
transition = 1.0;
|
2020-01-27 03:04:53 +01:00
|
|
|
next_keyframe = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AnimationKeyFrame() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-10 18:38:41 +01:00
|
|
|
public:
|
|
|
|
Ref<Animation> get_animation() const;
|
|
|
|
void set_animation(const Ref<Animation> &value);
|
|
|
|
|
2020-02-28 07:44:22 +01:00
|
|
|
int get_animation_fps() const;
|
|
|
|
void set_animation_fps(const int index);
|
|
|
|
|
2020-02-10 18:38:41 +01:00
|
|
|
String get_animation_keyframe_name(int keyframe_index) const;
|
|
|
|
void set_animation_keyframe_name(int keyframe_index, const String &value);
|
|
|
|
void remove_animation_keyframe_name(int keyframe_index);
|
|
|
|
PoolVector<String> get_animation_keyframe_names() const;
|
|
|
|
|
2020-03-25 16:47:49 +01:00
|
|
|
Vector2 get_start_node_position() const;
|
|
|
|
void set_start_node_position(const Vector2 &value);
|
2020-02-10 18:38:41 +01:00
|
|
|
|
2020-03-25 16:47:49 +01:00
|
|
|
int get_start_frame_index() const;
|
|
|
|
void set_start_frame_index(const int value);
|
2020-02-10 18:38:41 +01:00
|
|
|
|
|
|
|
//Keyframes
|
2020-03-25 16:47:49 +01:00
|
|
|
PoolVector<int> get_keyframe_indices() const;
|
|
|
|
int add_keyframe();
|
|
|
|
void remove_keyframe(const int keyframe_index);
|
|
|
|
bool has_keyframe(const int keyframe_index) const;
|
2020-02-10 18:38:41 +01:00
|
|
|
|
2020-03-25 16:47:49 +01:00
|
|
|
String get_keyframe_name(const int keyframe_index) const;
|
|
|
|
void set_keyframe_name(const int keyframe_index, const String &value);
|
2020-02-10 18:38:41 +01:00
|
|
|
|
2020-03-25 16:47:49 +01:00
|
|
|
int get_keyframe_animation_keyframe_index(const int keyframe_index) const;
|
2020-03-31 23:42:26 +02:00
|
|
|
void set_keyframe_animation_keyframe_index(const int keyframe_index, const int value);
|
2020-02-10 18:38:41 +01:00
|
|
|
|
2020-03-25 16:47:49 +01:00
|
|
|
int get_keyframe_next_keyframe_index(const int keyframe_index) const;
|
|
|
|
void set_keyframe_next_keyframe_index(const int keyframe_index, const int value);
|
2020-02-10 18:38:41 +01:00
|
|
|
|
2020-04-01 02:09:42 +02:00
|
|
|
float get_keyframe_transition(const int keyframe_index) const;
|
|
|
|
void set_keyframe_transition(const int keyframe_index, const float value);
|
|
|
|
|
2020-03-25 16:47:49 +01:00
|
|
|
Vector2 get_keyframe_node_position(const int keyframe_index) const;
|
|
|
|
void set_keyframe_node_position(const int keyframe_index, const Vector2 &value);
|
2020-02-10 18:38:41 +01:00
|
|
|
|
2020-03-31 23:42:26 +02:00
|
|
|
void process_animation_data();
|
2020-04-01 02:09:42 +02:00
|
|
|
void load_keyframe_data(const float keyframe_time, const float previous_keyframe_time, const int keyframe_index, const bool interpolation_allowed = false);
|
2020-02-10 18:38:41 +01:00
|
|
|
|
|
|
|
ProceduralAnimation();
|
|
|
|
~ProceduralAnimation();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2020-01-24 15:29:39 +01:00
|
|
|
private:
|
2020-02-10 18:38:41 +01:00
|
|
|
bool _initialized;
|
2020-02-28 07:44:22 +01:00
|
|
|
int _animation_fps;
|
2020-02-10 18:38:41 +01:00
|
|
|
|
2020-01-24 15:29:39 +01:00
|
|
|
String _editor_add_category_name;
|
|
|
|
String _add_editor_category_animation_name;
|
|
|
|
|
2020-03-25 16:47:49 +01:00
|
|
|
Vector2 _start_node_position;
|
|
|
|
int _start_frame_index;
|
|
|
|
Map<int, AnimationKeyFrame *> _keyframes;
|
|
|
|
|
2020-01-24 15:29:39 +01:00
|
|
|
Ref<Animation> _animation;
|
2020-01-27 03:04:53 +01:00
|
|
|
Map<int, String> _keyframe_names;
|
2020-01-24 15:29:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|