summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/variant.cpp15
-rw-r--r--core/variant.h2
-rw-r--r--core/variant_op.cpp53
-rw-r--r--scene/animation/animation_tree_player.cpp11
4 files changed, 77 insertions, 4 deletions
diff --git a/core/variant.cpp b/core/variant.cpp
index 3bd8d80528..1fdbc9f753 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1116,6 +1116,21 @@ void Variant::reference(const Variant& p_variant) {
}
+void Variant::zero() {
+ switch(type) {
+ case NIL: break;
+ case BOOL: this->_data._bool = false; break;
+ case INT: this->_data._int = 0; break;
+ case REAL: this->_data._real = 0; break;
+ case VECTOR2: *reinterpret_cast<Vector2*>(this->_data._mem) = Vector2(); break;
+ case RECT2: *reinterpret_cast<Rect2*>(this->_data._mem) = Rect2(); break;
+ case VECTOR3: *reinterpret_cast<Vector3*>(this->_data._mem) = Vector3(); break;
+ case PLANE: *reinterpret_cast<Plane*>(this->_data._mem) = Plane(); break;
+ case QUAT: *reinterpret_cast<Quat*>(this->_data._mem) = Quat(); break;
+ case COLOR: *reinterpret_cast<Color*>(this->_data._mem) = Color(); break;
+ default: this->clear(); break;
+ }
+}
void Variant::clear() {
switch(type) {
diff --git a/core/variant.h b/core/variant.h
index b58c781bdd..d8813c4937 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -372,6 +372,8 @@ public:
return res;
}
+ void zero();
+ static void blend(const Variant& a, const Variant& b, float c,Variant &r_dst);
static void interpolate(const Variant& a, const Variant& b, float c,Variant &r_dst);
struct CallError {
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 204a00e1d5..5463e1cabb 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -3431,6 +3431,59 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
}
+void Variant::blend(const Variant& a, const Variant& b, float c, Variant &r_dst) {
+ if (a.type!=b.type) {
+ if(a.is_num() && b.is_num()) {
+ real_t va=a;
+ real_t vb=b;
+ r_dst=va + vb * c;
+ } else {
+ r_dst=a;
+ }
+ return;
+ }
+
+ switch(a.type) {
+ case NIL: { r_dst=Variant(); } return;
+ case INT:{
+ int va=a._data._int;
+ int vb=b._data._int;
+ r_dst=int(va + vb * c + 0.5);
+ } return;
+ case REAL:{
+ double ra=a._data._real;
+ double rb=b._data._real;
+ r_dst=ra + rb * c;
+ } return;
+ case VECTOR2:{ r_dst=*reinterpret_cast<const Vector2*>(a._data._mem)+*reinterpret_cast<const Vector2*>(b._data._mem)*c; } return;
+ case RECT2:{
+ const Rect2 *ra = reinterpret_cast<const Rect2*>(a._data._mem);
+ const Rect2 *rb = reinterpret_cast<const Rect2*>(b._data._mem);
+ r_dst=Rect2(ra->pos + rb->pos * c, ra->size + rb->size * c);
+ } return;
+ case VECTOR3:{ r_dst=*reinterpret_cast<const Vector2*>(a._data._mem)+*reinterpret_cast<const Vector2*>(b._data._mem)*c; } return;
+ case _AABB:{
+ const AABB *ra = reinterpret_cast<const AABB*>(a._data._mem);
+ const AABB *rb = reinterpret_cast<const AABB*>(b._data._mem);
+ r_dst=AABB(ra->pos + rb->pos * c, ra->size + rb->size * c);
+ } return;
+ case COLOR:{
+ const Color *ca = reinterpret_cast<const Color*>(a._data._mem);
+ const Color *cb = reinterpret_cast<const Color*>(b._data._mem);
+ float r = ca->r + cb->r * c;
+ float g = ca->g + cb->g * c;
+ float b = ca->b + cb->b * c;
+ float a = ca->a + cb->a * c;
+ r = r > 1.0 ? 1.0 : r;
+ g = g > 1.0 ? 1.0 : g;
+ b = b > 1.0 ? 1.0 : b;
+ a = a > 1.0 ? 1.0 : a;
+ r_dst=Color(r, g, b, a);
+ } return;
+ default:{ r_dst = c<0.5 ? a : b; } return;
+ }
+}
+
void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r_dst) {
if (a.type!=b.type) {
diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp
index 77d9f77bb5..2594d65ae6 100644
--- a/scene/animation/animation_tree_player.cpp
+++ b/scene/animation/animation_tree_player.cpp
@@ -768,6 +768,10 @@ void AnimationTreePlayer::_process_animation(float p_delta) {
t.scale.x=0;
t.scale.y=0;
t.scale.z=0;
+
+ Variant value = t.node->get(t.property);
+ value.zero();
+ t.node->set(t.property, value);
}
@@ -777,11 +781,9 @@ void AnimationTreePlayer::_process_animation(float p_delta) {
Quat empty_rot;
- int total = 0;
while(anim_list) {
if (!anim_list->animation.is_null() && !anim_list->skip) {
- ++total;
//check if animation is meaningful
Animation *a = anim_list->animation.operator->();
@@ -816,8 +818,9 @@ void AnimationTreePlayer::_process_animation(float p_delta) {
case Animation::TYPE_VALUE: { ///< Set a value in a property, can be interpolated.
if (a->value_track_is_continuous(tr.local_track)) {
- Variant value = a->value_track_interpolate(tr.local_track,anim_list->time);
- tr.track->node->set(tr.track->property,value);
+ Variant blended, value = a->value_track_interpolate(tr.local_track,anim_list->time);
+ Variant::blend(tr.track->node->get(tr.track->property),value,blend,blended);
+ tr.track->node->set(tr.track->property,blended);
} else {
List<int> indices;