Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linear interpolation not working with mixed (int/float) keyframes #86046

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions scene/resources/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5485,7 +5485,7 @@ Variant Animation::cast_to_blendwise(const Variant p_value) {
switch (p_value.get_type()) {
case Variant::BOOL:
case Variant::INT: {
return p_value.operator real_t();
return p_value.operator double();
} break;
case Variant::STRING:
case Variant::STRING_NAME: {
Expand Down Expand Up @@ -5521,7 +5521,7 @@ Variant Animation::cast_from_blendwise(const Variant p_value, const Variant::Typ
return p_value.operator real_t() >= 0.5;
} break;
case Variant::INT: {
return (int)Math::round(p_value.operator real_t());
return (int64_t)Math::round(p_value.operator double());
} break;
case Variant::STRING: {
return array_to_string(p_value);
Expand Down Expand Up @@ -5594,16 +5594,20 @@ Variant Animation::array_to_string(const Variant p_value) {
}

Variant Animation::add_variant(const Variant &a, const Variant &b) {
if (a.get_type() != b.get_type() && !a.is_array()) {
return a;
if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) {
return add_variant(cast_to_blendwise(a), cast_to_blendwise(b));
} else if (!a.is_array()) {
return a;
}
}

switch (a.get_type()) {
case Variant::NIL: {
return Variant();
} break;
case Variant::FLOAT: {
return (a.operator real_t()) + (b.operator real_t());
return (a.operator double()) + (b.operator double());
} break;
case Variant::RECT2: {
const Rect2 ra = a.operator Rect2();
Expand Down Expand Up @@ -5704,16 +5708,20 @@ Variant Animation::add_variant(const Variant &a, const Variant &b) {
}

Variant Animation::subtract_variant(const Variant &a, const Variant &b) {
if (a.get_type() != b.get_type() && !a.is_array()) {
return a;
if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) {
return subtract_variant(cast_to_blendwise(a), cast_to_blendwise(b));
} else if (!a.is_array()) {
return a;
}
}

switch (a.get_type()) {
case Variant::NIL: {
return Variant();
} break;
case Variant::FLOAT: {
return (a.operator real_t()) - (b.operator real_t());
return (a.operator double()) - (b.operator double());
} break;
case Variant::RECT2: {
const Rect2 ra = a.operator Rect2();
Expand Down Expand Up @@ -5814,16 +5822,20 @@ Variant Animation::subtract_variant(const Variant &a, const Variant &b) {
}

Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) {
if (a.get_type() != b.get_type() && !a.is_array()) {
return a;
if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) {
return blend_variant(cast_to_blendwise(a), cast_to_blendwise(b), c);
} else if (!a.is_array()) {
return a;
}
}

switch (a.get_type()) {
case Variant::NIL: {
return Variant();
} break;
case Variant::FLOAT: {
return (a.operator real_t()) + (b.operator real_t()) * c;
return (a.operator double()) + (b.operator double()) * c;
} break;
case Variant::VECTOR2: {
return (a.operator Vector2()) + (b.operator Vector2()) * c;
Expand Down Expand Up @@ -5947,17 +5959,21 @@ Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) {
}

Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float c, bool p_snap_array_element) {
if (a.get_type() != b.get_type() && !a.is_array()) {
return a;
if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) {
return interpolate_variant(cast_to_blendwise(a), cast_to_blendwise(b), c);
AThousandShips marked this conversation as resolved.
Show resolved Hide resolved
} else if (!a.is_array()) {
return a;
}
}

switch (a.get_type()) {
case Variant::NIL: {
return Variant();
} break;
case Variant::FLOAT: {
const real_t va = a.operator real_t();
return va + ((b.operator real_t()) - va) * c;
const double va = a.operator double();
return va + ((b.operator double()) - va) * c;
} break;
case Variant::VECTOR2: {
return (a.operator Vector2()).lerp(b.operator Vector2(), c);
Expand Down
Loading