diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 8e74f5ddb15ba..c4d54d7f5fa34 100755 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -1102,7 +1102,7 @@ pub fn animate_targets( }; match animation_graph_node.node_type { - AnimationNodeType::Blend | AnimationNodeType::Add => { + AnimationNodeType::Blend => { // This is a blend node. for edge_index in threaded_animation_graph.sorted_edge_ranges [animation_graph_node_index.index()] @@ -1123,6 +1123,27 @@ pub fn animate_targets( } } + AnimationNodeType::Add => { + // This is an additive blend node. + for edge_index in threaded_animation_graph.sorted_edge_ranges + [animation_graph_node_index.index()] + .clone() + { + if let Err(err) = evaluation_state + .add_all(threaded_animation_graph.sorted_edges[edge_index as usize]) + { + warn!("Failed to blend animation: {:?}", err); + } + } + + if let Err(err) = evaluation_state.push_blend_register_all( + animation_graph_node.weight, + animation_graph_node_index, + ) { + warn!("Animation blending failed: {:?}", err); + } + } + AnimationNodeType::Clip(ref animation_clip_handle) => { // This is a clip node. let Some(active_animation) = animation_player @@ -1175,7 +1196,7 @@ pub fn animate_targets( continue; }; - let weight = active_animation.weight; + let weight = active_animation.weight * animation_graph_node.weight; let seek_time = active_animation.seek_time; for curve in curves { @@ -1323,6 +1344,20 @@ impl AnimationEvaluationState { Ok(()) } + /// Calls [`AnimationCurveEvaluator::add`] on all curve evaluator types + /// that we've been building up for a single target. + /// + /// The given `node_index` is the node that we're evaluating. + fn add_all(&mut self, node_index: AnimationNodeIndex) -> Result<(), AnimationEvaluationError> { + for curve_evaluator_type in self.current_curve_evaluator_types.keys() { + self.curve_evaluators + .get_mut(curve_evaluator_type) + .unwrap() + .add(node_index)?; + } + Ok(()) + } + /// Calls [`AnimationCurveEvaluator::push_blend_register`] on all curve /// evaluator types that we've been building up for a single target. ///