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