From 3e6fd0ee1d0d4f6f1eb6fa7eed86451946c690dc Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 27 Jun 2021 18:31:00 -0400 Subject: [PATCH] Setup animation mount points for quadruped medium, update offsets in common for new quadruped mediums, properly transform the offset in the mount system using ori, fix issue with composing in the base ori with the mounting bone ori in voxygen. --- common/src/comp/body.rs | 9 ++-- common/systems/src/mount.rs | 10 +---- voxygen/anim/src/quadruped_medium/mod.rs | 57 ++++++++++++++++++++++-- voxygen/src/scene/figure/mod.rs | 20 +++++---- 4 files changed, 71 insertions(+), 25 deletions(-) diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index 5032b622e0..182bc80e5c 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -804,11 +804,10 @@ impl Body { (quadruped_medium::Species::Dreadhorn, _) => [0.2, 0.2, 3.5], (quadruped_medium::Species::Moose, _) => [-0.6, -0.6, 2.1], (quadruped_medium::Species::Snowleopard, _) => [-0.5, -0.5, 1.4], - // TODO: Fill in these values - (quadruped_medium::Species::Mammoth, _) => [0.0, 0.0, 0.0], - (quadruped_medium::Species::Ngoubou, _) => [0.0, 0.0, 0.0], - (quadruped_medium::Species::Llama, _) => [0.0, 0.0, 0.0], - (quadruped_medium::Species::Alpaca, _) => [0.0, 0.0, 0.0], + (quadruped_medium::Species::Mammoth, _) => [0.0, 4.9, 7.2], + (quadruped_medium::Species::Ngoubou, _) => [0.0, 0.3, 2.0], + (quadruped_medium::Species::Llama, _) => [0.0, 0.1, 1.5], + (quadruped_medium::Species::Alpaca, _) => [0.0, -0.1, 1.0], } }, Body::Ship(ship) => match ship { diff --git a/common/systems/src/mount.rs b/common/systems/src/mount.rs index de92936062..04139ed167 100644 --- a/common/systems/src/mount.rs +++ b/common/systems/src/mount.rs @@ -69,14 +69,8 @@ impl<'a> System<'a> for Sys { let mounter_body = bodies.get(mounter); let mounting_offset = body.map_or(Vec3::unit_z(), Body::mountee_offset) + mounter_body.map_or(Vec3::zero(), Body::mounter_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 _ = positions + .insert(mounter, Pos(pos.0 + ori.to_quat() * mounting_offset)); let _ = orientations.insert(mounter, ori); let _ = velocities.insert(mounter, vel); } diff --git a/voxygen/anim/src/quadruped_medium/mod.rs b/voxygen/anim/src/quadruped_medium/mod.rs index 65a8bc36cd..0421678fd5 100644 --- a/voxygen/anim/src/quadruped_medium/mod.rs +++ b/voxygen/anim/src/quadruped_medium/mod.rs @@ -85,15 +85,22 @@ impl Skeleton for QuadrupedMediumSkeleton { make_bone(leg_br_mat * Mat4::::from(self.foot_br)), ]; + use comp::quadruped_medium::Species::*; + let (mount_bone_mat, mount_bone_ori) = match (body.species, body.body_type) { + (Mammoth, _) => ( + head_mat, + self.torso_front.orientation * self.neck.orientation * self.head.orientation, + ), + _ => (torso_front_mat, self.torso_front.orientation), + }; // Offset from the mounted bone's origin. - // Note: This could be its own bone if we need to animate it. - let mount_point = Vec3::new(0.0, -7.0, 3.0); - let mount_position = (torso_front_mat * Vec4::from_point(mount_point)) + // Note: This could be its own bone if we need to animate it independently. + let mount_position = (mount_bone_mat * Vec4::from_point(mount_point(&body))) .homogenized() .xyz(); // NOTE: We apply the ori from base_mat externally so we don't need to worry // about it here for now. - let mount_orientation = self.torso_front.orientation; + let mount_orientation = mount_bone_ori; Offsets { lantern: Vec3::default(), @@ -677,3 +684,45 @@ impl<'a> From<&'a Body> for SkeletonAttr { } } } + +fn mount_point(body: &Body) -> Vec3 { + use comp::quadruped_medium::{BodyType::*, Species::*}; + match (body.species, body.body_type) { + (Grolgar, _) => (0.0, -6.0, 6.0), + (Saber, _) => (0.0, -12.0, 4.0), + (Tuskram, _) => (0.0, -17.0, 2.0), + (Lion, _) => (0.0, -8.0, 4.0), + (Tarasque, _) => (0.0, -6.0, 4.0), + (Tiger, _) => (0.0, -8.0, 4.0), + (Wolf, _) => (0.0, -7.0, 3.0), + (Frostfang, _) => (0.0, -3.0, 4.0), + (Mouflon, _) => (0.0, -8.0, 2.0), + (Catoblepas, _) => (0.0, -8.0, 2.0), + (Bonerattler, _) => (0.0, -1.0, 4.0), + (Deer, _) => (0.0, -9.0, 3.0), + (Hirdrasil, _) => (0.0, -11.0, 3.0), + (Roshwalr, _) => (0.0, -1.0, 7.0), + (Donkey, _) => (0.0, -5.0, 2.0), + (Camel, _) => (0.0, -13.0, 5.0), + (Zebra, _) => (0.0, -6.0, 3.0), + (Antelope, _) => (0.0, -8.0, 3.0), + (Kelpie, _) => (0.0, -6.0, 3.0), + (Horse, _) => (0.0, -8.0, 3.0), + (Barghest, _) => (0.0, -8.0, 5.0), + (Cattle, Male) => (0.0, -3.0, 8.0), + (Cattle, Female) => (0.0, -2.0, 6.0), + (Darkhound, _) => (0.0, -2.0, 3.0), + (Highland, _) => (0.0, -3.0, 8.0), + (Yak, _) => (0.0, -8.0, 9.0), + (Panda, _) => (0.0, -10.0, 5.0), + (Bear, _) => (0.0, -11.0, 6.0), + (Dreadhorn, _) => (0.0, 0.0, 10.0), + (Moose, _) => (0.0, -9.0, 6.0), + (Snowleopard, _) => (0.0, -9.0, 4.0), + (Mammoth, _) => (0.0, 5.0, 8.0), + (Ngoubou, _) => (0.0, -7.0, 6.0), + (Llama, _) => (0.0, -6.0, 5.0), + (Alpaca, _) => (0.0, -9.0, 3.0), + } + .into() +} diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 22c469c68e..593a74e29d 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -5408,11 +5408,7 @@ impl FigureState { self.state_time += dt * state_animation_rate; let mat = { - let ori_scale = anim::vek::Mat4::from(*ori) - * anim::vek::Mat4::scaling_3d(anim::vek::Vec3::from(*scale)); - // NOTE: It is kind of a hack to use this entity's ori here if it is - // mounted on another but this happens to match the ori of the - // mountee so it works, change this if it causes jankiness in the future. + let scale_mat = anim::vek::Mat4::scaling_3d(anim::vek::Vec3::from(*scale)); if let Some((transform, _)) = *mount_transform_pos { // Note: if we had a way to compute a "default" transform of the bones then in // the animations we could make use of the mountee_offset from common by @@ -5423,13 +5419,21 @@ impl FigureState { // animations and keep it in sync. // // Component of mounting offset specific to the mounter. - let mounter_offset = anim::vek::Mat4::translation_3d( + let mounter_offset = anim::vek::Mat4::::translation_3d( body.map_or_else(Vec3::zero, |b| b.mounter_offset()), ); - anim::vek::Mat4::from(transform) * ori_scale * mounter_offset + // NOTE: It is kind of a hack to use this entity's ori here if it is + // mounted on another but this happens to match the ori of the + // mountee so it works, change this if it causes jankiness in the future. + let transform = anim::vek::Transform { + orientation: *ori * transform.orientation, + ..transform + }; + anim::vek::Mat4::from(transform) * mounter_offset * scale_mat } else { - ori_scale + let ori_mat = anim::vek::Mat4::from(*ori); + ori_mat * scale_mat } };