mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Use Body to determine mountee offsets
This commit is contained in:
parent
b063ec5a8f
commit
8745fb803a
@ -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: (
|
||||
|
@ -659,6 +659,7 @@ impl Body {
|
||||
)
|
||||
}
|
||||
|
||||
// Physical offset relative to the mountee
|
||||
pub fn mounting_offset(&self) -> Vec3<f32> {
|
||||
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])
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let upper_torso = Mat4::<f32>::from(self.upper_torso);
|
||||
|
||||
let torso_mat = base_mat * Mat4::<f32>::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::<f32>::from(self.hold)),
|
||||
];
|
||||
[Transform::default(), Transform::default()]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.torso,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
|
||||
let pants_mat = chest_mat * Mat4::<f32>::from(self.pants);
|
||||
let control_mat = chest_mat * Mat4::<f32>::from(self.control);
|
||||
@ -64,7 +64,10 @@ impl Skeleton for BipedSmallSkeleton {
|
||||
make_bone(base_mat * Mat4::<f32>::from(self.foot_l)),
|
||||
make_bone(base_mat * Mat4::<f32>::from(self.foot_r)),
|
||||
];
|
||||
[Transform::default(), Transform::default()]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.chest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
|
||||
let neck_mat = chest_mat * Mat4::<f32>::from(self.neck);
|
||||
let head_mat = neck_mat * Mat4::<f32>::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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let torso_mat = base_mat * Mat4::<f32>::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::<f32>::from(self.leg_l)),
|
||||
make_bone(base_mat * Mat4::<f32>::from(self.leg_r)),
|
||||
];
|
||||
[Transform::default(), self.torso]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.torso,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Transform<f32, f32, f32>>,
|
||||
hitbox_offsets: Option<vek::Vec3<f32>>,
|
||||
mountee_body: Option<comp::Body>,
|
||||
});
|
||||
|
||||
impl CharacterSkeleton {
|
||||
pub fn new(
|
||||
holding_lantern: bool,
|
||||
offsets: Option<Transform<f32, f32, f32>>,
|
||||
hitbox_offsets: Option<vek::Vec3<f32>>,
|
||||
mountee_body: Option<comp::Body>,
|
||||
) -> Self {
|
||||
Self {
|
||||
holding_lantern,
|
||||
offsets,
|
||||
hitbox_offsets,
|
||||
mountee_body,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
@ -105,18 +105,21 @@ impl Skeleton for CharacterSkeleton {
|
||||
&self,
|
||||
base_mat: Mat4<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let mut torso_mat = base_mat * Mat4::<f32>::from(self.torso);
|
||||
if let Some(offset) = self.offsets {
|
||||
let hitbox_offsets = self.hitbox_offsets.unwrap_or(vek::Vec3::<f32>::zero());
|
||||
torso_mat = base_mat
|
||||
* Mat4::<f32>::from(Transform {
|
||||
position: offset.position
|
||||
- Vec3::from([0.0, hitbox_offsets.y, hitbox_offsets.z]),
|
||||
orientation: offset.orientation,
|
||||
scale: Vec3::<f32>::one(),
|
||||
})
|
||||
* Mat4::<f32>::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::<f32>::from(Transform {
|
||||
position: offset.position
|
||||
- Vec3::from([0.0, hitbox_offsets.y, hitbox_offsets.z]),
|
||||
orientation: offset.orientation,
|
||||
scale: Vec3::<f32>::one(),
|
||||
})
|
||||
* Mat4::<f32>::from(self.torso).translated_3d(visual_offset);
|
||||
}
|
||||
}
|
||||
let chest_mat = torso_mat * Mat4::<f32>::from(self.chest);
|
||||
let head_mat = chest_mat * Mat4::<f32>::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::<f32>::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<f32> {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front);
|
||||
let chest_rear_mat = chest_front_mat * Mat4::<f32>::from(self.chest_rear);
|
||||
let head_lower_mat = chest_front_mat * Mat4::<f32>::from(self.head_lower);
|
||||
@ -69,7 +69,10 @@ impl Skeleton for DragonSkeleton {
|
||||
make_bone(chest_rear_mat * Mat4::<f32>::from(self.foot_bl)),
|
||||
make_bone(chest_rear_mat * Mat4::<f32>::from(self.foot_br)),
|
||||
];
|
||||
[Transform::default(), self.chest_front]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.chest_front,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front);
|
||||
let chest_back_mat = Mat4::<f32>::from(self.chest_back);
|
||||
let head_mat = Mat4::<f32>::from(self.head);
|
||||
@ -47,7 +47,10 @@ impl Skeleton for FishMediumSkeleton {
|
||||
make_bone(chest_front_mat * Mat4::<f32>::from(self.fin_l)),
|
||||
make_bone(chest_front_mat * Mat4::<f32>::from(self.fin_r)),
|
||||
];
|
||||
[Transform::default(), Transform::default()]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.chest_front,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let chest_mat = base_mat * Mat4::<f32>::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::<f32>::from(self.fin_l)),
|
||||
make_bone(chest_mat * Mat4::<f32>::from(self.fin_r)),
|
||||
];
|
||||
[Transform::default(), Transform::default()]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.chest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
buf[0] = make_bone(base_mat);
|
||||
[Transform::default(), Transform::default()]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: Transform::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let torso_mat = base_mat * Mat4::<f32>::from(self.torso);
|
||||
let upper_torso_mat = torso_mat * Mat4::<f32>::from(self.upper_torso);
|
||||
let lower_torso_mat = upper_torso_mat * Mat4::<f32>::from(self.lower_torso);
|
||||
@ -70,7 +70,10 @@ impl Skeleton for GolemSkeleton {
|
||||
make_bone(leg_l_mat * Mat4::<f32>::from(self.foot_l)),
|
||||
make_bone(leg_r_mat * Mat4::<f32>::from(self.foot_r)),
|
||||
];
|
||||
[Transform::default(), self.torso]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.torso,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,12 @@ fn make_bone(mat: Mat4<f32>) -> FigureBoneData {
|
||||
|
||||
pub type Bone = Transform<f32, f32, f32>;
|
||||
|
||||
// Offsets that will be returned after computing the skeleton matrices
|
||||
pub struct Offsets {
|
||||
pub lantern: Vec3<f32>,
|
||||
pub mount_bone: Transform<f32, f32, f32>,
|
||||
}
|
||||
|
||||
pub trait Skeleton: Send + Sync + 'static {
|
||||
type Attr;
|
||||
type Body;
|
||||
@ -102,14 +108,14 @@ pub trait Skeleton: Send + Sync + 'static {
|
||||
&self,
|
||||
base_mat: Mat4<f32>,
|
||||
buf: &mut [FigureBoneData; MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2];
|
||||
) -> Offsets;
|
||||
}
|
||||
|
||||
pub fn compute_matrices<S: Skeleton>(
|
||||
skeleton: &S,
|
||||
base_mat: Mat4<f32>,
|
||||
buf: &mut [FigureBoneData; MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
#[cfg(not(feature = "use-dyn-lib"))]
|
||||
{
|
||||
S::compute_matrices_inner(skeleton, base_mat, buf)
|
||||
@ -120,11 +126,7 @@ pub fn compute_matrices<S: Skeleton>(
|
||||
let lib = &lock.as_ref().unwrap().lib;
|
||||
|
||||
let compute_fn: libloading::Symbol<
|
||||
fn(
|
||||
&S,
|
||||
Mat4<f32>,
|
||||
&mut [FigureBoneData; MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2],
|
||||
fn(&S, Mat4<f32>, &mut [FigureBoneData; MAX_BONE_COUNT]) -> Offsets,
|
||||
> = unsafe { lib.get(S::COMPUTE_FN) }.unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Trying to use: {} but had error: {:?}",
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let bone0_mat = base_mat * Mat4::<f32>::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::<f32>::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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
|
||||
let tail_front = chest_mat * Mat4::<f32>::from(self.tail_front);
|
||||
let head_lower_mat = chest_mat * Mat4::<f32>::from(self.head_lower);
|
||||
@ -66,7 +66,10 @@ impl Skeleton for QuadrupedLowSkeleton {
|
||||
make_bone(chest_mat * Mat4::<f32>::from(self.foot_bl)),
|
||||
make_bone(chest_mat * Mat4::<f32>::from(self.foot_br)),
|
||||
];
|
||||
[Transform::default(), self.chest]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.chest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let torso_front_mat = base_mat * Mat4::<f32>::from(self.torso_front);
|
||||
let torso_back_mat = torso_front_mat * Mat4::<f32>::from(self.torso_back);
|
||||
let neck_mat = torso_front_mat * Mat4::<f32>::from(self.neck);
|
||||
@ -80,7 +81,10 @@ impl Skeleton for QuadrupedMediumSkeleton {
|
||||
make_bone(leg_bl_mat * Mat4::<f32>::from(self.foot_bl)),
|
||||
make_bone(leg_br_mat * Mat4::<f32>::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),
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let chest_mat = base_mat * Mat4::<f32>::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::<f32>::from(self.leg_br)),
|
||||
make_bone(chest_mat * Mat4::<f32>::from(self.tail)),
|
||||
];
|
||||
[Transform::default(), self.chest]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.chest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let bone0_mat = base_mat * Mat4::<f32>::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::<f32>::from(self.bone2) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */
|
||||
make_bone(bone0_mat * Mat4::<f32>::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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<f32>,
|
||||
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
|
||||
) -> [Transform<f32, f32, f32>; 2] {
|
||||
) -> Offsets {
|
||||
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front);
|
||||
let neck_mat = chest_front_mat * Mat4::<f32>::from(self.neck);
|
||||
let head_mat = neck_mat * Mat4::<f32>::from(self.head);
|
||||
@ -71,7 +71,10 @@ impl Skeleton for TheropodSkeleton {
|
||||
make_bone(leg_l_mat * Mat4::<f32>::from(self.foot_l)),
|
||||
make_bone(leg_r_mat * Mat4::<f32>::from(self.foot_r)),
|
||||
];
|
||||
[Transform::default(), self.chest_front]
|
||||
Offsets {
|
||||
lantern: Vec3::default(),
|
||||
mount_bone: self.chest_front,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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::<f32>::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::<UidAllocator>()
|
||||
.retrieve_entity_internal((*entity).into())?;
|
||||
let bodies = ecs.read_storage::<Body>();
|
||||
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<FigureBoneData>,
|
||||
locals: Consts<FigureLocals>,
|
||||
lantern_offset: anim::vek::Transform<f32, f32, f32>,
|
||||
lantern_offset: anim::vek::Vec3<f32>,
|
||||
mountee_offset: anim::vek::Transform<f32, f32, f32>,
|
||||
state_time: f32,
|
||||
last_ori: anim::vek::Quaternion<f32>,
|
||||
@ -5408,14 +5386,14 @@ impl<S> DerefMut for FigureState<S> {
|
||||
impl<S: Skeleton> FigureState<S> {
|
||||
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<S: Skeleton> FigureState<S> {
|
||||
);
|
||||
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<S: Skeleton> FigureState<S> {
|
||||
&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 {
|
||||
|
Loading…
Reference in New Issue
Block a user