diff --git a/assets/models/Martian Chess.glb b/assets/models/Martian Chess.glb index 4646b4a..cc542a5 100644 --- a/assets/models/Martian Chess.glb +++ b/assets/models/Martian Chess.glb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:49f948fda540e9c102acd28809dc86a90a2ac546d9064d9604b751b4798341c9 -size 56198272 +oid sha256:f42782476e71492478366b77ebe1c7b4880c10e1774cf605d5b3231d9b90a3a0 +size 56198208 diff --git a/src/display3d.rs b/src/display3d.rs index 16eb070..1d403ae 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -237,12 +237,12 @@ fn initialize(mut commands: Commands, board: Res, assets: Res>, >, // Only process newly created pieces (we do not delete pieces at runtime) - query: Query, Added)>, + query: Query<&Dissolvable, Added>, // Children of pieces are the actual meshes that need materials parents: Query<&Parent>, // Used to create DissolveMaterial @@ -1214,8 +1214,16 @@ fn setup_dissolve_materials( .for_each(|(child, std_handle, name)| { info!("Setting up dissolve material for {:?} {:?}", name, child); + // Get dissolvable data for percentage start + let dissolvable = query + .iter_many(parents.iter_ancestors(child)) + .next() + .expect("Dissolving data"); + // Extension we will add to existing gltf-sourced materials - let extension = DissolveExtension { percentage: 1.0 }; + let extension = DissolveExtension { + percentage: dissolvable.start, + }; // Base material we will extend for the duration of the dissolve effect let mut base: StandardMaterial = standard_materials .get(std_handle) @@ -1242,8 +1250,11 @@ fn setup_dissolve_materials( /// 3. Play the same "captured" animation in reverse /// The animation is like a 'beam me up scotty' sorta thing. fn capture_piece( - events: Query, Added)>, - mut query: Query<(&mut Transform, &Side), (With, With)>, + events: Query<(Entity, &Dissolvable), (With, Added)>, + mut query: Query< + (&mut Transform, &Side, &Dissolvable), + (With, With), + >, dissolving: Query>, mut state: Local>, mut commands: Commands, @@ -1252,9 +1263,11 @@ fn capture_piece( match *state { // State is None, so we need to initiate the animation None => { - *state = events.iter().next().map(|entity| { + *state = events.iter().next().map(|(entity, dissolvable)| { // Insert the "Dissolving::Out" tag on the entity we want to fade out - commands.entity(entity).insert(Dissolving::Out(3.0)); + commands + .entity(entity) + .insert(Dissolving::Out(dissolvable.duration)); // Set the next state to start fading out game::CaptureFlow::FadeOut(entity) @@ -1273,7 +1286,7 @@ fn capture_piece( } } game::CaptureFlow::Store(entity) => { - let (mut t, side) = query + let (mut t, side, dissolvable) = query .get_mut(entity) .expect("Visibility and Transform of captured piece"); @@ -1287,7 +1300,9 @@ fn capture_piece( t.translation = capture_translation(side, score.captures(!*side).saturating_sub(1)); - commands.entity(entity).insert(Dissolving::In(3.0)); + commands + .entity(entity) + .insert(Dissolving::In(dissolvable.duration)); *state = s.next(); } @@ -1351,15 +1366,25 @@ fn monitor_animations( }); } -fn intro_title_dissolve(mut query: Query>, mut commands: Commands) { - query.iter_mut().for_each(|entity| { - commands.entity(entity).insert(Dissolving::In(3.0)); +fn intro_title_dissolve( + mut query: Query<(Entity, &Dissolvable), With>, + mut commands: Commands, +) { + query.iter_mut().for_each(|(entity, dissolving)| { + commands + .entity(entity) + .insert(Dissolving::In(dissolving.duration)); }); } -fn outro_title_dissolve(mut query: Query>, mut commands: Commands) { - query.iter_mut().for_each(|entity| { - commands.entity(entity).insert(Dissolving::Out(3.0)); +fn outro_title_dissolve( + mut query: Query<(Entity, &Dissolvable), With>, + mut commands: Commands, +) { + query.iter_mut().for_each(|(entity, dissolving)| { + commands + .entity(entity) + .insert(Dissolving::Out(dissolving.duration)); }); }