Merge branch 'snowram/hacky-mount' into 'master'

Allow for collars to make QuadMed npcs mountable

See merge request veloren/veloren!2219
This commit is contained in:
Marcel 2021-05-14 12:27:19 +00:00
commit 7fe0db2261
29 changed files with 518 additions and 77 deletions

View File

@ -106,6 +106,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Merchants now use `/tell` instead of `/say` to communicate prices - Merchants now use `/tell` instead of `/say` to communicate prices
- Entities catch on fire if they stand too close to campfires - Entities catch on fire if they stand too close to campfires
- Water extinguishes entities on fire - Water extinguishes entities on fire
- Some tamed NPCs can now be mounted
### Removed ### Removed

View File

@ -159,7 +159,7 @@
central: ("npc.tuskram.male.neck"), central: ("npc.tuskram.male.neck"),
), ),
jaw: ( jaw: (
offset: (-5.0, 0.0, -1.5), offset: (-5.0, 0.0, -8.0),
central: ("npc.tuskram.male.jaw"), central: ("npc.tuskram.male.jaw"),
), ),
torso_front: ( torso_front: (

View File

@ -659,8 +659,49 @@ impl Body {
) )
} }
// Physical offset relative to the mountee
pub fn mounting_offset(&self) -> Vec3<f32> { pub fn mounting_offset(&self) -> Vec3<f32> {
match self { match self {
Body::QuadrupedMedium(quadruped_medium) => {
match (quadruped_medium.species, quadruped_medium.body_type) {
(quadruped_medium::Species::Grolgar, _) => Vec3::from([0.5, 0.5, 1.8]),
(quadruped_medium::Species::Saber, _) => Vec3::from([0.3, 0.3, 1.3]),
(quadruped_medium::Species::Tiger, _) => Vec3::from([0.2, 0.2, 1.4]),
(quadruped_medium::Species::Tuskram, _) => Vec3::from([-0.5, -0.5, 1.5]),
(quadruped_medium::Species::Lion, _) => Vec3::from([0.3, 0.3, 1.5]),
(quadruped_medium::Species::Tarasque, _) => Vec3::from([0.6, 0.6, 2.0]),
(quadruped_medium::Species::Wolf, _) => Vec3::from([0.5, 0.5, 1.3]),
(quadruped_medium::Species::Frostfang, _) => Vec3::from([0.5, 0.5, 1.2]),
(quadruped_medium::Species::Mouflon, _) => Vec3::from([0.3, 0.3, 1.2]),
(quadruped_medium::Species::Catoblepas, _) => Vec3::from([0.0, 0.0, 2.0]),
(quadruped_medium::Species::Bonerattler, _) => Vec3::from([0.5, 0.5, 1.2]),
(quadruped_medium::Species::Deer, _) => Vec3::from([0.2, 0.2, 1.3]),
(quadruped_medium::Species::Hirdrasil, _) => Vec3::from([0.0, 0.0, 1.4]),
(quadruped_medium::Species::Roshwalr, _) => Vec3::from([0.5, 0.5, 1.8]),
(quadruped_medium::Species::Donkey, _) => Vec3::from([0.5, 0.5, 1.5]),
(quadruped_medium::Species::Camel, _) => Vec3::from([-0.1, -0.1, 2.8]),
(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.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])
},
(quadruped_medium::Species::Cattle, quadruped_medium::BodyType::Female) => {
Vec3::from([0.7, 0.7, 2.2])
},
(quadruped_medium::Species::Darkhound, _) => Vec3::from([0.5, 0.5, 1.4]),
(quadruped_medium::Species::Highland, _) => Vec3::from([0.5, 0.5, 2.3]),
(quadruped_medium::Species::Yak, _) => Vec3::from([0.0, 0.0, 3.0]),
(quadruped_medium::Species::Panda, _) => Vec3::from([-0.2, -0.2, 1.4]),
(quadruped_medium::Species::Bear, _) => Vec3::from([-0.4, -0.4, 2.5]),
(quadruped_medium::Species::Dreadhorn, _) => Vec3::from([0.2, 0.2, 3.5]),
(quadruped_medium::Species::Moose, _) => Vec3::from([-0.6, -0.6, 2.1]),
(quadruped_medium::Species::Snowleopard, _) => Vec3::from([-0.5, -0.5, 1.4]),
}
},
Body::Ship(ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]), Body::Ship(ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]),
_ => Vec3::unit_z(), _ => Vec3::unit_z(),
} }

View File

@ -47,6 +47,7 @@ pub enum CharacterState {
Idle, Idle,
Climb(climb::Data), Climb(climb::Data),
Sit, Sit,
Mount,
Dance, Dance,
Talk, Talk,
Sneak, Sneak,

View File

@ -19,6 +19,7 @@ pub mod glide_wield;
pub mod healing_beam; pub mod healing_beam;
pub mod idle; pub mod idle;
pub mod leap_melee; pub mod leap_melee;
pub mod mount;
pub mod repeater_ranged; pub mod repeater_ranged;
pub mod roll; pub mod roll;
pub mod self_buff; pub mod self_buff;

View File

@ -0,0 +1,50 @@
use super::utils::*;
use crate::{
comp::{CharacterState, InventoryAction, StateUpdate},
states::behavior::{CharacterBehavior, JoinData},
};
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct Data;
impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data);
handle_wield(data, &mut update);
handle_jump(data, &mut update, 1.0);
// Try to Fall/Stand up/Move
if !data.physics.on_ground || data.inputs.move_dir.magnitude_squared() > 0.0 {
update.character = CharacterState::Idle;
}
update
}
fn wield(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data);
attempt_wield(data, &mut update);
update
}
fn dance(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data);
attempt_dance(data, &mut update);
update
}
fn stand(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data);
// Try to Fall/Stand up/Move
update.character = CharacterState::Idle;
update
}
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
let mut update = StateUpdate::from(data);
handle_manipulate_loadout(&data, &mut update, inv_action);
update
}
}

