diff --git a/crates/bevy_gltf_blueprints/src/animation.rs b/crates/bevy_gltf_blueprints/src/animation.rs index 70fb5a8..b7472d5 100644 --- a/crates/bevy_gltf_blueprints/src/animation.rs +++ b/crates/bevy_gltf_blueprints/src/animation.rs @@ -41,7 +41,7 @@ pub struct AnimationInfo { } /// Stores information about animations, to make things a bit easier api wise: -/// these components are automatically inserted by gltf_auto_export on entities that have animations +/// these components are automatically inserted by `gltf_auto_export` on entities that have animations #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] pub struct AnimationInfos { @@ -56,7 +56,7 @@ pub struct AnimationMarker { } /// Stores information about animation markers: practical for adding things like triggering events at specific keyframes etc -/// it is essentiall a hashmap of AnimationName => HashMap +/// it is essentiall a hashmap of `AnimationName` => `HashMap`<`FrameNumber`, Vec of marker names> #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] pub struct AnimationMarkers(pub HashMap>>); @@ -115,23 +115,23 @@ pub fn trigger_instance_animation_markers_events( let time_in_animation = animation_player.elapsed() - (animation_player.completions() as f32) * animation_length_seconds; let frame_seconds = - (animation_length_frames as f32 / animation_length_seconds) * time_in_animation; + (animation_length_frames / animation_length_seconds) * time_in_animation; let frame = frame_seconds as u32; let matching_animation_marker = &markers.0[animation_name]; if matching_animation_marker.contains_key(&frame) { let matching_markers_per_frame = matching_animation_marker.get(&frame).unwrap(); - let foo = animation_length_seconds - time_in_animation; - println!("foo {}", foo); + // let timediff = animation_length_seconds - time_in_animation; + // println!("timediff {}", timediff); // println!("FOUND A MARKER {:?} at frame {}", matching_markers_per_frame, frame); // emit an event AnimationMarkerReached(entity, animation_name, frame, marker_name) // FIXME: problem, this can fire multiple times in a row, depending on animation length , speed , etc for marker in matching_markers_per_frame { animation_marker_events.send(AnimationMarkerReached { - entity: entity, + entity, animation_name: animation_name.clone(), - frame: frame, + frame, marker_name: marker.clone(), }); } @@ -199,9 +199,9 @@ pub fn trigger_blueprint_animation_markers_events( if diff < 0.1 { for marker in matching_markers_per_frame { animation_marker_events.send(AnimationMarkerReached { - entity: entity, + entity, animation_name: animation_name.clone(), - frame: frame, + frame, marker_name: marker.clone(), }); } diff --git a/examples/bevy_gltf_blueprints/animation/src/game/in_game.rs b/examples/bevy_gltf_blueprints/animation/src/game/in_game.rs index 454ce27..5777bba 100644 --- a/examples/bevy_gltf_blueprints/animation/src/game/in_game.rs +++ b/examples/bevy_gltf_blueprints/animation/src/game/in_game.rs @@ -8,7 +8,7 @@ use std::time::Duration; use bevy::prelude::*; use bevy_gltf_blueprints::{ - AnimationPlayerLink, Animations, BluePrintBundle, BlueprintName, GameWorldTag, + BlueprintAnimationPlayerLink, BlueprintAnimations, BluePrintBundle, BlueprintName, GameWorldTag, }; use super::{Fox, Robot}; @@ -90,7 +90,7 @@ pub fn spawn_test( // example of changing animation of entities based on proximity to the player, for "fox" entities (Tag component) pub fn animation_change_on_proximity_foxes( players: Query<&GlobalTransform, With>, - animated_foxes: Query<(&GlobalTransform, &AnimationPlayerLink, &Animations), With>, + animated_foxes: Query<(&GlobalTransform, &BlueprintAnimationPlayerLink, &BlueprintAnimations), With>, mut animation_players: Query<&mut AnimationPlayer>, ) { @@ -126,7 +126,7 @@ pub fn animation_change_on_proximity_foxes( // example of changing animation of entities based on proximity to the player, this time for the "robot" entities (Tag component) pub fn animation_change_on_proximity_robots( players: Query<&GlobalTransform, With>, - animated_robots: Query<(&GlobalTransform, &AnimationPlayerLink, &Animations), With>, + animated_robots: Query<(&GlobalTransform, &BlueprintAnimationPlayerLink, &BlueprintAnimations), With>, mut animation_players: Query<&mut AnimationPlayer>, ) { @@ -162,13 +162,13 @@ pub fn animation_change_on_proximity_robots( } pub fn animation_control( - animated_enemies: Query<(&AnimationPlayerLink, &Animations), With>, - animated_foxes: Query<(&AnimationPlayerLink, &Animations), With>, + animated_enemies: Query<(&BlueprintAnimationPlayerLink, &BlueprintAnimations), With>, + animated_foxes: Query<(&BlueprintAnimationPlayerLink, &BlueprintAnimations), With>, mut animation_players: Query<&mut AnimationPlayer>, keycode: Res>, - // mut entities_with_animations : Query<(&mut AnimationPlayer, &mut Animations)>, + // mut entities_with_animations : Query<(&mut AnimationPlayer, &mut BlueprintAnimations)>, ) { // robots if keycode.just_pressed(KeyCode::KeyB) { diff --git a/testing/bevy_example/src/game/animation.rs b/testing/bevy_example/src/game/animation.rs index 0bdab6a..3b3ea69 100644 --- a/testing/bevy_example/src/game/animation.rs +++ b/testing/bevy_example/src/game/animation.rs @@ -34,6 +34,7 @@ pub fn setup_main_scene_animations(asset_server: Res, mut commands: commands.insert_resource(AnimTest(asset_server.load("models/World.glb"))); } +#[allow(clippy::type_complexity)] pub fn animations( added_animation_players: Query<(Entity, &Name, &AnimationPlayer)>, added_animation_infos: Query<(Entity, &Name, &AnimationInfos), Added>, @@ -71,10 +72,10 @@ pub fn animations( // info!("{:?} is an ancestor of {:?}", ancestor, player); } } - println!(""); } } +#[allow(clippy::type_complexity)] pub fn play_animations( animated_marker1: Query< (&SceneAnimationPlayerLink, &SceneAnimations), diff --git a/testing/bevy_example/src/game/mod.rs b/testing/bevy_example/src/game/mod.rs index c953270..fa46bc6 100644 --- a/testing/bevy_example/src/game/mod.rs +++ b/testing/bevy_example/src/game/mod.rs @@ -7,7 +7,7 @@ use std::{collections::HashMap, fs, time::Duration}; use bevy_gltf_blueprints::{ BlueprintAnimationPlayerLink, BlueprintName, BlueprintsList, - GltfBlueprintsSet, + GltfBlueprintsSet, SceneAnimations, }; use bevy::{ @@ -26,18 +26,20 @@ fn start_game(mut next_app_state: ResMut>) { // if the export from Blender worked correctly, we should have a blueprints_list // if the export from Blender worked correctly, we should have the correct tree of entities #[allow(clippy::too_many_arguments)] +#[allow(clippy::type_complexity)] fn validate_export( parents: Query<&Parent>, children: Query<&Children>, names: Query<&Name>, blueprints: Query<(Entity, &Name, &BlueprintName)>, animation_player_links: Query<(Entity, &BlueprintAnimationPlayerLink)>, + scene_animations: Query<(Entity, &SceneAnimations)>, empties_candidates: Query<(Entity, &Name, &GlobalTransform)>, blueprints_list: Query<(Entity, &BlueprintsList)>, root: Query<(Entity, &Name, &Children), (Without, With)>, ) { - let animations_found = !animation_player_links.is_empty(); + let animations_found = !animation_player_links.is_empty() && scene_animations.into_iter().len() == 4; let mut nested_blueprint_found = false; for (entity, name, blueprint_name) in blueprints.iter() {