Skip to content

Commit d3657a0

Browse files
authored
Fixes to animation graph evaluation (#15689)
# Objective Fix a couple of substantial errors found during the development of #15665: - `AnimationCurveEvaluator::add` was secretly unreachable. In other words, additive blending never actually occurred. - Weights from the animation graph nodes were ignored, and only `ActiveAnimation`'s weights were used. ## Solution Made additive blending reachable and included the graph node weight in the weight of the stack elements appended in the curve application loop of `animate_targets`. ## Testing Tested on existing examples and on the new example added in #15665.
1 parent 280f77a commit d3657a0

File tree

1 file changed

+37
-2
lines changed
  • crates/bevy_animation/src

1 file changed

+37
-2
lines changed

crates/bevy_animation/src/lib.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ pub fn animate_targets(
11021102
};
11031103

11041104
match animation_graph_node.node_type {
1105-
AnimationNodeType::Blend | AnimationNodeType::Add => {
1105+
AnimationNodeType::Blend => {
11061106
// This is a blend node.
11071107
for edge_index in threaded_animation_graph.sorted_edge_ranges
11081108
[animation_graph_node_index.index()]
@@ -1123,6 +1123,27 @@ pub fn animate_targets(
11231123
}
11241124
}
11251125

1126+
AnimationNodeType::Add => {
1127+
// This is an additive blend node.
1128+
for edge_index in threaded_animation_graph.sorted_edge_ranges
1129+
[animation_graph_node_index.index()]
1130+
.clone()
1131+
{
1132+
if let Err(err) = evaluation_state
1133+
.add_all(threaded_animation_graph.sorted_edges[edge_index as usize])
1134+
{
1135+
warn!("Failed to blend animation: {:?}", err);
1136+
}
1137+
}
1138+
1139+
if let Err(err) = evaluation_state.push_blend_register_all(
1140+
animation_graph_node.weight,
1141+
animation_graph_node_index,
1142+
) {
1143+
warn!("Animation blending failed: {:?}", err);
1144+
}
1145+
}
1146+
11261147
AnimationNodeType::Clip(ref animation_clip_handle) => {
11271148
// This is a clip node.
11281149
let Some(active_animation) = animation_player
@@ -1175,7 +1196,7 @@ pub fn animate_targets(
11751196
continue;
11761197
};
11771198

1178-
let weight = active_animation.weight;
1199+
let weight = active_animation.weight * animation_graph_node.weight;
11791200
let seek_time = active_animation.seek_time;
11801201

11811202
for curve in curves {
@@ -1323,6 +1344,20 @@ impl AnimationEvaluationState {
13231344
Ok(())
13241345
}
13251346

1347+
/// Calls [`AnimationCurveEvaluator::add`] on all curve evaluator types
1348+
/// that we've been building up for a single target.
1349+
///
1350+
/// The given `node_index` is the node that we're evaluating.
1351+
fn add_all(&mut self, node_index: AnimationNodeIndex) -> Result<(), AnimationEvaluationError> {
1352+
for curve_evaluator_type in self.current_curve_evaluator_types.keys() {
1353+
self.curve_evaluators
1354+
.get_mut(curve_evaluator_type)
1355+
.unwrap()
1356+
.add(node_index)?;
1357+
}
1358+
Ok(())
1359+
}
1360+
13261361
/// Calls [`AnimationCurveEvaluator::push_blend_register`] on all curve
13271362
/// evaluator types that we've been building up for a single target.
13281363
///

0 commit comments

Comments
 (0)