Started work on getting the actual data out from animation.

This commit is contained in:
Relintai 2020-02-27 14:54:52 +01:00
parent 00f6c128bd
commit 0e59990ff5
2 changed files with 69 additions and 21 deletions

View File

@ -56,7 +56,7 @@ PoolVector<String> ProceduralAnimation::get_animation_keyframe_names() const {
names.set(i, String::num(E->key()) + " " + _keyframe_names[E->key()]); names.set(i, String::num(E->key()) + " " + _keyframe_names[E->key()]);
++i; ++i;
} }
return names; return names;
} }
@ -70,7 +70,7 @@ PoolVector<int> ProceduralAnimation::get_category_indices() const {
idxr.set(i, E->key()); idxr.set(i, E->key());
++i; ++i;
} }
return idxr; return idxr;
} }
int ProceduralAnimation::add_category(const String &name) { int ProceduralAnimation::add_category(const String &name) {
@ -91,7 +91,7 @@ int ProceduralAnimation::add_category(const String &name) {
} }
void ProceduralAnimation::remove_category(const int index) { void ProceduralAnimation::remove_category(const int index) {
ERR_FAIL_COND(!_categories.has(index)); ERR_FAIL_COND(!_categories.has(index));
Category *category = _categories[index]; Category *category = _categories[index];
_categories.erase(index); _categories.erase(index);
@ -124,7 +124,7 @@ PoolVector<int> ProceduralAnimation::get_animation_indices(const int category_in
idxr.set(i, E->key()); idxr.set(i, E->key());
++i; ++i;
} }
return idxr; return idxr;
} }
int ProceduralAnimation::add_animation(const int category_index) { int ProceduralAnimation::add_animation(const int category_index) {
@ -235,7 +235,7 @@ PoolVector<int> ProceduralAnimation::get_keyframe_indices(const int category_ind
idxr.set(i, E->key()); idxr.set(i, E->key());
++i; ++i;
} }
return idxr; return idxr;
} }
int ProceduralAnimation::add_keyframe(const int category_index, const int animation_index) { int ProceduralAnimation::add_keyframe(const int category_index, const int animation_index) {
@ -415,7 +415,46 @@ void ProceduralAnimation::set_keyframe_node_position(const int category_index, c
} }
void ProceduralAnimation::initialize() { void ProceduralAnimation::initialize() {
ERR_FAIL_COND(!_animation.is_valid());
for (Map<int, Vector<AnimationKey> *>::Element *E = _animation_data.front(); E; E = E->next()) {
Vector<AnimationKey> *data = E->get();
data->clear();
memdelete(data);
}
_animation_data.clear();
for (Map<int, Category *>::Element *E = _categories.front(); E; E = E->next()) {
Category *category = E->get();
for (Map<int, AnimationEntry *>::Element *A = category->animations.front(); A; A = A->next()) {
AnimationEntry *anim_entry = A->get();
for (Map<int, AnimationKeyFrame *>::Element *K = anim_entry->keyframes.front(); K; K = K->next()) {
int keyframe_index = K->get()->animation_keyframe_index;
if (!_animation_data.has(keyframe_index))
load_keyframe_data(keyframe_index);
}
}
}
}
void ProceduralAnimation::load_keyframe_data(int keyframe_index) {
ERR_FAIL_COND(!_animation.is_valid());
Vector<AnimationKey> *vec = NULL;
if (_animation_data.has(keyframe_index)) {
//reload data
vec = _animation_data[keyframe_index];
vec->clear();
} else {
vec = memnew(Vector<AnimationKey>);
}
//_animation->get_
} }
ProceduralAnimation::ProceduralAnimation() { ProceduralAnimation::ProceduralAnimation() {
@ -427,12 +466,19 @@ ProceduralAnimation::~ProceduralAnimation() {
memdelete(E->get()); memdelete(E->get());
} }
for (Map<int, Vector<AnimationKey> *>::Element *E = _animation_data.front(); E; E = E->next()) {
Vector<AnimationKey> *data = E->get();
data->clear();
memdelete(data);
}
_animation_data.clear();
_categories.clear(); _categories.clear();
_animation.unref(); _animation.unref();
} }
ProceduralAnimation::TransformAnimationKey ProceduralAnimation::_interpolate(const ProceduralAnimation::TransformAnimationKey &p_a, const ProceduralAnimation::TransformAnimationKey &p_b, float p_c) const { ProceduralAnimation::TransformAnimationKey ProceduralAnimation::_interpolate(const ProceduralAnimation::TransformAnimationKey &p_a, const ProceduralAnimation::TransformAnimationKey &p_b, float p_c) const {
TransformAnimationKey ret; TransformAnimationKey ret;
@ -580,8 +626,8 @@ float ProceduralAnimation::_cubic_interpolate(const float &p_pre_a, const float
} }
template <class T> template <class T>
T ProceduralAnimation::_interpolate(const Vector<ProceduralAnimation::AnimationKey > &p_keys, float p_time, ProceduralAnimation::KeyInterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const { T ProceduralAnimation::_interpolate(const Vector<ProceduralAnimation::AnimationKey> &p_keys, float p_time, ProceduralAnimation::KeyInterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const {
/* /*
int len = _find(p_keys, length) + 1; // try to find last key (there may be more past the end) int len = _find(p_keys, length) + 1; // try to find last key (there may be more past the end)
if (len <= 0) { if (len <= 0) {
@ -953,7 +999,6 @@ void ProceduralAnimation::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::VECTOR2, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange)); p_list->push_back(PropertyInfo(Variant::VECTOR2, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange));
p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/start_frame_index", PROPERTY_HINT_NONE, "", property_usange)); p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/start_frame_index", PROPERTY_HINT_NONE, "", property_usange));
for (Map<int, AnimationKeyFrame *>::Element *K = animation->keyframes.front(); K; K = K->next()) { for (Map<int, AnimationKeyFrame *>::Element *K = animation->keyframes.front(); K; K = K->next()) {
p_list->push_back(PropertyInfo(Variant::STRING, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/name", PROPERTY_HINT_NONE, "", property_usange)); p_list->push_back(PropertyInfo(Variant::STRING, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/name", PROPERTY_HINT_NONE, "", property_usange));
p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/animation_keyframe_index", PROPERTY_HINT_NONE, "", property_usange)); p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/animation_keyframe_index", PROPERTY_HINT_NONE, "", property_usange));

View File

@ -26,9 +26,9 @@ SOFTWARE.
#include "core/resource.h" #include "core/resource.h"
#include "core/map.h" #include "core/map.h"
#include "core/vector.h"
#include "core/pool_vector.h"
#include "core/math/vector2.h" #include "core/math/vector2.h"
#include "core/pool_vector.h"
#include "core/vector.h"
#include "scene/resources/animation.h" #include "scene/resources/animation.h"
#include "scene/resources/curve.h" #include "scene/resources/curve.h"
@ -37,11 +37,11 @@ SOFTWARE.
class ProceduralAnimation : public Resource { class ProceduralAnimation : public Resource {
GDCLASS(ProceduralAnimation, Resource); GDCLASS(ProceduralAnimation, Resource);
friend class Animation; friend class Animation;
protected: protected:
enum AnimationKeyTrackType { enum AnimationKeyTrackType {
TYPE_VALUE = Animation::TYPE_VALUE, TYPE_VALUE = Animation::TYPE_VALUE,
TYPE_TRANSFORM = Animation::TYPE_TRANSFORM, TYPE_TRANSFORM = Animation::TYPE_TRANSFORM,
TYPE_METHOD = Animation::TYPE_METHOD, TYPE_METHOD = Animation::TYPE_METHOD,
TYPE_BEZIER = Animation::TYPE_BEZIER, TYPE_BEZIER = Animation::TYPE_BEZIER,
@ -63,7 +63,7 @@ protected:
NodePath path; NodePath path;
bool enabled; bool enabled;
AnimationKey() { AnimationKey() {
type = TYPE_NONE; type = TYPE_NONE;
enabled = true; enabled = true;
} }
@ -72,7 +72,7 @@ protected:
struct VariantAnimationKey : public AnimationKey { struct VariantAnimationKey : public AnimationKey {
Variant value; Variant value;
VariantAnimationKey() { VariantAnimationKey() {
type = TYPE_VALUE; type = TYPE_VALUE;
} }
}; };
@ -82,7 +82,8 @@ protected:
Quat rot; Quat rot;
Vector3 scale; Vector3 scale;
TransformAnimationKey() : AnimationKey() { TransformAnimationKey() :
AnimationKey() {
type = TYPE_TRANSFORM; type = TYPE_TRANSFORM;
} }
}; };
@ -91,7 +92,8 @@ protected:
StringName method; StringName method;
Vector<Variant> params; Vector<Variant> params;
MethodAnimationKey() : AnimationKey() { MethodAnimationKey() :
AnimationKey() {
type = TYPE_METHOD; type = TYPE_METHOD;
} }
}; };
@ -101,7 +103,8 @@ protected:
float start_offset; float start_offset;
float end_offset; float end_offset;
AudioAnimationKey() : AnimationKey() { AudioAnimationKey() :
AnimationKey() {
type = TYPE_AUDIO; type = TYPE_AUDIO;
start_offset = 0; start_offset = 0;
end_offset = 0; end_offset = 0;
@ -116,7 +119,6 @@ protected:
int next_keyframe; int next_keyframe;
Ref<Curve> in_curve; Ref<Curve> in_curve;
Vector2 position; Vector2 position;
Vector<AnimationKey> keys;
AnimationKeyFrame() { AnimationKeyFrame() {
animation_keyframe_index = 0; animation_keyframe_index = 0;
@ -126,7 +128,6 @@ protected:
~AnimationKeyFrame() { ~AnimationKeyFrame() {
in_curve.unref(); in_curve.unref();
keys.clear();
} }
}; };
@ -212,6 +213,7 @@ public:
void set_keyframe_node_position(const int category_index, const int animation_index, const int keyframe_index, const Vector2 &value); void set_keyframe_node_position(const int category_index, const int animation_index, const int keyframe_index, const Vector2 &value);
void initialize(); void initialize();
void load_keyframe_data(int keyframe_index);
ProceduralAnimation(); ProceduralAnimation();
~ProceduralAnimation(); ~ProceduralAnimation();
@ -231,7 +233,7 @@ protected:
_FORCE_INLINE_ float _cubic_interpolate(const float &p_pre_a, const float &p_a, const float &p_b, const float &p_post_b, float p_c) const; _FORCE_INLINE_ float _cubic_interpolate(const float &p_pre_a, const float &p_a, const float &p_b, const float &p_post_b, float p_c) const;
template <class T> template <class T>
_FORCE_INLINE_ T _interpolate(const Vector<AnimationKey > &p_keys, float p_time, KeyInterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const; _FORCE_INLINE_ T _interpolate(const Vector<AnimationKey> &p_keys, float p_time, KeyInterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const;
protected: protected:
bool _set(const StringName &p_name, const Variant &p_value); bool _set(const StringName &p_name, const Variant &p_value);
@ -246,6 +248,7 @@ private:
String _add_editor_category_animation_name; String _add_editor_category_animation_name;
Map<int, Category *> _categories; Map<int, Category *> _categories;
Map<int, Vector<AnimationKey> *> _animation_data;
Ref<Animation> _animation; Ref<Animation> _animation;
Map<int, String> _keyframe_names; Map<int, String> _keyframe_names;