veloren_voxygen_anim/crustacean/
mod.rs

1mod alpha;
2mod combomelee;
3mod idle;
4mod jump;
5mod leapmelee;
6mod ripostemelee;
7mod run;
8mod stunned;
9mod summon;
10mod swim;
11
12// Reexports
13pub use self::{
14    alpha::AlphaAnimation, combomelee::ComboAnimation, idle::IdleAnimation, jump::JumpAnimation,
15    leapmelee::LeapMeleeAnimation, ripostemelee::RiposteMeleeAnimation, run::RunAnimation,
16    stunned::StunnedAnimation, summon::SummonAnimation, swim::SwimAnimation,
17};
18
19use common::comp::{self};
20
21use super::{FigureBoneData, Offsets, Skeleton, make_bone, vek::*};
22
23pub type Body = comp::crustacean::Body;
24
25skeleton_impls!(struct CrustaceanSkeleton {
26    + chest,
27    + tail_f,
28    + tail_b,
29    + arm_l,
30    + pincer_l0,
31    + pincer_l1,
32    + arm_r,
33    + pincer_r0,
34    + pincer_r1,
35    + leg_fl,
36    + leg_cl,
37    + leg_bl,
38    + leg_fr,
39    + leg_cr,
40    + leg_br,
41});
42
43impl Skeleton for CrustaceanSkeleton {
44    type Attr = SkeletonAttr;
45    type Body = Body;
46
47    const BONE_COUNT: usize = 15;
48    #[cfg(feature = "use-dyn-lib")]
49    const COMPUTE_FN: &'static [u8] = b"crustacean_compute_s\0";
50
51    #[cfg_attr(feature = "be-dyn-lib", export_name = "crustacean_compute_s")]
52
53    fn compute_matrices_inner(
54        &self,
55        base_mat: Mat4<f32>,
56        buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
57        body: Self::Body,
58    ) -> Offsets {
59        let base_mat = base_mat * Mat4::scaling_3d(SkeletonAttr::from(&body).scaler / 6.0);
60
61        let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
62        let tail_f_mat = chest_mat * Mat4::<f32>::from(self.tail_f);
63        let tail_b_mat = chest_mat * Mat4::<f32>::from(self.tail_b);
64        let arm_l_mat = chest_mat * Mat4::<f32>::from(self.arm_l);
65        let pincer_l0_mat = arm_l_mat * Mat4::<f32>::from(self.pincer_l0);
66        let pincer_l1_mat = pincer_l0_mat * Mat4::<f32>::from(self.pincer_l1);
67        let arm_r_mat = chest_mat * Mat4::<f32>::from(self.arm_r);
68        let pincer_r0_mat = arm_r_mat * Mat4::<f32>::from(self.pincer_r0);
69        let pincer_r1_mat = pincer_r0_mat * Mat4::<f32>::from(self.pincer_r1);
70        let leg_fl_mat = chest_mat * Mat4::<f32>::from(self.leg_fl);
71        let leg_cl_mat = chest_mat * Mat4::<f32>::from(self.leg_cl);
72        let leg_bl_mat = chest_mat * Mat4::<f32>::from(self.leg_bl);
73        let leg_fr_mat = chest_mat * Mat4::<f32>::from(self.leg_fr);
74        let leg_cr_mat = chest_mat * Mat4::<f32>::from(self.leg_cr);
75        let leg_br_mat = chest_mat * Mat4::<f32>::from(self.leg_br);
76
77        *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
78            make_bone(chest_mat),
79            make_bone(tail_f_mat),
80            make_bone(tail_b_mat),
81            make_bone(arm_l_mat),
82            make_bone(pincer_l0_mat),
83            make_bone(pincer_l1_mat),
84            make_bone(arm_r_mat),
85            make_bone(pincer_r0_mat),
86            make_bone(pincer_r1_mat),
87            make_bone(leg_fl_mat),
88            make_bone(leg_cl_mat),
89            make_bone(leg_bl_mat),
90            make_bone(leg_fr_mat),
91            make_bone(leg_cr_mat),
92            make_bone(leg_br_mat),
93        ];
94
95        // TODO: mount points
96        //use comp::arthropod::Species::*;
97        let (mount_bone_mat, mount_bone_ori) = (chest_mat, self.chest.orientation);
98        // Offset from the mounted bone's origin.
99        // Note: This could be its own bone if we need to animate it independently.
100        let mount_position = (mount_bone_mat * Vec4::from_point(mount_point(&body)))
101            .homogenized()
102            .xyz();
103        // NOTE: We apply the ori from base_mat externally so we don't need to worry
104        // about it here for now.
105        let mount_orientation = mount_bone_ori;
106
107        Offsets {
108            viewpoint: Some((chest_mat * Vec4::new(0.0, 7.0, 0.0, 1.0)).xyz()),
109            mount_bone: Transform {
110                position: mount_position,
111                orientation: mount_orientation,
112                scale: Vec3::one(),
113            },
114            ..Default::default()
115        }
116    }
117}
118
119pub struct SkeletonAttr {
120    chest: (f32, f32),
121    arm: (f32, f32, f32),
122    leg_f: (f32, f32, f32),
123    leg_c: (f32, f32, f32),
124    leg_b: (f32, f32, f32),
125    leg_ori: (f32, f32, f32),
126    move_sideways: bool,
127    scaler: f32,
128}
129
130impl<'a> From<&'a Body> for SkeletonAttr {
131    fn from(body: &'a Body) -> Self {
132        use comp::crustacean::Species::*;
133        Self {
134            chest: match (body.species, body.body_type) {
135                (Crab, _) => (0.0, 0.0),
136                (SoldierCrab, _) => (0.0, 0.0),
137                (Karkatha, _) => (0.0, 0.0),
138            },
139            arm: match (body.species, body.body_type) {
140                (Crab, _) => (0.0, 5.0, 0.0),
141                (SoldierCrab, _) => (0.0, 5.0, 0.0),
142                (Karkatha, _) => (0.0, 0.0, 0.0),
143            },
144            leg_f: match (body.species, body.body_type) {
145                (Crab, _) => (0.0, 0.0, 0.0),
146                (SoldierCrab, _) => (0.0, 0.0, 0.0),
147                (Karkatha, _) => (3.0, 0.0, 0.0),
148            },
149            leg_c: match (body.species, body.body_type) {
150                (Crab, _) => (0.0, 0.0, 0.0),
151                (SoldierCrab, _) => (0.0, 0.0, 0.0),
152                (Karkatha, _) => (0.0, 0.0, 0.0),
153            },
154            leg_b: match (body.species, body.body_type) {
155                (Crab, _) => (0.0, 0.0, 0.0),
156                (SoldierCrab, _) => (0.0, 0.0, 0.0),
157                (Karkatha, _) => (0.0, 0.0, 0.0),
158            },
159            leg_ori: match (body.species, body.body_type) {
160                (Crab, _) => (-0.4, 0.0, 0.4),
161                (SoldierCrab, _) => (-0.4, 0.0, 0.4),
162                (Karkatha, _) => (-0.4, 0.0, 0.4),
163            },
164            move_sideways: match (body.species, body.body_type) {
165                (Crab, _) => true,
166                (SoldierCrab, _) => true,
167                (Karkatha, _) => false,
168            },
169            scaler: match (body.species, body.body_type) {
170                (Crab, _) => 0.62,
171                (SoldierCrab, _) => 0.62,
172                (Karkatha, _) => 1.2,
173            },
174        }
175    }
176}
177
178fn mount_point(body: &Body) -> Vec3<f32> {
179    use comp::crustacean::Species::*;
180    match (body.species, body.body_type) {
181        (Crab, _) => (0.0, -3.5, 6.0),
182        (SoldierCrab, _) => (0.0, -2.5, 8.0),
183        (Karkatha, _) => (0.0, -1.0, 32.0),
184    }
185    .into()
186}