View File

@ -315,6 +315,9 @@ impl<'a> System<'a> for Sys {
CharacterState::Sit => { CharacterState::Sit => {
states::sit::Data::handle_event(&states::sit::Data, &j, action) states::sit::Data::handle_event(&states::sit::Data, &j, action)
}, },
CharacterState::Mount => {
states::mount::Data::handle_event(&states::mount::Data, &j, action)
},
CharacterState::Dance => { CharacterState::Dance => {
states::dance::Data::handle_event(&states::dance::Data, &j, action) states::dance::Data::handle_event(&states::dance::Data, &j, action)
}, },
@ -352,9 +355,9 @@ impl<'a> System<'a> for Sys {
// If mounted, character state is controlled by mount // If mounted, character state is controlled by mount
// TODO: Make mounting a state // TODO: Make mounting a state
if let Some(Mounting(_)) = read_data.mountings.get(entity) { if let Some(Mounting(_)) = read_data.mountings.get(entity) {
let sit_state = CharacterState::Sit {}; let mount_state = CharacterState::Mount {};
if join_struct.char_state.get_unchecked() != &sit_state { if join_struct.char_state.get_unchecked() != &mount_state {
*join_struct.char_state.get_mut_unchecked() = sit_state; *join_struct.char_state.get_mut_unchecked() = mount_state;
} }
continue; continue;
} }
@ -374,6 +377,7 @@ impl<'a> System<'a> for Sys {
CharacterState::GlideWield => states::glide_wield::Data.behavior(&j), CharacterState::GlideWield => states::glide_wield::Data.behavior(&j),
CharacterState::Stunned(data) => data.behavior(&j), CharacterState::Stunned(data) => data.behavior(&j),
CharacterState::Sit => states::sit::Data::behavior(&states::sit::Data, &j), CharacterState::Sit => states::sit::Data::behavior(&states::sit::Data, &j),
CharacterState::Mount => states::mount::Data::behavior(&states::mount::Data, &j),
CharacterState::Dance => states::dance::Data::behavior(&states::dance::Data, &j), CharacterState::Dance => states::dance::Data::behavior(&states::dance::Data, &j),
CharacterState::Sneak => states::sneak::Data::behavior(&states::sneak::Data, &j), CharacterState::Sneak => states::sneak::Data::behavior(&states::sneak::Data, &j),
CharacterState::BasicBlock(data) => data.behavior(&j), CharacterState::BasicBlock(data) => data.behavior(&j),

View File

@ -68,7 +68,14 @@ impl<'a> System<'a> for Sys {
if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) { if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) {
let mounting_offset = let mounting_offset =
body.map_or(Vec3::unit_z(), Body::mounting_offset); body.map_or(Vec3::unit_z(), Body::mounting_offset);
let _ = positions.insert(mounter, Pos(pos.0 + mounting_offset)); let _ = positions.insert(
mounter,
Pos(Vec3 {
x: pos.0.x + ori.look_dir().x * mounting_offset.x,
y: pos.0.y + ori.look_dir().y * mounting_offset.y,
z: pos.0.z + mounting_offset.z,
}),
);
let _ = orientations.insert(mounter, ori); let _ = orientations.insert(mounter, ori);
let _ = velocities.insert(mounter, vel); let _ = velocities.insert(mounter, vel);
} }

View File

@ -193,6 +193,7 @@ impl<'a> System<'a> for Sys {
CharacterState::Idle { .. } CharacterState::Idle { .. }
| CharacterState::Talk { .. } | CharacterState::Talk { .. }
| CharacterState::Sit { .. } | CharacterState::Sit { .. }
| CharacterState::Mount { .. }
| CharacterState::Dance { .. } | CharacterState::Dance { .. }
| CharacterState::Sneak { .. } | CharacterState::Sneak { .. }
| CharacterState::Glide { .. } | CharacterState::Glide { .. }

View File

@ -349,6 +349,20 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
.write_storage() .write_storage()
.insert(tameable_entity, comp::Alignment::Owned(uid)); .insert(tameable_entity, comp::Alignment::Owned(uid));
// Make entity mountable if its Body is QuadrupedMedium
// TODO: Make mounting better so that all entities can be
// mounted?
if let Some(comp::Body::QuadrupedMedium(_)) = state
.ecs()
.read_storage::<comp::Body>()
.get(tameable_entity)
{
let _ = state.ecs().write_storage().insert(
tameable_entity,
comp::MountState::Unmounted,
);
}
// Add to group system // Add to group system
let clients = state.ecs().read_storage::<Client>(); let clients = state.ecs().read_storage::<Client>();
let uids = state.ecs().read_storage::<Uid>(); let uids = state.ecs().read_storage::<Uid>();

View File

@ -29,7 +29,7 @@ pub use self::{
stunned::StunnedAnimation, summon::SummonAnimation, wield::WieldAnimation, 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -77,7 +77,7 @@ impl Skeleton for BipedLargeSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let upper_torso = Mat4::<f32>::from(self.upper_torso); let upper_torso = Mat4::<f32>::from(self.upper_torso);
let torso_mat = base_mat * Mat4::<f32>::from(self.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? // FIXME: Should this be control_l_mat?
make_bone(upper_torso_mat * control_mat * hand_l_mat * Mat4::<f32>::from(self.hold)), make_bone(upper_torso_mat * control_mat * hand_l_mat * Mat4::<f32>::from(self.hold)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.torso,
}
} }
} }

View File

@ -12,7 +12,7 @@ pub use self::{
shoot::ShootAnimation, stunned::StunnedAnimation, wield::WieldAnimation, 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -47,7 +47,7 @@ impl Skeleton for BipedSmallSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest); let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
let pants_mat = chest_mat * Mat4::<f32>::from(self.pants); let pants_mat = chest_mat * Mat4::<f32>::from(self.pants);
let control_mat = chest_mat * Mat4::<f32>::from(self.control); 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_l)),
make_bone(base_mat * Mat4::<f32>::from(self.foot_r)), make_bone(base_mat * Mat4::<f32>::from(self.foot_r)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
} }
} }

