Ending the night here. Animation is hell, designing my own keyframe solution meanwhile

This commit is contained in:
Franklin Blanco 2023-09-16 22:00:25 -07:00
parent b01c9aad39
commit c135e7c557
13 changed files with 138 additions and 6 deletions

100
Cargo.lock generated
View File

@ -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"

View File

@ -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" ] }

Binary file not shown.

View File

@ -0,0 +1,13 @@
use bevy::prelude::*;
pub struct AnimationInstruction {
pub keyframes: Vec<AnimationKeyFrame>
}
/// 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<Transform>,
pub visibility: Option<Visibility>,
pub time: f32,
}

View File

@ -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,

View File

@ -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)) })*/
}
}

View File

@ -1,2 +1,3 @@
pub mod guns;
pub mod player;
pub mod animations;

View File

@ -1 +0,0 @@

View File

@ -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

View File

@ -17,7 +17,7 @@ use super::player_movement::{PlayerLinearXZState, PlayerLinearYState};
pub fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
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()

View File

@ -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);
}

7
src/setup/animations.rs Normal file
View File

@ -0,0 +1,7 @@
/*use bevy::prelude::*;
#[derive(Resource)]
pub struct FirearmAnimations {
pub reload_magazine: Handle<AnimationClip>,
pub rock_charging_handle: Handle<AnimationClip>,
}*/

View File

@ -1 +1,2 @@
pub mod gltf_assets;
pub mod animations;