From c94e21095482a8cb4ccda205c1f5c4d695d431cd Mon Sep 17 00:00:00 2001 From: jshipsey Date: Sun, 21 Apr 2019 13:35:43 -0400 Subject: [PATCH 01/12] velocity tilt Former-commit-id: 73368363ba89a42a8867a593d88d108e05e713f8 --- voxygen/src/anim/character/idle.rs | 27 ++++++++++------ voxygen/src/anim/character/mod.rs | 29 ++++++++++------- voxygen/src/anim/character/run.rs | 51 +++++++++++++++++++----------- voxygen/src/scene/figure.rs | 19 +++++------ 4 files changed, 79 insertions(+), 47 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index d6d48a5550..69f1ed5bfd 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -32,32 +32,41 @@ impl Animation for IdleAnimation { let waveultracos_slow = (time as f32 * 1.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::new(0.0, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; + next.head.offset = Vec3::new(-1.0, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; next.head.ori = Quaternion::rotation_y(waveultra_slow * 0.05); + next.head.scale = Vec3::one() / SCALE; - next.chest.offset = Vec3::new(0.0, 0.0, 8.0 + waveultra_slow * 0.4) / SCALE; + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + waveultra_slow * 0.4) / SCALE; next.chest.ori = Quaternion::rotation_y(0.0); + next.chest.scale = Vec3::one() / SCALE; - next.belt.offset = Vec3::new(0.0, 0.0, 6.0 + waveultra_slow * 0.4) / SCALE; + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + waveultra_slow * 0.4) / SCALE; next.belt.ori = Quaternion::rotation_y(0.0); + next.belt.scale = Vec3::one() / SCALE; - next.shorts.offset = Vec3::new(0.0, 0.0, 3.0 + waveultra_slow * 0.4) / SCALE; + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + waveultra_slow * 0.4) / SCALE; next.shorts.ori = Quaternion::rotation_y(0.0); + next.shorts.scale = Vec3::one() / SCALE; - next.l_hand.offset = Vec3::new(0.0 + waveultracos_slow * 0.3, 7.5, 11.0 + waveultra_slow * 1.1) / SCALE; + next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 13.5 + waveultra_slow * 1.1) / SCALE; next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.r_hand.offset = Vec3::new(0.0 + waveultracos_slow * 0.3 , - 7.5, 11.0 + waveultra_slow * 1.1) / SCALE; + next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 13.5 + waveultra_slow * 1.1) / SCALE; next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.l_foot.offset = Vec3::new(2.5, 3.4, 6.0) / SCALE; + next.l_foot.offset = Vec3::new(5.0, 3.4, 8.0) / SCALE; next.l_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); - next.r_foot.offset = Vec3::new(2.5, -3.4, 6.0) / SCALE; + next.r_foot.offset = Vec3::new(5.0, -3.4, 8.0) / SCALE; next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); - next.back.offset = Vec3::new(-6.5, 16.0, 15.0); + next.back.offset = Vec3::new(-4.5, 12.0, 11.0); next.back.ori = Quaternion::rotation_x(2.5); next.back.scale = Vec3::one(); + + next.torso.offset = Vec3::new(0.0, 0.0, 0.0); + next.torso.ori = Quaternion::rotation_y(0.0); + next.torso.scale = Vec3::one(); + next } } diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 3d6e3e1dfc..f043977867 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -27,6 +27,8 @@ pub struct CharacterSkeleton { l_foot: Bone, r_foot: Bone, back: Bone, + torso: Bone, + } impl CharacterSkeleton { @@ -41,6 +43,8 @@ impl CharacterSkeleton { l_foot: Bone::default(), r_foot: Bone::default(), back: Bone::default(), + torso: Bone::default(), + } } } @@ -48,24 +52,25 @@ impl CharacterSkeleton { impl Skeleton for CharacterSkeleton { fn compute_matrices(&self) -> [FigureBoneData; 16] { let chest_mat = self.chest.compute_base_matrix(); - + let torso_mat = self.torso.compute_base_matrix(); [ - FigureBoneData::new(self.head.compute_base_matrix()), - FigureBoneData::new(chest_mat), - FigureBoneData::new(self.belt.compute_base_matrix()), - FigureBoneData::new(self.shorts.compute_base_matrix()), - FigureBoneData::new(self.l_hand.compute_base_matrix()), - FigureBoneData::new(self.r_hand.compute_base_matrix()), - FigureBoneData::new(self.l_foot.compute_base_matrix()), - FigureBoneData::new(self.r_foot.compute_base_matrix()), - FigureBoneData::new(chest_mat * self.back.compute_base_matrix()), - FigureBoneData::default(), + FigureBoneData::new(torso_mat * self.head.compute_base_matrix()), + FigureBoneData::new(torso_mat * chest_mat), + FigureBoneData::new(torso_mat * self.belt.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.shorts.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.l_hand.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.r_hand.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.l_foot.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.r_foot.compute_base_matrix()), + FigureBoneData::new(torso_mat * chest_mat * self.back.compute_base_matrix()), + FigureBoneData::new(torso_mat), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), + ] } @@ -79,5 +84,7 @@ impl Skeleton for CharacterSkeleton { self.l_foot.interpolate(&target.l_foot); self.r_foot.interpolate(&target.r_foot); self.back.interpolate(&target.back); + self.torso.interpolate(&target.torso); + } } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index c5214bcb88..6ea0654d0f 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -23,39 +23,54 @@ impl Animation for RunAnimation { ) -> Self::Skeleton { let mut next = (*skeleton).clone(); - let wave = (time as f32 * 14.0).sin(); + let wave = (time as f32 * 16.0).sin(); + let wavetest = (wave.cbrt()); let fuzzwave = (time as f32 * 12.0).sin(); - let wavecos = (time as f32 * 14.0).cos(); + let wavecos = (time as f32 * 16.0).cos(); let wave_slow = (time as f32 * 8.0 + PI).sin(); let wavecos_slow = (time as f32 * 8.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::unit_z() * (12.0 + fuzzwave *1.0)/ SCALE; - next.chest.offset = Vec3::unit_z() * (8.0 + fuzzwave * 0.8) / SCALE; - next.chest.ori = Quaternion::rotation_z(wave * 0.3); + next.head.offset = Vec3::unit_z() * (12.0 + wave *1.3)/ SCALE; + next.chest.scale = Vec3::one() * 1.0; - next.belt.offset = Vec3::unit_z() * (6.0 + fuzzwave * 0.8) / SCALE; - next.belt.ori = Quaternion::rotation_z(wave * 0.3); + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wave * 1.1) / SCALE; + next.chest.ori = Quaternion::rotation_z(wavecos * 0.2); + next.chest.scale = Vec3::one() / SCALE; - next.shorts.offset = Vec3::unit_z() * (3.0 + fuzzwave * 0.8) / SCALE; - next.shorts.ori = Quaternion::rotation_z(wave * 0.2); + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wave * 1.1) / SCALE; + next.belt.ori = Quaternion::rotation_z(wavecos * 0.2); + next.belt.scale = Vec3::one() /SCALE; - next.l_hand.offset = Vec3::new(0.0 - wavecos * 1.0, 7.5, 11.0 - wave * 1.0) / SCALE; - next.l_hand.ori = Quaternion::rotation_y(wave * -1.8); - next.r_hand.offset = Vec3::new(0.0 + wavecos * 1.0, -7.5, 11.0 + wave * 1.0) / SCALE; - next.r_hand.ori = Quaternion::rotation_y(wave * 1.8); + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wave * 1.1) / SCALE; + next.shorts.ori = Quaternion::rotation_z(wavecos * 0.6); + next.shorts.scale = Vec3::one() /SCALE; - next.l_foot.offset = Vec3::new(2.5 - wavecos * 4.0, 3.4, 6.0 + wave * 2.9) / SCALE; - next.l_foot.ori = Quaternion::rotation_y(wave * -1.0); - next.r_foot.offset = Vec3::new(2.5 + wavecos * 4.0, -3.4, 6.0 - wave * 2.9) / SCALE; + next.l_hand.offset = Vec3::new(2.0 - wavecos * 1.0, 7.5, 11.0 - wave * 1.0) / SCALE; + next.l_hand.ori = Quaternion::rotation_y(wavecos * -1.8); + next.r_hand.offset = Vec3::new(2.0 + wavecos * 1.0, -7.5, 11.0 + wave * 1.0) / SCALE; + next.r_hand.ori = Quaternion::rotation_y(wavecos * 1.8); - next.r_foot.ori = Quaternion::rotation_y(wave * 1.0); + next.l_foot.offset = Vec3::new(3.5 - wave * 1.0, 3.4, 6.0) / SCALE; + next.l_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); + next.l_foot.scale = Vec3::one() / SCALE; - next.back.offset = Vec3::new(-6.0, 16.0, 15.0); + next.r_foot.offset = Vec3::new(3.5 + wave * 1.0, -3.4, 6.0) / SCALE; + next.r_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); + + next.back.offset = Vec3::new(-4.5, 12.0, 11.0); next.back.ori = Quaternion::rotation_x(2.5); next.back.scale = Vec3::one(); + next.torso.offset = Vec3::new(0.0, 0.0, 0.0); + next.torso.ori = Quaternion::rotation_y(0.2 + wave * 0.1); + + + next.torso.scale = Vec3::one(); + + + next } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 86a51be0eb..ec99764650 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -54,15 +54,16 @@ impl Figures { let bone_meshes = [ - Some(load_segment("head.vox").generate_mesh(Vec3::new(-3.5, -7.0, -6.0))), - Some(load_segment("chest.vox").generate_mesh(Vec3::new(-3.0, -6.0, 0.0))), - Some(load_segment("belt.vox").generate_mesh(Vec3::new(-3.0, -5.0, 0.0))), - Some(load_segment("pants.vox").generate_mesh(Vec3::new(-3.0, -5.0, 0.0))), - Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -6.0))), - Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -6.0))), - Some(load_segment("foot.vox").generate_mesh(Vec3::new(-4.0, -2.5, -6.0))), - Some(load_segment("foot.vox").generate_mesh(Vec3::new(-4.0, -2.5, -6.0))), - Some(load_segment("sword.vox").generate_mesh(Vec3::new(0.0, -0.0, 0.0))), + + Some(load_segment("head.vox").generate_mesh(Vec3::new(1.0, -7.0, -6.0))), + Some(load_segment("chest.vox").generate_mesh(Vec3::new(-2.5, -6.0, 0.0))), + Some(load_segment("belt.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), + Some(load_segment("pants.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), + Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -8.0))), + Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -8.0))), + Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), + Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), + Some(load_segment("sword.vox").generate_mesh(Vec3::new(0.0, -0.0, -4.0))), None, None, None, From af194d2e28c4fddf975fe483214299307e667680 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Tue, 23 Apr 2019 20:17:50 -0400 Subject: [PATCH 02/12] run animation incremental tweaks Former-commit-id: f8800cad3d50eb3c536a1673bbe216b3098ce81e --- voxygen/src/anim/character/idle.rs | 16 ++++++--- voxygen/src/anim/character/mod.rs | 10 ++++-- voxygen/src/anim/character/run.rs | 55 +++++++++++++++++------------- voxygen/src/scene/figure.rs | 10 +++--- 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index 69f1ed5bfd..26633b13c5 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -32,7 +32,7 @@ impl Animation for IdleAnimation { let waveultracos_slow = (time as f32 * 1.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::new(-1.0, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; + next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; next.head.ori = Quaternion::rotation_y(waveultra_slow * 0.05); next.head.scale = Vec3::one() / SCALE; @@ -48,9 +48,9 @@ impl Animation for IdleAnimation { next.shorts.ori = Quaternion::rotation_y(0.0); next.shorts.scale = Vec3::one() / SCALE; - next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 13.5 + waveultra_slow * 1.1) / SCALE; + next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 13.5 + waveultra_slow * 1.1) / SCALE; + next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); next.l_foot.offset = Vec3::new(5.0, 3.4, 8.0) / SCALE; @@ -58,7 +58,7 @@ impl Animation for IdleAnimation { next.r_foot.offset = Vec3::new(5.0, -3.4, 8.0) / SCALE; next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); - next.back.offset = Vec3::new(-4.5, 12.0, 11.0); + next.back.offset = Vec3::new(-4.5, 14.0, 13.0); next.back.ori = Quaternion::rotation_x(2.5); next.back.scale = Vec3::one(); @@ -67,6 +67,14 @@ impl Animation for IdleAnimation { next.torso.ori = Quaternion::rotation_y(0.0); next.torso.scale = Vec3::one(); + next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0) / SCALE; + next.l_shoulder.ori = Quaternion::rotation_y(0.0); + next.l_shoulder.scale = Vec3::one() / SCALE; + + next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0) / SCALE; + next.r_shoulder.ori = Quaternion::rotation_y(0.0); + next.r_shoulder.scale = Vec3::one() / SCALE; + next } } diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index f043977867..1579c6a906 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -28,6 +28,8 @@ pub struct CharacterSkeleton { r_foot: Bone, back: Bone, torso: Bone, + l_shoulder: Bone, + r_shoulder: Bone, } @@ -44,6 +46,8 @@ impl CharacterSkeleton { r_foot: Bone::default(), back: Bone::default(), torso: Bone::default(), + l_shoulder: Bone::default(), + r_shoulder: Bone::default(), } } @@ -64,8 +68,8 @@ impl Skeleton for CharacterSkeleton { FigureBoneData::new(torso_mat * self.r_foot.compute_base_matrix()), FigureBoneData::new(torso_mat * chest_mat * self.back.compute_base_matrix()), FigureBoneData::new(torso_mat), - FigureBoneData::default(), - FigureBoneData::default(), + FigureBoneData::new(torso_mat * self.l_shoulder.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.r_shoulder.compute_base_matrix()), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), @@ -85,6 +89,8 @@ impl Skeleton for CharacterSkeleton { self.r_foot.interpolate(&target.r_foot); self.back.interpolate(&target.back); self.torso.interpolate(&target.torso); + self.l_shoulder.interpolate(&target.l_shoulder); + self.r_shoulder.interpolate(&target.r_shoulder); } } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 6ea0654d0f..f2a769fcb3 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -23,53 +23,60 @@ impl Animation for RunAnimation { ) -> Self::Skeleton { let mut next = (*skeleton).clone(); - let wave = (time as f32 * 16.0).sin(); + let wave = (time as f32 * 14.0).sin(); let wavetest = (wave.cbrt()); let fuzzwave = (time as f32 * 12.0).sin(); - let wavecos = (time as f32 * 16.0).cos(); - let wave_slow = (time as f32 * 8.0 + PI).sin(); + let wavecos = (time as f32 * 14.0).cos(); + let wave_slow = (time as f32 * 7.0 + PI).sin(); let wavecos_slow = (time as f32 * 8.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::unit_z() * (12.0 + wave *1.3)/ SCALE; - next.chest.scale = Vec3::one() * 1.0; + next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3) / SCALE; + next.head.ori = Quaternion::rotation_y(-0.15); - next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wave * 1.1) / SCALE; - next.chest.ori = Quaternion::rotation_z(wavecos * 0.2); + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1) / SCALE; + next.chest.ori = Quaternion::rotation_z(wave * 0.1); next.chest.scale = Vec3::one() / SCALE; - next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wave * 1.1) / SCALE; - next.belt.ori = Quaternion::rotation_z(wavecos * 0.2); + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wavecos * 1.1) / SCALE; + next.belt.ori = Quaternion::rotation_z(wave * 0.25); next.belt.scale = Vec3::one() /SCALE; - next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wave * 1.1) / SCALE; - next.shorts.ori = Quaternion::rotation_z(wavecos * 0.6); + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wavecos * 1.1) / SCALE; + next.shorts.ori = Quaternion::rotation_z(wave * 0.6); next.shorts.scale = Vec3::one() /SCALE; - next.l_hand.offset = Vec3::new(2.0 - wavecos * 1.0, 7.5, 11.0 - wave * 1.0) / SCALE; - next.l_hand.ori = Quaternion::rotation_y(wavecos * -1.8); - next.r_hand.offset = Vec3::new(2.0 + wavecos * 1.0, -7.5, 11.0 + wave * 1.0) / SCALE; - next.r_hand.ori = Quaternion::rotation_y(wavecos * 1.8); + next.l_hand.offset = Vec3::new(2.0 - wavecos * 2.5, 7.5, 12.0 + wave * 1.5) / SCALE; + next.l_hand.ori = Quaternion::rotation_y(wavecos * 0.9); - next.l_foot.offset = Vec3::new(3.5 - wave * 1.0, 3.4, 6.0) / SCALE; - next.l_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); - next.l_foot.scale = Vec3::one() / SCALE; + next.r_hand.offset = Vec3::new(2.0 + wavecos * 2.5, -7.5, 12.0 - wave * 1.5) / SCALE; + next.r_hand.ori = Quaternion::rotation_y(wavecos * -0.9); - next.r_foot.offset = Vec3::new(3.5 + wave * 1.0, -3.4, 6.0) / SCALE; - next.r_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); + next.l_foot.offset = Vec3::new(3.5 + wave * 1.0, 3.4, 6.0) / SCALE; + next.l_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); - next.back.offset = Vec3::new(-4.5, 12.0, 11.0); + next.r_foot.offset = Vec3::new(3.5 - wave * 1.0, -3.4, 6.0) / SCALE; + next.r_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); + + next.back.offset = Vec3::new(-5.0, 14.0, 13.0); next.back.ori = Quaternion::rotation_x(2.5); next.back.scale = Vec3::one(); next.torso.offset = Vec3::new(0.0, 0.0, 0.0); - next.torso.ori = Quaternion::rotation_y(0.2 + wave * 0.1); - - + next.torso.ori = Quaternion::rotation_y(0.25 + wavecos * 0.1); next.torso.scale = Vec3::one(); + next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0) / SCALE; + next.l_shoulder.ori = Quaternion::rotation_y(0.0); + next.l_shoulder.scale = Vec3::one() / SCALE; + + next.r_shoulder.offset = Vec3::new(3.0, -6.0, 18.0) / SCALE; + next.r_shoulder.ori = Quaternion::rotation_y(0.0); + next.r_shoulder.scale = Vec3::one() / SCALE; //???why are shoulder scales like this + + next diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index ec99764650..96c938deba 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -55,18 +55,18 @@ impl Figures { let bone_meshes = [ - Some(load_segment("head.vox").generate_mesh(Vec3::new(1.0, -7.0, -6.0))), + Some(load_segment("head.vox").generate_mesh(Vec3::new(-5.5, -7.0, -6.0))), Some(load_segment("chest.vox").generate_mesh(Vec3::new(-2.5, -6.0, 0.0))), Some(load_segment("belt.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), Some(load_segment("pants.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), - Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -8.0))), - Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -8.0))), + Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), + Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), Some(load_segment("sword.vox").generate_mesh(Vec3::new(0.0, -0.0, -4.0))), None, - None, - None, + //Some(load_segment("shoulder_left.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), + //Some(load_segment("shoulder_right.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), None, None, None, From d51594006cdcea708f85744389bc8fa84442b733 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Tue, 23 Apr 2019 20:36:33 -0400 Subject: [PATCH 03/12] simplified scaling code Former-commit-id: 20bf8a426f9fc1fad523ed41688e3d419037a4a6 --- voxygen/src/anim/character/idle.rs | 43 +++++++++++++++++------------- voxygen/src/anim/character/run.rs | 38 ++++++++++++++------------ 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index 26633b13c5..2f7b1ad6ef 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -32,31 +32,38 @@ impl Animation for IdleAnimation { let waveultracos_slow = (time as f32 * 1.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; + next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4); next.head.ori = Quaternion::rotation_y(waveultra_slow * 0.05); - next.head.scale = Vec3::one() / SCALE; + next.head.scale = Vec3::one(); - next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + waveultra_slow * 0.4) / SCALE; + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + waveultra_slow * 0.4); next.chest.ori = Quaternion::rotation_y(0.0); - next.chest.scale = Vec3::one() / SCALE; + next.chest.scale = Vec3::one(); - next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + waveultra_slow * 0.4) / SCALE; + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + waveultra_slow * 0.4); next.belt.ori = Quaternion::rotation_y(0.0); - next.belt.scale = Vec3::one() / SCALE; + next.belt.scale = Vec3::one(); - next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + waveultra_slow * 0.4) / SCALE; + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + waveultra_slow * 0.4); next.shorts.ori = Quaternion::rotation_y(0.0); - next.shorts.scale = Vec3::one() / SCALE; + next.shorts.scale = Vec3::one(); - next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; + next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1); next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; - next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); + next.l_hand.scale = Vec3::one(); - next.l_foot.offset = Vec3::new(5.0, 3.4, 8.0) / SCALE; + next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1); + next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); + next.r_hand.scale = Vec3::one(); + + next.l_foot.offset = Vec3::new(5.0, 3.4, 8.0); next.l_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); - next.r_foot.offset = Vec3::new(5.0, -3.4, 8.0) / SCALE; + next.l_foot.scale = Vec3::one(); + + next.r_foot.offset = Vec3::new(5.0, -3.4, 8.0); next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); + next.r_foot.scale = Vec3::one(); + next.back.offset = Vec3::new(-4.5, 14.0, 13.0); next.back.ori = Quaternion::rotation_x(2.5); @@ -65,15 +72,15 @@ impl Animation for IdleAnimation { next.torso.offset = Vec3::new(0.0, 0.0, 0.0); next.torso.ori = Quaternion::rotation_y(0.0); - next.torso.scale = Vec3::one(); + next.torso.scale = Vec3::one() / 11.0; - next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0) / SCALE; + next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0); next.l_shoulder.ori = Quaternion::rotation_y(0.0); - next.l_shoulder.scale = Vec3::one() / SCALE; + next.l_shoulder.scale = Vec3::one(); - next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0) / SCALE; + next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0); next.r_shoulder.ori = Quaternion::rotation_y(0.0); - next.r_shoulder.scale = Vec3::one() / SCALE; + next.r_shoulder.scale = Vec3::one(); next } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index f2a769fcb3..ee1808a2d1 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -32,32 +32,37 @@ impl Animation for RunAnimation { let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3) / SCALE; + next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3); // / SCALE; next.head.ori = Quaternion::rotation_y(-0.15); + next.head.scale = Vec3::one(); // / SCALE; - next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1) / SCALE; + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1); next.chest.ori = Quaternion::rotation_z(wave * 0.1); - next.chest.scale = Vec3::one() / SCALE; + next.chest.scale = Vec3::one(); - next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wavecos * 1.1) / SCALE; + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wavecos * 1.1); next.belt.ori = Quaternion::rotation_z(wave * 0.25); - next.belt.scale = Vec3::one() /SCALE; + next.belt.scale = Vec3::one(); - next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wavecos * 1.1) / SCALE; + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wavecos * 1.1); next.shorts.ori = Quaternion::rotation_z(wave * 0.6); - next.shorts.scale = Vec3::one() /SCALE; + next.shorts.scale = Vec3::one(); - next.l_hand.offset = Vec3::new(2.0 - wavecos * 2.5, 7.5, 12.0 + wave * 1.5) / SCALE; + next.l_hand.offset = Vec3::new(2.0 - wavecos * 2.5, 7.5, 12.0 + wave * 1.5); next.l_hand.ori = Quaternion::rotation_y(wavecos * 0.9); + next.l_hand.scale = Vec3::one(); - next.r_hand.offset = Vec3::new(2.0 + wavecos * 2.5, -7.5, 12.0 - wave * 1.5) / SCALE; + next.r_hand.offset = Vec3::new(2.0 + wavecos * 2.5, -7.5, 12.0 - wave * 1.5); next.r_hand.ori = Quaternion::rotation_y(wavecos * -0.9); + next.r_hand.scale = Vec3::one(); - next.l_foot.offset = Vec3::new(3.5 + wave * 1.0, 3.4, 6.0) / SCALE; + next.l_foot.offset = Vec3::new(3.5 + wave * 1.0, 3.4, 6.0); next.l_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); + next.l_foot.scale = Vec3::one(); - next.r_foot.offset = Vec3::new(3.5 - wave * 1.0, -3.4, 6.0) / SCALE; + next.r_foot.offset = Vec3::new(3.5 - wave * 1.0, -3.4, 6.0); next.r_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); + next.r_foot.scale = Vec3::one(); next.back.offset = Vec3::new(-5.0, 14.0, 13.0); next.back.ori = Quaternion::rotation_x(2.5); @@ -65,17 +70,16 @@ impl Animation for RunAnimation { next.torso.offset = Vec3::new(0.0, 0.0, 0.0); next.torso.ori = Quaternion::rotation_y(0.25 + wavecos * 0.1); - next.torso.scale = Vec3::one(); + next.torso.scale = Vec3::one() / 11.0; - next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0) / SCALE; + next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0); next.l_shoulder.ori = Quaternion::rotation_y(0.0); - next.l_shoulder.scale = Vec3::one() / SCALE; + next.l_shoulder.scale = Vec3::one(); - next.r_shoulder.offset = Vec3::new(3.0, -6.0, 18.0) / SCALE; + next.r_shoulder.offset = Vec3::new(3.0, -6.0, 18.0); next.r_shoulder.ori = Quaternion::rotation_y(0.0); - next.r_shoulder.scale = Vec3::one() / SCALE; //???why are shoulder scales like this - + next.r_shoulder.scale = Vec3::one(); next From df39bcb2dc81850e4d97684c183017a9129d785b Mon Sep 17 00:00:00 2001 From: jshipsey Date: Sun, 21 Apr 2019 13:35:43 -0400 Subject: [PATCH 04/12] velocity tilt Former-commit-id: 7373827734c9a65813537d7a1cb49b400c7d6fb8 --- voxygen/src/anim/character/idle.rs | 27 ++- voxygen/src/anim/character/mod.rs | 29 +-- voxygen/src/anim/character/run.rs | 51 +++-- voxygen/src/scene/figure.rs | 297 +++++++++++++++++++++++++++++ 4 files changed, 366 insertions(+), 38 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index d6d48a5550..69f1ed5bfd 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -32,32 +32,41 @@ impl Animation for IdleAnimation { let waveultracos_slow = (time as f32 * 1.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::new(0.0, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; + next.head.offset = Vec3::new(-1.0, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; next.head.ori = Quaternion::rotation_y(waveultra_slow * 0.05); + next.head.scale = Vec3::one() / SCALE; - next.chest.offset = Vec3::new(0.0, 0.0, 8.0 + waveultra_slow * 0.4) / SCALE; + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + waveultra_slow * 0.4) / SCALE; next.chest.ori = Quaternion::rotation_y(0.0); + next.chest.scale = Vec3::one() / SCALE; - next.belt.offset = Vec3::new(0.0, 0.0, 6.0 + waveultra_slow * 0.4) / SCALE; + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + waveultra_slow * 0.4) / SCALE; next.belt.ori = Quaternion::rotation_y(0.0); + next.belt.scale = Vec3::one() / SCALE; - next.shorts.offset = Vec3::new(0.0, 0.0, 3.0 + waveultra_slow * 0.4) / SCALE; + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + waveultra_slow * 0.4) / SCALE; next.shorts.ori = Quaternion::rotation_y(0.0); + next.shorts.scale = Vec3::one() / SCALE; - next.l_hand.offset = Vec3::new(0.0 + waveultracos_slow * 0.3, 7.5, 11.0 + waveultra_slow * 1.1) / SCALE; + next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 13.5 + waveultra_slow * 1.1) / SCALE; next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.r_hand.offset = Vec3::new(0.0 + waveultracos_slow * 0.3 , - 7.5, 11.0 + waveultra_slow * 1.1) / SCALE; + next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 13.5 + waveultra_slow * 1.1) / SCALE; next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.l_foot.offset = Vec3::new(2.5, 3.4, 6.0) / SCALE; + next.l_foot.offset = Vec3::new(5.0, 3.4, 8.0) / SCALE; next.l_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); - next.r_foot.offset = Vec3::new(2.5, -3.4, 6.0) / SCALE; + next.r_foot.offset = Vec3::new(5.0, -3.4, 8.0) / SCALE; next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); - next.back.offset = Vec3::new(-6.5, 16.0, 15.0); + next.back.offset = Vec3::new(-4.5, 12.0, 11.0); next.back.ori = Quaternion::rotation_x(2.5); next.back.scale = Vec3::one(); + + next.torso.offset = Vec3::new(0.0, 0.0, 0.0); + next.torso.ori = Quaternion::rotation_y(0.0); + next.torso.scale = Vec3::one(); + next } } diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 3d6e3e1dfc..f043977867 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -27,6 +27,8 @@ pub struct CharacterSkeleton { l_foot: Bone, r_foot: Bone, back: Bone, + torso: Bone, + } impl CharacterSkeleton { @@ -41,6 +43,8 @@ impl CharacterSkeleton { l_foot: Bone::default(), r_foot: Bone::default(), back: Bone::default(), + torso: Bone::default(), + } } } @@ -48,24 +52,25 @@ impl CharacterSkeleton { impl Skeleton for CharacterSkeleton { fn compute_matrices(&self) -> [FigureBoneData; 16] { let chest_mat = self.chest.compute_base_matrix(); - + let torso_mat = self.torso.compute_base_matrix(); [ - FigureBoneData::new(self.head.compute_base_matrix()), - FigureBoneData::new(chest_mat), - FigureBoneData::new(self.belt.compute_base_matrix()), - FigureBoneData::new(self.shorts.compute_base_matrix()), - FigureBoneData::new(self.l_hand.compute_base_matrix()), - FigureBoneData::new(self.r_hand.compute_base_matrix()), - FigureBoneData::new(self.l_foot.compute_base_matrix()), - FigureBoneData::new(self.r_foot.compute_base_matrix()), - FigureBoneData::new(chest_mat * self.back.compute_base_matrix()), - FigureBoneData::default(), + FigureBoneData::new(torso_mat * self.head.compute_base_matrix()), + FigureBoneData::new(torso_mat * chest_mat), + FigureBoneData::new(torso_mat * self.belt.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.shorts.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.l_hand.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.r_hand.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.l_foot.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.r_foot.compute_base_matrix()), + FigureBoneData::new(torso_mat * chest_mat * self.back.compute_base_matrix()), + FigureBoneData::new(torso_mat), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), + ] } @@ -79,5 +84,7 @@ impl Skeleton for CharacterSkeleton { self.l_foot.interpolate(&target.l_foot); self.r_foot.interpolate(&target.r_foot); self.back.interpolate(&target.back); + self.torso.interpolate(&target.torso); + } } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index c5214bcb88..6ea0654d0f 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -23,39 +23,54 @@ impl Animation for RunAnimation { ) -> Self::Skeleton { let mut next = (*skeleton).clone(); - let wave = (time as f32 * 14.0).sin(); + let wave = (time as f32 * 16.0).sin(); + let wavetest = (wave.cbrt()); let fuzzwave = (time as f32 * 12.0).sin(); - let wavecos = (time as f32 * 14.0).cos(); + let wavecos = (time as f32 * 16.0).cos(); let wave_slow = (time as f32 * 8.0 + PI).sin(); let wavecos_slow = (time as f32 * 8.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::unit_z() * (12.0 + fuzzwave *1.0)/ SCALE; - next.chest.offset = Vec3::unit_z() * (8.0 + fuzzwave * 0.8) / SCALE; - next.chest.ori = Quaternion::rotation_z(wave * 0.3); + next.head.offset = Vec3::unit_z() * (12.0 + wave *1.3)/ SCALE; + next.chest.scale = Vec3::one() * 1.0; - next.belt.offset = Vec3::unit_z() * (6.0 + fuzzwave * 0.8) / SCALE; - next.belt.ori = Quaternion::rotation_z(wave * 0.3); + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wave * 1.1) / SCALE; + next.chest.ori = Quaternion::rotation_z(wavecos * 0.2); + next.chest.scale = Vec3::one() / SCALE; - next.shorts.offset = Vec3::unit_z() * (3.0 + fuzzwave * 0.8) / SCALE; - next.shorts.ori = Quaternion::rotation_z(wave * 0.2); + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wave * 1.1) / SCALE; + next.belt.ori = Quaternion::rotation_z(wavecos * 0.2); + next.belt.scale = Vec3::one() /SCALE; - next.l_hand.offset = Vec3::new(0.0 - wavecos * 1.0, 7.5, 11.0 - wave * 1.0) / SCALE; - next.l_hand.ori = Quaternion::rotation_y(wave * -1.8); - next.r_hand.offset = Vec3::new(0.0 + wavecos * 1.0, -7.5, 11.0 + wave * 1.0) / SCALE; - next.r_hand.ori = Quaternion::rotation_y(wave * 1.8); + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wave * 1.1) / SCALE; + next.shorts.ori = Quaternion::rotation_z(wavecos * 0.6); + next.shorts.scale = Vec3::one() /SCALE; - next.l_foot.offset = Vec3::new(2.5 - wavecos * 4.0, 3.4, 6.0 + wave * 2.9) / SCALE; - next.l_foot.ori = Quaternion::rotation_y(wave * -1.0); - next.r_foot.offset = Vec3::new(2.5 + wavecos * 4.0, -3.4, 6.0 - wave * 2.9) / SCALE; + next.l_hand.offset = Vec3::new(2.0 - wavecos * 1.0, 7.5, 11.0 - wave * 1.0) / SCALE; + next.l_hand.ori = Quaternion::rotation_y(wavecos * -1.8); + next.r_hand.offset = Vec3::new(2.0 + wavecos * 1.0, -7.5, 11.0 + wave * 1.0) / SCALE; + next.r_hand.ori = Quaternion::rotation_y(wavecos * 1.8); - next.r_foot.ori = Quaternion::rotation_y(wave * 1.0); + next.l_foot.offset = Vec3::new(3.5 - wave * 1.0, 3.4, 6.0) / SCALE; + next.l_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); + next.l_foot.scale = Vec3::one() / SCALE; - next.back.offset = Vec3::new(-6.0, 16.0, 15.0); + next.r_foot.offset = Vec3::new(3.5 + wave * 1.0, -3.4, 6.0) / SCALE; + next.r_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); + + next.back.offset = Vec3::new(-4.5, 12.0, 11.0); next.back.ori = Quaternion::rotation_x(2.5); next.back.scale = Vec3::one(); + next.torso.offset = Vec3::new(0.0, 0.0, 0.0); + next.torso.ori = Quaternion::rotation_y(0.2 + wave * 0.1); + + + next.torso.scale = Vec3::one(); + + + next } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 985e1746a0..bc4422e6ea 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -52,6 +52,105 @@ pub struct FigureCache { states: HashMap>, } +impl FigureCache { + pub fn new() -> Self { + Self { + models: HashMap::new(), + states: HashMap::new(), + } + } + +<<<<<<< HEAD + pub fn get_or_create_model<'a>( + models: &'a mut HashMap, u64)>, + renderer: &mut Renderer, + tick: u64, + character: Character) + -> &'a (Model, u64) { + match models.get_mut(&character) { + Some((model, last_used)) => { + *last_used = tick; + } + None => { + models.insert(character, ({ + let bone_meshes = [ + Some(Self::load_head(character.head)), + Some(Self::load_chest(character.chest)), + Some(Self::load_belt(character.belt)), + Some(Self::load_pants(character.pants)), + Some(Self::load_left_hand(character.hand)), + Some(Self::load_right_hand(character.hand)), + Some(Self::load_left_foot(character.foot)), + Some(Self::load_right_foot(character.foot)), + Some(Self::load_weapon(character.weapon)), + None, + None, + None, + None, + None, + None, + None, + ]; +======= + let bone_meshes = [ + + + Some(load_segment("head.vox").generate_mesh(Vec3::new(1.0, -7.0, -6.0))), + Some(load_segment("chest.vox").generate_mesh(Vec3::new(-2.5, -6.0, 0.0))), +use std::{ + collections::HashMap, + f32, +}; +use specs::{Entity as EcsEntity, Component, VecStorage, Join}; +use vek::*; +use client::Client; +use common::{ + comp::{ + self, + character::{ + Character, + Head, + Chest, + Belt, + Pants, + Hand, + Foot, + Weapon, + } + }, + figure::Segment, + msg, + assets, +}; +use crate::{ + Error, + render::{ + Consts, + Globals, + Mesh, + Model, + Renderer, + FigurePipeline, + FigureBoneData, + FigureLocals, + }, + anim::{ + Animation, + Skeleton, + character::{ + CharacterSkeleton, + RunAnimation, + IdleAnimation, + }, + }, + mesh::Meshable, +}; + +pub struct FigureCache { + models: HashMap, u64)>, + states: HashMap>, +} + impl FigureCache { pub fn new() -> Self { Self { @@ -91,6 +190,204 @@ impl FigureCache { None, ]; + let mut mesh = Mesh::new(); + bone_meshes + .iter() + .enumerate() + .filter_map(|(i, bm)| bm.as_ref().map(|bm| (i, bm))) + .for_each(|(i, bone_mesh)| { + mesh.push_mesh_map(bone_mesh, |vert| vert.with_bone_idx(i as u8)) + }); + + let mut mesh = Mesh::new(); + bone_meshes + .iter() + .enumerate() + .filter_map(|(i, bm)| bm.as_ref().map(|bm| (i, bm))) + .for_each(|(i, bone_mesh)| { + mesh.push_mesh_map(bone_mesh, |vert| vert.with_bone_idx(i as u8)) + }); + + renderer.create_model(&mesh).unwrap() + }, tick)); + } + } + + &models[&character] + } + + pub fn clean(&mut self, tick: u64) { + // TODO: Don't hard-code this + self.models.retain(|_, (_, last_used)| *last_used + 60 > tick); + } + + fn load_mesh(filename: &'static str, position: Vec3) -> Mesh { + let fullpath: String = ["/voxygen/voxel/", filename].concat(); + Segment::from(dot_vox::load_bytes( + assets::load(fullpath.as_str()) + .expect("Error loading file") + .as_slice(), + ).unwrap()) + .generate_mesh(position) + } + + fn load_head(head: Head) -> Mesh { + Self::load_mesh(match head { + Head::DefaultHead => "head.vox", + }, Vec3::new(-5.5, -7.0, -6.0)) + } + + fn load_chest(chest: Chest) -> Mesh { + Self::load_mesh(match chest { + Chest::DefaultChest => "chest.vox", + }, Vec3::new(-2.5, -6.0, 0.0)) + } + + fn load_belt(belt: Belt) -> Mesh { + Self::load_mesh(match belt { + Belt::DefaultBelt => "belt.vox", + }, Vec3::new(-2.5, -5.0, 0.0)) + } + + fn load_pants(pants: Pants) -> Mesh { + Self::load_mesh(match pants { + Pants::DefaultPants => "pants.vox", + }, Vec3::new(-2.5, -5.0, 0.0)) + } + + fn load_left_hand(hand: Hand) -> Mesh { + Self::load_mesh(match hand { + Hand::DefaultHand => "hand.vox", + }, Vec3::new(0.0, -2.0, -7.0)) + } + + fn load_right_hand(hand: Hand) -> Mesh { + Self::load_mesh(match hand { + Hand::DefaultHand => "hand.vox", + }, Vec3::new(0.0, -2.0, -7.0)) + } + + fn load_left_foot(foot: Foot) -> Mesh { + Self::load_mesh(match foot { + Foot::DefaultFoot => "foot.vox", + }, Vec3::new(-3.5, -2.5, -8.0)) + } + + fn load_right_foot(foot: Foot) -> Mesh { + Self::load_mesh(match foot { + Foot::DefaultFoot => "foot.vox", + }, Vec3::new(-3.5, -2.5, -8.0)) + } + + fn load_weapon(weapon: Weapon) -> Mesh { + Self::load_mesh(match weapon { + Weapon::Sword => "sword.vox", + // TODO actually match against other weapons and set the right model + _ => "sword.vox", + }, Vec3::new(0.0, 0.0, -4.0)) + } + + + pub fn maintain(&mut self, renderer: &mut Renderer, client: &mut Client) { + let time = client.state().get_time(); + let ecs = client.state_mut().ecs_mut(); + for (entity, pos, dir, character, animation_history) in ( + &ecs.entities(), + &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), + ).join() { + let state = self.states + .entry(entity) + .or_insert_with(|| FigureState::new(renderer, CharacterSkeleton::new())); + + let target_skeleton = match animation_history.current { + comp::character::Animation::Idle => IdleAnimation::update_skeleton(&mut state.skeleton, time), + comp::character::Animation::Run => RunAnimation::update_skeleton(&mut state.skeleton, time), + }; + + state.skeleton.interpolate(&target_skeleton); + + state.update(renderer, pos.0, dir.0); + } + + self.states.retain(|entity, _| ecs.entities().is_alive(*entity)); + } + + pub fn render(&mut self, renderer: &mut Renderer, client: &mut Client, globals: &Consts) { + let tick = client.get_tick(); + let ecs = client.state().ecs(); + let models = &mut self.models; + + for (entity, &character) in ( + &ecs.entities(), + &ecs.read_storage::(), + ).join() { + let model = Self::get_or_create_model(models, renderer, tick, character); + let state = self.states.get(&entity).unwrap(); + renderer.render_figure( + &model.0, + globals, + &state.locals, + &state.bone_consts, + ); + } + } +} + +pub struct FigureState { + bone_consts: Consts, + locals: Consts, + skeleton: S, +} + +impl FigureState { + pub fn new(renderer: &mut Renderer, skeleton: S) -> Self { + Self { + bone_consts: renderer.create_consts(&skeleton.compute_matrices()).unwrap(), + locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(), + skeleton, + } + } + + fn update(&mut self, renderer: &mut Renderer, pos: Vec3, dir: Vec3) { + let mat = + Mat4::::identity() * + Mat4::translation_3d(pos) * + Mat4::rotation_z(dir.y.atan2(dir.x));// + f32//::consts)::PI / 2.0); + + let locals = FigureLocals::new(mat); + renderer.update_consts(&mut self.locals, &[locals]).unwrap(); + + renderer.update_consts(&mut self.bone_consts, &self.skeleton.compute_matrices()).unwrap(); + } +} + Some(load_segment("pants.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), + Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -8.0))), + Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -8.0))), + Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), + Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), + Some(load_segment("sword.vox").generate_mesh(Vec3::new(0.0, -0.0, -4.0))), + None, + None, + None, + None, + None, + None, + None, + ]; + + let mut mesh = Mesh::new(); + bone_meshes + .iter() + .enumerate() + .filter_map(|(i, bm)| bm.as_ref().map(|bm| (i, bm))) + .for_each(|(i, bone_mesh)| { + mesh.push_mesh_map(bone_mesh, |vert| vert.with_bone_idx(i as u8)) + }); +>>>>>>> velocity tilt + let mut mesh = Mesh::new(); bone_meshes .iter() From 4d0660affbb5ad56c630a4c4991f36e4e091ede8 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Tue, 23 Apr 2019 20:17:50 -0400 Subject: [PATCH 05/12] run animation incremental tweaks Former-commit-id: c80f014baf3b9ddb73bb01cf6fd83272d890ab55 --- voxygen/src/anim/character/idle.rs | 16 ++++++--- voxygen/src/anim/character/mod.rs | 10 ++++-- voxygen/src/anim/character/run.rs | 55 +++++++++++++++++------------- voxygen/src/scene/figure.rs | 10 +++--- 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index 69f1ed5bfd..26633b13c5 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -32,7 +32,7 @@ impl Animation for IdleAnimation { let waveultracos_slow = (time as f32 * 1.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::new(-1.0, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; + next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; next.head.ori = Quaternion::rotation_y(waveultra_slow * 0.05); next.head.scale = Vec3::one() / SCALE; @@ -48,9 +48,9 @@ impl Animation for IdleAnimation { next.shorts.ori = Quaternion::rotation_y(0.0); next.shorts.scale = Vec3::one() / SCALE; - next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 13.5 + waveultra_slow * 1.1) / SCALE; + next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 13.5 + waveultra_slow * 1.1) / SCALE; + next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); next.l_foot.offset = Vec3::new(5.0, 3.4, 8.0) / SCALE; @@ -58,7 +58,7 @@ impl Animation for IdleAnimation { next.r_foot.offset = Vec3::new(5.0, -3.4, 8.0) / SCALE; next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); - next.back.offset = Vec3::new(-4.5, 12.0, 11.0); + next.back.offset = Vec3::new(-4.5, 14.0, 13.0); next.back.ori = Quaternion::rotation_x(2.5); next.back.scale = Vec3::one(); @@ -67,6 +67,14 @@ impl Animation for IdleAnimation { next.torso.ori = Quaternion::rotation_y(0.0); next.torso.scale = Vec3::one(); + next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0) / SCALE; + next.l_shoulder.ori = Quaternion::rotation_y(0.0); + next.l_shoulder.scale = Vec3::one() / SCALE; + + next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0) / SCALE; + next.r_shoulder.ori = Quaternion::rotation_y(0.0); + next.r_shoulder.scale = Vec3::one() / SCALE; + next } } diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index f043977867..1579c6a906 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -28,6 +28,8 @@ pub struct CharacterSkeleton { r_foot: Bone, back: Bone, torso: Bone, + l_shoulder: Bone, + r_shoulder: Bone, } @@ -44,6 +46,8 @@ impl CharacterSkeleton { r_foot: Bone::default(), back: Bone::default(), torso: Bone::default(), + l_shoulder: Bone::default(), + r_shoulder: Bone::default(), } } @@ -64,8 +68,8 @@ impl Skeleton for CharacterSkeleton { FigureBoneData::new(torso_mat * self.r_foot.compute_base_matrix()), FigureBoneData::new(torso_mat * chest_mat * self.back.compute_base_matrix()), FigureBoneData::new(torso_mat), - FigureBoneData::default(), - FigureBoneData::default(), + FigureBoneData::new(torso_mat * self.l_shoulder.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.r_shoulder.compute_base_matrix()), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), @@ -85,6 +89,8 @@ impl Skeleton for CharacterSkeleton { self.r_foot.interpolate(&target.r_foot); self.back.interpolate(&target.back); self.torso.interpolate(&target.torso); + self.l_shoulder.interpolate(&target.l_shoulder); + self.r_shoulder.interpolate(&target.r_shoulder); } } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 6ea0654d0f..f2a769fcb3 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -23,53 +23,60 @@ impl Animation for RunAnimation { ) -> Self::Skeleton { let mut next = (*skeleton).clone(); - let wave = (time as f32 * 16.0).sin(); + let wave = (time as f32 * 14.0).sin(); let wavetest = (wave.cbrt()); let fuzzwave = (time as f32 * 12.0).sin(); - let wavecos = (time as f32 * 16.0).cos(); - let wave_slow = (time as f32 * 8.0 + PI).sin(); + let wavecos = (time as f32 * 14.0).cos(); + let wave_slow = (time as f32 * 7.0 + PI).sin(); let wavecos_slow = (time as f32 * 8.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::unit_z() * (12.0 + wave *1.3)/ SCALE; - next.chest.scale = Vec3::one() * 1.0; + next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3) / SCALE; + next.head.ori = Quaternion::rotation_y(-0.15); - next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wave * 1.1) / SCALE; - next.chest.ori = Quaternion::rotation_z(wavecos * 0.2); + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1) / SCALE; + next.chest.ori = Quaternion::rotation_z(wave * 0.1); next.chest.scale = Vec3::one() / SCALE; - next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wave * 1.1) / SCALE; - next.belt.ori = Quaternion::rotation_z(wavecos * 0.2); + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wavecos * 1.1) / SCALE; + next.belt.ori = Quaternion::rotation_z(wave * 0.25); next.belt.scale = Vec3::one() /SCALE; - next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wave * 1.1) / SCALE; - next.shorts.ori = Quaternion::rotation_z(wavecos * 0.6); + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wavecos * 1.1) / SCALE; + next.shorts.ori = Quaternion::rotation_z(wave * 0.6); next.shorts.scale = Vec3::one() /SCALE; - next.l_hand.offset = Vec3::new(2.0 - wavecos * 1.0, 7.5, 11.0 - wave * 1.0) / SCALE; - next.l_hand.ori = Quaternion::rotation_y(wavecos * -1.8); - next.r_hand.offset = Vec3::new(2.0 + wavecos * 1.0, -7.5, 11.0 + wave * 1.0) / SCALE; - next.r_hand.ori = Quaternion::rotation_y(wavecos * 1.8); + next.l_hand.offset = Vec3::new(2.0 - wavecos * 2.5, 7.5, 12.0 + wave * 1.5) / SCALE; + next.l_hand.ori = Quaternion::rotation_y(wavecos * 0.9); - next.l_foot.offset = Vec3::new(3.5 - wave * 1.0, 3.4, 6.0) / SCALE; - next.l_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); - next.l_foot.scale = Vec3::one() / SCALE; + next.r_hand.offset = Vec3::new(2.0 + wavecos * 2.5, -7.5, 12.0 - wave * 1.5) / SCALE; + next.r_hand.ori = Quaternion::rotation_y(wavecos * -0.9); - next.r_foot.offset = Vec3::new(3.5 + wave * 1.0, -3.4, 6.0) / SCALE; - next.r_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); + next.l_foot.offset = Vec3::new(3.5 + wave * 1.0, 3.4, 6.0) / SCALE; + next.l_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); - next.back.offset = Vec3::new(-4.5, 12.0, 11.0); + next.r_foot.offset = Vec3::new(3.5 - wave * 1.0, -3.4, 6.0) / SCALE; + next.r_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); + + next.back.offset = Vec3::new(-5.0, 14.0, 13.0); next.back.ori = Quaternion::rotation_x(2.5); next.back.scale = Vec3::one(); next.torso.offset = Vec3::new(0.0, 0.0, 0.0); - next.torso.ori = Quaternion::rotation_y(0.2 + wave * 0.1); - - + next.torso.ori = Quaternion::rotation_y(0.25 + wavecos * 0.1); next.torso.scale = Vec3::one(); + next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0) / SCALE; + next.l_shoulder.ori = Quaternion::rotation_y(0.0); + next.l_shoulder.scale = Vec3::one() / SCALE; + + next.r_shoulder.offset = Vec3::new(3.0, -6.0, 18.0) / SCALE; + next.r_shoulder.ori = Quaternion::rotation_y(0.0); + next.r_shoulder.scale = Vec3::one() / SCALE; //???why are shoulder scales like this + + next diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index bc4422e6ea..b6d3c4532e 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -95,7 +95,7 @@ impl FigureCache { let bone_meshes = [ - Some(load_segment("head.vox").generate_mesh(Vec3::new(1.0, -7.0, -6.0))), + Some(load_segment("head.vox").generate_mesh(Vec3::new(-5.5, -7.0, -6.0))), Some(load_segment("chest.vox").generate_mesh(Vec3::new(-2.5, -6.0, 0.0))), use std::{ collections::HashMap, @@ -364,14 +364,14 @@ impl FigureState { } } Some(load_segment("pants.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), - Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -8.0))), - Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -8.0))), + Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), + Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), Some(load_segment("sword.vox").generate_mesh(Vec3::new(0.0, -0.0, -4.0))), None, - None, - None, + //Some(load_segment("shoulder_left.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), + //Some(load_segment("shoulder_right.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), None, None, None, From 97603120a2d1b6e521bfc90f3d5938d526b8d1b7 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Tue, 23 Apr 2019 20:36:33 -0400 Subject: [PATCH 06/12] simplified scaling code Former-commit-id: 3f85bf6aef1f3931570fafb8b2aa5b0dc26f8fad --- voxygen/src/anim/character/idle.rs | 43 +++++++++++++++++------------- voxygen/src/anim/character/run.rs | 38 ++++++++++++++------------ 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index 26633b13c5..2f7b1ad6ef 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -32,31 +32,38 @@ impl Animation for IdleAnimation { let waveultracos_slow = (time as f32 * 1.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; + next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4); next.head.ori = Quaternion::rotation_y(waveultra_slow * 0.05); - next.head.scale = Vec3::one() / SCALE; + next.head.scale = Vec3::one(); - next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + waveultra_slow * 0.4) / SCALE; + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + waveultra_slow * 0.4); next.chest.ori = Quaternion::rotation_y(0.0); - next.chest.scale = Vec3::one() / SCALE; + next.chest.scale = Vec3::one(); - next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + waveultra_slow * 0.4) / SCALE; + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + waveultra_slow * 0.4); next.belt.ori = Quaternion::rotation_y(0.0); - next.belt.scale = Vec3::one() / SCALE; + next.belt.scale = Vec3::one(); - next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + waveultra_slow * 0.4) / SCALE; + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + waveultra_slow * 0.4); next.shorts.ori = Quaternion::rotation_y(0.0); - next.shorts.scale = Vec3::one() / SCALE; + next.shorts.scale = Vec3::one(); - next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; + next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1); next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; - next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); + next.l_hand.scale = Vec3::one(); - next.l_foot.offset = Vec3::new(5.0, 3.4, 8.0) / SCALE; + next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1); + next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); + next.r_hand.scale = Vec3::one(); + + next.l_foot.offset = Vec3::new(5.0, 3.4, 8.0); next.l_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); - next.r_foot.offset = Vec3::new(5.0, -3.4, 8.0) / SCALE; + next.l_foot.scale = Vec3::one(); + + next.r_foot.offset = Vec3::new(5.0, -3.4, 8.0); next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); + next.r_foot.scale = Vec3::one(); + next.back.offset = Vec3::new(-4.5, 14.0, 13.0); next.back.ori = Quaternion::rotation_x(2.5); @@ -65,15 +72,15 @@ impl Animation for IdleAnimation { next.torso.offset = Vec3::new(0.0, 0.0, 0.0); next.torso.ori = Quaternion::rotation_y(0.0); - next.torso.scale = Vec3::one(); + next.torso.scale = Vec3::one() / 11.0; - next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0) / SCALE; + next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0); next.l_shoulder.ori = Quaternion::rotation_y(0.0); - next.l_shoulder.scale = Vec3::one() / SCALE; + next.l_shoulder.scale = Vec3::one(); - next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0) / SCALE; + next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0); next.r_shoulder.ori = Quaternion::rotation_y(0.0); - next.r_shoulder.scale = Vec3::one() / SCALE; + next.r_shoulder.scale = Vec3::one(); next } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index f2a769fcb3..ee1808a2d1 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -32,32 +32,37 @@ impl Animation for RunAnimation { let wave_dip = (wave_slow.abs() - 0.5).abs(); - next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3) / SCALE; + next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3); // / SCALE; next.head.ori = Quaternion::rotation_y(-0.15); + next.head.scale = Vec3::one(); // / SCALE; - next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1) / SCALE; + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1); next.chest.ori = Quaternion::rotation_z(wave * 0.1); - next.chest.scale = Vec3::one() / SCALE; + next.chest.scale = Vec3::one(); - next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wavecos * 1.1) / SCALE; + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wavecos * 1.1); next.belt.ori = Quaternion::rotation_z(wave * 0.25); - next.belt.scale = Vec3::one() /SCALE; + next.belt.scale = Vec3::one(); - next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wavecos * 1.1) / SCALE; + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wavecos * 1.1); next.shorts.ori = Quaternion::rotation_z(wave * 0.6); - next.shorts.scale = Vec3::one() /SCALE; + next.shorts.scale = Vec3::one(); - next.l_hand.offset = Vec3::new(2.0 - wavecos * 2.5, 7.5, 12.0 + wave * 1.5) / SCALE; + next.l_hand.offset = Vec3::new(2.0 - wavecos * 2.5, 7.5, 12.0 + wave * 1.5); next.l_hand.ori = Quaternion::rotation_y(wavecos * 0.9); + next.l_hand.scale = Vec3::one(); - next.r_hand.offset = Vec3::new(2.0 + wavecos * 2.5, -7.5, 12.0 - wave * 1.5) / SCALE; + next.r_hand.offset = Vec3::new(2.0 + wavecos * 2.5, -7.5, 12.0 - wave * 1.5); next.r_hand.ori = Quaternion::rotation_y(wavecos * -0.9); + next.r_hand.scale = Vec3::one(); - next.l_foot.offset = Vec3::new(3.5 + wave * 1.0, 3.4, 6.0) / SCALE; + next.l_foot.offset = Vec3::new(3.5 + wave * 1.0, 3.4, 6.0); next.l_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); + next.l_foot.scale = Vec3::one(); - next.r_foot.offset = Vec3::new(3.5 - wave * 1.0, -3.4, 6.0) / SCALE; + next.r_foot.offset = Vec3::new(3.5 - wave * 1.0, -3.4, 6.0); next.r_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); + next.r_foot.scale = Vec3::one(); next.back.offset = Vec3::new(-5.0, 14.0, 13.0); next.back.ori = Quaternion::rotation_x(2.5); @@ -65,17 +70,16 @@ impl Animation for RunAnimation { next.torso.offset = Vec3::new(0.0, 0.0, 0.0); next.torso.ori = Quaternion::rotation_y(0.25 + wavecos * 0.1); - next.torso.scale = Vec3::one(); + next.torso.scale = Vec3::one() / 11.0; - next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0) / SCALE; + next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0); next.l_shoulder.ori = Quaternion::rotation_y(0.0); - next.l_shoulder.scale = Vec3::one() / SCALE; + next.l_shoulder.scale = Vec3::one(); - next.r_shoulder.offset = Vec3::new(3.0, -6.0, 18.0) / SCALE; + next.r_shoulder.offset = Vec3::new(3.0, -6.0, 18.0); next.r_shoulder.ori = Quaternion::rotation_y(0.0); - next.r_shoulder.scale = Vec3::one() / SCALE; //???why are shoulder scales like this - + next.r_shoulder.scale = Vec3::one(); next From 9510edd1485fbbce6ea2b01878ace8352913eedc Mon Sep 17 00:00:00 2001 From: jshipsey Date: Sun, 21 Apr 2019 13:35:43 -0400 Subject: [PATCH 07/12] velocity tilt Former-commit-id: 34443765d993ec5036d2b3e08e7dff5a68193de6 --- voxygen/src/anim/character/idle.rs | 8 +- voxygen/src/anim/character/mod.rs | 15 +- voxygen/src/anim/character/run.rs | 12 +- voxygen/src/scene/figure.rs | 309 ++--------------------------- 4 files changed, 38 insertions(+), 306 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index 2f7b1ad6ef..c3d335654f 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -13,7 +13,6 @@ use super::{ pub struct IdleAnimation; -//TODO: Make it actually good, possibly add the head rotating slightly, add breathing, etc. impl Animation for IdleAnimation { type Skeleton = CharacterSkeleton; type Dependency = f64; @@ -64,10 +63,9 @@ impl Animation for IdleAnimation { next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); next.r_foot.scale = Vec3::one(); - - next.back.offset = Vec3::new(-4.5, 14.0, 13.0); - next.back.ori = Quaternion::rotation_x(2.5); - next.back.scale = Vec3::one(); + next.weapon.offset = Vec3::new(-4.5, 14.0, 13.0); + next.weapon.ori = Quaternion::rotation_x(2.5); + next.weapon.scale = Vec3::one(); next.torso.offset = Vec3::new(0.0, 0.0, 0.0); diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 1579c6a906..b699c2ed88 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -26,11 +26,10 @@ pub struct CharacterSkeleton { r_hand: Bone, l_foot: Bone, r_foot: Bone, - back: Bone, + weapon: Bone, torso: Bone, l_shoulder: Bone, r_shoulder: Bone, - } impl CharacterSkeleton { @@ -44,7 +43,7 @@ impl CharacterSkeleton { r_hand: Bone::default(), l_foot: Bone::default(), r_foot: Bone::default(), - back: Bone::default(), + weapon: Bone::default(), torso: Bone::default(), l_shoulder: Bone::default(), r_shoulder: Bone::default(), @@ -66,10 +65,12 @@ impl Skeleton for CharacterSkeleton { FigureBoneData::new(torso_mat * self.r_hand.compute_base_matrix()), FigureBoneData::new(torso_mat * self.l_foot.compute_base_matrix()), FigureBoneData::new(torso_mat * self.r_foot.compute_base_matrix()), - FigureBoneData::new(torso_mat * chest_mat * self.back.compute_base_matrix()), + FigureBoneData::new(torso_mat * chest_mat * self.weapon.compute_base_matrix()), FigureBoneData::new(torso_mat), - FigureBoneData::new(torso_mat * self.l_shoulder.compute_base_matrix()), - FigureBoneData::new(torso_mat * self.r_shoulder.compute_base_matrix()), + //FigureBoneData::new(torso_mat * self.l_shoulder.compute_base_matrix()), + //FigureBoneData::new(torso_mat * self.r_shoulder.compute_base_matrix()), + FigureBoneData::default(), + FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), @@ -87,7 +88,7 @@ impl Skeleton for CharacterSkeleton { self.r_hand.interpolate(&target.r_hand); self.l_foot.interpolate(&target.l_foot); self.r_foot.interpolate(&target.r_foot); - self.back.interpolate(&target.back); + self.weapon.interpolate(&target.weapon); self.torso.interpolate(&target.torso); self.l_shoulder.interpolate(&target.l_shoulder); self.r_shoulder.interpolate(&target.r_shoulder); diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index ee1808a2d1..33a8e79b95 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -31,10 +31,9 @@ impl Animation for RunAnimation { let wavecos_slow = (time as f32 * 8.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); - - next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3); // / SCALE; + next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3); next.head.ori = Quaternion::rotation_y(-0.15); - next.head.scale = Vec3::one(); // / SCALE; + next.head.scale = Vec3::one(); next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1); next.chest.ori = Quaternion::rotation_z(wave * 0.1); @@ -64,15 +63,14 @@ impl Animation for RunAnimation { next.r_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); next.r_foot.scale = Vec3::one(); - next.back.offset = Vec3::new(-5.0, 14.0, 13.0); - next.back.ori = Quaternion::rotation_x(2.5); - next.back.scale = Vec3::one(); + next.weapon.offset = Vec3::new(-5.0, 14.0, 13.0); + next.weapon.ori = Quaternion::rotation_x(2.5); + next.weapon.scale = Vec3::one(); next.torso.offset = Vec3::new(0.0, 0.0, 0.0); next.torso.ori = Quaternion::rotation_y(0.25 + wavecos * 0.1); next.torso.scale = Vec3::one() / 11.0; - next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0); next.l_shoulder.ori = Quaternion::rotation_y(0.0); next.l_shoulder.scale = Vec3::one(); diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index b6d3c4532e..02a99c64e1 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -52,105 +52,6 @@ pub struct FigureCache { states: HashMap>, } -impl FigureCache { - pub fn new() -> Self { - Self { - models: HashMap::new(), - states: HashMap::new(), - } - } - -<<<<<<< HEAD - pub fn get_or_create_model<'a>( - models: &'a mut HashMap, u64)>, - renderer: &mut Renderer, - tick: u64, - character: Character) - -> &'a (Model, u64) { - match models.get_mut(&character) { - Some((model, last_used)) => { - *last_used = tick; - } - None => { - models.insert(character, ({ - let bone_meshes = [ - Some(Self::load_head(character.head)), - Some(Self::load_chest(character.chest)), - Some(Self::load_belt(character.belt)), - Some(Self::load_pants(character.pants)), - Some(Self::load_left_hand(character.hand)), - Some(Self::load_right_hand(character.hand)), - Some(Self::load_left_foot(character.foot)), - Some(Self::load_right_foot(character.foot)), - Some(Self::load_weapon(character.weapon)), - None, - None, - None, - None, - None, - None, - None, - ]; -======= - let bone_meshes = [ - - - Some(load_segment("head.vox").generate_mesh(Vec3::new(-5.5, -7.0, -6.0))), - Some(load_segment("chest.vox").generate_mesh(Vec3::new(-2.5, -6.0, 0.0))), -use std::{ - collections::HashMap, - f32, -}; -use specs::{Entity as EcsEntity, Component, VecStorage, Join}; -use vek::*; -use client::Client; -use common::{ - comp::{ - self, - character::{ - Character, - Head, - Chest, - Belt, - Pants, - Hand, - Foot, - Weapon, - } - }, - figure::Segment, - msg, - assets, -}; -use crate::{ - Error, - render::{ - Consts, - Globals, - Mesh, - Model, - Renderer, - FigurePipeline, - FigureBoneData, - FigureLocals, - }, - anim::{ - Animation, - Skeleton, - character::{ - CharacterSkeleton, - RunAnimation, - IdleAnimation, - }, - }, - mesh::Meshable, -}; - -pub struct FigureCache { - models: HashMap, u64)>, - states: HashMap>, -} - impl FigureCache { pub fn new() -> Self { Self { @@ -189,6 +90,28 @@ impl FigureCache { None, None, ]; +// let bone_meshes = [ +// +// +// Some(load_segment("head.vox").generate_mesh(Vec3::new(-5.5, -7.0, -6.0))), +// Some(load_segment("chest.vox").generate_mesh(Vec3::new(-2.5, -6.0, 0.0))), +// Some(load_segment("belt.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), +// Some(load_segment("pants.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), +// Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), +// Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), +// Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), +// Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), +// Some(load_segment("sword.vox").generate_mesh(Vec3::new(0.0, -0.0, -4.0))), +// None, + //Some(load_segment("shoulder_left.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), + //Some(load_segment("shoulder_right.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), +// None, +// None, +// None, +// None, +// None, +// None, +// ]; let mut mesh = Mesh::new(); bone_meshes @@ -342,194 +265,6 @@ pub struct FigureState { skeleton: S, } -impl FigureState { - pub fn new(renderer: &mut Renderer, skeleton: S) -> Self { - Self { - bone_consts: renderer.create_consts(&skeleton.compute_matrices()).unwrap(), - locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(), - skeleton, - } - } - - fn update(&mut self, renderer: &mut Renderer, pos: Vec3, dir: Vec3) { - let mat = - Mat4::::identity() * - Mat4::translation_3d(pos) * - Mat4::rotation_z(dir.y.atan2(dir.x));// + f32//::consts)::PI / 2.0); - - let locals = FigureLocals::new(mat); - renderer.update_consts(&mut self.locals, &[locals]).unwrap(); - - renderer.update_consts(&mut self.bone_consts, &self.skeleton.compute_matrices()).unwrap(); - } -} - Some(load_segment("pants.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), - Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), - Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), - Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), - Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), - Some(load_segment("sword.vox").generate_mesh(Vec3::new(0.0, -0.0, -4.0))), - None, - //Some(load_segment("shoulder_left.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), - //Some(load_segment("shoulder_right.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), - None, - None, - None, - None, - ]; - - let mut mesh = Mesh::new(); - bone_meshes - .iter() - .enumerate() - .filter_map(|(i, bm)| bm.as_ref().map(|bm| (i, bm))) - .for_each(|(i, bone_mesh)| { - mesh.push_mesh_map(bone_mesh, |vert| vert.with_bone_idx(i as u8)) - }); ->>>>>>> velocity tilt - - let mut mesh = Mesh::new(); - bone_meshes - .iter() - .enumerate() - .filter_map(|(i, bm)| bm.as_ref().map(|bm| (i, bm))) - .for_each(|(i, bone_mesh)| { - mesh.push_mesh_map(bone_mesh, |vert| vert.with_bone_idx(i as u8)) - }); - - renderer.create_model(&mesh).unwrap() - }, tick)); - } - } - - &models[&character] - } - - pub fn clean(&mut self, tick: u64) { - // TODO: Don't hard-code this - self.models.retain(|_, (_, last_used)| *last_used + 60 > tick); - } - - fn load_mesh(filename: &'static str, position: Vec3) -> Mesh { - let fullpath: String = ["/voxygen/voxel/", filename].concat(); - Segment::from(dot_vox::load_bytes( - assets::load(fullpath.as_str()) - .expect("Error loading file") - .as_slice(), - ).unwrap()) - .generate_mesh(position) - } - - fn load_head(head: Head) -> Mesh { - Self::load_mesh(match head { - Head::DefaultHead => "head.vox", - }, Vec3::new(-3.5, -7.0, -6.0)) - } - - fn load_chest(chest: Chest) -> Mesh { - Self::load_mesh(match chest { - Chest::DefaultChest => "chest.vox", - }, Vec3::new(-3.0, -6.0, 0.0)) - } - - fn load_belt(belt: Belt) -> Mesh { - Self::load_mesh(match belt { - Belt::DefaultBelt => "belt.vox", - }, Vec3::new(-3.0, -5.0, 0.0)) - } - - fn load_pants(pants: Pants) -> Mesh { - Self::load_mesh(match pants { - Pants::DefaultPants => "pants.vox", - }, Vec3::new(-3.0, -5.0, 0.0)) - } - - fn load_left_hand(hand: Hand) -> Mesh { - Self::load_mesh(match hand { - Hand::DefaultHand => "hand.vox", - }, Vec3::new(0.0, -2.0, -6.0)) - } - - fn load_right_hand(hand: Hand) -> Mesh { - Self::load_mesh(match hand { - Hand::DefaultHand => "hand.vox", - }, Vec3::new(0.0, -2.0, -6.0)) - } - - fn load_left_foot(foot: Foot) -> Mesh { - Self::load_mesh(match foot { - Foot::DefaultFoot => "foot.vox", - }, Vec3::new(-4.0, -2.5, -6.0)) - } - - fn load_right_foot(foot: Foot) -> Mesh { - Self::load_mesh(match foot { - Foot::DefaultFoot => "foot.vox", - }, Vec3::new(-4.0, -2.5, -6.0)) - } - - fn load_weapon(weapon: Weapon) -> Mesh { - Self::load_mesh(match weapon { - Weapon::Sword => "sword.vox", - // TODO actually match against other weapons and set the right model - _ => "sword.vox", - }, Vec3::new(0.0, 0.0, 0.0)) - } - - pub fn maintain(&mut self, renderer: &mut Renderer, client: &mut Client) { - let time = client.state().get_time(); - let ecs = client.state_mut().ecs_mut(); - for (entity, pos, dir, character, animation_history) in ( - &ecs.entities(), - &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), - ).join() { - let state = self.states - .entry(entity) - .or_insert_with(|| FigureState::new(renderer, CharacterSkeleton::new())); - - let target_skeleton = match animation_history.current { - comp::character::Animation::Idle => IdleAnimation::update_skeleton(&mut state.skeleton, time), - comp::character::Animation::Run => RunAnimation::update_skeleton(&mut state.skeleton, time), - }; - - state.skeleton.interpolate(&target_skeleton); - - state.update(renderer, pos.0, dir.0); - } - - self.states.retain(|entity, _| ecs.entities().is_alive(*entity)); - } - - pub fn render(&mut self, renderer: &mut Renderer, client: &mut Client, globals: &Consts) { - let tick = client.get_tick(); - let ecs = client.state().ecs(); - let models = &mut self.models; - - for (entity, &character) in ( - &ecs.entities(), - &ecs.read_storage::(), - ).join() { - let model = Self::get_or_create_model(models, renderer, tick, character); - let state = self.states.get(&entity).unwrap(); - renderer.render_figure( - &model.0, - globals, - &state.locals, - &state.bone_consts, - ); - } - } -} - -pub struct FigureState { - bone_consts: Consts, - locals: Consts, - skeleton: S, -} - impl FigureState { pub fn new(renderer: &mut Renderer, skeleton: S) -> Self { Self { From 9c15fa08a8e49d388e05f0478590a8e38a8ee6d5 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Tue, 23 Apr 2019 20:17:50 -0400 Subject: [PATCH 08/12] run animation incremental tweaks Former-commit-id: 3abad8762a7a2daaf96c955cf89bcf5713ae7318 --- voxygen/src/anim/character/idle.rs | 24 +++++ voxygen/src/anim/character/mod.rs | 153 +++++++++++++---------------- voxygen/src/scene/figure.rs | 22 ----- 3 files changed, 95 insertions(+), 104 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index c3d335654f..89aef55694 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -31,7 +31,11 @@ impl Animation for IdleAnimation { let waveultracos_slow = (time as f32 * 1.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); +<<<<<<< HEAD next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4); +======= + next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; +>>>>>>> run animation incremental tweaks next.head.ori = Quaternion::rotation_y(waveultra_slow * 0.05); next.head.scale = Vec3::one(); @@ -47,11 +51,17 @@ impl Animation for IdleAnimation { next.shorts.ori = Quaternion::rotation_y(0.0); next.shorts.scale = Vec3::one(); +<<<<<<< HEAD next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1); next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); next.l_hand.scale = Vec3::one(); next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1); +======= + next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; + next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); + next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; +>>>>>>> run animation incremental tweaks next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); next.r_hand.scale = Vec3::one(); @@ -63,9 +73,15 @@ impl Animation for IdleAnimation { next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); next.r_foot.scale = Vec3::one(); +<<<<<<< HEAD next.weapon.offset = Vec3::new(-4.5, 14.0, 13.0); next.weapon.ori = Quaternion::rotation_x(2.5); next.weapon.scale = Vec3::one(); +======= + next.back.offset = Vec3::new(-4.5, 14.0, 13.0); + next.back.ori = Quaternion::rotation_x(2.5); + next.back.scale = Vec3::one(); +>>>>>>> run animation incremental tweaks next.torso.offset = Vec3::new(0.0, 0.0, 0.0); @@ -80,6 +96,14 @@ impl Animation for IdleAnimation { next.r_shoulder.ori = Quaternion::rotation_y(0.0); next.r_shoulder.scale = Vec3::one(); + next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0) / SCALE; + next.l_shoulder.ori = Quaternion::rotation_y(0.0); + next.l_shoulder.scale = Vec3::one() / SCALE; + + next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0) / SCALE; + next.r_shoulder.ori = Quaternion::rotation_y(0.0); + next.r_shoulder.scale = Vec3::one() / SCALE; + next } } diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index b699c2ed88..33a8e79b95 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -1,97 +1,86 @@ -pub mod run; -pub mod idle; +// Standard +use std::f32::consts::PI; -// Reexports -pub use self::run::RunAnimation; -pub use self::idle::IdleAnimation; - -// Crate -use crate::render::FigureBoneData; +// Library +use vek::*; // Local use super::{ - Skeleton, - Bone, + CharacterSkeleton, + super::Animation, + SCALE }; -const SCALE: f32 = 11.0; +pub struct RunAnimation; -#[derive(Clone)] -pub struct CharacterSkeleton { - head: Bone, - chest: Bone, - belt: Bone, - shorts: Bone, - l_hand: Bone, - r_hand: Bone, - l_foot: Bone, - r_foot: Bone, - weapon: Bone, - torso: Bone, - l_shoulder: Bone, - r_shoulder: Bone, -} +impl Animation for RunAnimation { + type Skeleton = CharacterSkeleton; + type Dependency = f64; -impl CharacterSkeleton { - pub fn new() -> Self { - Self { - head: Bone::default(), - chest: Bone::default(), - belt: Bone::default(), - shorts: Bone::default(), - l_hand: Bone::default(), - r_hand: Bone::default(), - l_foot: Bone::default(), - r_foot: Bone::default(), - weapon: Bone::default(), - torso: Bone::default(), - l_shoulder: Bone::default(), - r_shoulder: Bone::default(), + fn update_skeleton( + skeleton: &Self::Skeleton, + time: f64, + ) -> Self::Skeleton { + let mut next = (*skeleton).clone(); - } - } -} + let wave = (time as f32 * 14.0).sin(); + let wavetest = (wave.cbrt()); + let fuzzwave = (time as f32 * 12.0).sin(); + let wavecos = (time as f32 * 14.0).cos(); + let wave_slow = (time as f32 * 7.0 + PI).sin(); + let wavecos_slow = (time as f32 * 8.0 + PI).cos(); + let wave_dip = (wave_slow.abs() - 0.5).abs(); -impl Skeleton for CharacterSkeleton { - fn compute_matrices(&self) -> [FigureBoneData; 16] { - let chest_mat = self.chest.compute_base_matrix(); - let torso_mat = self.torso.compute_base_matrix(); - [ - FigureBoneData::new(torso_mat * self.head.compute_base_matrix()), - FigureBoneData::new(torso_mat * chest_mat), - FigureBoneData::new(torso_mat * self.belt.compute_base_matrix()), - FigureBoneData::new(torso_mat * self.shorts.compute_base_matrix()), - FigureBoneData::new(torso_mat * self.l_hand.compute_base_matrix()), - FigureBoneData::new(torso_mat * self.r_hand.compute_base_matrix()), - FigureBoneData::new(torso_mat * self.l_foot.compute_base_matrix()), - FigureBoneData::new(torso_mat * self.r_foot.compute_base_matrix()), - FigureBoneData::new(torso_mat * chest_mat * self.weapon.compute_base_matrix()), - FigureBoneData::new(torso_mat), - //FigureBoneData::new(torso_mat * self.l_shoulder.compute_base_matrix()), - //FigureBoneData::new(torso_mat * self.r_shoulder.compute_base_matrix()), - FigureBoneData::default(), - FigureBoneData::default(), - FigureBoneData::default(), - FigureBoneData::default(), - FigureBoneData::default(), - FigureBoneData::default(), + next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3); + next.head.ori = Quaternion::rotation_y(-0.15); + next.head.scale = Vec3::one(); - ] - } + next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1); + next.chest.ori = Quaternion::rotation_z(wave * 0.1); + next.chest.scale = Vec3::one(); - fn interpolate(&mut self, target: &Self) { - self.head.interpolate(&target.head); - self.chest.interpolate(&target.chest); - self.belt.interpolate(&target.belt); - self.shorts.interpolate(&target.shorts); - self.l_hand.interpolate(&target.l_hand); - self.r_hand.interpolate(&target.r_hand); - self.l_foot.interpolate(&target.l_foot); - self.r_foot.interpolate(&target.r_foot); - self.weapon.interpolate(&target.weapon); - self.torso.interpolate(&target.torso); - self.l_shoulder.interpolate(&target.l_shoulder); - self.r_shoulder.interpolate(&target.r_shoulder); + next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wavecos * 1.1); + next.belt.ori = Quaternion::rotation_z(wave * 0.25); + next.belt.scale = Vec3::one(); + + next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wavecos * 1.1); + next.shorts.ori = Quaternion::rotation_z(wave * 0.6); + next.shorts.scale = Vec3::one(); + + next.l_hand.offset = Vec3::new(2.0 - wavecos * 2.5, 7.5, 12.0 + wave * 1.5); + next.l_hand.ori = Quaternion::rotation_y(wavecos * 0.9); + next.l_hand.scale = Vec3::one(); + + next.r_hand.offset = Vec3::new(2.0 + wavecos * 2.5, -7.5, 12.0 - wave * 1.5); + next.r_hand.ori = Quaternion::rotation_y(wavecos * -0.9); + next.r_hand.scale = Vec3::one(); + + next.l_foot.offset = Vec3::new(3.5 + wave * 1.0, 3.4, 6.0); + next.l_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); + next.l_foot.scale = Vec3::one(); + + next.r_foot.offset = Vec3::new(3.5 - wave * 1.0, -3.4, 6.0); + next.r_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); + next.r_foot.scale = Vec3::one(); + + next.weapon.offset = Vec3::new(-5.0, 14.0, 13.0); + next.weapon.ori = Quaternion::rotation_x(2.5); + next.weapon.scale = Vec3::one(); + + next.torso.offset = Vec3::new(0.0, 0.0, 0.0); + next.torso.ori = Quaternion::rotation_y(0.25 + wavecos * 0.1); + next.torso.scale = Vec3::one() / 11.0; + + next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0); + next.l_shoulder.ori = Quaternion::rotation_y(0.0); + next.l_shoulder.scale = Vec3::one(); + + next.r_shoulder.offset = Vec3::new(3.0, -6.0, 18.0); + next.r_shoulder.ori = Quaternion::rotation_y(0.0); + next.r_shoulder.scale = Vec3::one(); + + + next } } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 02a99c64e1..84355186e1 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -90,28 +90,6 @@ impl FigureCache { None, None, ]; -// let bone_meshes = [ -// -// -// Some(load_segment("head.vox").generate_mesh(Vec3::new(-5.5, -7.0, -6.0))), -// Some(load_segment("chest.vox").generate_mesh(Vec3::new(-2.5, -6.0, 0.0))), -// Some(load_segment("belt.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), -// Some(load_segment("pants.vox").generate_mesh(Vec3::new(-2.5, -5.0, 0.0))), -// Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), -// Some(load_segment("hand.vox").generate_mesh(Vec3::new(0.0, -2.0, -7.0))), -// Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), -// Some(load_segment("foot.vox").generate_mesh(Vec3::new(-3.5, -2.5, -8.0))), -// Some(load_segment("sword.vox").generate_mesh(Vec3::new(0.0, -0.0, -4.0))), -// None, - //Some(load_segment("shoulder_left.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), - //Some(load_segment("shoulder_right.vox").generate_mesh(Vec3::new(-3.0, -2.5, -8.0))), -// None, -// None, -// None, -// None, -// None, -// None, -// ]; let mut mesh = Mesh::new(); bone_meshes From 56a8a247cc016abb06620186e9fdcdb1f0f661cc Mon Sep 17 00:00:00 2001 From: jshipsey Date: Tue, 23 Apr 2019 20:36:33 -0400 Subject: [PATCH 09/12] simplified scaling code Former-commit-id: 2a1c8450f002862f67873c375674413902e138ef --- voxygen/src/anim/character/idle.rs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index 89aef55694..c3d335654f 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -31,11 +31,7 @@ impl Animation for IdleAnimation { let waveultracos_slow = (time as f32 * 1.0 + PI).cos(); let wave_dip = (wave_slow.abs() - 0.5).abs(); -<<<<<<< HEAD next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4); -======= - next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4) / SCALE; ->>>>>>> run animation incremental tweaks next.head.ori = Quaternion::rotation_y(waveultra_slow * 0.05); next.head.scale = Vec3::one(); @@ -51,17 +47,11 @@ impl Animation for IdleAnimation { next.shorts.ori = Quaternion::rotation_y(0.0); next.shorts.scale = Vec3::one(); -<<<<<<< HEAD next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1); next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); next.l_hand.scale = Vec3::one(); next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1); -======= - next.l_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3, 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; - next.l_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); - next.r_hand.offset = Vec3::new(2.0 + waveultracos_slow * 0.3 , - 7.5, 12.5 + waveultra_slow * 1.1) / SCALE; ->>>>>>> run animation incremental tweaks next.r_hand.ori = Quaternion::rotation_y(0.0 + waveultra_slow * 0.06); next.r_hand.scale = Vec3::one(); @@ -73,15 +63,9 @@ impl Animation for IdleAnimation { next.r_foot.ori = Quaternion::rotation_y(0.04 + waveultra_slow * 0.04); next.r_foot.scale = Vec3::one(); -<<<<<<< HEAD next.weapon.offset = Vec3::new(-4.5, 14.0, 13.0); next.weapon.ori = Quaternion::rotation_x(2.5); next.weapon.scale = Vec3::one(); -======= - next.back.offset = Vec3::new(-4.5, 14.0, 13.0); - next.back.ori = Quaternion::rotation_x(2.5); - next.back.scale = Vec3::one(); ->>>>>>> run animation incremental tweaks next.torso.offset = Vec3::new(0.0, 0.0, 0.0); @@ -96,14 +80,6 @@ impl Animation for IdleAnimation { next.r_shoulder.ori = Quaternion::rotation_y(0.0); next.r_shoulder.scale = Vec3::one(); - next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0) / SCALE; - next.l_shoulder.ori = Quaternion::rotation_y(0.0); - next.l_shoulder.scale = Vec3::one() / SCALE; - - next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0) / SCALE; - next.r_shoulder.ori = Quaternion::rotation_y(0.0); - next.r_shoulder.scale = Vec3::one() / SCALE; - next } } From bc5074a2b883308733cdf2de690b2bc31bbf3e40 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Sun, 21 Apr 2019 13:35:43 -0400 Subject: [PATCH 10/12] velocity tilt Former-commit-id: 362232bff35784828ee8766e77dadc4e83bf3753 --- voxygen/src/anim/character/mod.rs | 153 ++++++++++++++++-------------- voxygen/src/scene/figure.rs | 1 + 2 files changed, 83 insertions(+), 71 deletions(-) diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 33a8e79b95..b699c2ed88 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -1,86 +1,97 @@ -// Standard -use std::f32::consts::PI; +pub mod run; +pub mod idle; -// Library -use vek::*; +// Reexports +pub use self::run::RunAnimation; +pub use self::idle::IdleAnimation; + +// Crate +use crate::render::FigureBoneData; // Local use super::{ - CharacterSkeleton, - super::Animation, - SCALE + Skeleton, + Bone, }; -pub struct RunAnimation; +const SCALE: f32 = 11.0; -impl Animation for RunAnimation { - type Skeleton = CharacterSkeleton; - type Dependency = f64; +#[derive(Clone)] +pub struct CharacterSkeleton { + head: Bone, + chest: Bone, + belt: Bone, + shorts: Bone, + l_hand: Bone, + r_hand: Bone, + l_foot: Bone, + r_foot: Bone, + weapon: Bone, + torso: Bone, + l_shoulder: Bone, + r_shoulder: Bone, +} - fn update_skeleton( - skeleton: &Self::Skeleton, - time: f64, - ) -> Self::Skeleton { - let mut next = (*skeleton).clone(); +impl CharacterSkeleton { + pub fn new() -> Self { + Self { + head: Bone::default(), + chest: Bone::default(), + belt: Bone::default(), + shorts: Bone::default(), + l_hand: Bone::default(), + r_hand: Bone::default(), + l_foot: Bone::default(), + r_foot: Bone::default(), + weapon: Bone::default(), + torso: Bone::default(), + l_shoulder: Bone::default(), + r_shoulder: Bone::default(), - let wave = (time as f32 * 14.0).sin(); - let wavetest = (wave.cbrt()); - let fuzzwave = (time as f32 * 12.0).sin(); - let wavecos = (time as f32 * 14.0).cos(); - let wave_slow = (time as f32 * 7.0 + PI).sin(); - let wavecos_slow = (time as f32 * 8.0 + PI).cos(); - let wave_dip = (wave_slow.abs() - 0.5).abs(); + } + } +} - next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3); - next.head.ori = Quaternion::rotation_y(-0.15); - next.head.scale = Vec3::one(); +impl Skeleton for CharacterSkeleton { + fn compute_matrices(&self) -> [FigureBoneData; 16] { + let chest_mat = self.chest.compute_base_matrix(); + let torso_mat = self.torso.compute_base_matrix(); + [ + FigureBoneData::new(torso_mat * self.head.compute_base_matrix()), + FigureBoneData::new(torso_mat * chest_mat), + FigureBoneData::new(torso_mat * self.belt.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.shorts.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.l_hand.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.r_hand.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.l_foot.compute_base_matrix()), + FigureBoneData::new(torso_mat * self.r_foot.compute_base_matrix()), + FigureBoneData::new(torso_mat * chest_mat * self.weapon.compute_base_matrix()), + FigureBoneData::new(torso_mat), + //FigureBoneData::new(torso_mat * self.l_shoulder.compute_base_matrix()), + //FigureBoneData::new(torso_mat * self.r_shoulder.compute_base_matrix()), + FigureBoneData::default(), + FigureBoneData::default(), + FigureBoneData::default(), + FigureBoneData::default(), + FigureBoneData::default(), + FigureBoneData::default(), - next.chest.offset = Vec3::new(2.5, 0.0, 8.0 + wavecos * 1.1); - next.chest.ori = Quaternion::rotation_z(wave * 0.1); - next.chest.scale = Vec3::one(); + ] + } - next.belt.offset = Vec3::new(2.5, 0.0, 6.0 + wavecos * 1.1); - next.belt.ori = Quaternion::rotation_z(wave * 0.25); - next.belt.scale = Vec3::one(); - - next.shorts.offset = Vec3::new(2.5, 0.0, 3.0 + wavecos * 1.1); - next.shorts.ori = Quaternion::rotation_z(wave * 0.6); - next.shorts.scale = Vec3::one(); - - next.l_hand.offset = Vec3::new(2.0 - wavecos * 2.5, 7.5, 12.0 + wave * 1.5); - next.l_hand.ori = Quaternion::rotation_y(wavecos * 0.9); - next.l_hand.scale = Vec3::one(); - - next.r_hand.offset = Vec3::new(2.0 + wavecos * 2.5, -7.5, 12.0 - wave * 1.5); - next.r_hand.ori = Quaternion::rotation_y(wavecos * -0.9); - next.r_hand.scale = Vec3::one(); - - next.l_foot.offset = Vec3::new(3.5 + wave * 1.0, 3.4, 6.0); - next.l_foot.ori = Quaternion::rotation_y(-0.0 - wave * 1.5); - next.l_foot.scale = Vec3::one(); - - next.r_foot.offset = Vec3::new(3.5 - wave * 1.0, -3.4, 6.0); - next.r_foot.ori = Quaternion::rotation_y(-0.0 + wave * 1.5); - next.r_foot.scale = Vec3::one(); - - next.weapon.offset = Vec3::new(-5.0, 14.0, 13.0); - next.weapon.ori = Quaternion::rotation_x(2.5); - next.weapon.scale = Vec3::one(); - - next.torso.offset = Vec3::new(0.0, 0.0, 0.0); - next.torso.ori = Quaternion::rotation_y(0.25 + wavecos * 0.1); - next.torso.scale = Vec3::one() / 11.0; - - next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0); - next.l_shoulder.ori = Quaternion::rotation_y(0.0); - next.l_shoulder.scale = Vec3::one(); - - next.r_shoulder.offset = Vec3::new(3.0, -6.0, 18.0); - next.r_shoulder.ori = Quaternion::rotation_y(0.0); - next.r_shoulder.scale = Vec3::one(); - - - next + fn interpolate(&mut self, target: &Self) { + self.head.interpolate(&target.head); + self.chest.interpolate(&target.chest); + self.belt.interpolate(&target.belt); + self.shorts.interpolate(&target.shorts); + self.l_hand.interpolate(&target.l_hand); + self.r_hand.interpolate(&target.r_hand); + self.l_foot.interpolate(&target.l_foot); + self.r_foot.interpolate(&target.r_foot); + self.weapon.interpolate(&target.weapon); + self.torso.interpolate(&target.torso); + self.l_shoulder.interpolate(&target.l_shoulder); + self.r_shoulder.interpolate(&target.r_shoulder); } } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 84355186e1..08362b3e3f 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -91,6 +91,7 @@ impl FigureCache { None, ]; + let mut mesh = Mesh::new(); bone_meshes .iter() From 0a34bfab9b8b8b927fdb3d32c54b1b66249a8b78 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Tue, 23 Apr 2019 20:17:50 -0400 Subject: [PATCH 11/12] run animation incremental tweaks Former-commit-id: fa43d89890e22da665dc29606baed46e23f8eb6e --- voxygen/src/anim/character/idle.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index c3d335654f..1bc954f68a 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -80,6 +80,14 @@ impl Animation for IdleAnimation { next.r_shoulder.ori = Quaternion::rotation_y(0.0); next.r_shoulder.scale = Vec3::one(); + next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0) / SCALE; + next.l_shoulder.ori = Quaternion::rotation_y(0.0); + next.l_shoulder.scale = Vec3::one() / SCALE; + + next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0) / SCALE; + next.r_shoulder.ori = Quaternion::rotation_y(0.0); + next.r_shoulder.scale = Vec3::one() / SCALE; + next } } From c0a8a677b79aa0c83a6862a113be812ffa078a58 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Tue, 23 Apr 2019 20:36:33 -0400 Subject: [PATCH 12/12] simplified scaling code Former-commit-id: 9e35a57ea812f1446958daac2ccd4c3492d19347 --- voxygen/src/anim/character/idle.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index 1bc954f68a..c3d335654f 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -80,14 +80,6 @@ impl Animation for IdleAnimation { next.r_shoulder.ori = Quaternion::rotation_y(0.0); next.r_shoulder.scale = Vec3::one(); - next.l_shoulder.offset = Vec3::new(2.9, 6.0, 18.0) / SCALE; - next.l_shoulder.ori = Quaternion::rotation_y(0.0); - next.l_shoulder.scale = Vec3::one() / SCALE; - - next.r_shoulder.offset = Vec3::new(2.9, -6.0, 18.0) / SCALE; - next.r_shoulder.ori = Quaternion::rotation_y(0.0); - next.r_shoulder.scale = Vec3::one() / SCALE; - next } }