View File

@ -16,7 +16,7 @@ pub use self::{
stunned::StunnedAnimation, swim::SwimAnimation, stunned::StunnedAnimation, swim::SwimAnimation,
}; };
use super::{make_bone, vek::*, FigureBoneData, Skeleton}; use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self}; use common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -55,7 +55,7 @@ impl Skeleton for BirdLargeSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest); let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
let neck_mat = chest_mat * Mat4::<f32>::from(self.neck); let neck_mat = chest_mat * Mat4::<f32>::from(self.neck);
let head_mat = neck_mat * Mat4::<f32>::from(self.head); 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_l_mat),
make_bone(foot_r_mat), make_bone(foot_r_mat),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
} }
} }

View File

@ -6,7 +6,7 @@ pub mod run;
// Reexports // Reexports
pub use self::{feed::FeedAnimation, fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation}; 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -36,7 +36,7 @@ impl Skeleton for BirdMediumSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let torso_mat = base_mat * Mat4::<f32>::from(self.torso); let torso_mat = base_mat * Mat4::<f32>::from(self.torso);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ *(<&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_l)),
make_bone(base_mat * Mat4::<f32>::from(self.leg_r)), make_bone(base_mat * Mat4::<f32>::from(self.leg_r)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.torso,
}
} }
} }

View File

@ -12,6 +12,7 @@ pub mod gliding;
pub mod idle; pub mod idle;
pub mod jump; pub mod jump;
pub mod leapmelee; pub mod leapmelee;
pub mod mount;
pub mod repeater; pub mod repeater;
pub mod roll; pub mod roll;
pub mod run; pub mod run;
@ -35,13 +36,13 @@ pub use self::{
chargeswing::ChargeswingAnimation, climb::ClimbAnimation, dance::DanceAnimation, chargeswing::ChargeswingAnimation, climb::ClimbAnimation, dance::DanceAnimation,
dash::DashAnimation, equip::EquipAnimation, glidewield::GlideWieldAnimation, dash::DashAnimation, equip::EquipAnimation, glidewield::GlideWieldAnimation,
gliding::GlidingAnimation, idle::IdleAnimation, jump::JumpAnimation, leapmelee::LeapAnimation, gliding::GlidingAnimation, idle::IdleAnimation, jump::JumpAnimation, leapmelee::LeapAnimation,
repeater::RepeaterAnimation, roll::RollAnimation, run::RunAnimation, mount::MountAnimation, repeater::RepeaterAnimation, roll::RollAnimation, run::RunAnimation,
shockwave::ShockwaveAnimation, shoot::ShootAnimation, sit::SitAnimation, sneak::SneakAnimation, shockwave::ShockwaveAnimation, shoot::ShootAnimation, sit::SitAnimation, sneak::SneakAnimation,
spin::SpinAnimation, spinmelee::SpinMeleeAnimation, staggered::StaggeredAnimation, spin::SpinAnimation, spinmelee::SpinMeleeAnimation, staggered::StaggeredAnimation,
stand::StandAnimation, stunned::StunnedAnimation, swim::SwimAnimation, stand::StandAnimation, stunned::StunnedAnimation, swim::SwimAnimation,
swimwield::SwimWieldAnimation, talk::TalkAnimation, wield::WieldAnimation, 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 common::comp;
use core::convert::TryFrom; use core::convert::TryFrom;
use std::f32::consts::PI; use std::f32::consts::PI;
@ -71,12 +72,20 @@ skeleton_impls!(struct CharacterSkeleton {
control_r, control_r,
:: // Begin non-bone fields :: // Begin non-bone fields
holding_lantern: bool, holding_lantern: bool,
offsets: Option<Transform<f32, f32, f32>>,
mountee_body: Option<comp::Body>,
}); });
impl CharacterSkeleton { impl CharacterSkeleton {
pub fn new(holding_lantern: bool) -> Self { pub fn new(
holding_lantern: bool,
offsets: Option<Transform<f32, f32, f32>>,
mountee_body: Option<comp::Body>,
) -> Self {
Self { Self {
holding_lantern, holding_lantern,
offsets,
mountee_body,
..Self::default() ..Self::default()
} }
} }
@ -96,8 +105,22 @@ impl Skeleton for CharacterSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let torso_mat = base_mat * Mat4::<f32>::from(self.torso); let mut torso_mat = base_mat * Mat4::<f32>::from(self.torso);
if let Some(offset) = self.offsets {
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 chest_mat = torso_mat * Mat4::<f32>::from(self.chest);
let head_mat = chest_mat * Mat4::<f32>::from(self.head); let head_mat = chest_mat * Mat4::<f32>::from(self.head);
let shorts_mat = chest_mat * Mat4::<f32>::from(self.shorts); let shorts_mat = chest_mat * Mat4::<f32>::from(self.shorts);
@ -132,7 +155,10 @@ impl Skeleton for CharacterSkeleton {
// FIXME: Should this be control_l_mat? // FIXME: Should this be control_l_mat?
make_bone(control_mat * hand_l_mat * Mat4::<f32>::from(self.hold)), 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() Offsets {
lantern: (lantern_mat * Vec4::new(0.0, 0.0, -4.0, 1.0)).xyz(),
mount_bone: self.chest,
}
} }
} }
@ -329,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(),
}
}

