veloren_voxygen_anim/bird_large/
mod.rs

1pub mod alpha;
2pub mod aura;
3pub mod breathe;
4pub mod combomelee;
5pub mod dash;
6pub mod feed;
7pub mod fly;
8pub mod idle;
9pub mod run;
10pub mod selfbuff;
11pub mod shockwave;
12pub mod shoot;
13pub mod stunned;
14pub mod summon;
15pub mod swim;
16
17// Reexports
18pub use self::{
19    alpha::AlphaAnimation, aura::AuraAnimation, breathe::BreatheAnimation,
20    combomelee::ComboAnimation, dash::DashAnimation, feed::FeedAnimation, fly::FlyAnimation,
21    idle::IdleAnimation, run::RunAnimation, selfbuff::SelfBuffAnimation,
22    shockwave::ShockwaveAnimation, shoot::ShootAnimation, stunned::StunnedAnimation,
23    summon::SummonAnimation, swim::SwimAnimation,
24};
25
26use super::{FigureBoneData, Skeleton, vek::*};
27use common::comp::{self};
28use core::convert::TryFrom;
29
30pub type Body = comp::bird_large::Body;
31
32skeleton_impls!(struct BirdLargeSkeleton ComputedBirdLargeSkeleton {
33    + head
34    + beak
35    + neck
36    + chest
37    + tail_front
38    + tail_rear
39    + wing_in_l
40    + wing_in_r
41    + wing_mid_l
42    + wing_mid_r
43    + wing_out_l
44    + wing_out_r
45    + leg_l
46    + leg_r
47    + foot_l
48    + foot_r
49});
50
51impl Skeleton for BirdLargeSkeleton {
52    type Attr = SkeletonAttr;
53    type Body = Body;
54    type ComputedSkeleton = ComputedBirdLargeSkeleton;
55
56    const BONE_COUNT: usize = ComputedBirdLargeSkeleton::BONE_COUNT;
57    #[cfg(feature = "use-dyn-lib")]
58    const COMPUTE_FN: &'static [u8] = b"bird_large_compute_mats\0";
59
60    #[cfg_attr(
61        feature = "be-dyn-lib",
62        unsafe(export_name = "bird_large_compute_mats")
63    )]
64
65    fn compute_matrices_inner(
66        &self,
67        base_mat: Mat4<f32>,
68        buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
69        body: Self::Body,
70    ) -> Self::ComputedSkeleton {
71        let base_mat = base_mat * Mat4::scaling_3d(SkeletonAttr::from(&body).scaler / 8.0);
72
73        let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
74        let neck_mat = chest_mat * Mat4::<f32>::from(self.neck);
75        let head_mat = neck_mat * Mat4::<f32>::from(self.head);
76        let beak_mat = head_mat * Mat4::<f32>::from(self.beak);
77        let tail_front_mat = chest_mat * Mat4::<f32>::from(self.tail_front);
78        let tail_rear_mat = tail_front_mat * Mat4::<f32>::from(self.tail_rear);
79        let wing_in_l_mat = chest_mat * Mat4::<f32>::from(self.wing_in_l);
80        let wing_in_r_mat = chest_mat * Mat4::<f32>::from(self.wing_in_r);
81        let wing_mid_l_mat = wing_in_l_mat * Mat4::<f32>::from(self.wing_mid_l);
82        let wing_mid_r_mat = wing_in_r_mat * Mat4::<f32>::from(self.wing_mid_r);
83        let wing_out_l_mat = wing_mid_l_mat * Mat4::<f32>::from(self.wing_out_l);
84        let wing_out_r_mat = wing_mid_r_mat * Mat4::<f32>::from(self.wing_out_r);
85        let leg_l_mat = base_mat * Mat4::<f32>::from(self.leg_l);
86        let leg_r_mat = base_mat * Mat4::<f32>::from(self.leg_r);
87        let foot_l_mat = leg_l_mat * Mat4::<f32>::from(self.foot_l);
88        let foot_r_mat = leg_r_mat * Mat4::<f32>::from(self.foot_r);
89
90        let computed_skeleton = ComputedBirdLargeSkeleton {
91            head: head_mat,
92            beak: beak_mat,
93            neck: neck_mat,
94            chest: chest_mat,
95            tail_front: tail_front_mat,
96            tail_rear: tail_rear_mat,
97            wing_in_l: wing_in_l_mat,
98            wing_in_r: wing_in_r_mat,
99            wing_mid_l: wing_mid_l_mat,
100            wing_mid_r: wing_mid_r_mat,
101            wing_out_l: wing_out_l_mat,
102            wing_out_r: wing_out_r_mat,
103            leg_l: leg_l_mat,
104            leg_r: leg_r_mat,
105            foot_l: foot_l_mat,
106            foot_r: foot_r_mat,
107        };
108
109        computed_skeleton.set_figure_bone_data(buf);
110        computed_skeleton
111    }
112}
113
114pub struct SkeletonAttr {
115    chest: (f32, f32),
116    neck: (f32, f32),
117    head: (f32, f32),
118    beak: (f32, f32),
119    tail_front: (f32, f32),
120    tail_rear: (f32, f32),
121    wing_in: (f32, f32, f32),
122    wing_mid: (f32, f32, f32),
123    wing_out: (f32, f32, f32),
124    leg: (f32, f32, f32),
125    foot: (f32, f32, f32),
126    scaler: f32,
127    feed: f32,
128    wyvern: bool,
129}
130
131impl<'a> TryFrom<&'a comp::Body> for SkeletonAttr {
132    type Error = ();
133
134    fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
135        match body {
136            comp::Body::BirdLarge(body) => Ok(SkeletonAttr::from(body)),
137            _ => Err(()),
138        }
139    }
140}
141
142impl Default for SkeletonAttr {
143    fn default() -> Self {
144        Self {
145            chest: (0.0, 0.0),
146            neck: (0.0, 0.0),
147            head: (0.0, 0.0),
148            beak: (0.0, 0.0),
149            tail_front: (0.0, 0.0),
150            tail_rear: (0.0, 0.0),
151            wing_in: (0.0, 0.0, 0.0),
152            wing_mid: (0.0, 0.0, 0.0),
153            wing_out: (0.0, 0.0, 0.0),
154            leg: (0.0, 0.0, 0.0),
155            foot: (0.0, 0.0, 0.0),
156            scaler: 0.0,
157            feed: 0.0,
158            wyvern: false,
159        }
160    }
161}
162
163impl<'a> From<&'a Body> for SkeletonAttr {
164    fn from(body: &'a Body) -> Self {
165        use comp::bird_large::Species::*;
166        Self {
167            chest: match (body.species, body.body_type) {
168                (Phoenix, _) => (2.5, 16.0),
169                (Cockatrice, _) => (2.5, 16.0),
170                (Roc, _) => (2.5, 27.5),
171                (FlameWyvern, _) => (2.5, 20.5),
172                (CloudWyvern, _) => (2.5, 20.5),
173                (FrostWyvern, _) => (2.5, 20.5),
174                (SeaWyvern, _) => (2.5, 20.5),
175                (WealdWyvern, _) => (2.5, 20.5),
176            },
177            neck: match (body.species, body.body_type) {
178                (Phoenix, _) => (2.5, -5.5),
179                (Cockatrice, _) => (5.0, -1.5),
180                (Roc, _) => (9.5, -1.5),
181                (FlameWyvern, _) => (11.0, -0.5),
182                (CloudWyvern, _) => (11.0, -0.5),
183                (FrostWyvern, _) => (11.0, -0.5),
184                (SeaWyvern, _) => (11.0, -0.5),
185                (WealdWyvern, _) => (11.0, -0.5),
186            },
187            head: match (body.species, body.body_type) {
188                (Phoenix, _) => (6.0, 12.0),
189                (Cockatrice, _) => (8.0, 4.5),
190                (Roc, _) => (17.0, -3.5),
191                (FlameWyvern, _) => (10.0, -1.5),
192                (CloudWyvern, _) => (10.0, -1.5),
193                (FrostWyvern, _) => (10.0, -1.5),
194                (SeaWyvern, _) => (10.0, 2.5),
195                (WealdWyvern, _) => (10.0, -1.5),
196            },
197            beak: match (body.species, body.body_type) {
198                (Phoenix, _) => (5.0, 3.0),
199                (Cockatrice, _) => (2.0, -3.0),
200                (Roc, _) => (0.0, -3.0),
201                (FlameWyvern, _) => (-3.0, 2.0),
202                (CloudWyvern, _) => (-3.0, 2.0),
203                (FrostWyvern, _) => (-3.0, 2.0),
204                (SeaWyvern, _) => (-3.0, 2.0),
205                (WealdWyvern, _) => (-3.0, 2.0),
206            },
207            tail_front: match (body.species, body.body_type) {
208                (Phoenix, _) => (-9.5, -1.0),
209                (Cockatrice, _) => (-5.0, -2.5),
210                (Roc, _) => (-7.5, -3.5),
211                (FlameWyvern, _) => (-10.0, -5.0),
212                (CloudWyvern, _) => (-10.0, -5.0),
213                (FrostWyvern, _) => (-10.0, -5.0),
214                (SeaWyvern, _) => (-10.0, -5.0),
215                (WealdWyvern, _) => (-10.0, -5.0),
216            },
217            tail_rear: match (body.species, body.body_type) {
218                (Phoenix, _) => (-11.0, 0.0),
219                (Cockatrice, _) => (-8.0, -3.0),
220                (Roc, _) => (-8.0, -3.0),
221                (FlameWyvern, _) => (-11.0, -1.0),
222                (CloudWyvern, _) => (-11.0, -1.0),
223                (FrostWyvern, _) => (-11.0, -1.0),
224                (SeaWyvern, _) => (-11.0, -1.0),
225                (WealdWyvern, _) => (-11.0, -1.0),
226            },
227            wing_in: match (body.species, body.body_type) {
228                (Phoenix, _) => (3.0, 2.5, 2.0),
229                (Cockatrice, _) => (3.5, 7.0, 3.5),
230                (Roc, _) => (5.5, 7.5, -1.0),
231                (FlameWyvern, _) => (6.5, 11.5, -2.0),
232                (CloudWyvern, _) => (3.5, 11.5, -1.5),
233                (FrostWyvern, _) => (5.0, 10.5, -1.5),
234                (SeaWyvern, _) => (4.0, 11.5, -0.0),
235                (WealdWyvern, _) => (5.0, 11.5, -1.0),
236            },
237            wing_mid: match (body.species, body.body_type) {
238                (Phoenix, _) => (10.0, 1.0, 0.0),
239                (Cockatrice, _) => (6.0, 0.0, 0.0),
240                (Roc, _) => (12.0, 1.0, -0.5),
241                (FlameWyvern, _) => (19.0, 11.5, 1.0),
242                (CloudWyvern, _) => (19.0, 10.5, 1.0),
243                (FrostWyvern, _) => (18.5, 11.5, 0.5),
244                (SeaWyvern, _) => (19.0, 11.5, 0.5),
245                (WealdWyvern, _) => (19.0, 11.5, 0.0),
246            },
247            wing_out: match (body.species, body.body_type) {
248                (Phoenix, _) => (7.0, 2.0, 1.5),
249                (Cockatrice, _) => (4.0, -1.0, 1.0),
250                (Roc, _) => (10.0, -2.0, 0.0),
251                (FlameWyvern, _) => (11.0, -1.0, 0.0),
252                (CloudWyvern, _) => (11.0, -2.0, 0.0),
253                (FrostWyvern, _) => (10.0, -1.5, 0.5),
254                (SeaWyvern, _) => (12.0, -1.0, 0.0),
255                (WealdWyvern, _) => (16.0, -4.0, -1.0),
256            },
257            leg: match (body.species, body.body_type) {
258                (Phoenix, _) => (4.0, 1.5, 12.0),
259                (Cockatrice, _) => (3.5, 2.5, 13.0),
260                (Roc, _) => (5.5, -1.5, 17.5),
261                (FlameWyvern, _) => (5.5, 2.0, 15.5),
262                (CloudWyvern, _) => (5.5, 2.0, 15.5),
263                (FrostWyvern, _) => (5.5, 2.0, 15.5),
264                (SeaWyvern, _) => (5.5, 2.0, 15.5),
265                (WealdWyvern, _) => (5.5, 2.0, 15.5),
266            },
267            foot: match (body.species, body.body_type) {
268                (Phoenix, _) => (0.5, -0.5, -2.5),
269                (Cockatrice, _) => (0.5, -3.0, -3.0),
270                (Roc, _) => (2.5, -2.5, -5.5),
271                (FlameWyvern, _) => (0.5, 0.0, -3.5),
272                (CloudWyvern, _) => (0.5, 0.0, -3.5),
273                (FrostWyvern, _) => (0.5, 0.0, -3.5),
274                (SeaWyvern, _) => (0.5, 0.0, -3.5),
275                (WealdWyvern, _) => (0.5, 0.0, -3.5),
276            },
277            scaler: match (body.species, body.body_type) {
278                (Phoenix, _) => 1.0,
279                (Cockatrice, _) => 1.0,
280                (Roc, _) => 1.0,
281                (FlameWyvern, _)
282                | (CloudWyvern, _)
283                | (FrostWyvern, _)
284                | (SeaWyvern, _)
285                | (WealdWyvern, _) => 1.0,
286            },
287            feed: match (body.species, body.body_type) {
288                (Phoenix, _) => -0.65,
289                (Cockatrice, _) => -0.5,
290                (Roc, _) => -0.4,
291                (FlameWyvern, _)
292                | (CloudWyvern, _)
293                | (FrostWyvern, _)
294                | (SeaWyvern, _)
295                | (WealdWyvern, _) => -0.65,
296            },
297            wyvern: matches!(
298                (body.species, body.body_type),
299                (FlameWyvern, _)
300                    | (CloudWyvern, _)
301                    | (FrostWyvern, _)
302                    | (SeaWyvern, _)
303                    | (WealdWyvern, _)
304            ),
305        }
306    }
307}
308
309pub fn mount_mat(
310    body: &Body,
311    computed_skeleton: &ComputedBirdLargeSkeleton,
312    skeleton: &BirdLargeSkeleton,
313) -> (Mat4<f32>, Quaternion<f32>) {
314    use comp::bird_large::Species::*;
315
316    match (body.species, body.body_type) {
317        (SeaWyvern | FlameWyvern | Phoenix | Cockatrice, _) => {
318            (computed_skeleton.chest, skeleton.chest.orientation)
319        },
320        _ => (
321            computed_skeleton.neck,
322            skeleton.chest.orientation * skeleton.neck.orientation,
323        ),
324    }
325}
326
327pub fn mount_transform(
328    body: &Body,
329    computed_skeleton: &ComputedBirdLargeSkeleton,
330    skeleton: &BirdLargeSkeleton,
331) -> Transform<f32, f32, f32> {
332    use comp::bird_large::Species::*;
333
334    let mount_point = match (body.species, body.body_type) {
335        (Phoenix, _) => (0.0, 0.5, 7.5),
336        (Cockatrice, _) => (0.0, 5.0, 6.5),
337        (Roc, _) => (0.0, 5.5, 6.5),
338        (FlameWyvern, _) => (0.0, 9.5, 7.0),
339        (CloudWyvern, _) => (0.0, -0.5, 6.5),
340        (FrostWyvern, _) => (0.0, 0.5, 6.0),
341        (SeaWyvern, _) => (0.0, 8.0, 7.0),
342        (WealdWyvern, _) => (0.0, 0.0, 9.0),
343    }
344    .into();
345
346    let (mount_mat, orientation) = mount_mat(body, computed_skeleton, skeleton);
347    Transform {
348        position: mount_mat.mul_point(mount_point),
349        orientation,
350        scale: Vec3::one(),
351    }
352}