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