View File

@ -0,0 +1,149 @@
use super::{
super::{vek::*, Animation},
CharacterSkeleton, SkeletonAttr,
};
use common::comp::item::ToolKind;
use std::{f32::consts::PI, ops::Mul};
pub struct MountAnimation;
impl Animation for MountAnimation {
#[allow(clippy::type_complexity)]
type Dependency<'a> = (
Option<ToolKind>,
Option<ToolKind>,
f32,
Vec3<f32>,
Vec3<f32>,
Vec3<f32>,
Vec3<f32>,
Option<Transform<f32, f32, f32>>,
);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_mount\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_mount")]
fn update_skeleton_inner<'a>(
skeleton: &Self::Skeleton,
(
_active_tool_kind,
_second_tool_kind,
global_time,
velocity,
avg_vel,
orientation,
last_ori,
_mount_offset,
): Self::Dependency<'a>,
anim_time: f32,
_rate: &mut f32,
s_a: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let slow = (anim_time * 1.0).sin();
let slowa = (anim_time * 1.0 + PI / 2.0).sin();
let stop = (anim_time * 3.0).min(PI / 2.0).sin();
let head_look = Vec2::new(
(global_time * 0.05 + anim_time / 15.0)
.floor()
.mul(7331.0)
.sin()
* 0.25,
(global_time * 0.05 + anim_time / 15.0)
.floor()
.mul(1337.0)
.sin()
* 0.125,
);
let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori);
let speed = (Vec2::<f32>::from(velocity).magnitude()).min(24.0);
let canceler = (speed / 24.0).powf(0.6);
let _x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude()) * canceler;
let _tilt = if ::vek::Vec2::new(ori, last_ori)
.map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite())
.reduce_and()
&& ori.angle_between(last_ori).is_finite()
{
ori.angle_between(last_ori).min(0.2)
* last_ori.determine_side(Vec2::zero(), ori).signum()
} else {
0.0
} * 1.3;
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + slow * 0.1 + stop * -0.8);
next.head.orientation = Quaternion::rotation_z(head_look.x + slow * 0.2 - slow * 0.1)
* Quaternion::rotation_x((0.4 + slowa * -0.1 + slow * 0.1 + head_look.y).abs());
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1);
next.chest.orientation = Quaternion::rotation_x(-0.6 + stop * 0.15);
next.belt.position = Vec3::new(0.0, s_a.belt.0 + stop * 1.2, s_a.belt.1);
next.belt.orientation = Quaternion::rotation_x(stop * 0.3);
next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
next.shorts.position = Vec3::new(0.0, s_a.shorts.0 + stop * 2.5, s_a.shorts.1 + stop * 0.6);
next.shorts.orientation = Quaternion::rotation_x(stop * 0.6);
next.hand_l.position = Vec3::new(
-s_a.hand.0 + 4.0,
s_a.hand.1 + slowa * 0.15 + stop * 8.0,
s_a.hand.2 + slow * 0.7 + stop * 4.0,
);
next.hand_l.orientation =
Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_z(-PI / 2.0);
next.hand_r.position = Vec3::new(
s_a.hand.0 - 4.0,
s_a.hand.1 + slowa * 0.15 + stop * 8.0,
s_a.hand.2 + slow * 0.7 + stop * 4.0,
);
next.hand_r.orientation =
Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_z(PI / 2.0);
next.foot_l.position = Vec3::new(-s_a.foot.0 - 2.0, 4.0 + s_a.foot.1, s_a.foot.2);
next.foot_l.orientation = Quaternion::rotation_x(slow * 0.1 + stop * 0.4 + slow * 0.1)
* Quaternion::rotation_y(0.5);
next.foot_r.position = Vec3::new(s_a.foot.0 + 2.0, 4.0 + s_a.foot.1, s_a.foot.2);
next.foot_r.orientation = Quaternion::rotation_x(slowa * 0.1 + stop * 0.4 + slowa * 0.1)
* Quaternion::rotation_y(-0.5);
next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
next.shoulder_l.orientation = Quaternion::rotation_x(0.0);
next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
next.shoulder_r.orientation = Quaternion::rotation_x(0.0);
next.torso.position = Vec3::new(0.0, 0.0, stop * -0.16) * s_a.scaler;
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(
s_a.hand.0 + 1.0 - head_look.x * 8.0,
s_a.hand.1 + 5.0 + head_look.x * 6.0,
s_a.hand.2 + 9.0 + head_look.y * 6.0,
);
next.hand_r.orientation = Quaternion::rotation_x(2.25)
* Quaternion::rotation_z(0.9)
* Quaternion::rotation_y(head_look.x * 3.0)
* Quaternion::rotation_x(head_look.y * 3.0);
let fast = (anim_time * 5.0).sin();
let fast2 = (anim_time * 4.5 + 8.0).sin();
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x(fast * 0.1)
* Quaternion::rotation_y(fast2 * 0.1);
}
next
}
}

