veloren_voxygen_anim/item_drop/
mod.rs

1pub mod idle;
2
3// Reexports
4pub use self::idle::IdleAnimation;
5
6use super::{FigureBoneData, Offsets, Skeleton, make_bone, vek::*};
7use common::comp::{self, item_drop::ItemDropArmorKind};
8use core::convert::TryFrom;
9
10pub type Body = comp::item_drop::Body;
11
12skeleton_impls!(struct ItemDropSkeleton {
13    + bone0,
14});
15
16impl Skeleton for ItemDropSkeleton {
17    type Attr = SkeletonAttr;
18    type Body = Body;
19
20    const BONE_COUNT: usize = 1;
21    #[cfg(feature = "use-dyn-lib")]
22    const COMPUTE_FN: &'static [u8] = b"item_drop_compute_mats\0";
23
24    #[cfg_attr(feature = "be-dyn-lib", export_name = "item_drop_compute_mats")]
25    fn compute_matrices_inner(
26        &self,
27        base_mat: Mat4<f32>,
28        buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
29        body: Self::Body,
30    ) -> Offsets {
31        let scale_mat = Mat4::scaling_3d(1.0 / 11.0 * Self::scale(&body));
32
33        let bone0_mat = base_mat * scale_mat * Mat4::<f32>::from(self.bone0);
34
35        *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) =
36            [make_bone(bone0_mat)];
37        Offsets {
38            lantern: Some((bone0_mat * Vec4::new(0.0, 0.0, 3.5, 1.0)).xyz()),
39            mount_bone: Transform {
40                position: comp::Body::ItemDrop(body)
41                    .mount_offset()
42                    .into_tuple()
43                    .into(),
44                ..Default::default()
45            },
46            ..Default::default()
47        }
48    }
49}
50
51impl ItemDropSkeleton {
52    pub fn scale(body: &Body) -> f32 {
53        match body {
54            Body::Tool(_) => 0.8,
55            Body::Glider => 0.45,
56            Body::Coins => 0.3,
57            Body::Armor(kind) => match kind {
58                ItemDropArmorKind::Neck | ItemDropArmorKind::Ring => 0.5,
59                ItemDropArmorKind::Back => 0.7,
60                _ => 0.8,
61            },
62            _ => 1.0,
63        }
64    }
65}
66
67pub struct SkeletonAttr {
68    bone0: (f32, f32, f32),
69}
70
71impl<'a> TryFrom<&'a comp::Body> for SkeletonAttr {
72    type Error = ();
73
74    fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
75        match body {
76            comp::Body::ItemDrop(body) => Ok(SkeletonAttr::from(body)),
77            _ => Err(()),
78        }
79    }
80}
81
82impl Default for SkeletonAttr {
83    fn default() -> Self {
84        Self {
85            bone0: (0.0, 0.0, 0.0),
86        }
87    }
88}
89
90impl<'a> From<&'a Body> for SkeletonAttr {
91    fn from(_body: &'a Body) -> Self {
92        Self {
93            bone0: (0.0, 0.0, 0.0),
94        }
95    }
96}