veloren_voxygen_anim/object/
mod.rs

1pub mod beam;
2pub mod idle;
3pub mod shoot;
4
5// Reexports
6pub use self::{beam::BeamAnimation, idle::IdleAnimation, shoot::ShootAnimation};
7
8use super::{FigureBoneData, Offsets, Skeleton, make_bone, vek::*};
9use common::comp::{self};
10use core::convert::TryFrom;
11
12pub type Body = comp::object::Body;
13
14skeleton_impls!(struct ObjectSkeleton {
15    + bone0,
16    + bone1,
17});
18
19impl Skeleton for ObjectSkeleton {
20    type Attr = SkeletonAttr;
21    type Body = Body;
22
23    const BONE_COUNT: usize = 2;
24    #[cfg(feature = "use-dyn-lib")]
25    const COMPUTE_FN: &'static [u8] = b"object_compute_mats\0";
26
27    #[cfg_attr(feature = "be-dyn-lib", export_name = "object_compute_mats")]
28    fn compute_matrices_inner(
29        &self,
30        base_mat: Mat4<f32>,
31        buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
32        body: Self::Body,
33    ) -> Offsets {
34        let scale_mat = Mat4::scaling_3d(1.0 / 11.0);
35
36        let bone0_mat = base_mat * scale_mat * Mat4::<f32>::from(self.bone0);
37
38        *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
39            make_bone(bone0_mat),
40            make_bone(scale_mat * Mat4::<f32>::from(self.bone1)), /* Decorellated from ori */
41        ];
42        Offsets {
43            // TODO: see quadruped_medium for how to animate this
44            mount_bone: Transform {
45                position: comp::Body::Object(body).mount_offset().into_tuple().into(),
46                ..Default::default()
47            },
48            ..Default::default()
49        }
50    }
51}
52
53pub struct SkeletonAttr {
54    bone0: (f32, f32, f32),
55    bone1: (f32, f32, f32),
56}
57
58impl<'a> TryFrom<&'a comp::Body> for SkeletonAttr {
59    type Error = ();
60
61    fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
62        match body {
63            comp::Body::Object(body) => Ok(SkeletonAttr::from(body)),
64            _ => Err(()),
65        }
66    }
67}
68
69impl Default for SkeletonAttr {
70    fn default() -> Self {
71        Self {
72            bone0: (0.0, 0.0, 0.0),
73            bone1: (0.0, 0.0, 0.0),
74        }
75    }
76}
77
78impl<'a> From<&'a Body> for SkeletonAttr {
79    fn from(body: &'a Body) -> Self {
80        use comp::object::Body::*;
81        Self {
82            bone0: match body {
83                Crossbow => (0.0, 0.0, 11.0),
84                Flamethrower => (0.0, 0.0, 11.0),
85                HaniwaSentry => (0.0, 0.0, 10.5),
86                _ => (0.0, 0.0, 0.0),
87            },
88            bone1: match body {
89                Crossbow => (0.0, 0.0, 8.0),
90                Flamethrower => (0.0, 0.0, 8.0),
91                HaniwaSentry => (0.0, 0.0, 3.0),
92                _ => (0.0, 0.0, 0.0),
93            },
94        }
95    }
96}