diff --git a/src/visual.rs b/src/visual.rs index 7358753..c966385 100644 --- a/src/visual.rs +++ b/src/visual.rs @@ -12,6 +12,7 @@ use crate::prelude::*; use bevy::prelude::*; +use std::time::Duration; pub struct VisualPlugin; @@ -57,13 +58,36 @@ pub struct SpawnEffectEvent { pub duration: f64, } -pub fn setup(settings: Res, mut ew_effect: EventWriter) { +#[derive(Resource)] +pub struct SuitAnimation { + index: AnimationNodeIndex, + graph: Handle +} + +pub fn setup( + settings: Res, + asset_server: Res, + mut commands: Commands, + mut ew_effect: EventWriter, + mut graphs: ResMut>, +) { if !settings.dev_mode { ew_effect.send(SpawnEffectEvent { class: Effects::FadeIn(Color::BLACK), duration: 4.0, }); } + + let mut graph = AnimationGraph::new(); + let index = graph.add_clip( + asset_server.load(GltfAssetLabel::Animation(0).from_asset("models/suit_v2/suit_v2.glb")), + 1.0, + graph.root, + ); + + let graph = graphs.add(graph); + commands.insert_resource(SuitAnimation { index, graph }); + // Blackout disabled for now // commands.spawn(( // BlackOutOverlay, @@ -157,12 +181,17 @@ pub fn update_fadeout( } fn play_animations( - mut players: Query<&mut AnimationPlayer, Added>, - asset_server: Res, + mut commands: Commands, + mut players: Query<(Entity, &mut AnimationPlayer), Added>, + suit_animation: Res, ) { - for mut player in &mut players { - let animation = asset_server.load("models/suit_v2/suit_v2.glb#Animation0"); - player.play(animation.clone()).repeat(); + for (entity, mut player) in &mut players { + let mut transitions = AnimationTransitions::new(); + transitions + .play(&mut player, suit_animation.index, Duration::ZERO) + .repeat(); + commands.entity(entity).insert(suit_animation.graph.clone()).insert(transitions); + //player.play(suit_ani_node_index.0).repeat(); } }