From 33329152232072212be199e49d7bec66b19dd05e Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Thu, 10 Aug 2023 13:29:10 +0100 Subject: [PATCH 1/8] anim-check-root --- crates/bevy_animation/src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 866eb59cda6e8..a48730e66a587 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -119,7 +119,7 @@ impl AnimationClip { /// Whether this animation clip can run on entity with given [`Name`]. pub fn compatible_with(&self, name: &Name) -> bool { - self.paths.keys().all(|path| &path.parts[0] == name) + self.paths.keys().any(|path| &path.parts[0] == name) } } @@ -295,8 +295,16 @@ fn entity_from_path( // PERF: finding the target entity can be optimised let mut current_entity = root; path_cache.resize(path.parts.len(), None); - // Ignore the first name, it is the root node which we already have - for (idx, part) in path.parts.iter().enumerate().skip(1) { + + let mut parts = path.parts.iter().enumerate(); + + // check the first name is the root node which we already have + let root_name = parts.next().unwrap().1; + if names.get(current_entity) != Ok(root_name) { + return None; + } + + for (idx, part) in parts { let mut found = false; let children = children.get(current_entity).ok()?; if let Some(cached) = path_cache[idx] { From c377ee1581d4267780802fbc527859a2e1af183c Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Thu, 10 Aug 2023 13:44:41 +0100 Subject: [PATCH 2/8] dont unwrap --- crates/bevy_animation/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index a48730e66a587..57021c0c572f8 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -299,7 +299,9 @@ fn entity_from_path( let mut parts = path.parts.iter().enumerate(); // check the first name is the root node which we already have - let root_name = parts.next().unwrap().1; + let Some((_, root_name) = parts.next() else { + return None; + }; if names.get(current_entity) != Ok(root_name) { return None; } From 1ef51b9864830eeaa6674de8c543badd8cdd0e07 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Thu, 10 Aug 2023 13:49:16 +0100 Subject: [PATCH 3/8] duh --- crates/bevy_animation/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 57021c0c572f8..bbcfa3f7421f5 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -299,7 +299,7 @@ fn entity_from_path( let mut parts = path.parts.iter().enumerate(); // check the first name is the root node which we already have - let Some((_, root_name) = parts.next() else { + let Some((_, root_name)) = parts.next() else { return None; }; if names.get(current_entity) != Ok(root_name) { From 4ba07d27160ea8ac92606c5a71ad74fcdc7a90d0 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:00:33 +0100 Subject: [PATCH 4/8] add warning --- crates/bevy_animation/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index bbcfa3f7421f5..d3daabeb3342c 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -507,10 +507,12 @@ fn apply_animation( return; } + let mut any_path_found = false; for (path, bone_id) in &animation_clip.paths { let cached_path = &mut animation.path_cache[*bone_id]; let curves = animation_clip.get_curves(*bone_id).unwrap(); let Some(target) = entity_from_path(root, path, children, names, cached_path) else { continue }; + any_path_found = true; // SAFETY: The verify_no_ancestor_player check above ensures that two animation players cannot alias // any of their descendant Transforms. // @@ -597,6 +599,10 @@ fn apply_animation( } } } + + if !any_path_found { + warn!("Animation player on {:?} did not match any entity paths.", root); + } } } From f24ac9e6abeb6016ce58035181a2b74baacf8458 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:27:35 +0100 Subject: [PATCH 5/8] fmt --- crates/bevy_animation/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index d3daabeb3342c..7cf0649a8a864 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -601,7 +601,10 @@ fn apply_animation( } if !any_path_found { - warn!("Animation player on {:?} did not match any entity paths.", root); + warn!( + "Animation player on {:?} did not match any entity paths.", + root + ); } } } From 0acc31ee51bc33eea1c2170dde6e17b4d579a0f0 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:31:57 +0100 Subject: [PATCH 6/8] Update crates/bevy_animation/src/lib.rs Co-authored-by: Nicola Papale --- crates/bevy_animation/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 7cf0649a8a864..b3e77e6f5e05a 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -601,10 +601,7 @@ fn apply_animation( } if !any_path_found { - warn!( - "Animation player on {:?} did not match any entity paths.", - root - ); + warn!("Animation player on {root:?} did not match any entity paths."); } } } From 6966b9bd8362702ca12a700de0ab88f8a6287617 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sat, 26 Aug 2023 15:20:55 +0100 Subject: [PATCH 7/8] let-else fmt = conflict apparently --- crates/bevy_animation/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 7f50692369f23..333ed93ad8cdf 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -517,7 +517,9 @@ fn apply_animation( for (path, bone_id) in &animation_clip.paths { let cached_path = &mut animation.path_cache[*bone_id]; let curves = animation_clip.get_curves(*bone_id).unwrap(); - let Some(target) = entity_from_path(root, path, children, names, cached_path) else { continue }; + let Some(target) = entity_from_path(root, path, children, names, cached_path) else { + continue + }; any_path_found = true; // SAFETY: The verify_no_ancestor_player check above ensures that two animation players cannot alias // any of their descendant Transforms. From 064621855d3bbe9878b54c69797e5925b59c9fae Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sat, 26 Aug 2023 15:38:21 +0100 Subject: [PATCH 8/8] fmt fmt --- crates/bevy_animation/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 087c1b6d85986..6aca532f669b0 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -521,8 +521,8 @@ fn apply_animation( for (path, bone_id) in &animation_clip.paths { let cached_path = &mut animation.path_cache[*bone_id]; let curves = animation_clip.get_curves(*bone_id).unwrap(); - let Some(target) = entity_from_path(root, path, children, names, cached_path) else { - continue + let Some(target) = entity_from_path(root, path, children, names, cached_path) else { + continue; }; any_path_found = true; // SAFETY: The verify_no_ancestor_player check above ensures that two animation players cannot alias