From 788aa5a10e023bdb7424e50310f63b90cf73bb5b Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Fri, 26 Jan 2024 19:30:08 -0500 Subject: [PATCH] fix: bug fixes, demo updates --- demo/src/main.rs | 111 ++++++++++++++++++++++++------------ src/animation_controller.rs | 50 ++++++++++------ 2 files changed, 106 insertions(+), 55 deletions(-) diff --git a/demo/src/main.rs b/demo/src/main.rs index f9d51cf..01e6f9c 100644 --- a/demo/src/main.rs +++ b/demo/src/main.rs @@ -1,9 +1,9 @@ -use bevy::{asset::AssetMetaCheck, prelude::*, render::color}; +use bevy::{asset::AssetMetaCheck, prelude::*}; use bevy_egui::{egui, EguiContexts, EguiPlugin}; use bevy_vello::{ - debug::DebugVisualizations, AnimationDirection, AnimationLoopBehavior, AnimationState, - AnimationTransition, ColorPaletteSwap, LottiePlayer, PlaybackSettings, Vector, VelloAsset, - VelloAssetBundle, VelloPlugin, VelloText, VelloTextBundle, + debug::DebugVisualizations, vello_svg::usvg::strict_num::Ulps, AnimationDirection, + AnimationState, AnimationTransition, ColorPaletteSwap, LottiePlayer, PlaybackSettings, Vector, + VelloAsset, VelloAssetBundle, VelloPlugin, VelloText, VelloTextBundle, }; fn main() { @@ -25,28 +25,29 @@ fn setup_vector_graphics(mut commands: Commands, asset_server: ResMut bool { + self.playing + } + + pub fn is_paused(&self) -> bool { + self.stopped || !self.playing + } + + pub fn is_stopped(&self) -> bool { + self.stopped + } } #[derive(Debug, Clone)] @@ -216,7 +226,7 @@ pub struct AnimationControllerPlugin; impl Plugin for AnimationControllerPlugin { fn build(&self, app: &mut bevy::prelude::App) { app.add_systems( - Update, + PostUpdate, ( systems::apply_player_inputs, systems::advance_playheads, @@ -257,7 +267,7 @@ pub mod systems { continue; }; - if let Some(direction) = player.pending_direction { + if let Some(direction) = player.pending_direction.take() { for playback_settings in player .states .values_mut() @@ -267,7 +277,7 @@ pub mod systems { playback_settings.direction = direction; } } - if let Some(intermission) = player.pending_intermission { + if let Some(intermission) = player.pending_intermission.take() { // Adjust to the new intermission let loops_played = *rendered_frames / (composition.frames.end - composition.frames.start @@ -285,7 +295,7 @@ pub mod systems { playback_settings.intermission = intermission; } } - if let Some(loop_behavior) = player.pending_loop_behavior { + if let Some(loop_behavior) = player.pending_loop_behavior.take() { // Apply for playback_settings in player .states @@ -296,7 +306,7 @@ pub mod systems { playback_settings.looping = loop_behavior; } } - if let Some(play_mode) = player.pending_play_mode { + if let Some(play_mode) = player.pending_play_mode.take() { // Apply for playback_settings in player .states @@ -307,19 +317,23 @@ pub mod systems { playback_settings.play_mode = play_mode; } } - if let Some(seek_frame) = player.pending_seek_frame { + if let Some(seek_frame) = player.pending_seek_frame.take() { + let start_frame = playback_settings + .segments + .start + .max(composition.frames.start); + let end_frame = playback_settings.segments.end.min(composition.frames.end); + // FIXME: This should keep the correct number of loops. This resets the loops played! // Bound the seek frame - let seek_frame = seek_frame.clamp(composition.frames.start, composition.frames.end); - // Get the frame local to this loop - let local_frame = *rendered_frames - % (composition.frames.end - composition.frames.start - + playback_settings.intermission); - // Bound the seek frame within the composition - let local_seek_frame = - seek_frame % (composition.frames.end - composition.frames.start); - *rendered_frames = *rendered_frames - local_frame + local_seek_frame; + let seek_frame = match playback_settings.direction { + AnimationDirection::Normal => seek_frame.clamp(start_frame, end_frame), + AnimationDirection::Reverse => { + end_frame - seek_frame.clamp(start_frame, end_frame) + } + }; + *rendered_frames = seek_frame; } - if let Some(speed) = player.pending_speed { + if let Some(speed) = player.pending_speed.take() { // Apply for playback_settings in player .states