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 3b804c4..539abd9 100644 Binary files a/assets/weapons/m4a1_rifle.glb and b/assets/weapons/m4a1_rifle.glb differ 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