From 8745fb803a594b92fd5577447b876816d31d3cd5 Mon Sep 17 00:00:00 2001 From: Snowram Date: Thu, 13 May 2021 14:32:00 +0200 Subject: [PATCH] Use Body to determine mountee offsets --- .../quadruped_medium_central_manifest.ron | 2 +- common/src/comp/body.rs | 3 +- voxygen/anim/src/biped_large/mod.rs | 9 +- voxygen/anim/src/biped_small/mod.rs | 9 +- voxygen/anim/src/bird_large/mod.rs | 9 +- voxygen/anim/src/bird_medium/mod.rs | 9 +- voxygen/anim/src/character/mod.rs | 90 +++++++++++++++---- voxygen/anim/src/dragon/mod.rs | 9 +- voxygen/anim/src/fish_medium/mod.rs | 9 +- voxygen/anim/src/fish_small/mod.rs | 9 +- voxygen/anim/src/fixture/mod.rs | 9 +- voxygen/anim/src/golem/mod.rs | 9 +- voxygen/anim/src/lib.rs | 16 ++-- voxygen/anim/src/object/mod.rs | 9 +- voxygen/anim/src/quadruped_low/mod.rs | 9 +- voxygen/anim/src/quadruped_medium/mod.rs | 20 +++-- voxygen/anim/src/quadruped_small/mod.rs | 9 +- voxygen/anim/src/ship/mod.rs | 9 +- voxygen/anim/src/theropod/mod.rs | 9 +- voxygen/src/scene/figure/mod.rs | 58 ++++-------- 20 files changed, 197 insertions(+), 118 deletions(-) diff --git a/assets/voxygen/voxel/quadruped_medium_central_manifest.ron b/assets/voxygen/voxel/quadruped_medium_central_manifest.ron index 72e6b57a67..6ad1c58005 100644 --- a/assets/voxygen/voxel/quadruped_medium_central_manifest.ron +++ b/assets/voxygen/voxel/quadruped_medium_central_manifest.ron @@ -159,7 +159,7 @@ central: ("npc.tuskram.male.neck"), ), jaw: ( - offset: (-5.0, 0.0, -1.5), + offset: (-5.0, 0.0, -8.0), central: ("npc.tuskram.male.jaw"), ), torso_front: ( diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index 749a75ea95..63421765f4 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -659,6 +659,7 @@ impl Body { ) } + // Physical offset relative to the mountee pub fn mounting_offset(&self) -> Vec3 { match self { Body::QuadrupedMedium(quadruped_medium) => { @@ -682,7 +683,7 @@ impl Body { (quadruped_medium::Species::Zebra, _) => Vec3::from([0.5, 0.5, 1.8]), (quadruped_medium::Species::Antelope, _) => Vec3::from([0.3, 0.3, 1.4]), (quadruped_medium::Species::Kelpie, _) => Vec3::from([0.5, 0.5, 1.9]), - (quadruped_medium::Species::Horse, _) => Vec3::from([0.1, 0.1, 2.0]), + (quadruped_medium::Species::Horse, _) => Vec3::from([0.0, 0.0, 2.0]), (quadruped_medium::Species::Barghest, _) => Vec3::from([0.5, 0.5, 2.2]), (quadruped_medium::Species::Cattle, quadruped_medium::BodyType::Male) => { Vec3::from([0.5, 0.5, 2.6]) diff --git a/voxygen/anim/src/biped_large/mod.rs b/voxygen/anim/src/biped_large/mod.rs index 3f7bb42b2f..cf2dc88c2b 100644 --- a/voxygen/anim/src/biped_large/mod.rs +++ b/voxygen/anim/src/biped_large/mod.rs @@ -29,7 +29,7 @@ pub use self::{ stunned::StunnedAnimation, summon::SummonAnimation, wield::WieldAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -77,7 +77,7 @@ impl Skeleton for BipedLargeSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let upper_torso = Mat4::::from(self.upper_torso); let torso_mat = base_mat * Mat4::::from(self.torso); @@ -124,7 +124,10 @@ impl Skeleton for BipedLargeSkeleton { // FIXME: Should this be control_l_mat? make_bone(upper_torso_mat * control_mat * hand_l_mat * Mat4::::from(self.hold)), ]; - [Transform::default(), Transform::default()] + Offsets { + lantern: Vec3::default(), + mount_bone: self.torso, + } } } diff --git a/voxygen/anim/src/biped_small/mod.rs b/voxygen/anim/src/biped_small/mod.rs index ae5857f9d1..1d4c0c1e57 100644 --- a/voxygen/anim/src/biped_small/mod.rs +++ b/voxygen/anim/src/biped_small/mod.rs @@ -12,7 +12,7 @@ pub use self::{ shoot::ShootAnimation, stunned::StunnedAnimation, wield::WieldAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -47,7 +47,7 @@ impl Skeleton for BipedSmallSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let chest_mat = base_mat * Mat4::::from(self.chest); let pants_mat = chest_mat * Mat4::::from(self.pants); let control_mat = chest_mat * Mat4::::from(self.control); @@ -64,7 +64,10 @@ impl Skeleton for BipedSmallSkeleton { make_bone(base_mat * Mat4::::from(self.foot_l)), make_bone(base_mat * Mat4::::from(self.foot_r)), ]; - [Transform::default(), Transform::default()] + Offsets { + lantern: Vec3::default(), + mount_bone: self.chest, + } } } diff --git a/voxygen/anim/src/bird_large/mod.rs b/voxygen/anim/src/bird_large/mod.rs index 7427609919..fe2ad93863 100644 --- a/voxygen/anim/src/bird_large/mod.rs +++ b/voxygen/anim/src/bird_large/mod.rs @@ -16,7 +16,7 @@ pub use self::{ stunned::StunnedAnimation, swim::SwimAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -55,7 +55,7 @@ impl Skeleton for BirdLargeSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let chest_mat = base_mat * Mat4::::from(self.chest); let neck_mat = chest_mat * Mat4::::from(self.neck); let head_mat = neck_mat * Mat4::::from(self.head); @@ -91,7 +91,10 @@ impl Skeleton for BirdLargeSkeleton { make_bone(foot_l_mat), make_bone(foot_r_mat), ]; - [Transform::default(), self.chest] + Offsets { + lantern: Vec3::default(), + mount_bone: self.chest, + } } } diff --git a/voxygen/anim/src/bird_medium/mod.rs b/voxygen/anim/src/bird_medium/mod.rs index 66c5d347aa..14f85db654 100644 --- a/voxygen/anim/src/bird_medium/mod.rs +++ b/voxygen/anim/src/bird_medium/mod.rs @@ -6,7 +6,7 @@ pub mod run; // Reexports pub use self::{feed::FeedAnimation, fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation}; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -36,7 +36,7 @@ impl Skeleton for BirdMediumSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let torso_mat = base_mat * Mat4::::from(self.torso); *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ @@ -48,7 +48,10 @@ impl Skeleton for BirdMediumSkeleton { make_bone(base_mat * Mat4::::from(self.leg_l)), make_bone(base_mat * Mat4::::from(self.leg_r)), ]; - [Transform::default(), self.torso] + Offsets { + lantern: Vec3::default(), + mount_bone: self.torso, + } } } diff --git a/voxygen/anim/src/character/mod.rs b/voxygen/anim/src/character/mod.rs index c1e0c2312c..40e5603785 100644 --- a/voxygen/anim/src/character/mod.rs +++ b/voxygen/anim/src/character/mod.rs @@ -42,7 +42,7 @@ pub use self::{ stand::StandAnimation, stunned::StunnedAnimation, swim::SwimAnimation, swimwield::SwimWieldAnimation, talk::TalkAnimation, wield::WieldAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp; use core::convert::TryFrom; use std::f32::consts::PI; @@ -73,19 +73,19 @@ skeleton_impls!(struct CharacterSkeleton { :: // Begin non-bone fields holding_lantern: bool, offsets: Option>, - hitbox_offsets: Option>, + mountee_body: Option, }); impl CharacterSkeleton { pub fn new( holding_lantern: bool, offsets: Option>, - hitbox_offsets: Option>, + mountee_body: Option, ) -> Self { Self { holding_lantern, offsets, - hitbox_offsets, + mountee_body, ..Self::default() } } @@ -105,18 +105,21 @@ impl Skeleton for CharacterSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let mut torso_mat = base_mat * Mat4::::from(self.torso); if let Some(offset) = self.offsets { - let hitbox_offsets = self.hitbox_offsets.unwrap_or(vek::Vec3::::zero()); - torso_mat = base_mat - * Mat4::::from(Transform { - position: offset.position - - Vec3::from([0.0, hitbox_offsets.y, hitbox_offsets.z]), - orientation: offset.orientation, - scale: Vec3::::one(), - }) - * Mat4::::from(self.torso).translated_3d(Vec3::from([0.0, -0.8, 0.15])); //.translated_3d(Vec3::from([0.0, -0.8, 0.15]) + if let Some(body) = self.mountee_body { + let hitbox_offsets = body.mounting_offset(); + let visual_offset = mounting_offset(body); + torso_mat = base_mat + * Mat4::::from(Transform { + position: offset.position + - Vec3::from([0.0, hitbox_offsets.y, hitbox_offsets.z]), + orientation: offset.orientation, + scale: Vec3::::one(), + }) + * Mat4::::from(self.torso).translated_3d(visual_offset); + } } let chest_mat = torso_mat * Mat4::::from(self.chest); let head_mat = chest_mat * Mat4::::from(self.head); @@ -152,11 +155,10 @@ impl Skeleton for CharacterSkeleton { // FIXME: Should this be control_l_mat? make_bone(control_mat * hand_l_mat * Mat4::::from(self.hold)), ]; - [ - //(lantern_mat * Vec4::new(0.0, 0.0, -4.0, 1.0)).xyz(), - Transform::default(), - self.chest - ] + Offsets { + lantern: (lantern_mat * Vec4::new(0.0, 0.0, -4.0, 1.0)).xyz(), + mount_bone: self.chest, + } } } @@ -353,3 +355,53 @@ impl<'a> From<&'a Body> for SkeletonAttr { } } } + +pub fn mounting_offset(body: comp::Body) -> Vec3 { + match body { + comp::Body::QuadrupedMedium(quadruped_medium) => { + match (quadruped_medium.species, quadruped_medium.body_type) { + (comp::quadruped_medium::Species::Grolgar, _) => Vec3::from([0.0, -0.6, 0.5]), + (comp::quadruped_medium::Species::Saber, _) => Vec3::from([0.0, -0.75, 0.23]), + (comp::quadruped_medium::Species::Tiger, _) => Vec3::from([0.0, -0.75, 0.23]), + (comp::quadruped_medium::Species::Tuskram, _) => Vec3::from([0.0, -0.75, 0.25]), + (comp::quadruped_medium::Species::Lion, _) => Vec3::from([0.0, -0.9, 0.25]), + (comp::quadruped_medium::Species::Tarasque, _) => Vec3::from([0.0, -1.1, 0.3]), + (comp::quadruped_medium::Species::Wolf, _) => Vec3::from([0.0, -0.7, 0.15]), + (comp::quadruped_medium::Species::Frostfang, _) => Vec3::from([0.0, -0.8, 0.1]), + (comp::quadruped_medium::Species::Mouflon, _) => Vec3::from([0.0, -0.8, 0.1]), + (comp::quadruped_medium::Species::Catoblepas, _) => Vec3::from([0.0, -0.4, 0.4]), + (comp::quadruped_medium::Species::Bonerattler, _) => Vec3::from([0.0, -0.3, 0.2]), + (comp::quadruped_medium::Species::Deer, _) => Vec3::from([0.0, -0.9, 0.1]), + (comp::quadruped_medium::Species::Hirdrasil, _) => Vec3::from([0.0, -1.0, 0.0]), + (comp::quadruped_medium::Species::Roshwalr, _) => Vec3::from([0.0, -0.2, 0.7]), + (comp::quadruped_medium::Species::Donkey, _) => Vec3::from([0.0, -0.5, 0.15]), + (comp::quadruped_medium::Species::Camel, _) => Vec3::from([0.0, -1.4, 0.3]), + (comp::quadruped_medium::Species::Zebra, _) => Vec3::from([0.0, -0.6, 0.1]), + (comp::quadruped_medium::Species::Antelope, _) => Vec3::from([0.0, -0.8, 0.1]), + (comp::quadruped_medium::Species::Kelpie, _) => Vec3::from([0.0, -0.8, 0.05]), + (comp::quadruped_medium::Species::Horse, _) => Vec3::from([0.0, -0.8, 0.1]), + (comp::quadruped_medium::Species::Barghest, _) => Vec3::from([0.0, -0.8, 0.6]), + ( + comp::quadruped_medium::Species::Cattle, + comp::quadruped_medium::BodyType::Male, + ) => Vec3::from([0.0, -0.4, 0.7]), + ( + comp::quadruped_medium::Species::Cattle, + comp::quadruped_medium::BodyType::Female, + ) => Vec3::from([0.0, -0.3, 0.5]), + (comp::quadruped_medium::Species::Darkhound, _) => Vec3::from([0.0, -0.5, 0.2]), + (comp::quadruped_medium::Species::Highland, _) => Vec3::from([0.0, -0.2, 0.8]), + (comp::quadruped_medium::Species::Yak, _) => Vec3::from([0.0, -0.2, 0.8]), + (comp::quadruped_medium::Species::Panda, _) => Vec3::from([0.0, -0.8, 0.2]), + (comp::quadruped_medium::Species::Bear, _) => Vec3::from([0.0, -1.5, 0.6]), + (comp::quadruped_medium::Species::Dreadhorn, _) => Vec3::from([0.0, -1.5, 1.6]), + (comp::quadruped_medium::Species::Moose, _) => Vec3::from([0.0, -0.9, 0.3]), + (comp::quadruped_medium::Species::Snowleopard, _) => Vec3::from([0.0, -0.9, 0.2]), + } + }, + + comp::Body::Ship(comp::ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]), + comp::Body::Dragon(_) => Vec3::from([0.0, -0.7, 6.4]), + _ => Vec3::unit_z(), + } +} diff --git a/voxygen/anim/src/dragon/mod.rs b/voxygen/anim/src/dragon/mod.rs index 96cc77eb8e..4b3221dc40 100644 --- a/voxygen/anim/src/dragon/mod.rs +++ b/voxygen/anim/src/dragon/mod.rs @@ -5,7 +5,7 @@ pub mod run; // Reexports pub use self::{fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation}; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -43,7 +43,7 @@ impl Skeleton for DragonSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let chest_front_mat = base_mat * Mat4::::from(self.chest_front); let chest_rear_mat = chest_front_mat * Mat4::::from(self.chest_rear); let head_lower_mat = chest_front_mat * Mat4::::from(self.head_lower); @@ -69,7 +69,10 @@ impl Skeleton for DragonSkeleton { make_bone(chest_rear_mat * Mat4::::from(self.foot_bl)), make_bone(chest_rear_mat * Mat4::::from(self.foot_br)), ]; - [Transform::default(), self.chest_front] + Offsets { + lantern: Vec3::default(), + mount_bone: self.chest_front, + } } } diff --git a/voxygen/anim/src/fish_medium/mod.rs b/voxygen/anim/src/fish_medium/mod.rs index 010433efc9..6ed92d7259 100644 --- a/voxygen/anim/src/fish_medium/mod.rs +++ b/voxygen/anim/src/fish_medium/mod.rs @@ -4,7 +4,7 @@ pub mod swim; // Reexports pub use self::{idle::IdleAnimation, swim::SwimAnimation}; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -33,7 +33,7 @@ impl Skeleton for FishMediumSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let chest_front_mat = base_mat * Mat4::::from(self.chest_front); let chest_back_mat = Mat4::::from(self.chest_back); let head_mat = Mat4::::from(self.head); @@ -47,7 +47,10 @@ impl Skeleton for FishMediumSkeleton { make_bone(chest_front_mat * Mat4::::from(self.fin_l)), make_bone(chest_front_mat * Mat4::::from(self.fin_r)), ]; - [Transform::default(), Transform::default()] + Offsets { + lantern: Vec3::default(), + mount_bone: self.chest_front, + } } } diff --git a/voxygen/anim/src/fish_small/mod.rs b/voxygen/anim/src/fish_small/mod.rs index 25a9d74453..198ce1fac7 100644 --- a/voxygen/anim/src/fish_small/mod.rs +++ b/voxygen/anim/src/fish_small/mod.rs @@ -4,7 +4,7 @@ pub mod swim; // Reexports pub use self::{idle::IdleAnimation, swim::SwimAnimation}; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -30,7 +30,7 @@ impl Skeleton for FishSmallSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let chest_mat = base_mat * Mat4::::from(self.chest); *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ @@ -39,7 +39,10 @@ impl Skeleton for FishSmallSkeleton { make_bone(chest_mat * Mat4::::from(self.fin_l)), make_bone(chest_mat * Mat4::::from(self.fin_r)), ]; - [Transform::default(), Transform::default()] + Offsets { + lantern: Vec3::default(), + mount_bone: self.chest, + } } } diff --git a/voxygen/anim/src/fixture/mod.rs b/voxygen/anim/src/fixture/mod.rs index 0f37921b55..f24e2918f8 100644 --- a/voxygen/anim/src/fixture/mod.rs +++ b/voxygen/anim/src/fixture/mod.rs @@ -1,4 +1,4 @@ -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; pub type Body = (); @@ -31,9 +31,12 @@ impl Skeleton for FixtureSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { buf[0] = make_bone(base_mat); - [Transform::default(), Transform::default()] + Offsets { + lantern: Vec3::default(), + mount_bone: Transform::default(), + } } } diff --git a/voxygen/anim/src/golem/mod.rs b/voxygen/anim/src/golem/mod.rs index 31a92c64a9..af19354a00 100644 --- a/voxygen/anim/src/golem/mod.rs +++ b/voxygen/anim/src/golem/mod.rs @@ -12,7 +12,7 @@ pub use self::{ shockwave::ShockwaveAnimation, shoot::ShootAnimation, spinmelee::SpinMeleeAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -47,7 +47,7 @@ impl Skeleton for GolemSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let torso_mat = base_mat * Mat4::::from(self.torso); let upper_torso_mat = torso_mat * Mat4::::from(self.upper_torso); let lower_torso_mat = upper_torso_mat * Mat4::::from(self.lower_torso); @@ -70,7 +70,10 @@ impl Skeleton for GolemSkeleton { make_bone(leg_l_mat * Mat4::::from(self.foot_l)), make_bone(leg_r_mat * Mat4::::from(self.foot_r)), ]; - [Transform::default(), self.torso] + Offsets { + lantern: Vec3::default(), + mount_bone: self.torso, + } } } diff --git a/voxygen/anim/src/lib.rs b/voxygen/anim/src/lib.rs index 6c06fa21c4..6f73fd4081 100644 --- a/voxygen/anim/src/lib.rs +++ b/voxygen/anim/src/lib.rs @@ -89,6 +89,12 @@ fn make_bone(mat: Mat4) -> FigureBoneData { pub type Bone = Transform; +// Offsets that will be returned after computing the skeleton matrices +pub struct Offsets { + pub lantern: Vec3, + pub mount_bone: Transform, +} + pub trait Skeleton: Send + Sync + 'static { type Attr; type Body; @@ -102,14 +108,14 @@ pub trait Skeleton: Send + Sync + 'static { &self, base_mat: Mat4, buf: &mut [FigureBoneData; MAX_BONE_COUNT], - ) -> [Transform; 2]; + ) -> Offsets; } pub fn compute_matrices( skeleton: &S, base_mat: Mat4, buf: &mut [FigureBoneData; MAX_BONE_COUNT], -) -> [Transform; 2] { +) -> Offsets { #[cfg(not(feature = "use-dyn-lib"))] { S::compute_matrices_inner(skeleton, base_mat, buf) @@ -120,11 +126,7 @@ pub fn compute_matrices( let lib = &lock.as_ref().unwrap().lib; let compute_fn: libloading::Symbol< - fn( - &S, - Mat4, - &mut [FigureBoneData; MAX_BONE_COUNT], - ) -> [Transform; 2], + fn(&S, Mat4, &mut [FigureBoneData; MAX_BONE_COUNT]) -> Offsets, > = unsafe { lib.get(S::COMPUTE_FN) }.unwrap_or_else(|e| { panic!( "Trying to use: {} but had error: {:?}", diff --git a/voxygen/anim/src/object/mod.rs b/voxygen/anim/src/object/mod.rs index ec5cace245..acafbd4497 100644 --- a/voxygen/anim/src/object/mod.rs +++ b/voxygen/anim/src/object/mod.rs @@ -5,7 +5,7 @@ pub mod shoot; // Reexports pub use self::{beam::BeamAnimation, idle::IdleAnimation, shoot::ShootAnimation}; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -29,14 +29,17 @@ impl Skeleton for ObjectSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let bone0_mat = base_mat * Mat4::::from(self.bone0); *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ make_bone(bone0_mat * Mat4::scaling_3d(1.0 / 11.0)), make_bone(Mat4::::from(self.bone1) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */ ]; - [Transform::default(), Transform::default()] + Offsets { + lantern: Vec3::default(), + mount_bone: self.bone0, + } } } diff --git a/voxygen/anim/src/quadruped_low/mod.rs b/voxygen/anim/src/quadruped_low/mod.rs index 607c00fa6f..5942a5cbc1 100644 --- a/voxygen/anim/src/quadruped_low/mod.rs +++ b/voxygen/anim/src/quadruped_low/mod.rs @@ -16,7 +16,7 @@ pub use self::{ stunned::StunnedAnimation, tailwhip::TailwhipAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -48,7 +48,7 @@ impl Skeleton for QuadrupedLowSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let chest_mat = base_mat * Mat4::::from(self.chest); let tail_front = chest_mat * Mat4::::from(self.tail_front); let head_lower_mat = chest_mat * Mat4::::from(self.head_lower); @@ -66,7 +66,10 @@ impl Skeleton for QuadrupedLowSkeleton { make_bone(chest_mat * Mat4::::from(self.foot_bl)), make_bone(chest_mat * Mat4::::from(self.foot_br)), ]; - [Transform::default(), self.chest] + Offsets { + lantern: Vec3::default(), + mount_bone: self.chest, + } } } diff --git a/voxygen/anim/src/quadruped_medium/mod.rs b/voxygen/anim/src/quadruped_medium/mod.rs index a71d72138e..611a7f4307 100644 --- a/voxygen/anim/src/quadruped_medium/mod.rs +++ b/voxygen/anim/src/quadruped_medium/mod.rs @@ -16,7 +16,7 @@ pub use self::{ run::RunAnimation, stunned::StunnedAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -38,6 +38,7 @@ skeleton_impls!(struct QuadrupedMediumSkeleton { + foot_fr, + foot_bl, + foot_br, + mount, }); impl Skeleton for QuadrupedMediumSkeleton { @@ -53,7 +54,7 @@ impl Skeleton for QuadrupedMediumSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let torso_front_mat = base_mat * Mat4::::from(self.torso_front); let torso_back_mat = torso_front_mat * Mat4::::from(self.torso_back); let neck_mat = torso_front_mat * Mat4::::from(self.neck); @@ -80,7 +81,10 @@ impl Skeleton for QuadrupedMediumSkeleton { make_bone(leg_bl_mat * Mat4::::from(self.foot_bl)), make_bone(leg_br_mat * Mat4::::from(self.foot_br)), ]; - [Transform::default(), self.torso_front] + Offsets { + lantern: Vec3::default(), + mount_bone: self.torso_front, + } } } @@ -152,7 +156,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { (Frostfang, _) => (1.0, -2.0), (Mouflon, _) => (0.5, 1.5), (Catoblepas, _) => (-1.0, -6.5), - (Bonerattler, _) => (1.0, 2.5), + (Bonerattler, _) => (0.0, 1.5), (Deer, Male) => (1.5, 3.5), (Deer, Female) => (1.5, 3.5), (Hirdrasil, _) => (0.0, 5.0), @@ -187,7 +191,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { (Frostfang, _) => (0.5, 1.5), (Mouflon, _) => (-1.0, 1.0), (Catoblepas, _) => (19.5, -2.0), - (Bonerattler, _) => (9.0, -0.5), + (Bonerattler, _) => (7.0, -0.5), (Deer, _) => (-2.5, 1.0), (Hirdrasil, _) => (-1.0, 0.5), (Roshwalr, _) => (0.0, 1.0), @@ -287,7 +291,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { (Frostfang, _) => (9.0, 11.5), (Mouflon, _) => (11.0, 14.0), (Catoblepas, _) => (7.5, 19.5), - (Bonerattler, _) => (6.0, 12.5), + (Bonerattler, _) => (6.0, 11.0), (Deer, _) => (11.0, 13.5), (Hirdrasil, _) => (11.0, 14.5), (Roshwalr, _) => (6.0, 12.5), @@ -387,7 +391,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { (Frostfang, _) => (5.5, -5.5, -2.0), (Mouflon, _) => (4.0, -5.0, -4.0), (Catoblepas, _) => (7.0, 2.0, -5.0), - (Bonerattler, _) => (5.5, 5.0, -4.0), + (Bonerattler, _) => (5.5, 5.0, -2.5), (Deer, _) => (3.5, -4.5, -3.5), (Hirdrasil, _) => (4.5, -5.0, -2.5), (Roshwalr, _) => (8.0, -2.5, -2.5), @@ -420,7 +424,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { (Frostfang, _) => (3.5, -4.5, -2.0), (Mouflon, _) => (3.5, -8.0, -3.5), (Catoblepas, _) => (6.0, -2.5, -2.5), - (Bonerattler, _) => (6.0, -8.0, -4.0), + (Bonerattler, _) => (6.0, -8.0, -2.5), (Deer, _) => (3.0, -6.5, -3.5), (Hirdrasil, _) => (4.0, -6.5, -3.0), (Roshwalr, _) => (7.0, -7.0, -2.5), diff --git a/voxygen/anim/src/quadruped_small/mod.rs b/voxygen/anim/src/quadruped_small/mod.rs index 09cc8930f1..537257b84a 100644 --- a/voxygen/anim/src/quadruped_small/mod.rs +++ b/voxygen/anim/src/quadruped_small/mod.rs @@ -11,7 +11,7 @@ pub use self::{ run::RunAnimation, stunned::StunnedAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -40,7 +40,7 @@ impl Skeleton for QuadrupedSmallSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let chest_mat = base_mat * Mat4::::from(self.chest); *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ @@ -52,7 +52,10 @@ impl Skeleton for QuadrupedSmallSkeleton { make_bone(chest_mat * Mat4::::from(self.leg_br)), make_bone(chest_mat * Mat4::::from(self.tail)), ]; - [Transform::default(), self.chest] + Offsets { + lantern: Vec3::default(), + mount_bone: self.chest, + } } } diff --git a/voxygen/anim/src/ship/mod.rs b/voxygen/anim/src/ship/mod.rs index c0bb7f65d9..190ccaaedc 100644 --- a/voxygen/anim/src/ship/mod.rs +++ b/voxygen/anim/src/ship/mod.rs @@ -3,7 +3,7 @@ pub mod idle; // Reexports pub use self::idle::IdleAnimation; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -29,7 +29,7 @@ impl Skeleton for ShipSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let bone0_mat = base_mat * Mat4::::from(self.bone0); *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ @@ -38,7 +38,10 @@ impl Skeleton for ShipSkeleton { make_bone(bone0_mat * Mat4::::from(self.bone2) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */ make_bone(bone0_mat * Mat4::::from(self.bone3) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */ ]; - [Transform::default(), self.bone0] + Offsets { + lantern: Vec3::default(), + mount_bone: self.bone0, + } } } diff --git a/voxygen/anim/src/theropod/mod.rs b/voxygen/anim/src/theropod/mod.rs index 31743f4ff2..75f0852b73 100644 --- a/voxygen/anim/src/theropod/mod.rs +++ b/voxygen/anim/src/theropod/mod.rs @@ -11,7 +11,7 @@ pub use self::{ jump::JumpAnimation, run::RunAnimation, }; -use super::{make_bone, vek::*, FigureBoneData, Skeleton}; +use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use common::comp::{self}; use core::convert::TryFrom; @@ -47,7 +47,7 @@ impl Skeleton for TheropodSkeleton { &self, base_mat: Mat4, buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], - ) -> [Transform; 2] { + ) -> Offsets { let chest_front_mat = base_mat * Mat4::::from(self.chest_front); let neck_mat = chest_front_mat * Mat4::::from(self.neck); let head_mat = neck_mat * Mat4::::from(self.head); @@ -71,7 +71,10 @@ impl Skeleton for TheropodSkeleton { make_bone(leg_l_mat * Mat4::::from(self.foot_l)), make_bone(leg_r_mat * Mat4::::from(self.foot_r)), ]; - [Transform::default(), self.chest_front] + Offsets { + lantern: Vec3::default(), + mount_bone: self.chest_front, + } } } diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 0952a4be16..25a4561d84 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -449,10 +449,7 @@ impl FigureMgr { (vek::Rgb::zero(), 0.0, 0.0, true) }; if let Some(state) = body.and_then(|body| self.states.get_mut(body, &entity)) { - light_anim.offset = (vek::Mat4::from_col_array( - anim::vek::Mat4::::from(state.lantern_offset).into_col_array(), - ) * Vec4::one()) - .xyz(); + light_anim.offset = vek::Vec3::from(state.lantern_offset); } if !light_anim.strength.is_normal() { light_anim.strength = 0.0; @@ -752,21 +749,18 @@ impl FigureMgr { let hands = (active_tool_hand, second_tool_hand); - //let mut state_mountee = self.states.get_mut(entity.get(body), &entity); - - //vek::Mat4::from_col_array(state.lantern_offset[0].into_col_array() - + // If a mountee exists, get its physical mounting offsets and its body let mut f = || -> Option<_> { let Mounting(entity) = mountings?; let entity = ecs .read_resource::() .retrieve_entity_internal((*entity).into())?; let bodies = ecs.read_storage::(); - let body = bodies.get(entity)?; - let meta = self.states.get_mut(body, &entity)?; - Some((Some(meta.mountee_offset), Some(Body::mounting_offset(body)))) + let body = *bodies.get(entity)?; + let meta = self.states.get_mut(&body, &entity)?; + Some((Some(meta.mountee_offset), Some(body))) }; - let (mountee_offsets, hitbox_offsets) = f().unwrap_or((None, None)); + let (mountee_offsets, mountee_body) = f().unwrap_or((None, None)); match body { Body::Humanoid(body) => { @@ -800,7 +794,7 @@ impl FigureMgr { CharacterSkeleton::new( holding_lantern, mountee_offsets, - hitbox_offsets, + mountee_body, ), ) }); @@ -824,11 +818,7 @@ impl FigureMgr { ) { // Standing (true, false, false) => anim::character::StandAnimation::update_skeleton( - &CharacterSkeleton::new( - holding_lantern, - mountee_offsets, - hitbox_offsets, - ), + &CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body), (active_tool_kind, second_tool_kind, hands, time, rel_avg_vel), state.state_time, &mut state_animation_rate, @@ -836,11 +826,7 @@ impl FigureMgr { ), // Running (true, true, false) => anim::character::RunAnimation::update_skeleton( - &CharacterSkeleton::new( - holding_lantern, - mountee_offsets, - hitbox_offsets, - ), + &CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body), ( active_tool_kind, second_tool_kind, @@ -859,11 +845,7 @@ impl FigureMgr { ), // In air (false, _, false) => anim::character::JumpAnimation::update_skeleton( - &CharacterSkeleton::new( - holding_lantern, - mountee_offsets, - hitbox_offsets, - ), + &CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body), ( active_tool_kind, second_tool_kind, @@ -880,11 +862,7 @@ impl FigureMgr { ), // Swim (_, _, true) => anim::character::SwimAnimation::update_skeleton( - &CharacterSkeleton::new( - holding_lantern, - mountee_offsets, - hitbox_offsets, - ), + &CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body), ( active_tool_kind, second_tool_kind, @@ -5367,7 +5345,7 @@ impl FigureColLights { pub struct FigureStateMeta { bone_consts: Consts, locals: Consts, - lantern_offset: anim::vek::Transform, + lantern_offset: anim::vek::Vec3, mountee_offset: anim::vek::Transform, state_time: f32, last_ori: anim::vek::Quaternion, @@ -5408,14 +5386,14 @@ impl DerefMut for FigureState { impl FigureState { pub fn new(renderer: &mut Renderer, skeleton: S) -> Self { let mut buf = [Default::default(); anim::MAX_BONE_COUNT]; - let body_offsets = anim::compute_matrices(&skeleton, anim::vek::Mat4::identity(), &mut buf); + let offsets = anim::compute_matrices(&skeleton, anim::vek::Mat4::identity(), &mut buf); let bone_consts = figure_bone_data_from_anim(&buf); Self { meta: FigureStateMeta { bone_consts: renderer.create_consts(bone_consts).unwrap(), locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(), - lantern_offset: body_offsets[0], - mountee_offset: body_offsets[1], + lantern_offset: offsets.lantern, + mountee_offset: offsets.mount_bone, state_time: 0.0, last_ori: Ori::default().into(), lpindex: 0, @@ -5539,7 +5517,7 @@ impl FigureState { ); renderer.update_consts(&mut self.locals, &[locals]).unwrap(); - let body_offsets = anim::compute_matrices(&self.skeleton, mat, buf); + let offsets = anim::compute_matrices(&self.skeleton, mat, buf); let new_bone_consts = figure_bone_data_from_anim(buf); @@ -5549,8 +5527,8 @@ impl FigureState { &new_bone_consts[0..S::BONE_COUNT], ) .unwrap(); - self.lantern_offset = body_offsets[0]; - self.mountee_offset = body_offsets[1]; + self.lantern_offset = offsets.lantern; + self.mountee_offset = offsets.mount_bone; let smoothing = (5.0 * dt).min(1.0); if let Some(last_pos) = self.last_pos {