View File

@ -5,7 +5,7 @@ pub mod run;
// Reexports // Reexports
pub use self::{fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation}; 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -43,7 +43,7 @@ impl Skeleton for DragonSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front); 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 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); 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_bl)),
make_bone(chest_rear_mat * Mat4::<f32>::from(self.foot_br)), make_bone(chest_rear_mat * Mat4::<f32>::from(self.foot_br)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.chest_front,
}
} }
} }

View File

@ -4,7 +4,7 @@ pub mod swim;
// Reexports // Reexports
pub use self::{idle::IdleAnimation, swim::SwimAnimation}; 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -33,7 +33,7 @@ impl Skeleton for FishMediumSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front); let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front);
let chest_back_mat = Mat4::<f32>::from(self.chest_back); let chest_back_mat = Mat4::<f32>::from(self.chest_back);
let head_mat = Mat4::<f32>::from(self.head); 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_l)),
make_bone(chest_front_mat * Mat4::<f32>::from(self.fin_r)), make_bone(chest_front_mat * Mat4::<f32>::from(self.fin_r)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.chest_front,
}
} }
} }

View File

@ -4,7 +4,7 @@ pub mod swim;
// Reexports // Reexports
pub use self::{idle::IdleAnimation, swim::SwimAnimation}; 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -30,7 +30,7 @@ impl Skeleton for FishSmallSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest); let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ *(<&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_l)),
make_bone(chest_mat * Mat4::<f32>::from(self.fin_r)), make_bone(chest_mat * Mat4::<f32>::from(self.fin_r)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
} }
} }

View File

@ -1,4 +1,4 @@
use super::{make_bone, vek::*, FigureBoneData, Skeleton}; use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
pub type Body = (); pub type Body = ();
@ -31,9 +31,12 @@ impl Skeleton for FixtureSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
buf[0] = make_bone(base_mat); buf[0] = make_bone(base_mat);
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: Transform::default(),
}
} }
} }

View File

@ -12,7 +12,7 @@ pub use self::{
shockwave::ShockwaveAnimation, shoot::ShootAnimation, spinmelee::SpinMeleeAnimation, 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -47,7 +47,7 @@ impl Skeleton for GolemSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let torso_mat = base_mat * Mat4::<f32>::from(self.torso); let torso_mat = base_mat * Mat4::<f32>::from(self.torso);
let upper_torso_mat = torso_mat * Mat4::<f32>::from(self.upper_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); 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_l_mat * Mat4::<f32>::from(self.foot_l)),
make_bone(leg_r_mat * Mat4::<f32>::from(self.foot_r)), make_bone(leg_r_mat * Mat4::<f32>::from(self.foot_r)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.torso,
}
} }
} }

View File

@ -89,6 +89,12 @@ fn make_bone(mat: Mat4<f32>) -> FigureBoneData {
pub type Bone = Transform<f32, f32, f32>; 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 { pub trait Skeleton: Send + Sync + 'static {
type Attr; type Attr;
type Body; type Body;
@ -102,14 +108,14 @@ pub trait Skeleton: Send + Sync + 'static {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; MAX_BONE_COUNT], buf: &mut [FigureBoneData; MAX_BONE_COUNT],
) -> Vec3<f32>; ) -> Offsets;
} }
pub fn compute_matrices<S: Skeleton>( pub fn compute_matrices<S: Skeleton>(
skeleton: &S, skeleton: &S,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; MAX_BONE_COUNT], buf: &mut [FigureBoneData; MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
#[cfg(not(feature = "use-dyn-lib"))] #[cfg(not(feature = "use-dyn-lib"))]
{ {
S::compute_matrices_inner(skeleton, base_mat, buf) S::compute_matrices_inner(skeleton, base_mat, buf)
@ -120,7 +126,7 @@ pub fn compute_matrices<S: Skeleton>(
let lib = &lock.as_ref().unwrap().lib; let lib = &lock.as_ref().unwrap().lib;
let compute_fn: libloading::Symbol< let compute_fn: libloading::Symbol<
fn(&S, Mat4<f32>, &mut [FigureBoneData; MAX_BONE_COUNT]) -> Vec3<f32>, fn(&S, Mat4<f32>, &mut [FigureBoneData; MAX_BONE_COUNT]) -> Offsets,
> = unsafe { lib.get(S::COMPUTE_FN) }.unwrap_or_else(|e| { > = unsafe { lib.get(S::COMPUTE_FN) }.unwrap_or_else(|e| {
panic!( panic!(
"Trying to use: {} but had error: {:?}", "Trying to use: {} but had error: {:?}",

View File

@ -5,7 +5,7 @@ pub mod shoot;
// Reexports // Reexports
pub use self::{beam::BeamAnimation, idle::IdleAnimation, shoot::ShootAnimation}; 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -29,14 +29,17 @@ impl Skeleton for ObjectSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let bone0_mat = base_mat * Mat4::<f32>::from(self.bone0); let bone0_mat = base_mat * Mat4::<f32>::from(self.bone0);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ *(<&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(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 */ make_bone(Mat4::<f32>::from(self.bone1) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */
]; ];
Vec3::unit_z() * 0.5 Offsets {
lantern: Vec3::default(),
mount_bone: self.bone0,
}
} }
} }

View File

@ -16,7 +16,7 @@ pub use self::{
stunned::StunnedAnimation, tailwhip::TailwhipAnimation, stunned::StunnedAnimation, tailwhip::TailwhipAnimation,
}; };
use super::{make_bone, vek::*, FigureBoneData, Skeleton}; use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self}; use common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -48,7 +48,7 @@ impl Skeleton for QuadrupedLowSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest); let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
let tail_front = chest_mat * Mat4::<f32>::from(self.tail_front); let tail_front = chest_mat * Mat4::<f32>::from(self.tail_front);
let head_lower_mat = chest_mat * Mat4::<f32>::from(self.head_lower); 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_bl)),
make_bone(chest_mat * Mat4::<f32>::from(self.foot_br)), make_bone(chest_mat * Mat4::<f32>::from(self.foot_br)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
} }
} }

