From efc019f7a41dc026e6551a70f0cc9b0ff7e5382c Mon Sep 17 00:00:00 2001 From: jshipsey Date: Wed, 15 May 2019 00:24:36 -0400 Subject: [PATCH] idle, run, jump animations Former-commit-id: e476dc3aaf2197876c80eeba17837aee976f8df9 --- assets/voxygen/voxel/pigchest.vox | 4 +- voxygen/src/anim/quadruped/idle.rs | 75 ++++++++++++++++++++++++++++++ voxygen/src/anim/quadruped/jump.rs | 59 +++++++++++++++++++++++ voxygen/src/anim/quadruped/mod.rs | 6 +++ voxygen/src/anim/quadruped/run.rs | 38 ++++++++------- voxygen/src/scene/figure.rs | 22 ++++++--- 6 files changed, 178 insertions(+), 26 deletions(-) create mode 100644 voxygen/src/anim/quadruped/idle.rs create mode 100644 voxygen/src/anim/quadruped/jump.rs diff --git a/assets/voxygen/voxel/pigchest.vox b/assets/voxygen/voxel/pigchest.vox index 4063be81c1..4bff8ba86c 100644 --- a/assets/voxygen/voxel/pigchest.vox +++ b/assets/voxygen/voxel/pigchest.vox @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:64a54c644c5963ebbfdbddbeeb0efe42f32546c6c7f83e9a94782111119da1ed -size 2612 +oid sha256:326da92dc4af851d907d674ce07cd63cc032477eae901c57dc5f4742cc215954 +size 2752 diff --git a/voxygen/src/anim/quadruped/idle.rs b/voxygen/src/anim/quadruped/idle.rs new file mode 100644 index 0000000000..e41a0dce09 --- /dev/null +++ b/voxygen/src/anim/quadruped/idle.rs @@ -0,0 +1,75 @@ +// Standard +use std::{f32::consts::PI, ops::Mul}; + +// Library +use vek::*; + +// Local +use super::{super::Animation, QuadrupedSkeleton, SCALE}; + +pub struct IdleAnimation; + +impl Animation for IdleAnimation { + type Skeleton = QuadrupedSkeleton; + type Dependency = (f64); + + fn update_skeleton( + skeleton: &Self::Skeleton, + global_time: Self::Dependency, + anim_time: f64, + ) -> Self::Skeleton { + let mut next = (*skeleton).clone(); + + let wave = (anim_time as f32 * 14.0).sin(); + let wavetest = (wave.cbrt()); + let waveultra_slow = (anim_time as f32 * 1.0 + PI).sin(); + let waveultracos_slow = (anim_time as f32 * 1.0 + PI).cos(); + let fuzzwave = (anim_time as f32 * 12.0).sin(); + let wavecos = (anim_time as f32 * 14.0).cos(); + let wave_slow = (anim_time as f32 * 3.5 + PI).sin(); + let wavecos_slow = (anim_time as f32 * 3.5 + PI).cos(); + let wave_dip = (wave_slow.abs() - 0.5).abs(); + + let pighead_look = Vec2::new( + ((global_time + anim_time) as f32 / 8.0) + .floor() + .mul(7331.0) + .sin() + * 0.5, + ((global_time + anim_time) as f32 / 8.0) + .floor() + .mul(1337.0) + .sin() + * 0.25, + ); + + next.pighead.offset = Vec3::new(0.0, 7.0, -1.5 + wave * 0.2) / 11.0; + next.pighead.ori = Quaternion::rotation_z(pighead_look.x) * Quaternion::rotation_x(pighead_look.y + wavecos_slow * 0.03); + next.pighead.scale = Vec3::one() / 10.5; + + next.pigchest.offset = Vec3::new(wave_slow * 0.05, 0.0, 1.5 + wavecos_slow * 0.4) / 11.0; + next.pigchest.ori = Quaternion::rotation_y(wave_slow * 0.05); + next.pigchest.scale = Vec3::one() / 11.0; + + next.piglf_leg.offset = Vec3::new(-4.5, 11.0, 1.5) / 11.0; + next.piglf_leg.ori = Quaternion::rotation_x(wave_slow * 0.08); + next.piglf_leg.scale = Vec3::one() / 11.0; + + next.pigrf_leg.offset = Vec3::new(2.5, 11.0, 1.5) / 11.0; + next.pigrf_leg.ori = Quaternion::rotation_x(wavecos_slow * 0.08); + next.pigrf_leg.scale = Vec3::one() / 11.0; + + next.piglb_leg.offset = Vec3::new(-4.5, 6.0, 1.5) / 11.0; + next.piglb_leg.ori = Quaternion::rotation_x(wavecos_slow * 0.08); + next.piglb_leg.scale = Vec3::one() / 11.0; + + next.pigrb_leg.offset = Vec3::new(2.5, 6.0, 1.5) / 11.0; + next.pigrb_leg.ori = Quaternion::rotation_x(wave_slow * 0.08); + next.pigrb_leg.scale = Vec3::one() / 11.0; + + + + + next + } +} diff --git a/voxygen/src/anim/quadruped/jump.rs b/voxygen/src/anim/quadruped/jump.rs new file mode 100644 index 0000000000..da2e17fa76 --- /dev/null +++ b/voxygen/src/anim/quadruped/jump.rs @@ -0,0 +1,59 @@ +// Standard +use std::f32::consts::PI; + +// Library +use vek::*; + +// Local +use super::{super::Animation, QuadrupedSkeleton, SCALE}; + +pub struct JumpAnimation; + +impl Animation for JumpAnimation { + type Skeleton = QuadrupedSkeleton; + type Dependency = (f32, f64); + + fn update_skeleton( + skeleton: &Self::Skeleton, + (velocity, global_time): Self::Dependency, + anim_time: f64, + ) -> Self::Skeleton { + let mut next = (*skeleton).clone(); + + let wave = (anim_time as f32 * 14.0).sin(); + let wavetest = (wave.cbrt()); + let fuzzwave = (anim_time as f32 * 12.0).sin(); + let wavecos = (anim_time as f32 * 14.0).cos(); + let wave_slow = (anim_time as f32 * 7.0 + PI).sin(); + let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos(); + let wave_dip = (wave_slow.abs() - 0.5).abs(); + let wave_stop = (anim_time as f32 * 4.5).min(PI / 2.0).sin(); + + + next.pighead.offset = Vec3::new(0.0, 9.0, -1.5 ) / 11.0; + next.pighead.ori = Quaternion::rotation_x(wave_stop * 0.4); + next.pighead.scale = Vec3::one() / 10.5; + + next.pigchest.offset = Vec3::new(0.0, 0.0, 1.5) / 11.0; + next.pigchest.ori = Quaternion::rotation_x(0.0); + next.pigchest.scale = Vec3::one() / 11.0; + + next.piglf_leg.offset = Vec3::new(-4.5, 12.0, 1.5) / 11.0; + next.piglf_leg.ori = Quaternion::rotation_x(wave_stop * 0.6); + next.piglf_leg.scale = Vec3::one() / 11.0; + + next.pigrf_leg.offset = Vec3::new(2.5, 12.0, 1.5) / 11.0; + next.pigrf_leg.ori = Quaternion::rotation_x(wave_stop * 0.6 - wave_slow * 0.3); + next.pigrf_leg.scale = Vec3::one() / 11.0; + + next.piglb_leg.offset = Vec3::new(-4.5, 5.0, 2.0) / 11.0; + next.piglb_leg.ori = Quaternion::rotation_x(wave_stop * -0.6 + wave_slow * 0.3); + next.piglb_leg.scale = Vec3::one() / 11.0; + + next.pigrb_leg.offset = Vec3::new(2.5, 5.0, 2.0) / 11.0; + next.pigrb_leg.ori = Quaternion::rotation_x(wave_stop * -0.6 + wave_slow * 0.3); + next.pigrb_leg.scale = Vec3::one() / 11.0; + + next + } +} diff --git a/voxygen/src/anim/quadruped/mod.rs b/voxygen/src/anim/quadruped/mod.rs index ba5db031c0..a6b7e4474c 100644 --- a/voxygen/src/anim/quadruped/mod.rs +++ b/voxygen/src/anim/quadruped/mod.rs @@ -1,8 +1,14 @@ pub mod run; +pub mod idle; +pub mod jump; + // Reexports pub use self::run::RunAnimation; +pub use self::idle::IdleAnimation; +pub use self::jump::JumpAnimation; + // Crate use crate::render::FigureBoneData; diff --git a/voxygen/src/anim/quadruped/run.rs b/voxygen/src/anim/quadruped/run.rs index c1db8eca76..9c0db36edd 100644 --- a/voxygen/src/anim/quadruped/run.rs +++ b/voxygen/src/anim/quadruped/run.rs @@ -21,6 +21,8 @@ impl Animation for RunAnimation { let mut next = (*skeleton).clone(); let wave = (anim_time as f32 * 14.0).sin(); + let wavequick = (anim_time as f32 * 20.0).sin(); + let wavequickcos = (anim_time as f32 * 20.0).cos(); let wavetest = (wave.cbrt()); let fuzzwave = (anim_time as f32 * 12.0).sin(); let wavecos = (anim_time as f32 * 14.0).cos(); @@ -28,29 +30,29 @@ impl Animation for RunAnimation { let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.pighead.offset = Vec3::new(5.5, 2.0, 11.0 + wavecos * 1.3); - next.pighead.ori = Quaternion::rotation_x(0.15); - next.pighead.scale = Vec3::one(); + next.pighead.offset = Vec3::new(0.0, 9.0, -1.5 + wave * 1.5) / 11.0; + next.pighead.ori = Quaternion::rotation_x(0.2 + wave * 0.05) * Quaternion::rotation_y(wavecos * 0.03); + next.pighead.scale = Vec3::one() / 10.5; - next.pigchest.offset = Vec3::new(5.5, 0.0, 7.0 + wavecos * 1.1); - next.pigchest.ori = Quaternion::rotation_z(wave * 0.1); - next.pigchest.scale = Vec3::one(); + next.pigchest.offset = Vec3::new(0.0, 0.0, 1.5 + wavecos * 1.2) / 11.0; + next.pigchest.ori = Quaternion::rotation_x(wave * 0.1); + next.pigchest.scale = Vec3::one() / 11.0; - next.piglf_leg.offset = Vec3::new(5.5, 0.0, 5.0 + wavecos * 1.1); - next.piglf_leg.ori = Quaternion::rotation_z(wave * 0.25); - next.piglf_leg.scale = Vec3::one(); + next.piglf_leg.offset = Vec3::new(-4.5, 11.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0; + next.piglf_leg.ori = Quaternion::rotation_x(wavequick * 0.3); + next.piglf_leg.scale = Vec3::one() / 11.0; - next.pigrf_leg.offset = Vec3::new(5.5, 0.0, 2.0 + wavecos * 1.1); - next.pigrf_leg.ori = Quaternion::rotation_z(wave * 0.6); - next.pigrf_leg.scale = Vec3::one(); + next.pigrf_leg.offset = Vec3::new(2.5, 11.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0; + next.pigrf_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3); + next.pigrf_leg.scale = Vec3::one() / 11.0; - next.piglb_leg.offset = Vec3::new(-6.0, 0.0 + wavecos * 2.5, 11.0 - wave * 1.5); - next.piglb_leg.ori = Quaternion::rotation_x(wavecos * 0.9); - next.piglb_leg.scale = Vec3::one(); + next.piglb_leg.offset = Vec3::new(-4.5, 6.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0; + next.piglb_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3); + next.piglb_leg.scale = Vec3::one() / 11.0; - next.pigrb_leg.offset = Vec3::new(9.0, 0.0 - wavecos * 2.5, 11.0 + wave * 1.5); - next.pigrb_leg.ori = Quaternion::rotation_x(wavecos * -0.9); - next.pigrb_leg.scale = Vec3::one(); + next.pigrb_leg.offset = Vec3::new(2.5, 6.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0; + next.pigrb_leg.ori = Quaternion::rotation_x(wavequick * 0.3); + next.pigrb_leg.scale = Vec3::one() / 11.0; next } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 54babc7875..b93b72ab3b 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -243,7 +243,7 @@ impl FigureModelCache { match pighead { Pighead::Default => "pighead.vox", }, - Vec3::new(0.0, 5.0, 0.0), + Vec3::new(-6.0, 4.5, 3.0), ) } @@ -252,7 +252,7 @@ impl FigureModelCache { match pigchest { Pigchest::Default => "pigchest.vox", }, - Vec3::new(0.0, 0.0, 0.0), + Vec3::new(-5.0, 4.5, 0.0), ) } @@ -261,7 +261,7 @@ impl FigureModelCache { match pigleg_l { Pigleg_l::Default => "pigleg_l.vox", }, - Vec3::new(0.0, 0.0, 0.0), + Vec3::new(0.0, -1.0, -1.5), ) } @@ -270,7 +270,7 @@ impl FigureModelCache { match pigleg_r { Pigleg_r::Default => "pigleg_r.vox", }, - Vec3::new(0.0, 0.0, 0.0), + Vec3::new(0.0, -1.0, -1.5), ) } @@ -279,7 +279,7 @@ impl FigureModelCache { match pigleg_l { Pigleg_l::Default => "pigleg_l.vox", }, - Vec3::new(0.0, 0.0, 0.0), + Vec3::new(0.0, -1.0, -1.5), ) } @@ -288,7 +288,7 @@ impl FigureModelCache { match pigleg_r { Pigleg_r::Default => "pigleg_r.vox", }, - Vec3::new(0.0, 0.0, 0.0), + Vec3::new(0.0, -1.0, -1.5), ) } } @@ -366,6 +366,16 @@ impl FigureMgr { (vel.0.magnitude(), time), animation_history.time, ), + comp::Animation::Idle => quadruped::IdleAnimation::update_skeleton( + state.skeleton_mut(), + time, + animation_history.time, + ), + comp::Animation::Jump => quadruped::JumpAnimation::update_skeleton( + state.skeleton_mut(), + (vel.0.magnitude(), time), + animation_history.time, + ), // TODO! _ => state.skeleton_mut().clone(), };