Merge pull request #19774 from karroffel/blendspace-1d-sync-fix

ensure BlendSpace1D syncs animations
This commit is contained in:
Rémi Verschelde 2018-06-26 09:59:26 +02:00 committed by GitHub
commit e574c7cedc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -187,6 +187,8 @@ float AnimationNodeBlendSpace1D::process(float p_time, bool p_seek) {
return blend_node(blend_points[0].node, p_time, p_seek, 1.0, FILTER_IGNORE, false); return blend_node(blend_points[0].node, p_time, p_seek, 1.0, FILTER_IGNORE, false);
} }
float weights[MAX_BLEND_POINTS] = {};
int point_lower = -1; int point_lower = -1;
float pos_lower = 0.0; float pos_lower = 0.0;
int point_higher = -1; int point_higher = -1;
@ -216,18 +218,21 @@ float AnimationNodeBlendSpace1D::process(float p_time, bool p_seek) {
} }
} }
// fill in weights
if (point_lower == -1) { if (point_lower == -1) {
// we are on the left side, no other point to the left // we are on the left side, no other point to the left
// we just play the next point. // we just play the next point.
return blend_node(blend_points[point_higher].node, p_time, p_seek, 1.0, FILTER_IGNORE, false); weights[point_higher] = 1.0;
} else if (point_higher == -1) { } else if (point_higher == -1) {
// we are on the right side, no other point to the right // we are on the right side, no other point to the right
// we just play the previous point // we just play the previous point
return blend_node(blend_points[point_lower].node, p_time, p_seek, 1.0, FILTER_IGNORE, false);
weights[point_lower] = 1.0;
} else { } else {
//w we are between two points. // we are between two points.
// figure out weights, then blend the animations // figure out weights, then blend the animations
float distance_between_points = pos_higher - pos_lower; float distance_between_points = pos_higher - pos_lower;
@ -239,14 +244,21 @@ float AnimationNodeBlendSpace1D::process(float p_time, bool p_seek) {
float blend_lower = 1.0 - blend_percentage; float blend_lower = 1.0 - blend_percentage;
float blend_higher = blend_percentage; float blend_higher = blend_percentage;
float time_remaining_lower = 0.0; weights[point_lower] = blend_lower;
float time_remaining_higher = 0.0; weights[point_higher] = blend_higher;
time_remaining_lower = blend_node(blend_points[point_lower].node, p_time, p_seek, blend_lower, FILTER_IGNORE, false);
time_remaining_higher = blend_node(blend_points[point_higher].node, p_time, p_seek, blend_higher, FILTER_IGNORE, false);
return MAX(time_remaining_lower, time_remaining_higher);
} }
// actually blend the animations now
float max_time_remaining = 0.0;
for (int i = 0; i < blend_points_used; i++) {
float remaining = blend_node(blend_points[i].node, p_time, p_seek, weights[i], FILTER_IGNORE, false);
max_time_remaining = MAX(max_time_remaining, remaining);
}
return max_time_remaining;
} }
String AnimationNodeBlendSpace1D::get_caption() const { String AnimationNodeBlendSpace1D::get_caption() const {