View File

@ -16,7 +16,7 @@ pub use self::{
run::RunAnimation, stunned::StunnedAnimation, run::RunAnimation, stunned::StunnedAnimation,
}; };
use super::{make_bone, vek::*, FigureBoneData, Skeleton}; use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self}; use common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -38,6 +38,7 @@ skeleton_impls!(struct QuadrupedMediumSkeleton {
+ foot_fr, + foot_fr,
+ foot_bl, + foot_bl,
+ foot_br, + foot_br,
mount,
}); });
impl Skeleton for QuadrupedMediumSkeleton { impl Skeleton for QuadrupedMediumSkeleton {
@ -53,7 +54,7 @@ impl Skeleton for QuadrupedMediumSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let torso_front_mat = base_mat * Mat4::<f32>::from(self.torso_front); 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 torso_back_mat = torso_front_mat * Mat4::<f32>::from(self.torso_back);
let neck_mat = torso_front_mat * Mat4::<f32>::from(self.neck); 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_bl_mat * Mat4::<f32>::from(self.foot_bl)),
make_bone(leg_br_mat * Mat4::<f32>::from(self.foot_br)), make_bone(leg_br_mat * Mat4::<f32>::from(self.foot_br)),
]; ];
Vec3::default() 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), (Frostfang, _) => (1.0, -2.0),
(Mouflon, _) => (0.5, 1.5), (Mouflon, _) => (0.5, 1.5),
(Catoblepas, _) => (-1.0, -6.5), (Catoblepas, _) => (-1.0, -6.5),
(Bonerattler, _) => (1.0, 2.5), (Bonerattler, _) => (0.0, 1.5),
(Deer, Male) => (1.5, 3.5), (Deer, Male) => (1.5, 3.5),
(Deer, Female) => (1.5, 3.5), (Deer, Female) => (1.5, 3.5),
(Hirdrasil, _) => (0.0, 5.0), (Hirdrasil, _) => (0.0, 5.0),
@ -187,7 +191,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
(Frostfang, _) => (0.5, 1.5), (Frostfang, _) => (0.5, 1.5),
(Mouflon, _) => (-1.0, 1.0), (Mouflon, _) => (-1.0, 1.0),
(Catoblepas, _) => (19.5, -2.0), (Catoblepas, _) => (19.5, -2.0),
(Bonerattler, _) => (9.0, -0.5), (Bonerattler, _) => (7.0, -0.5),
(Deer, _) => (-2.5, 1.0), (Deer, _) => (-2.5, 1.0),
(Hirdrasil, _) => (-1.0, 0.5), (Hirdrasil, _) => (-1.0, 0.5),
(Roshwalr, _) => (0.0, 1.0), (Roshwalr, _) => (0.0, 1.0),
@ -287,7 +291,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
(Frostfang, _) => (9.0, 11.5), (Frostfang, _) => (9.0, 11.5),
(Mouflon, _) => (11.0, 14.0), (Mouflon, _) => (11.0, 14.0),
(Catoblepas, _) => (7.5, 19.5), (Catoblepas, _) => (7.5, 19.5),
(Bonerattler, _) => (6.0, 12.5), (Bonerattler, _) => (6.0, 11.0),
(Deer, _) => (11.0, 13.5), (Deer, _) => (11.0, 13.5),
(Hirdrasil, _) => (11.0, 14.5), (Hirdrasil, _) => (11.0, 14.5),
(Roshwalr, _) => (6.0, 12.5), (Roshwalr, _) => (6.0, 12.5),
@ -387,7 +391,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
(Frostfang, _) => (5.5, -5.5, -2.0), (Frostfang, _) => (5.5, -5.5, -2.0),
(Mouflon, _) => (4.0, -5.0, -4.0), (Mouflon, _) => (4.0, -5.0, -4.0),
(Catoblepas, _) => (7.0, 2.0, -5.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), (Deer, _) => (3.5, -4.5, -3.5),
(Hirdrasil, _) => (4.5, -5.0, -2.5), (Hirdrasil, _) => (4.5, -5.0, -2.5),
(Roshwalr, _) => (8.0, -2.5, -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), (Frostfang, _) => (3.5, -4.5, -2.0),
(Mouflon, _) => (3.5, -8.0, -3.5), (Mouflon, _) => (3.5, -8.0, -3.5),
(Catoblepas, _) => (6.0, -2.5, -2.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), (Deer, _) => (3.0, -6.5, -3.5),
(Hirdrasil, _) => (4.0, -6.5, -3.0), (Hirdrasil, _) => (4.0, -6.5, -3.0),
(Roshwalr, _) => (7.0, -7.0, -2.5), (Roshwalr, _) => (7.0, -7.0, -2.5),

View File

@ -11,7 +11,7 @@ pub use self::{
run::RunAnimation, stunned::StunnedAnimation, run::RunAnimation, stunned::StunnedAnimation,
}; };
use super::{make_bone, vek::*, FigureBoneData, Skeleton}; use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self}; use common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -40,7 +40,7 @@ impl Skeleton for QuadrupedSmallSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest); let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ *(<&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.leg_br)),
make_bone(chest_mat * Mat4::<f32>::from(self.tail)), make_bone(chest_mat * Mat4::<f32>::from(self.tail)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
} }
} }

