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, Offsets, Skeleton, make_bone, vek::*};
27use common::comp::{self};
28use core::convert::TryFrom;
29
30pub type Body = comp::bird_large::Body;
31
32skeleton_impls!(struct BirdLargeSkeleton {
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
55    const BONE_COUNT: usize = 16;
56    #[cfg(feature = "use-dyn-lib")]
57    const COMPUTE_FN: &'static [u8] = b"bird_large_compute_mats\0";
58
59    #[cfg_attr(
60        feature = "be-dyn-lib",
61        unsafe(export_name = "bird_large_compute_mats")
62    )]
63
64    fn compute_matrices_inner(
65        &self,
66        base_mat: Mat4<f32>,
67        buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
68        body: Self::Body,
69    ) -> Offsets {
70        let base_mat = base_mat * Mat4::scaling_3d(SkeletonAttr::from(&body).scaler / 8.0);
71
72        let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
73        let neck_mat = chest_mat * Mat4::<f32>::from(self.neck);
74        let head_mat = neck_mat * Mat4::<f32>::from(self.head);
75        let beak_mat = head_mat * Mat4::<f32>::from(self.beak);
76        let tail_front_mat = chest_mat * Mat4::<f32>::from(self.tail_front);
77        let tail_rear_mat = tail_front_mat * Mat4::<f32>::from(self.tail_rear);
78        let wing_in_l_mat = chest_mat * Mat4::<f32>::from(self.wing_in_l);
79        let wing_in_r_mat = chest_mat * Mat4::<f32>::from(self.wing_in_r);
80        let wing_mid_l_mat = wing_in_l_mat * Mat4::<f32>::from(self.wing_mid_l);
81        let wing_mid_r_mat = wing_in_r_mat * Mat4::<f32>::from(self.wing_mid_r);
82        let wing_out_l_mat = wing_mid_l_mat * Mat4::<f32>::from(self.wing_out_l);
83        let wing_out_r_mat = wing_mid_r_mat * Mat4::<f32>::from(self.wing_out_r);
84        let leg_l_mat = base_mat * Mat4::<f32>::from(self.leg_l);
85        let leg_r_mat = base_mat * Mat4::<f32>::from(self.leg_r);
86        let foot_l_mat = leg_l_mat * Mat4::<f32>::from(self.foot_l);
87        let foot_r_mat = leg_r_mat * Mat4::<f32>::from(self.foot_r);
88
89        *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
90            make_bone(head_mat),
91            make_bone(beak_mat),
92            make_bone(neck_mat),
93            make_bone(chest_mat),
94            make_bone(tail_front_mat),
95            make_bone(tail_rear_mat),
96            make_bone(wing_in_l_mat),
97            make_bone(wing_in_r_mat),
98            make_bone(wing_mid_l_mat),
99            make_bone(wing_mid_r_mat),
100            make_bone(wing_out_l_mat),
101            make_bone(wing_out_r_mat),
102            make_bone(leg_l_mat),
103            make_bone(leg_r_mat),
104            make_bone(foot_l_mat),
105            make_bone(foot_r_mat),
106        ];
107
108        use comp::bird_large::Species::*;
109        // NOTE: We apply the ori from base_mat externally so we don't need to worry
110        // about it here for now.
111        let (mount_mat, mount_orientation) = match (body.species, body.body_type) {
112            (SeaWyvern | FlameWyvern | Phoenix | Cockatrice, _) => {
113                (chest_mat, self.chest.orientation)
114            },
115            _ => (neck_mat, self.chest.orientation * self.neck.orientation),
116        };
117
118        // Offset from the mounted bone's origin.
119        let mount_position = (mount_mat * Vec4::from_point(mount_point(&body)))
120            .homogenized()
121            .xyz();
122
123        Offsets {
124            viewpoint: Some((head_mat * Vec4::new(0.0, 3.0, 6.0, 1.0)).xyz()),
125            mount_bone: Transform {
126                position: mount_position,
127                orientation: mount_orientation,
128                scale: Vec3::one(),
129            },
130            ..Default::default()
131        }
132    }
133}
134
135pub struct SkeletonAttr {
136    chest: (f32, f32),
137    neck: (f32, f32),
138    head: (f32, f32),
139    beak: (f32, f32),
140    tail_front: (f32, f32),
141    tail_rear: (f32, f32),
142    wing_in: (f32, f32, f32),
143    wing_mid: (f32, f32, f32),
144    wing_out: (f32, f32, f32),
145    leg: (f32, f32, f32),
146    foot: (f32, f32, f32),
147    scaler: f32,
148    feed: f32,
149    wyvern: bool,
150}
151
152impl<'a> TryFrom<&'a comp::Body> for SkeletonAttr {
153    type Error = ();
154
155    fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
156        match body {
157            comp::Body::BirdLarge(body) => Ok(SkeletonAttr::from(body)),
158            _ => Err(()),
159        }
160    }
161}
162
163impl Default for SkeletonAttr {
164    fn default() -> Self {
165        Self {
166            chest: (0.0, 0.0),
167            neck: (0.0, 0.0),
168            head: (0.0, 0.0),
169            beak: (0.0, 0.0),
170            tail_front: (0.0, 0.0),
171            tail_rear: (0.0, 0.0),
172            wing_in: (0.0, 0.0, 0.0),
173            wing_mid: (0.0, 0.0, 0.0),
174            wing_out: (0.0, 0.0, 0.0),
175            leg: (0.0, 0.0, 0.0),
176            foot: (0.0, 0.0, 0.0),
177            scaler: 0.0,
178            feed: 0.0,
179            wyvern: false,
180        }
181    }
182}
183
184impl<'a> From<&'a Body> for SkeletonAttr {
185    fn from(body: &'a Body) -> Self {
186        use comp::bird_large::Species::*;
187        Self {
188            chest: match (body.species, body.body_type) {
189                (Phoenix, _) => (2.5, 16.0),
190                (Cockatrice, _) => (2.5, 16.0),
191                (Roc, _) => (2.5, 27.5),
192                (FlameWyvern, _) => (2.5, 20.5),
193                (CloudWyvern, _) => (2.5, 20.5),
194                (FrostWyvern, _) => (2.5, 20.5),
195                (SeaWyvern, _) => (2.5, 20.5),
196                (WealdWyvern, _) => (2.5, 20.5),
197            },
198            neck: match (body.species, body.body_type) {
199                (Phoenix, _) => (2.5, -5.5),
200                (Cockatrice, _) => (5.0, -1.5),
201                (Roc, _) => (9.5, -1.5),
202                (FlameWyvern, _) => (11.0, -0.5),
203                (CloudWyvern, _) => (11.0, -0.5),
204                (FrostWyvern, _) => (11.0, -0.5),
205                (SeaWyvern, _) => (11.0, -0.5),
206                (WealdWyvern, _) => (11.0, -0.5),
207            },
208            head: match (body.species, body.body_type) {
209                (Phoenix, _) => (6.0, 12.0),
210                (Cockatrice, _) => (8.0, 4.5),
211                (Roc, _) => (17.0, -3.5),
212                (FlameWyvern, _) => (10.0, -1.5),
213                (CloudWyvern, _) => (10.0, -1.5),
214                (FrostWyvern, _) => (10.0, -1.5),
215                (SeaWyvern, _) => (10.0, 2.5),
216                (WealdWyvern, _) => (10.0, -1.5),
217            },
218            beak: match (body.species, body.body_type) {
219                (Phoenix, _) => (5.0, 3.0),
220                (Cockatrice, _) => (2.0, -3.0),
221                (Roc, _) => (0.0, -3.0),
222                (FlameWyvern, _) => (-3.0, 2.0),
223                (CloudWyvern, _) => (-3.0, 2.0),
224                (FrostWyvern, _) => (-3.0, 2.0),
225                (SeaWyvern, _) => (-3.0, 2.0),
226                (WealdWyvern, _) => (-3.0, 2.0),
227            },
228            tail_front: match (body.species, body.body_type) {
229                (Phoenix, _) => (-9.5, -1.0),
230                (Cockatrice, _) => (-5.0, -2.5),
231                (Roc, _) => (-7.5, -3.5),
232                (FlameWyvern, _) => (-10.0, -5.0),
233                (CloudWyvern, _) => (-10.0, -5.0),
234                (FrostWyvern, _) => (-10.0, -5.0),
235                (SeaWyvern, _) => (-10.0, -5.0),
236                (WealdWyvern, _) => (-10.0, -5.0),
237            },
238            tail_rear: match (body.species, body.body_type) {
239                (Phoenix, _) => (-11.0, 0.0),
240                (Cockatrice, _) => (-8.0, -3.0),
241                (Roc, _) => (-8.0, -3.0),
242                (FlameWyvern, _) => (-11.0, -1.0),
243                (CloudWyvern, _) => (-11.0, -1.0),
244                (FrostWyvern, _) => (-11.0, -1.0),
245                (SeaWyvern, _) => (-11.0, -1.0),
246                (WealdWyvern, _) => (-11.0, -1.0),
247            },
248            wing_in: match (body.species, body.body_type) {
249                (Phoenix, _) => (3.0, 2.5, 2.0),
250                (Cockatrice, _) => (3.5, 7.0, 3.5),
251                (Roc, _) => (5.5, 7.5, -1.0),
252                (FlameWyvern, _) => (6.5, 11.5, -2.0),
253                (CloudWyvern, _) => (3.5, 11.5, -1.5),
254                (FrostWyvern, _) => (5.0, 10.5, -1.5),
255                (SeaWyvern, _) => (4.0, 11.5, -0.0),
256                (WealdWyvern, _) => (5.0, 11.5, -1.0),
257            },
258            wing_mid: match (body.species, body.body_type) {
259                (Phoenix, _) => (10.0, 1.0, 0.0),
260                (Cockatrice, _) => (6.0, 0.0, 0.0),
261                (Roc, _) => (12.0, 1.0, -0.5),
262                (FlameWyvern, _) => (19.0, 11.5, 1.0),
263                (CloudWyvern, _) => (19.0, 10.5, 1.0),
264                (FrostWyvern, _) => (18.5, 11.5, 0.5),
265                (SeaWyvern, _) => (19.0, 11.5, 0.5),
266                (WealdWyvern, _) => (19.0, 11.5, 0.0),
267            },
268            wing_out: match (body.species, body.body_type) {
269                (Phoenix, _) => (7.0, 2.0, 1.5),
270                (Cockatrice, _) => (4.0, -1.0, 1.0),
271                (Roc, _) => (10.0, -2.0, 0.0),
272                (FlameWyvern, _) => (11.0, -1.0, 0.0),
273                (CloudWyvern, _) => (11.0, -2.0, 0.0),
274                (FrostWyvern, _) => (10.0, -1.5, 0.5),
275                (SeaWyvern, _) => (12.0, -1.0, 0.0),
276                (WealdWyvern, _) => (16.0, -4.0, -1.0),
277            },
278            leg: match (body.species, body.body_type) {
279                (Phoenix, _) => (4.0, 1.5, 12.0),
280                (Cockatrice, _) => (3.5, 2.5, 13.0),
281                (Roc, _) => (5.5, -1.5, 17.5),
282                (FlameWyvern, _) => (5.5, 2.0, 15.5),
283                (CloudWyvern, _) => (5.5, 2.0, 15.5),
284                (FrostWyvern, _) => (5.5, 2.0, 15.5),
285                (SeaWyvern, _) => (5.5, 2.0, 15.5),
286                (WealdWyvern, _) => (5.5, 2.0, 15.5),
287            },
288            foot: match (body.species, body.body_type) {
289                (Phoenix, _) => (0.5, -0.5, -2.5),
290                (Cockatrice, _) => (0.5, -3.0, -3.0),
291                (Roc, _) => (2.5, -2.5, -5.5),
292                (FlameWyvern, _) => (0.5, 0.0, -3.5),
293                (CloudWyvern, _) => (0.5, 0.0, -3.5),
294                (FrostWyvern, _) => (0.5, 0.0, -3.5),
295                (SeaWyvern, _) => (0.5, 0.0, -3.5),
296                (WealdWyvern, _) => (0.5, 0.0, -3.5),
297            },
298            scaler: match (body.species, body.body_type) {
299                (Phoenix, _) => 1.0,
300                (Cockatrice, _) => 1.0,
301                (Roc, _) => 1.0,
302                (FlameWyvern, _)
303                | (CloudWyvern, _)
304                | (FrostWyvern, _)
305                | (SeaWyvern, _)
306                | (WealdWyvern, _) => 1.0,
307            },
308            feed: match (body.species, body.body_type) {
309                (Phoenix, _) => -0.65,
310                (Cockatrice, _) => -0.5,
311                (Roc, _) => -0.4,
312                (FlameWyvern, _)
313                | (CloudWyvern, _)
314                | (FrostWyvern, _)
315                | (SeaWyvern, _)
316                | (WealdWyvern, _) => -0.65,
317            },
318            wyvern: matches!(
319                (body.species, body.body_type),
320                (FlameWyvern, _)
321                    | (CloudWyvern, _)
322                    | (FrostWyvern, _)
323                    | (SeaWyvern, _)
324                    | (WealdWyvern, _)
325            ),
326        }
327    }
328}
329
330fn mount_point(body: &Body) -> Vec3<f32> {
331    use comp::bird_large::Species::*;
332    match (body.species, body.body_type) {
333        (Phoenix, _) => (0.0, 0.5, 7.5),
334        (Cockatrice, _) => (0.0, 5.0, 6.5),
335        (Roc, _) => (0.0, 5.5, 6.5),
336        (FlameWyvern, _) => (0.0, 9.5, 7.0),
337        (CloudWyvern, _) => (0.0, -0.5, 6.5),
338        (FrostWyvern, _) => (0.0, 0.5, 6.0),
339        (SeaWyvern, _) => (0.0, 8.0, 7.0),
340        (WealdWyvern, _) => (0.0, 0.0, 9.0),
341    }
342    .into()
343}