From c135e7c55755ba366234600afe3bffafd82100ff Mon Sep 17 00:00:00 2001 From: Franklin Blanco Date: Sat, 16 Sep 2023 22:00:25 -0700 Subject: [PATCH] Ending the night here. Animation is hell, designing my own keyframe solution meanwhile --- Cargo.lock | 100 ++++++++++++++++++++++++ Cargo.toml | 1 + assets/weapons/m4a1_rifle.glb | Bin 64116836 -> 55106408 bytes src/logic/core/animations/mod.rs | 13 +++ src/logic/core/guns/firearm.rs | 5 +- src/logic/core/guns/spawn_firearm.rs | 6 +- src/logic/core/mod.rs | 1 + src/logic/core/player/camera_effects.rs | 1 - src/logic/core/player/hands.rs | 4 +- src/logic/core/player/spawn_player.rs | 2 +- src/scenes/scene1/init.rs | 3 + src/setup/animations.rs | 7 ++ src/setup/mod.rs | 1 + 13 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 src/logic/core/animations/mod.rs create mode 100644 src/setup/animations.rs diff --git a/Cargo.lock b/Cargo.lock index 670f806..6714412 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -652,6 +652,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "bevy_hanabi" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03238827ce780a00e7ab07fcdc59d8a90424fee861f95d37b3a23deab061d56d" +dependencies = [ + "anyhow", + "bevy", + "bitflags 2.4.0", + "bytemuck", + "copyless", + "rand", + "rand_pcg", + "ron", + "serde", + "typetag", +] + [[package]] name = "bevy_hierarchy" version = "0.11.2" @@ -1359,6 +1377,12 @@ dependencies = [ "const_soft_float", ] +[[package]] +name = "copyless" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" + [[package]] name = "core-foundation" version = "0.9.3" @@ -1690,6 +1714,7 @@ version = "0.1.0" dependencies = [ "bevy", "bevy-inspector-egui", + "bevy_hanabi", "bevy_rapier3d", ] @@ -2152,6 +2177,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "inventory" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1be380c410bf0595e94992a648ea89db4dd3f3354ba54af206fd2a68cf5ac8e" + [[package]] name = "io-kit-sys" version = "0.3.0" @@ -2988,6 +3019,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "pretty-type-name" version = "1.0.1" @@ -3034,6 +3071,45 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17fd96390ed3feda12e1dfe2645ed587e0bea749e319333f104a33ff62f77a0b" +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core", +] + [[package]] name = "range-alloc" version = "0.1.3" @@ -3604,6 +3680,30 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "typetag" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80960fd143d4c96275c0e60b08f14b81fbb468e79bc0ef8fbda69fb0afafae43" +dependencies = [ + "erased-serde", + "inventory", + "once_cell", + "serde", + "typetag-impl", +] + +[[package]] +name = "typetag-impl" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfc13d450dc4a695200da3074dacf43d449b968baee95e341920e47f61a3b40f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + [[package]] name = "unicode-bidi" version = "0.3.13" diff --git a/Cargo.toml b/Cargo.toml index 26c3d61..10a916f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ opt-level = 3 bevy = { version = "0.11.2", features = ["dynamic_linking"]} bevy-inspector-egui = "0.19.0" bevy_rapier3d = { version = "0.22.0", features = ["debug-render-3d"] } +bevy_hanabi = { version = "0.7", default-features = false, features = [ "3d" ] } \ No newline at end of file diff --git a/assets/weapons/m4a1_rifle.glb b/assets/weapons/m4a1_rifle.glb index 3b804c4a66cdc96c094fcacee96336d0cc6af91b..539abd980a017acd4ace605bf446a2b2da496e7b 100644 GIT binary patch delta 5530 zcmciGcU;x=9>;Np14n`&?r}V(0v`12K`NRfHAk9|3+1RFC>#)QOJHgyW@ukmZgW&< zso^TimF+Uyd+(|3eY@`$7PosJ_i_Kc=ka(w`TWNDo^yU@{J{qY9&i82k)5rZOv@WR zFd{50Ea&w>k%xS%o0v$O!?Ait^T>g@MP^l0tEgmWcaP0(vzv?2%@3ZA3Qx29T>+Qh z6A0Ms-F*(b-{Ez*-2u1D>GHX3$@cDcyUQ8yc|A^-$L@3ay>7QxXWH#l?6k&`N5Lhf>5zmTwtA&6AXp2@-A%@2lET_vWl!JcAK>%STrrG z#G10e8Y-BoM|aw+g~5^>Yl^j`C>Scvt69TZTB_$43g+ts>!_@}g5cC)!D+$yxuGnp zp7*8YF0Gv#Dx9U|5?o%JH8)g}Ra98;=Nc*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vl@{iYA5xeSOvCe(xa&;S}j7BqrvXberDDda#iFlZiGX)ZU??c#-%JD-n;7vM#B z30A;Lco|-SSK&2y9o~R9VHLautKn@}1Mk3ESO@RIde{IPVH0eI_uzf_06v6|;A8j% zw!l{S6h4E`VHvfB>(^b diff --git a/src/logic/core/animations/mod.rs b/src/logic/core/animations/mod.rs new file mode 100644 index 0000000..6e806eb --- /dev/null +++ b/src/logic/core/animations/mod.rs @@ -0,0 +1,13 @@ +use bevy::prelude::*; + +pub struct AnimationInstruction { + pub keyframes: Vec +} + +/// This represents a blender keyframe. +/// In the system part every keyframe's transform will be lerped linearly with the time in between them. +pub struct AnimationKeyFrame { + pub transform: Option, + pub visibility: Option, + pub time: f32, +} \ No newline at end of file diff --git a/src/logic/core/guns/firearm.rs b/src/logic/core/guns/firearm.rs index f9eeb61..7287551 100644 --- a/src/logic/core/guns/firearm.rs +++ b/src/logic/core/guns/firearm.rs @@ -25,11 +25,14 @@ impl Firearm { 1.0, 1.2, 1.3, -1.6, 1.5, -1.7, -1.5, 1.5, -1.5, 2.0 // 10 for now ]), }, - asset_path: "weapons/m4a1_rifle.glb#Scene0", + asset_path: "weapons/m4a1_rifle.glb", final_aimed_rotation: Quat::from_rotation_x(0.026), final_rotation: Quat::default(), final_aimed_position: Vec3 { + // x: -0.003, + // y: -0.35, + // z: -10.6, x: -0.003, y: -0.35, z: -1.6, diff --git a/src/logic/core/guns/spawn_firearm.rs b/src/logic/core/guns/spawn_firearm.rs index a996a50..9be1f48 100644 --- a/src/logic/core/guns/spawn_firearm.rs +++ b/src/logic/core/guns/spawn_firearm.rs @@ -21,10 +21,11 @@ pub fn spawn_firearm_on_player_hands( firearm_transform.rotate_y(utils::rad_deg::radians_from_degrees( DEFAULT_PLAYER_FIREARM.holdable_object_data().y_rot, )); + let firearm = commands .spawn(( SceneBundle { - scene: asset_server.load(DEFAULT_PLAYER_FIREARM.firearm_data().asset_path), + scene: asset_server.load(format!("{}#Scene0", DEFAULT_PLAYER_FIREARM.firearm_data().asset_path)), visibility: Visibility::Inherited, transform: firearm_transform, ..default() @@ -43,5 +44,8 @@ pub fn spawn_firearm_on_player_hands( Duration::from_secs_f32(time_in_secs_between_each_round), TimerMode::Once, ); + // Load animations + /*commands.insert_resource(FirearmAnimations { reload_magazine: asset_server.load(format!("{}#Animation0", DEFAULT_PLAYER_FIREARM.firearm_data().asset_path)), + rock_charging_handle: asset_server.load(format!("{}#Animation1", DEFAULT_PLAYER_FIREARM.firearm_data().asset_path)) })*/ } } diff --git a/src/logic/core/mod.rs b/src/logic/core/mod.rs index c305a4a..a33b729 100644 --- a/src/logic/core/mod.rs +++ b/src/logic/core/mod.rs @@ -1,2 +1,3 @@ pub mod guns; pub mod player; +pub mod animations; \ No newline at end of file diff --git a/src/logic/core/player/camera_effects.rs b/src/logic/core/player/camera_effects.rs index 8b13789..e69de29 100644 --- a/src/logic/core/player/camera_effects.rs +++ b/src/logic/core/player/camera_effects.rs @@ -1 +0,0 @@ - diff --git a/src/logic/core/player/hands.rs b/src/logic/core/player/hands.rs index 52f9b92..dc9eaaf 100644 --- a/src/logic/core/player/hands.rs +++ b/src/logic/core/player/hands.rs @@ -35,10 +35,10 @@ pub fn capture_hand_usage( } else { hand_transform.rotation = hand_transform .rotation - .lerp(firearm_data.final_rotation, (time.delta_seconds() / 0.5).clamp(0.0, 1.0)); + .lerp(firearm_data.final_rotation, (time.delta_seconds() / firearm_data.rebound_time_seconds).clamp(0.0, 1.0)); hand_transform.translation = hand_transform.translation.lerp( firearm_data.final_position, - (time.delta_seconds() / 0.5).clamp(0.0, 1.0), + (time.delta_seconds() / firearm_data.rebound_time_seconds).clamp(0.0, 1.0), ); } // SHOOTING & RECOIL diff --git a/src/logic/core/player/spawn_player.rs b/src/logic/core/player/spawn_player.rs index 095087d..2bf54e0 100644 --- a/src/logic/core/player/spawn_player.rs +++ b/src/logic/core/player/spawn_player.rs @@ -17,7 +17,7 @@ use super::player_movement::{PlayerLinearXZState, PlayerLinearYState}; pub fn spawn_player(mut commands: Commands, asset_server: Res) { let player_hand = commands .spawn(PlayerHand) - .insert(TransformBundle::from(Transform::from_xyz(0.6, -0.45, -2.7))) + .insert(TransformBundle::from(Transform::from_xyz(0.6, -0.45, -20.0))) .insert(VisibilityBundle { visibility: Visibility::Inherited, ..Default::default() diff --git a/src/scenes/scene1/init.rs b/src/scenes/scene1/init.rs index 43e5ef0..a9764e0 100644 --- a/src/scenes/scene1/init.rs +++ b/src/scenes/scene1/init.rs @@ -33,6 +33,7 @@ pub fn load_scene(application: &mut App) { ); // Update + application.add_systems(Update, capture_input); //application.add_systems(Update, capture_cursor); application.add_systems(Update, sync_player_y_state); @@ -42,4 +43,6 @@ pub fn load_scene(application: &mut App) { application.add_systems(Update, capture_hand_usage); application.add_systems(Startup, setup_lighting); + //application.add_systems(Update, setup_scene_once_loaded); + //application.add_systems(Update, play_animation); } diff --git a/src/setup/animations.rs b/src/setup/animations.rs new file mode 100644 index 0000000..2cd2990 --- /dev/null +++ b/src/setup/animations.rs @@ -0,0 +1,7 @@ +/*use bevy::prelude::*; + +#[derive(Resource)] +pub struct FirearmAnimations { + pub reload_magazine: Handle, + pub rock_charging_handle: Handle, +}*/ \ No newline at end of file diff --git a/src/setup/mod.rs b/src/setup/mod.rs index 919e0c0..69d15d7 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -1 +1,2 @@ pub mod gltf_assets; +pub mod animations; \ No newline at end of file