View File

@ -3,7 +3,7 @@ pub mod idle;
// Reexports // Reexports
pub use self::idle::IdleAnimation; 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 common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -29,7 +29,7 @@ impl Skeleton for ShipSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let bone0_mat = base_mat * Mat4::<f32>::from(self.bone0); let bone0_mat = base_mat * Mat4::<f32>::from(self.bone0);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [ *(<&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.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 */ make_bone(bone0_mat * Mat4::<f32>::from(self.bone3) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */
]; ];
Vec3::unit_z() * 0.5 Offsets {
lantern: Vec3::default(),
mount_bone: self.bone0,
}
} }
} }

View File

@ -11,7 +11,7 @@ pub use self::{
jump::JumpAnimation, run::RunAnimation, jump::JumpAnimation, run::RunAnimation,
}; };
use super::{make_bone, vek::*, FigureBoneData, Skeleton}; use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self}; use common::comp::{self};
use core::convert::TryFrom; use core::convert::TryFrom;
@ -47,7 +47,7 @@ impl Skeleton for TheropodSkeleton {
&self, &self,
base_mat: Mat4<f32>, base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT], buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> { ) -> Offsets {
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front); let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front);
let neck_mat = chest_front_mat * Mat4::<f32>::from(self.neck); let neck_mat = chest_front_mat * Mat4::<f32>::from(self.neck);
let head_mat = neck_mat * Mat4::<f32>::from(self.head); 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_l_mat * Mat4::<f32>::from(self.foot_l)),
make_bone(leg_r_mat * Mat4::<f32>::from(self.foot_r)), make_bone(leg_r_mat * Mat4::<f32>::from(self.foot_r)),
]; ];
Vec3::default() Offsets {
lantern: Vec3::default(),
mount_bone: self.chest_front,
}
} }
} }

View File

@ -30,11 +30,12 @@ use common::{
inventory::slot::EquipSlot, inventory::slot::EquipSlot,
item::{Hands, ItemKind, ToolKind}, item::{Hands, ItemKind, ToolKind},
Body, CharacterState, Controller, Health, Inventory, Item, Last, LightAnimation, Body, CharacterState, Controller, Health, Inventory, Item, Last, LightAnimation,
LightEmitter, Ori, PhysicsState, PoiseState, Pos, Scale, Vel, LightEmitter, Mounting, Ori, PhysicsState, PoiseState, Pos, Scale, Vel,
}, },
resources::DeltaTime, resources::DeltaTime,
states::utils::StageSection, states::utils::StageSection,
terrain::TerrainChunk, terrain::TerrainChunk,
uid::UidAllocator,
util::Dir, util::Dir,
vol::RectRasterableVol, vol::RectRasterableVol,
}; };
@ -48,7 +49,7 @@ use core::{
}; };
use guillotiere::AtlasAllocator; use guillotiere::AtlasAllocator;
use hashbrown::HashMap; use hashbrown::HashMap;
use specs::{Entity as EcsEntity, Join, LazyUpdate, WorldExt}; use specs::{saveload::MarkerAllocator, Entity as EcsEntity, Join, LazyUpdate, WorldExt};
use treeculler::{BVol, BoundingSphere}; use treeculler::{BVol, BoundingSphere};
use vek::*; use vek::*;
@ -585,6 +586,7 @@ impl FigureMgr {
inventory, inventory,
item, item,
light_emitter, light_emitter,
mountings,
), ),
) in ( ) in (
&ecs.entities(), &ecs.entities(),
@ -601,6 +603,7 @@ impl FigureMgr {
ecs.read_storage::<Inventory>().maybe(), ecs.read_storage::<Inventory>().maybe(),
ecs.read_storage::<Item>().maybe(), ecs.read_storage::<Item>().maybe(),
ecs.read_storage::<LightEmitter>().maybe(), ecs.read_storage::<LightEmitter>().maybe(),
ecs.read_storage::<Mounting>().maybe(),
) )
.join() .join()
.enumerate() .enumerate()
@ -685,7 +688,7 @@ impl FigureMgr {
// shadow correctly until their next update. For now, we treat this // shadow correctly until their next update. For now, we treat this
// as an acceptable tradeoff. // as an acceptable tradeoff.
let radius = scale.unwrap_or(&Scale(1.0)).0 * 2.0; let radius = scale.unwrap_or(&Scale(1.0)).0 * 2.0;
let (in_frustum, lpindex) = if let Some(mut meta) = state { let (in_frustum, lpindex) = if let Some(ref mut meta) = state {
let (in_frustum, lpindex) = BoundingSphere::new(pos.0.into_array(), radius) let (in_frustum, lpindex) = BoundingSphere::new(pos.0.into_array(), radius)
.coherent_test_against_frustum(frustum, meta.lpindex); .coherent_test_against_frustum(frustum, meta.lpindex);
let in_frustum = in_frustum || matches!(body, Body::Ship(_)); let in_frustum = in_frustum || matches!(body, Body::Ship(_));
@ -746,6 +749,19 @@ impl FigureMgr {
let hands = (active_tool_hand, second_tool_hand); let hands = (active_tool_hand, second_tool_hand);
// 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)))
};
let (mountee_offsets, mountee_body) = f().unwrap_or((None, None));
match body { match body {
Body::Humanoid(body) => { Body::Humanoid(body) => {
let (model, skeleton_attr) = self.model_cache.get_or_create_model( let (model, skeleton_attr) = self.model_cache.get_or_create_model(
@ -773,7 +789,14 @@ impl FigureMgr {
.character_states .character_states
.entry(entity) .entry(entity)
.or_insert_with(|| { .or_insert_with(|| {
FigureState::new(renderer, CharacterSkeleton::new(holding_lantern)) FigureState::new(
renderer,
CharacterSkeleton::new(
holding_lantern,
mountee_offsets,
mountee_body,
),
)
}); });
// Average velocity relative to the current ground // Average velocity relative to the current ground
@ -795,7 +818,7 @@ impl FigureMgr {
) { ) {
// Standing // Standing
(true, false, false) => anim::character::StandAnimation::update_skeleton( (true, false, false) => anim::character::StandAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern), &CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body),
(active_tool_kind, second_tool_kind, hands, time, rel_avg_vel), (active_tool_kind, second_tool_kind, hands, time, rel_avg_vel),
state.state_time, state.state_time,
&mut state_animation_rate, &mut state_animation_rate,
@ -803,7 +826,7 @@ impl FigureMgr {
), ),
// Running // Running
(true, true, false) => anim::character::RunAnimation::update_skeleton( (true, true, false) => anim::character::RunAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern), &CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body),
( (
active_tool_kind, active_tool_kind,
second_tool_kind, second_tool_kind,
@ -822,7 +845,7 @@ impl FigureMgr {
), ),
// In air // In air
(false, _, false) => anim::character::JumpAnimation::update_skeleton( (false, _, false) => anim::character::JumpAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern), &CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body),
( (
active_tool_kind, active_tool_kind,
second_tool_kind, second_tool_kind,
@ -839,7 +862,7 @@ impl FigureMgr {
), ),
// Swim // Swim
(_, _, true) => anim::character::SwimAnimation::update_skeleton( (_, _, true) => anim::character::SwimAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern), &CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body),
( (
active_tool_kind, active_tool_kind,
second_tool_kind, second_tool_kind,
@ -1505,6 +1528,25 @@ impl FigureMgr {
skeleton_attr, skeleton_attr,
) )
}, },
CharacterState::Mount { .. } => {
anim::character::MountAnimation::update_skeleton(
&target_base,
(
active_tool_kind,
second_tool_kind,
time,
rel_vel,
rel_avg_vel,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
mountee_offsets,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
)
},
CharacterState::GlideWield { .. } => { CharacterState::GlideWield { .. } => {
anim::character::GlideWieldAnimation::update_skeleton( anim::character::GlideWieldAnimation::update_skeleton(
&target_base, &target_base,
@ -5304,6 +5346,7 @@ pub struct FigureStateMeta {
bone_consts: Consts<FigureBoneData>, bone_consts: Consts<FigureBoneData>,
locals: Consts<FigureLocals>, locals: Consts<FigureLocals>,
lantern_offset: anim::vek::Vec3<f32>, lantern_offset: anim::vek::Vec3<f32>,
mountee_offset: anim::vek::Transform<f32, f32, f32>,
state_time: f32, state_time: f32,
last_ori: anim::vek::Quaternion<f32>, last_ori: anim::vek::Quaternion<f32>,
lpindex: u8, lpindex: u8,
@ -5343,14 +5386,14 @@ impl<S> DerefMut for FigureState<S> {
impl<S: Skeleton> FigureState<S> { impl<S: Skeleton> FigureState<S> {
pub fn new(renderer: &mut Renderer, skeleton: S) -> Self { pub fn new(renderer: &mut Renderer, skeleton: S) -> Self {
let mut buf = [Default::default(); anim::MAX_BONE_COUNT]; let mut buf = [Default::default(); anim::MAX_BONE_COUNT];
let lantern_offset = let offsets = anim::compute_matrices(&skeleton, anim::vek::Mat4::identity(), &mut buf);
anim::compute_matrices(&skeleton, anim::vek::Mat4::identity(), &mut buf);
let bone_consts = figure_bone_data_from_anim(&buf); let bone_consts = figure_bone_data_from_anim(&buf);
Self { Self {
meta: FigureStateMeta { meta: FigureStateMeta {
bone_consts: renderer.create_consts(bone_consts).unwrap(), bone_consts: renderer.create_consts(bone_consts).unwrap(),
locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(), locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(),
lantern_offset, lantern_offset: offsets.lantern,
mountee_offset: offsets.mount_bone,
state_time: 0.0, state_time: 0.0,
last_ori: Ori::default().into(), last_ori: Ori::default().into(),
lpindex: 0, lpindex: 0,
@ -5474,7 +5517,7 @@ impl<S: Skeleton> FigureState<S> {
); );
renderer.update_consts(&mut self.locals, &[locals]).unwrap(); renderer.update_consts(&mut self.locals, &[locals]).unwrap();
let lantern_offset = 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); let new_bone_consts = figure_bone_data_from_anim(buf);
@ -5484,7 +5527,8 @@ impl<S: Skeleton> FigureState<S> {
&new_bone_consts[0..S::BONE_COUNT], &new_bone_consts[0..S::BONE_COUNT],
) )
.unwrap(); .unwrap();
self.lantern_offset = lantern_offset; self.lantern_offset = offsets.lantern;
self.mountee_offset = offsets.mount_bone;
let smoothing = (5.0 * dt).min(1.0); let smoothing = (5.0 * dt).min(1.0);
if let Some(last_pos) = self.last_pos { if let Some(last_pos) = self.last_pos {